Step 4 - Manage perks

This commit is contained in:
2022-02-10 19:03:09 +01:00
parent 0a5e52ec4e
commit d17afaf142
12 changed files with 184 additions and 145 deletions

View File

@ -343,10 +343,98 @@ export class PegasusActor extends Actor {
}
/* -------------------------------------------- */
updatePerkRounds(itemId, roundValue) {
async perkEffectUsed( itemId) {
let effect = this.items.get(itemId)
if (effect) {
PegasusUtility.createChatWithRollMode(effect.name, {
content: await renderTemplate(`systems/fvtt-pegasus-rpg/templates/chat-effect-used.html`, effect.data)
});
this.deleteEmbeddedDocuments('Item', [ effect.id] )
}
}
/* -------------------------------------------- */
async updatePerkStatus(itemId, status) {
let item = this.items.get(itemId)
if (item) {
this.updateEmbeddedDocuments('Item', [{ _id: item.id, 'data.roundcount': roundValue }]);
if (item.data.data.status == status) return;// Ensure we are really changing the status
let updateOK = true
if ( status == "ready") {
let effects = []
for( let item of this.data.items) {
if ( item.type == "effect" && item.data.data.perkId == itemId) {
effects.push( item.id)
}
}
if ( effects.length) {
await this.deleteEmbeddedDocuments('Item', effects )
}
if ( item.data.data.features.nrgcost.flag ) {
let nrg = duplicate(this.data.data.nrg)
nrg.activated -= item.data.data.features.nrgcost.value
this.update( {'data.nrg': nrg } )
}
if (item.data.data.features.bonushealth.flag) {
let health = duplicate(this.data.data.secondary.health)
health.bonus -= item.data.data.features.bonushealth.value
this.update( {'data.secondary.health': health } )
}
if (item.data.data.features.bonusdelirium.flag) {
let delirium = duplicate(this.data.data.delirium.delirium)
delirium.bonus -= item.data.data.features.bonusdelirium.value
this.update( {'data.secondary.delirium': delirium } )
}
if (item.data.data.features.bonusnrg.flag) {
let nrg = duplicate(this.data.data.nrg)
nrg.mod -= item.data.data.features.bonusnrg.value
this.update( {'data.nrg': nrg } )
}
}
if ( status == "activated") {
// Add effects linked to the perk
let effects = []
for( let effect of item.data.data.effectsgained) {
effect.data.perkId = itemId // Link to the perk, in order to dynamically remove them
effect.data.isUsed = false // Flag to indicate removal when used in a roll window
effects.push( effect )
}
if ( effects.length) {
await this.createEmbeddedDocuments('Item', effects )
}
// Manage additional flags
if ( item.data.data.features.nrgcost.flag ) {
if (this.data.data.nrg.value >= item.data.data.features.nrgcost.value) {
let nrg = duplicate(this.data.data.nrg)
nrg.activated += item.data.data.features.nrgcost.value
nrg.value -= item.data.data.features.nrgcost.value
this.update( {'data.nrg': nrg } )
} else {
updateOK = false
ui.notifications.warn("Not enough NRG to activate the Perk " + item.name)
}
}
if (item.data.data.features.bonushealth.flag) {
let health = duplicate(this.data.data.secondary.health)
health.bonus += item.data.data.features.bonushealth.value
this.update( {'data.secondary.health': health } )
}
if (item.data.data.features.bonusdelirium.flag) {
let delirium = duplicate(this.data.data.delirium.delirium)
delirium.bonus += item.data.data.features.bonusdelirium.value
this.update( {'data.secondary.delirium': delirium } )
}
if (item.data.data.features.bonusnrg.flag) {
let nrg = duplicate(this.data.data.nrg)
nrg.mod += item.data.data.features.bonusnrg.value
this.update( {'data.nrg': nrg } )
}
}
if (updateOK) {
this.updateEmbeddedDocuments('Item', [{ _id: item.id, 'data.status': status }])
}
}
}