Various fixes

This commit is contained in:
sladecraven 2022-02-16 14:13:16 +01:00
parent 8dd7217e69
commit 7da8f7d9f1
2 changed files with 53 additions and 51 deletions

View File

@ -478,6 +478,7 @@ export class PegasusActor extends Actor {
} }
} }
if (effects.length > 0) { if (effects.length > 0) {
console.log("DELET!!!!", effects, this)
await this.deleteEmbeddedDocuments('Item', effects) await this.deleteEmbeddedDocuments('Item', effects)
} }
} }
@ -487,22 +488,16 @@ export class PegasusActor extends Actor {
let item = this.items.get(itemId) let item = this.items.get(itemId)
if (item && index) { if (item && index) {
let key = "data.used" + index let key = "data.used" + index
await this.updateEmbeddedDocuments('Item', [{ _id: itemId, [`${key}`]: checked }] ) await this.updateEmbeddedDocuments('Item', [{ _id: itemId, [`${key}`]: checked }])
item = this.items.get(itemId) // Refresh item = this.items.get(itemId) // Refresh
if (item.data.data.nbuse == "next1action" && item.data.data.used1) { if (item.data.data.nbuse == "next1action" && item.data.data.used1) {
this.cleanPerkEffects(itemId) this.cleanPerkEffects(itemId)
await this.updateEmbeddedDocuments('Item', [ { _id: itemId, 'data.status': "ready", 'data.used1': false },
{ _id: itemId, 'data.used2': false}, { _id: itemId,'data.used3': false } ] ) // Reset on Ready
} }
if (item.data.data.nbuse == "next2action" && item.data.data.used1 && item.data.data.used2) { if (item.data.data.nbuse == "next2action" && item.data.data.used1 && item.data.data.used2) {
this.cleanPerkEffects(itemId) this.cleanPerkEffects(itemId)
await this.updateEmbeddedDocuments('Item', [ { _id: itemId, 'data.status': "ready", 'data.used1': false },
{ _id: itemId, 'data.used2': false}, { _id: itemId,'data.used3': false } ] ) // Reset on Ready
} }
if (item.data.data.nbuse == "next3action" && item.data.data.used1 && item.data.data.used2 && item.data.data.used3) { if (item.data.data.nbuse == "next3action" && item.data.data.used1 && item.data.data.used2 && item.data.data.used3) {
this.cleanPerkEffects(itemId) this.cleanPerkEffects(itemId)
await this.updateEmbeddedDocuments('Item', [ { _id: itemId, 'data.status': "ready", 'data.used1': false },
{ _id: itemId, 'data.used2': false}, { _id: itemId,'data.used3': false } ] ) // Reset on Ready
} }
} }
} }
@ -525,10 +520,8 @@ export class PegasusActor extends Actor {
let updateOK = true let updateOK = true
if (status == "ready") { if (status == "ready") {
console.log("Cleaning effects") await this.cleanPerkEffects(itemId)
this.cleanPerkEffects(itemId) await this.updateEmbeddedDocuments('Item', [{ _id: itemId, 'data.used1': false, 'data.used2': false, 'data.used3': false }])
await this.updateEmbeddedDocuments('Item', [ { _id: itemId, 'data.status': "ready", 'data.used1': false },
{ _id: itemId, 'data.used2': false}, { _id: itemId,'data.used3': false } ] ) // Reset on Ready
if (item.data.data.features.nrgcost.flag) { if (item.data.data.features.nrgcost.flag) {
let nrg = duplicate(this.data.data.nrg) let nrg = duplicate(this.data.data.nrg)
nrg.activated -= item.data.data.features.nrgcost.value nrg.activated -= item.data.data.features.nrgcost.value
@ -539,19 +532,19 @@ export class PegasusActor extends Actor {
let health = duplicate(this.data.data.secondary.health) let health = duplicate(this.data.data.secondary.health)
health.value -= Number(item.data.data.features.bonushealth.value) || 0 health.value -= Number(item.data.data.features.bonushealth.value) || 0
health.max -= Number(item.data.data.features.bonushealth.value) || 0 health.max -= Number(item.data.data.features.bonushealth.value) || 0
this.update({ 'data.secondary.health': health }) await this.update({ 'data.secondary.health': health })
} }
if (item.data.data.features.bonusdelirium.flag) { if (item.data.data.features.bonusdelirium.flag) {
let delirium = duplicate(this.data.data.secondary.delirium) let delirium = duplicate(this.data.data.secondary.delirium)
delirium.value -= Number(item.data.data.features.bonusdelirium.value) || 0 delirium.value -= Number(item.data.data.features.bonusdelirium.value) || 0
delirium.max -= Number(item.data.data.features.bonusdelirium.value) || 0 delirium.max -= Number(item.data.data.features.bonusdelirium.value) || 0
this.update({ 'data.secondary.delirium': delirium }) await this.update({ 'data.secondary.delirium': delirium })
} }
if (item.data.data.features.bonusnrg.flag) { if (item.data.data.features.bonusnrg.flag) {
let nrg = duplicate(this.data.data.nrg) let nrg = duplicate(this.data.data.nrg)
nrg.value -= Number(item.data.data.features.bonusnrg.value) || 0 nrg.value -= Number(item.data.data.features.bonusnrg.value) || 0
nrg.max -= Number(item.data.data.features.bonusnrg.value) || 0 nrg.max -= Number(item.data.data.features.bonusnrg.value) || 0
this.update({ 'data.nrg': nrg }) await this.update({ 'data.nrg': nrg })
} }
this.disableWeaverPerk(item) this.disableWeaverPerk(item)
} }
@ -568,12 +561,12 @@ export class PegasusActor extends Actor {
} }
// Manage additional flags // Manage additional flags
if (item.data.data.features.nrgcost.flag) { if (item.data.data.features.nrgcost.flag) {
if ( (this.data.data.nrg.value >= item.data.data.features.nrgcost.value) && (this.data.data.nrg.max >= item.data.data.features.nrgcost.value)) { if ((this.data.data.nrg.value >= item.data.data.features.nrgcost.value) && (this.data.data.nrg.max >= item.data.data.features.nrgcost.value)) {
let nrg = duplicate(this.data.data.nrg) let nrg = duplicate(this.data.data.nrg)
nrg.activated += item.data.data.features.nrgcost.value nrg.activated += item.data.data.features.nrgcost.value
nrg.value -= item.data.data.features.nrgcost.value nrg.value -= item.data.data.features.nrgcost.value
nrg.max -= item.data.data.features.nrgcost.value nrg.max -= item.data.data.features.nrgcost.value
this.update({ 'data.nrg': nrg }) await this.update({ 'data.nrg': nrg })
} else { } else {
updateOK = false updateOK = false
ui.notifications.warn("Not enough NRG to activate the Perk " + item.name) ui.notifications.warn("Not enough NRG to activate the Perk " + item.name)
@ -583,24 +576,24 @@ export class PegasusActor extends Actor {
let health = duplicate(this.data.data.secondary.health) let health = duplicate(this.data.data.secondary.health)
health.value += Number(item.data.data.features.bonushealth.value) || 0 health.value += Number(item.data.data.features.bonushealth.value) || 0
health.max += Number(item.data.data.features.bonushealth.value) || 0 health.max += Number(item.data.data.features.bonushealth.value) || 0
this.update({ 'data.secondary.health': health }) await this.update({ 'data.secondary.health': health })
} }
if (item.data.data.features.bonusdelirium.flag) { if (item.data.data.features.bonusdelirium.flag) {
let delirium = duplicate(this.data.data.secondary.delirium) let delirium = duplicate(this.data.data.secondary.delirium)
delirium.value += Number(item.data.data.features.bonusdelirium.value) || 0 delirium.value += Number(item.data.data.features.bonusdelirium.value) || 0
delirium.max += Number(item.data.data.features.bonusdelirium.value) || 0 delirium.max += Number(item.data.data.features.bonusdelirium.value) || 0
this.update({ 'data.secondary.delirium': delirium }) await this.update({ 'data.secondary.delirium': delirium })
} }
if (item.data.data.features.bonusnrg.flag) { if (item.data.data.features.bonusnrg.flag) {
let nrg = duplicate(this.data.data.nrg) let nrg = duplicate(this.data.data.nrg)
nrg.value += Number(item.data.data.features.bonusnrg.value) || 0 nrg.value += Number(item.data.data.features.bonusnrg.value) || 0
nrg.max += Number(item.data.data.features.bonusnrg.value) || 0 nrg.max += Number(item.data.data.features.bonusnrg.value) || 0
this.update({ 'data.nrg': nrg }) await this.update({ 'data.nrg': nrg })
} }
this.enableWeaverPerk(item) this.enableWeaverPerk(item)
} }
if (updateOK) { if (updateOK) {
this.updateEmbeddedDocuments('Item', [{ _id: item.id, 'data.status': status }]) await this.updateEmbeddedDocuments('Item', [{ _id: item.id, 'data.status': status }])
} }
} }
} }
@ -620,48 +613,49 @@ export class PegasusActor extends Actor {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
async computeNRGHealth( ) { async computeNRGHealth() {
if (this.isToken) return //if (this.isToken) return
if (this.isOwner || game.user.isGM) { if (this.isOwner || game.user.isGM) {
let updates = {} let updates = {}
let phyDiceValue = PegasusUtility.getDiceValue(this.data.data.statistics.phy.value) + this.data.data.secondary.health.bonus + this.data.data.statistics.phy.mod; let phyDiceValue = PegasusUtility.getDiceValue(this.data.data.statistics.phy.value) + this.data.data.secondary.health.bonus + this.data.data.statistics.phy.mod;
if (phyDiceValue != this.data.data.secondary.health.max) { if (phyDiceValue != this.data.data.secondary.health.max) {
updates['data.secondary.health.max'] = phyDiceValue updates['data.secondary.health.max'] = phyDiceValue
}
if (this.computeValue) { if (this.computeValue) {
updates['data.secondary.health.value'] = phyDiceValue updates['data.secondary.health.value'] = phyDiceValue
} }
}
let mndDiceValue = PegasusUtility.getDiceValue(this.data.data.statistics.mnd.value) + this.data.data.secondary.delirium.bonus + this.data.data.statistics.mnd.mod; let mndDiceValue = PegasusUtility.getDiceValue(this.data.data.statistics.mnd.value) + this.data.data.secondary.delirium.bonus + this.data.data.statistics.mnd.mod;
if (mndDiceValue != this.data.data.secondary.delirium.max) { if (mndDiceValue != this.data.data.secondary.delirium.max) {
updates['data.secondary.delirium.max'] = mndDiceValue updates['data.secondary.delirium.max'] = mndDiceValue
}
if (this.computeValue) { if (this.computeValue) {
updates['data.secondary.delirium.value'] = mndDiceValue updates['data.secondary.delirium.value'] = mndDiceValue
} }
}
let stlDiceValue = PegasusUtility.getDiceValue(this.data.data.statistics.stl.value) + this.data.data.secondary.stealthhealth.bonus + this.data.data.statistics.stl.mod; let stlDiceValue = PegasusUtility.getDiceValue(this.data.data.statistics.stl.value) + this.data.data.secondary.stealthhealth.bonus + this.data.data.statistics.stl.mod;
if (stlDiceValue != this.data.data.secondary.stealthhealth.max) { if (stlDiceValue != this.data.data.secondary.stealthhealth.max) {
updates['data.secondary.stealthhealth.max'] = stlDiceValue updates['data.secondary.stealthhealth.max'] = stlDiceValue
}
if (this.computeValue) { if (this.computeValue) {
updates['data.secondary.stealthhealth.value'] = stlDiceValue updates['data.secondary.stealthhealth.value'] = stlDiceValue
} }
}
let socDiceValue = PegasusUtility.getDiceValue(this.data.data.statistics.soc.value) + this.data.data.secondary.socialhealth.bonus + this.data.data.statistics.soc.mod; let socDiceValue = PegasusUtility.getDiceValue(this.data.data.statistics.soc.value) + this.data.data.secondary.socialhealth.bonus + this.data.data.statistics.soc.mod;
if (socDiceValue != this.data.data.secondary.socialhealth.max) { if (socDiceValue != this.data.data.secondary.socialhealth.max) {
updates['data.secondary.socialhealth.max'] = socDiceValue updates['data.secondary.socialhealth.max'] = socDiceValue
}
if (this.computeValue) { if (this.computeValue) {
updates['data.secondary.socialhealth.value'] = socDiceValue updates['data.secondary.socialhealth.value'] = socDiceValue
} }
}
let nrgValue = PegasusUtility.getDiceValue(this.data.data.statistics.foc.value) + this.data.data.nrg.mod + this.data.data.statistics.foc.mod; let nrgValue = PegasusUtility.getDiceValue(this.data.data.statistics.foc.value) + this.data.data.nrg.mod + this.data.data.statistics.foc.mod;
if (nrgValue != this.data.data.nrg.absolutemax) { if (nrgValue != this.data.data.nrg.absolutemax) {
updates['data.nrg.absolutemax'] = nrgValue updates['data.nrg.absolutemax'] = nrgValue
}
if (this.computeValue) { if (this.computeValue) {
updates['data.nrg.max'] = nrgValue updates['data.nrg.max'] = nrgValue
updates['data.nrg.value'] = nrgValue updates['data.nrg.value'] = nrgValue
} }
}
nrgValue = PegasusUtility.getDiceValue(this.data.data.statistics.foc.value) + this.data.data.statistics.foc.mod; nrgValue = PegasusUtility.getDiceValue(this.data.data.statistics.foc.value) + this.data.data.statistics.foc.mod;
if (nrgValue != this.data.data.combat.stunthreshold) { if (nrgValue != this.data.data.combat.stunthreshold) {
updates['data.combat.stunthreshold'] = nrgValue updates['data.combat.stunthreshold'] = nrgValue
@ -691,6 +685,7 @@ export class PegasusActor extends Actor {
await this.update(updates) await this.update(updates)
} }
if (this.isOwner || game.user.isGM) {
// Update current hindrance level // Update current hindrance level
let hindrance = this.data.data.combat.hindrancedice let hindrance = this.data.data.combat.hindrancedice
if (this.data.data.secondary.health.value < 0) { if (this.data.data.secondary.health.value < 0) {
@ -701,6 +696,7 @@ export class PegasusActor extends Actor {
} }
this.data.data.combat.hindrancedice = hindrance this.data.data.combat.hindrancedice = hindrance
} }
}
/* -------------------------------------------- */ /* -------------------------------------------- */
async modStat(key, inc = 1) { async modStat(key, inc = 1) {
@ -876,11 +872,16 @@ export class PegasusActor extends Actor {
for (let effect of effects) { for (let effect of effects) {
effect = duplicate(effect) effect = duplicate(effect)
if (!effect.data.hindrance if (!effect.data.hindrance
&& effect.data.stataffected != "notapplicable" && (effect.data.stataffected != "notapplicable" || effect.data.specaffected.length > 0)
&& effect.data.stataffected != "special") { && effect.data.stataffected != "special") {
if ( effect.data.effectstatlevel && effect.data.effectstat == rollData.statKey) { if (effect.data.effectstatlevel) {
if ( effect.data.effectstat == rollData.statKey ) {
effect.data.effectlevel = rollData.statDicesLevel effect.data.effectlevel = rollData.statDicesLevel
} }
if ( effect.data.stataffected == "all") { // Real nightmare
effect.data.effectlevel = this.data.data.statistics[effect.data.effectstat].value
}
}
rollData.effectsList.push({ label: effect.name, type: "effect", applied: false, effect: effect, value: effect.data.effectlevel }) rollData.effectsList.push({ label: effect.name, type: "effect", applied: false, effect: effect, value: effect.data.effectlevel })
} }
} }
@ -953,7 +954,7 @@ export class PegasusActor extends Actor {
/* -------------------------------------------- */ /* -------------------------------------------- */
async startRoll(rollData) { async startRoll(rollData) {
this.syncRoll(rollData); this.syncRoll(rollData);
console.log("ROLL DATA", rollData) //console.log("ROLL DATA", rollData)
let rollDialog = await PegasusRollDialog.create(this, rollData); let rollDialog = await PegasusRollDialog.create(this, rollData);
console.log(rollDialog); console.log(rollDialog);
rollDialog.render(true); rollDialog.render(true);
@ -966,6 +967,7 @@ export class PegasusActor extends Actor {
if (stat) { if (stat) {
let rollData = this.getCommonRollData(statKey, useShield) let rollData = this.getCommonRollData(statKey, useShield)
rollData.mode = "stat" rollData.mode = "stat"
rollData.title = `Roll : ${stat.label} `
this.startRoll(rollData) this.startRoll(rollData)
} else { } else {

View File

@ -183,6 +183,6 @@
"templateVersion": 78, "templateVersion": 78,
"title": "Pegasus RPG", "title": "Pegasus RPG",
"url": "https://www.uberwald.me/data/files/fvtt-pegasus-rpg", "url": "https://www.uberwald.me/data/files/fvtt-pegasus-rpg",
"version": "0.4.13", "version": "0.4.14",
"background" : "./images/ui/pegasus_welcome_page.webp" "background" : "./images/ui/pegasus_welcome_page.webp"
} }