Add worstfear/desires

This commit is contained in:
sladecraven 2022-02-10 21:58:19 +01:00
parent d17afaf142
commit ef8e737d1c
11 changed files with 311 additions and 105 deletions

View File

@ -105,6 +105,17 @@ export class PegasusActorSheet extends ActorSheet {
PegasusUtility.confirmDelete(this, li);
});
html.find('.spec-group-activate').click(ev => {
const li = $(ev.currentTarget).parents(".item");
let itemId = li.data("item-id");
this.actor.specPowerActivate( itemId)
});
html.find('.spec-group-deactivate').click(ev => {
const li = $(ev.currentTarget).parents(".item");
let itemId = li.data("item-id");
this.actor.specPowerDeactivate( itemId)
});
html.find('.effect-used').click(ev => {
const li = $(ev.currentTarget).parents(".item");
let itemId = li.data("item-id");
@ -224,6 +235,13 @@ export class PegasusActorSheet extends ActorSheet {
this.render(true);
});
html.find('.change-worstfear').change(ev => {
this.actor.manageWorstFear( ev.currentTarget.checked )
});
html.find('.change-desires').change(ev => {
this.actor.manageDesires( ev.currentTarget.checked )
});
html.find('.update-field').change(ev => {
const fieldName = $(ev.currentTarget).data("field-name");
let value = Number(ev.currentTarget.value);

View File

@ -177,6 +177,35 @@ export class PegasusActor extends Actor {
}
return comp;
}
/* -------------------------------------------- */
async manageWorstFear(flag) {
if (flag) {
let effect = await PegasusUtility.getEffectFromCompendium( "Worst Fear" )
console.log("got effect", effect)
effect.data.worstfear = true
this.createEmbeddedDocuments( 'Item', [effect])
} else {
let effect = this.data.items.find( item => item.type == "effect" && item.data.data.worstfear )
if (effect) {
this.deleteEmbeddedDocuments( 'Item', [ effect.id ])
}
}
}
/* -------------------------------------------- */
async manageDesires(flag) {
if (flag) {
let effect = await PegasusUtility.getEffectFromCompendium( "Desires" )
effect.data.desires = true
this.createEmbeddedDocuments( 'Item', [effect])
} else {
let effect = this.data.items.find( item => item.type == "effect" && item.data.data.desires )
if (effect) {
this.deleteEmbeddedDocuments( 'Item', [ effect.id ])
}
}
}
/* -------------------------------------------- */
getRelevantSpec(statKey) {
let comp = duplicate(this.data.items.filter(item => item.type == 'specialisation' && item.data.data.statistic == statKey) || []);
@ -197,10 +226,43 @@ export class PegasusActor extends Actor {
/* -------------------------------------------- */
async activatePower(itemId) {
let item = this.data.items.find(item => item.id == itemId);
let item = this.data.items.find(item => item.id == itemId)
if (item && item.data.data) {
let update = { _id: item.id, "data.activated": !item.data.data.activated };
await this.updateEmbeddedDocuments('Item', [update]); // Updates one EmbeddedEntity
let nrg = duplicate(this.data.data.nrg)
if ( !item.data.data.activated) { // Current value
if ( item.data.data.cost > nrg.value) {
return ui.notifications.warn("Not enough NRG to activate the Power " + item.name )
}
nrg.activated += item.data.data.cost
nrg.value -= item.data.data.cost
this.update({ 'data.nrg': nrg })
let effects = []
for (let effect of item.data.data.effectsgained) {
effect.data.powerId = itemId // Link to the perk, in order to dynamically remove them
effects.push(effect)
}
if (effects.length) {
await this.createEmbeddedDocuments('Item', effects)
}
} else {
nrg.activated -= item.data.data.cost
this.update({ 'data.nrg': nrg })
let toRem = []
for( let item of this.data.items) {
if (item.type == 'effect' && item.data.data.powerId == itemId) {
toRem.push( item.id)
}
}
if (toRem.length) {
await this.deleteEmbeddedDocuments('Item', toRem)
}
}
let update = { _id: item.id, "data.activated": !item.data.data.activated }
await this.updateEmbeddedDocuments('Item', [update]) // Updates one EmbeddedEntity
}
}
@ -334,7 +396,7 @@ export class PegasusActor extends Actor {
/* -------------------------------------------- */
getOneSpec(specId) {
let spec = this.data.items.find(item => item.type == 'specialisation' && item.id == specId);
let spec = this.data.items.find(item => item.type == 'specialisation' && item.id == specId)
if (spec) {
spec = duplicate(spec);
spec.data.dice = PegasusUtility.getDiceFromLevel(spec.data.level);
@ -342,6 +404,36 @@ export class PegasusActor extends Actor {
return spec;
}
/* -------------------------------------------- */
specPowerActivate(specId) {
let spec = this.getOneSpec(specId)
if (spec) {
let powers = []
for (let power of spec.data.powers) {
power.data.specId = specId
powers.push(power)
}
if (powers.length > 0) {
this.createEmbeddedDocuments('Item', powers)
}
this.updateEmbeddedDocuments('Item', [{ _id: specId, 'data.powersactivated': true }])
}
}
/* -------------------------------------------- */
specPowerDeactivate(specId) {
let toRem = []
for (let power of this.data.items) {
if (power.type == "power" && power.data.data.specId && power.data.data.specId == specId) {
toRem.push(power.id)
}
}
if (toRem.length > 0) {
this.deleteEmbeddedDocuments('Item', toRem)
}
this.updateEmbeddedDocuments('Item', [{ _id: specId, 'data.powersactivated': false }])
}
/* -------------------------------------------- */
async perkEffectUsed(itemId) {
let effect = this.items.get(itemId)
@ -354,6 +446,28 @@ export class PegasusActor extends Actor {
}
}
/* -------------------------------------------- */
disableWeaverPerk(perk) {
if (perk.data.data.isweaver) {
for (let spec of this.data.items) {
if (spec.type == 'specialisation' && spec.data.data.ispowergroup) {
this.specPowerDeactivate(spec.id)
}
}
}
}
/* -------------------------------------------- */
enableWeaverPerk(perk) {
if (perk.data.data.isweaver) {
for (let spec of this.data.items) {
if (spec.type == 'specialisation' && spec.data.data.ispowergroup) {
this.specPowerActivate(spec.id)
}
}
}
}
/* -------------------------------------------- */
async updatePerkStatus(itemId, status) {
let item = this.items.get(itemId)
@ -392,6 +506,7 @@ export class PegasusActor extends Actor {
nrg.mod -= item.data.data.features.bonusnrg.value
this.update({ 'data.nrg': nrg })
}
this.disableWeaverPerk(item)
}
if (status == "activated") {
// Add effects linked to the perk
@ -431,6 +546,7 @@ export class PegasusActor extends Actor {
nrg.mod += item.data.data.features.bonusnrg.value
this.update({ 'data.nrg': nrg })
}
this.enableWeaverPerk(item)
}
if (updateOK) {
this.updateEmbeddedDocuments('Item', [{ _id: item.id, 'data.status': status }])

View File

@ -348,6 +348,16 @@ export class PegasusItemSheet extends ItemSheet {
}
}
/* -------------------------------------------- */
async addEffectPower( event, item, dataItem) {
let newItem = duplicate(item.data)
if ( event.toElement.className == 'drop-power-effect') {
let effectArray = duplicate(this.object.data.data.effectsgained)
effectArray.push( newItem );
await this.object.update( { 'data.effectsgained': effectArray} )
}
}
/* -------------------------------------------- */
async addEffectSpec( event, item, dataItem) {
let newItem = duplicate(item.data);
@ -365,7 +375,18 @@ export class PegasusItemSheet extends ItemSheet {
/* -------------------------------------------- */
async _onDrop(event) {
//console.log(event);
if (this.object.type == 'power' ) {
let data = event.dataTransfer.getData('text/plain');
if (data) {
let dataItem = JSON.parse( data );
let item = await PegasusUtility.searchItem( dataItem);
if ( item.data.type == 'effect') {
return this.addEffectPower( event, item, dataItem);
}
}
}
if (this.object.type == 'effect' ) {
let data = event.dataTransfer.getData('text/plain');
if (data) {

View File

@ -186,6 +186,22 @@ export class PegasusUtility {
return loadTemplates(templatePaths);
}
/* -------------------------------------------- */
static async getEffectFromCompendium(effectName) {
effectName = effectName.toLowerCase()
let effect = game.items.find(item => item.data.type == 'effect' && item.name.toLowerCase() == effectName)
if (!effect) {
let effects = await this.loadCompendium('fvtt-pegasus.effect', item => item.name.toLowerCase() == effectName)
let objs = effects.map(i => i.toObject())
effect = objs[0]
} else {
effect = duplicate(effect);
}
console.log("Effect", effect)
return effect
}
/* -------------------------------------------- */
static removeChatMessageId(messageId) {
if (messageId) {

View File

@ -1163,6 +1163,8 @@ ul, li {
.ul-level1 {
padding-left: 2rem;
}
.drop-power-effect,
.drop-perk-effect,
.drop-ability-effect,
.drop-effect-specaffected,

View File

@ -180,9 +180,9 @@
"styles": [
"styles/simple.css"
],
"templateVersion": 69,
"templateVersion": 73,
"title": "Pegasus RPG",
"url": "https://www.uberwald.me/data/files/fvtt-pegasus-rpg",
"version": "0.4.2",
"version": "0.4.8",
"background" : "./images/ui/pegasus_welcome_page.webp"
}

View File

@ -13,7 +13,9 @@
"eyes": "",
"description": "",
"worstfear": "",
"worstfearactive": false,
"desires": "",
"desiresactive": false,
"preferredhand": "",
"catchphrase": "",
"catchphraseused": false,
@ -251,6 +253,7 @@
"level": 1,
"ispowergroup": false,
"powersource": "",
"powersactivated": false,
"powers": [],
"description": ""
},
@ -258,6 +261,7 @@
"level": 1,
"active": false,
"duration": "",
"isweaver": false,
"effectsgained": [],
"features": {
"nrgcost": {
@ -312,6 +316,7 @@
"effects": "",
"activated": false,
"purchasedeffects": "",
"effectsgained": [],
"description": ""
},
"armor": {

View File

@ -121,6 +121,15 @@
<span class="stat-label"><a class="roll-spec">{{spec.name}}</a></span>
<span class="stat-label">{{upper spec.data.statistic}}</span>
<span class="stat-label">{{spec.data.dice}}</span>
{{#if spec.data.ispowergroup}}
{{#if spec.data.powersactivated}}
<span class="stat-label"><a class="spec-group-deactivate">Deactivate</a></span>
{{else}}
<span class="stat-label"><a class="spec-group-activate">Activate</a></span>
{{/if}}
{{else}}
<span class="stat-label">&nbsp;</span>
{{/if}}
<div class="item-controls">
<a class="item-control item-edit" title="Edit Item"><i class="fas fa-edit"></i></a>
<a class="item-control item-delete" title="Delete Item"><i class="fas fa-trash"></i></a>
@ -493,13 +502,13 @@
<ul>
<li class="flexrow">
<label class="short-label">Worst Fear </label>
<input type="text" class="" name="data.biodata.worstfear" value="{{data.biodata.worstfear}}"
data-dtype="String" />
<input type="text" class="" name="data.biodata.worstfear" value="{{data.biodata.worstfear}}" data-dtype="String" />
<label class="attribute-value checkbox"><input type="checkbox" class="change-worstfear" name="data.biodata.worstfearactive" {{checked data.biodata.worstfearactive}}/> Active ?</label>
</li>
<li class="flexrow">
<label class="short-label">Desires </label>
<input type="text" class="" name="data.biodata.desires" value="{{data.biodata.desires}}"
data-dtype="String" />
<input type="text" class="" name="data.biodata.desires" value="{{data.biodata.desires}}" data-dtype="String" />
<label class="attribute-value checkbox"><input type="checkbox" class="change-desires" name="data.biodata.desiresactive" {{checked data.biodata.desiresactive}}/> Active ?</label>
</li>
</ul>

View File

@ -11,12 +11,10 @@
<div class="tab" data-group="primary">
<ul>
<li class="flexrow"><label class="generic-label">Active ?</label>
<label class="attribute-value checkbox"><input type="checkbox" name="data.active" {{checked data.active}}/></label>
</li>
<li class="flexrow"><label class="generic-label">Level</label>
<input type="text" class="input-numeric-short padd-right" name="data.level" value="{{data.level}}" data-dtype="Number"/>
</li>
<li class="flexrow"><label class="generic-label">Perk Status</label>
<select class="competence-base flexrow" type="text" name="data.status" value="{{data.status}}" data-dtype="String">
{{#select data.status}}
@ -37,6 +35,9 @@
{{/select}}
</select>
</li>
<li class="flexrow"><label class="generic-label">Is Weaver Perk?</label>
<label class="attribute-value checkbox"><input type="checkbox" name="data.isweaver" {{checked data.isweaver}}/></label>
</li>
<li class="flexrow"><label class="generic-label">Effects Gained</label>
</li>

View File

@ -71,6 +71,24 @@
<li class="flexrow"><label class="generic-label">Power Source</label>
<input type="text" class="padd-right" name="data.powersource" value="{{data.powersource}}" data-dtype="String"/>
</li>
<li class="flexrow"><label class="generic-label">Effects Gained</label>
</li>
<li>
<ul class="ul-level1">
<li class="flexrow"><div class="drop-power-effect"><label>Drop Effects here !</label></div>
</li>
{{#each data.effectsgained as |effect idx|}}
<li class="flexrow">
<label name="data.effectsgained[{{idx}}].name"><a class="view-subitem" data-type="effectsgained" data-index="{{idx}}">{{effect.name}}</a></label>
<div class="item-controls padd-left">
<a class="item-control delete-subitem padd-left" data-type="effectsgained" data-index="{{idx}}" title="Delete Effect"><i class="fas fa-trash"></i></a>
</div>
</li>
{{/each}}
</ul>
</li>
<li class="flexrow"><label class="generic-label">Available Effects</label>
<div class="small-editor item-text-long-line">
{{editor content=data.effects target="data.effects" button=true owner=owner editable=editable}}

View File

@ -1,7 +1,7 @@
{{#if notapplicable}}
<option value="notapplicable">Not applicable</option>
{{/if}}
<option value="touch">Touch</option>
<option value="touch">Self Only</option>
<option value="touchself">Touch/Self</option>
<option value="tz">Threat Zone</option>
<option value="close">Close</option>