Manage hindrance dices

This commit is contained in:
LeRatierBretonnien 2023-09-13 08:06:08 +02:00
parent b81e5ec17e
commit d5f27ae9ea
8 changed files with 143 additions and 53 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

View File

@ -959,7 +959,7 @@ export class PegasusActor extends Actor {
async equipGear(equipmentId) { async equipGear(equipmentId) {
let item = this.items.find(item => item.id == equipmentId); let item = this.items.find(item => item.id == equipmentId);
if (item && item.system) { if (item && item.system) {
let update = { _id: item.id, "data.equipped": !item.system.equipped }; let update = { _id: item.id, "system.equipped": !item.system.equipped };
await this.updateEmbeddedDocuments('Item', [update]); // Updates one EmbeddedEntity await this.updateEmbeddedDocuments('Item', [update]); // Updates one EmbeddedEntity
} }
} }
@ -1154,7 +1154,7 @@ export class PegasusActor extends Actor {
async updatePerkUsed(itemId, index, checked) { async updatePerkUsed(itemId, index, checked) {
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 = "system.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.system.nbuse == "next1action" && item.system.used1) { if (item.system.nbuse == "next1action" && item.system.used1) {
@ -1349,7 +1349,7 @@ export class PegasusActor extends Actor {
if (this.system.secondary.delirium.status == "trauma") { if (this.system.secondary.delirium.status == "trauma") {
this.traumaState = "trauma" this.traumaState = "trauma"
} }
if ( this.system.secondary.delirium.status == "severetrauma") { if (this.system.secondary.delirium.status == "severetrauma" || this.system.secondary.delirium.status == "defeated") {
this.traumaState = "severetrauma" this.traumaState = "severetrauma"
} }
} }
@ -1540,7 +1540,7 @@ export class PegasusActor extends Actor {
if (this.system.secondary.health.status == "wounded") { if (this.system.secondary.health.status == "wounded") {
hindrance += 1 hindrance += 1
} }
if (this.system.secondary.health.status == "severelywounded") { if (this.system.secondary.health.status == "severlywounded" || this.system.secondary.health.status == "defeated") {
hindrance += 3 hindrance += 3
} }
} }
@ -1567,6 +1567,8 @@ export class PegasusActor extends Actor {
return return
} }
let updates = [] let updates = []
let role = this.getRole() // Get the role for optionnal bonuses
let roleBonus = 0
/* Get MDL bonus */ /* Get MDL bonus */
let meleeBonus = 0 let meleeBonus = 0
@ -1587,9 +1589,12 @@ export class PegasusActor extends Actor {
for (let e of effects) { for (let e of effects) {
rangedBonus += Number(e.system.effectlevel) rangedBonus += Number(e.system.effectlevel)
} }
let weaponsRanged = this.items.filter( it => it.type == "weapon" && it.system.statistic.toLowerCase() == "agi") if (role?.name?.toLowerCase() == "ranged") { // Add ranged bonus to ADRL
roleBonus = this.getRoleLevel()
}
let weaponsRanged = this.items.filter(it => it.type == "weapon" && it.system.damagestatistic.toLowerCase() == "pre")
for (let w of weaponsRanged) { for (let w of weaponsRanged) {
let damage = Number(w.system.damage) + rangedBonus let damage = roleBonus + Number(w.system.damage) + rangedBonus
if (damage != w.system.rdl) { if (damage != w.system.rdl) {
updates.push({ _id: w.id, "system.rdl": damage }) updates.push({ _id: w.id, "system.rdl": damage })
} }
@ -1600,9 +1605,13 @@ export class PegasusActor extends Actor {
for (let e of effects) { for (let e of effects) {
armorBonus += Number(e.system.effectlevel) armorBonus += Number(e.system.effectlevel)
} }
roleBonus = 0
if (role?.name?.toLowerCase() == "defender") { // Add defender bonus to ADRL
roleBonus = this.getRoleLevel()
}
let armors = this.items.filter(it => it.type == "armor") let armors = this.items.filter(it => it.type == "armor")
for (let a of armors) { for (let a of armors) {
let adrl = this.system.statistics.phy.value + this.system.statistics.phy.bonuseffect + this.system.biodata.sizenum + this.system.biodata.sizebonus + a.system.resistance + armorBonus let adrl = roleBonus + this.system.statistics.phy.value + this.system.statistics.phy.bonuseffect + this.system.biodata.sizenum + this.system.biodata.sizebonus + a.system.resistance + armorBonus
if (adrl != a.system.adrl) { if (adrl != a.system.adrl) {
updates.push({ _id: a.id, "system.adrl": adrl }) updates.push({ _id: a.id, "system.adrl": adrl })
} }
@ -1693,7 +1702,7 @@ export class PegasusActor extends Actor {
async modStat(key, inc = 1) { async modStat(key, inc = 1) {
let stat = duplicate(this.system.statistics[key]) let stat = duplicate(this.system.statistics[key])
stat.mod += parseInt(inc) stat.mod += parseInt(inc)
await this.update({ [`data.statistics.${key}`]: stat }) await this.update({ [`system.statistics.${key}`]: stat })
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -1701,7 +1710,7 @@ export class PegasusActor extends Actor {
key = key.toLowerCase() key = key.toLowerCase()
let stat = duplicate(this.system.statistics[key]) let stat = duplicate(this.system.statistics[key])
stat.value += parseInt(inc) stat.value += parseInt(inc)
await this.update({ [`data.statistics.${key}`]: stat }) await this.update({ [`system.statistics.${key}`]: stat })
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -1709,11 +1718,11 @@ export class PegasusActor extends Actor {
if (key == "nrg") { if (key == "nrg") {
let nrg = duplicate(this.system.nrg) let nrg = duplicate(this.system.nrg)
nrg.mod += parseInt(inc) nrg.mod += parseInt(inc)
await this.update({ [`data.nrg`]: nrg }) await this.update({ [`system.nrg`]: nrg })
} else { } else {
let status = duplicate(this.system.secondary[key]) let status = duplicate(this.system.secondary[key])
status.bonus += parseInt(inc) status.bonus += parseInt(inc)
await this.update({ [`data.secondary.${key}`]: status }) await this.update({ [`system.secondary.${key}`]: status })
} }
} }
@ -1752,7 +1761,7 @@ export class PegasusActor extends Actor {
if (objetQ) { if (objetQ) {
let newQ = objetQ.system.quantity + incDec let newQ = objetQ.system.quantity + incDec
if (newQ >= 0) { if (newQ >= 0) {
const updated = await this.updateEmbeddedDocuments('Item', [{ _id: objetQ.id, 'system.quantity': newQ }]) // pdates one EmbeddedEntity await this.updateEmbeddedDocuments('Item', [{ _id: objetQ.id, 'system.quantity': newQ }]) // pdates one EmbeddedEntity
} }
} }
} }
@ -1881,7 +1890,7 @@ export class PegasusActor extends Actor {
getIncreaseStatValue(updates, statKey) { getIncreaseStatValue(updates, statKey) {
let stat = duplicate(this.system.statistics[statKey]) let stat = duplicate(this.system.statistics[statKey])
stat.value += 1; stat.value += 1;
updates[`data.statistics.${statKey}`] = stat updates[`system.statistics.${statKey}`] = stat
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -1906,6 +1915,48 @@ export class PegasusActor extends Actor {
} }
/* -------------------------------------------- */
computeCurrentHindrances() {
let hindrancesDices = 0
if (this.type == "character") {
if (this.system.combat.stunlevel > 0) {
hindrancesDices += 2
}
hindrancesDices += this.system.combat.hindrancedice
let overCapacity = Math.floor(this.encCurrent / this.getEncumbranceCapacity())
if (overCapacity > 0) {
hindrancesDices += overCapacity
}
let effects = this.items.filter(item => item.type == 'effect')
for (let effect of effects) {
if (effect.system.hindrance) {
hindrancesDices += effect.system.effectlevel
}
}
}
if (this.type == "vehicle") {
if (this.system.stun.value > 0) {
hindrancesDices += 2
}
if (this.isVehicleCrawling()) {
hindrancesDices += 3
}
if (this.isVehicleSlow()) {
hindrancesDices += 1
}
if (this.isVehicleAverage()) {
hindrancesDices += 1
}
if (this.isVehicleFast()) {
hindrancesDices += 3
}
if (this.isVehicleExFast()) {
hindrancesDices += 5
}
}
return hindrancesDices
}
/* -------------------------------------------- */ /* -------------------------------------------- */
addHindrancesList(effectsList) { addHindrancesList(effectsList) {
@ -1993,7 +2044,7 @@ export class PegasusActor extends Actor {
rollData.effectsList.push({ label: "Ranged Role Bonus", type: "effect", applied: true, isdynamic: true, value: this.getRoleLevel() }) rollData.effectsList.push({ label: "Ranged Role Bonus", type: "effect", applied: true, isdynamic: true, value: this.getRoleLevel() })
rollData.dicePool = rollData.dicePool.concat(PegasusUtility.buildDicePool("effect-bonus-dice", this.getRoleLevel(), 0, "Ranged Role Bonus")) rollData.dicePool = rollData.dicePool.concat(PegasusUtility.buildDicePool("effect-bonus-dice", this.getRoleLevel(), 0, "Ranged Role Bonus"))
} }
if (role && role.name.toLowerCase() == "defender" && subKey == "defence") { if (role && role.name.toLowerCase() == "defender" && (subKey == "defence" || subKey == "dmg-res")) {
rollData.effectsList.push({ label: "Defender Role Bonus", type: "effect", applied: true, isdynamic: true, value: this.getRoleLevel() }) rollData.effectsList.push({ label: "Defender Role Bonus", type: "effect", applied: true, isdynamic: true, value: this.getRoleLevel() })
rollData.dicePool = rollData.dicePool.concat(PegasusUtility.buildDicePool("effect-bonus-dice", this.getRoleLevel(), 0, "Defender Role Bonus")) rollData.dicePool = rollData.dicePool.concat(PegasusUtility.buildDicePool("effect-bonus-dice", this.getRoleLevel(), 0, "Defender Role Bonus"))
} }
@ -2179,6 +2230,8 @@ export class PegasusActor extends Actor {
} }
} }
rollData.hindranceDices = this.computeCurrentHindrances()
this.processSizeBonus(rollData) this.processSizeBonus(rollData)
this.addEffects(rollData, isInit, isPower, subKey == "power-dmg") this.addEffects(rollData, isInit, isPower, subKey == "power-dmg")
this.addArmorsShields(rollData, statKey, useShield, subKey) this.addArmorsShields(rollData, statKey, useShield, subKey)

View File

@ -72,9 +72,22 @@ export class PegasusUtility {
}) })
Handlebars.registerHelper('getStatusConfig', function (a) { Handlebars.registerHelper('getStatusConfig', function (a) {
let key = a + "Status" let key = a + "Status"
console.log("TABE", key, game.system.pegasus.config[key] ) //console.log("TABE", key, game.system.pegasus.config[key] )
return game.system.pegasus.config[key] return game.system.pegasus.config[key]
}) })
Handlebars.registerHelper('valueAtIndex', function (arr, idx) {
return arr[idx];
})
Handlebars.registerHelper('for', function (from, to, incr, block) {
let accum = '';
for (let i = from; i <= to; i += incr)
accum += block.fn(i);
return accum;
})
Handlebars.registerHelper('isGM', function () {
return game.user.isGM
})
} }
@ -136,10 +149,10 @@ export class PegasusUtility {
let diceKey = PegasusUtility.getDiceFromLevel(level) let diceKey = PegasusUtility.getDiceFromLevel(level)
let diceList = diceKey.split(" ") let diceList = diceKey.split(" ")
for (let myDice of diceList) { for (let myDice of diceList) {
myDice = myDice.trim() let myDiceTrim = myDice.trim()
let newDice = { let newDice = {
name: name, key: myDice, level: PegasusUtility.getLevelFromDice(myDice), mod: mod, effect: effectName, name: name, key: myDiceTrim, level: PegasusUtility.getLevelFromDice(myDiceTrim), mod: mod, effect: effectName,
img: `systems/fvtt-pegasus-rpg/images/dice/${myDice}.webp` img: `systems/fvtt-pegasus-rpg/images/dice/${myDiceTrim}.webp`
} }
dicePool.push(newDice) dicePool.push(newDice)
mod = 0 // Only first dice has modifier mod = 0 // Only first dice has modifier
@ -151,10 +164,10 @@ export class PegasusUtility {
static updateEffectsBonusDice(rollData) { static updateEffectsBonusDice(rollData) {
let newDicePool = rollData.dicePool.filter(dice => dice.name != "effect-bonus-dice") let newDicePool = rollData.dicePool.filter(dice => dice.name != "effect-bonus-dice")
for (let effect of rollData.effectsList) { for (let effect of rollData.effectsList) {
if (effect && effect.applied && effect.type == "effect" && !effect.effect?.system?.hindrance && effect.effect && effect.effect.system.bonusdice) { if (effect?.applied && effect.type == "effect" && !effect.effect?.system?.hindrance && effect.effect && effect.effect.system.bonusdice) {
newDicePool = newDicePool.concat(this.buildDicePool("effect-bonus-dice", effect.effect.system.effectlevel, 0, effect.effect.name)) newDicePool = newDicePool.concat(this.buildDicePool("effect-bonus-dice", effect.effect.system.effectlevel, 0, effect.effect.name))
} }
if (effect && effect.applied && effect.type == "effect" && effect.value && effect.isdynamic && !effect.effect?.system?.hindrance) { if (effect?.applied && effect.type == "effect" && effect.value && effect.isdynamic && !effect.effect?.system?.hindrance) {
newDicePool = newDicePool.concat(this.buildDicePool("effect-bonus-dice", effect.value, 0, effect.name)) newDicePool = newDicePool.concat(this.buildDicePool("effect-bonus-dice", effect.value, 0, effect.name))
} }
} }
@ -165,7 +178,7 @@ export class PegasusUtility {
static updateHindranceBonusDice(rollData) { static updateHindranceBonusDice(rollData) {
let newDicePool = rollData.dicePool.filter(dice => dice.name != "effect-hindrance") let newDicePool = rollData.dicePool.filter(dice => dice.name != "effect-hindrance")
for (let hindrance of rollData.effectsList) { for (let hindrance of rollData.effectsList) {
if (hindrance && hindrance.applied && (hindrance.type == "hindrance" || (hindrance.type == "effect" && hindrance.effect?.system?.hindrance))) { if (hindrance?.applied && (hindrance.type == "hindrance" || (hindrance.type == "effect" && hindrance.effect?.system?.hindrance))) {
console.log("Adding Hindrance 1", hindrance, newDicePool) console.log("Adding Hindrance 1", hindrance, newDicePool)
newDicePool = newDicePool.concat(this.buildDicePool("effect-hindrance", (hindrance.value) ? hindrance.value : hindrance.effect.system.effectlevel, 0, hindrance.name)) newDicePool = newDicePool.concat(this.buildDicePool("effect-hindrance", (hindrance.value) ? hindrance.value : hindrance.effect.system.effectlevel, 0, hindrance.name))
console.log("Adding Hindrance 2", newDicePool) console.log("Adding Hindrance 2", newDicePool)
@ -826,9 +839,19 @@ export class PegasusUtility {
let myRoll = rollData.roll let myRoll = rollData.roll
if (!myRoll || rollData.rerollHero || rollData.rerollMomentum) { // New rolls only of no rerolls if (!myRoll || rollData.rerollHero || rollData.rerollMomentum) { // New rolls only of no rerolls
myRoll = new Roll(diceFormula).roll({ async: false }) myRoll = new Roll(diceFormula).roll({ async: false })
await this.showDiceSoNice(myRoll, game.settings.get("core", "rollMode"))
rollData.roll = myRoll rollData.roll = myRoll
} }
if ( rollData.hindranceDices > 0) {
rollData.hindranceRoll = new Roll(rollData.hindranceDices + "d6").roll({ async: false })
this.showDiceSoNice(rollData.hindranceRoll, game.settings.get("core", "rollMode"))
for (let res of rollData.hindranceRoll.terms[0].results) {
if (res.result == 6) {
rollData.hindranceFailure = true
}
}
}
await this.showDiceSoNice(myRoll, game.settings.get("core", "rollMode"))
// Final score and keep data // Final score and keep data
rollData.finalScore = myRoll.total rollData.finalScore = myRoll.total
@ -1048,7 +1071,7 @@ export class PegasusUtility {
} }
//rollData.attackerId = this.id //rollData.attackerId = this.id
console.log("Target/DEFENDER", defenderActor) console.log("Target/DEFENDER", defenderActor)
defenderActor.addHindrancesList(rollData.effectsList) //defenderActor.addHindrancesList(rollData.effectsList) /* No more used */
} }
} }

View File

@ -252,7 +252,7 @@
], ],
"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": "11.0.3", "version": "11.0.4",
"download": "https://www.uberwald.me/gitea/uberwald/fvtt-pegasus-rpg/archive/fvtt-pegasus-rpg-v11.0.3.zip", "download": "https://www.uberwald.me/gitea/uberwald/fvtt-pegasus-rpg/archive/fvtt-pegasus-rpg-v11.0.4.zip",
"background": "systems/fvtt-pegasus-rpg/images/ui/pegasus_welcome_page.webp" "background": "systems/fvtt-pegasus-rpg/images/ui/pegasus_welcome_page.webp"
} }

View File

@ -56,11 +56,11 @@
<li>Power Damage type : {{power.system.powerdamagetype}} {{power.system.powerdamagetypelevel}}</li> <li>Power Damage type : {{power.system.powerdamagetype}} {{power.system.powerdamagetypelevel}}</li>
{{/if}} {{/if}}
{{#if hindranceFailure}}
<li><strong>Failed due to Hindrance Dice(s) !!</strong>
{{else}}
{{#if isResistance}} {{#if isResistance}}
<li><strong>Defense Result : {{finalScore}}</strong> <li><strong>Defense Result : {{finalScore}}</strong>
{{else}}
{{#if isDamage}}
<li><strong>Damages : {{finalScore}}</strong>
{{else}} {{else}}
<li><strong>Final Result : {{finalScore}}</strong> <li><strong>Final Result : {{finalScore}}</strong>
{{/if}} {{/if}}

View File

@ -26,7 +26,7 @@
</select> </select>
</li> </li>
<li class="flexrow"><label class="generic-label">DMG RES Dice</label> <li class="flexrow"><label class="generic-label">Damage Resistance</label>
<select class="competence-base flexrow" type="text" name="system.resistance" value="{{data.resistance}}" data-dtype="Number"> <select class="competence-base flexrow" type="text" name="system.resistance" value="{{data.resistance}}" data-dtype="Number">
{{#select data.resistance}} {{#select data.resistance}}
{{{optionsDiceList}}} {{{optionsDiceList}}}

View File

@ -44,7 +44,7 @@
<label class="competence-base">{{data.mdl}}</label> <label class="competence-base">{{data.mdl}}</label>
</li> </li>
{{/if}} {{/if}}
{{#if (and owner (eq data.statistic "agi"))}} {{#if (and owner (eq data.damagestatistic "pre"))}}
<li class="flexrow"> <li class="flexrow">
<label class="generic-label">RDL</label> <label class="generic-label">RDL</label>
<label class="competence-base">{{data.rdl}}</label> <label class="competence-base">{{data.rdl}}</label>

View File

@ -87,7 +87,7 @@
<div class="flexrow dice-pool-stack"> <div class="flexrow dice-pool-stack">
{{#each dicePool as |dice idx|}} {{#each dicePool as |dice idx|}}
<span><a class="pool-remove-dice" data-dice-idx="{{idx}}" data-dice-level="{{dice.level}}" data-dice-key="{{dice.key}}"><img class="dice-pool-image" <span><a class="pool-remove-dice" data-dice-idx="{{idx}}" data-dice-level="{{dice.level}}" data-dice-key="{{dice.key}}"><img class="dice-pool-image"
src="{{dice.img}}"></a></span> src="{{dice.img}}" alt="dices"></a></span>
{{/each}} {{/each}}
</div> </div>
</div> </div>
@ -100,11 +100,25 @@
<div class="flexrow"> <div class="flexrow">
{{#each diceList as |dice idx|}} {{#each diceList as |dice idx|}}
<span><a class="pool-add-dice" data-dice-key="{{dice.key}}" data-dice-level="{{dice.level}}"><img class="dice-pool-image" <span><a class="pool-add-dice" data-dice-key="{{dice.key}}" data-dice-level="{{dice.level}}"><img class="dice-pool-image"
src="{{dice.img}}"></a></span> src="{{dice.img}}" alt="dices"></a></span>
{{/each}} {{/each}}
</div> </div>
{{/if}} {{/if}}
{{#if hindranceDices}}
<div class="dice-pool-div">
<span>
<h3 class="dice-pool-label">Hindrance Dices</h3>
</span>
<div class="flexrow dice-pool-stack">
{{#for 1 hindranceDices 1}}
<span><a class="" data-dice-idx="{{idx}}" data-dice-level="2" data-dice-key="d6"><img class="dice-pool-image"
src="systems/fvtt-pegasus-rpg/images/dice/hindrance-dice.png" alt="dices"></a></span>
{{/for}}
</div>
</div>
{{/if}}
<div class="flexrow"> <div class="flexrow">
<span class="roll-dialog-label">Modifiers : </span> <span class="roll-dialog-label">Modifiers : </span>