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

@ -114,10 +114,10 @@ export class PegasusActor extends Actor {
prepareDerivedData() {
if (this.system.secondary.stealthhealth) {
this.update({"system.secondary": {"-=stealthhealth": null}} )
this.update({ "system.secondary": { "-=stealthhealth": null } })
}
if (this.system.secondary.socialhealth) {
this.update({"system.secondary": {"-=socialhealth": null}} )
this.update({ "system.secondary": { "-=socialhealth": null } })
}
if (!this.traumaState) {
@ -770,7 +770,7 @@ export class PegasusActor extends Actor {
let combat = duplicate(myself.system.combat)
combat.stunlevel += incDec
if (combat.stunlevel >= 0) {
myself.update({ 'system.combat': combat } )
myself.update({ 'system.combat': combat })
let chatData = {
user: game.user.id,
rollMode: game.settings.get("core", "rollMode"),
@ -959,7 +959,7 @@ export class PegasusActor extends Actor {
async equipGear(equipmentId) {
let item = this.items.find(item => item.id == equipmentId);
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
}
}
@ -1154,7 +1154,7 @@ export class PegasusActor extends Actor {
async updatePerkUsed(itemId, index, checked) {
let item = this.items.get(itemId)
if (item && index) {
let key = "data.used" + index
let key = "system.used" + index
await this.updateEmbeddedDocuments('Item', [{ _id: itemId, [`${key}`]: checked }])
item = this.items.get(itemId) // Refresh
if (item.system.nbuse == "next1action" && item.system.used1) {
@ -1346,10 +1346,10 @@ export class PegasusActor extends Actor {
getTraumaState() {
this.traumaState = "none"
if (this.type == "character") {
if ( this.system.secondary.delirium.status == "trauma") {
if (this.system.secondary.delirium.status == "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"
}
}
@ -1540,7 +1540,7 @@ export class PegasusActor extends Actor {
if (this.system.secondary.health.status == "wounded") {
hindrance += 1
}
if (this.system.secondary.health.status == "severelywounded") {
if (this.system.secondary.health.status == "severlywounded" || this.system.secondary.health.status == "defeated") {
hindrance += 3
}
}
@ -1555,7 +1555,7 @@ export class PegasusActor extends Actor {
/* -------------------------------------------- */
getArmorResistanceBonus() {
let bonus = 0
let bonus = 0
for (let a of armors) {
bonus += Number(a.system.resistance)
}
@ -1567,43 +1567,52 @@ export class PegasusActor extends Actor {
return
}
let updates = []
let role = this.getRole() // Get the role for optionnal bonuses
let roleBonus = 0
/* Get MDL bonus */
let meleeBonus = 0
let effects = this.items.filter(effect => effect.type == "effect" && effect.system.affectstatus && effect.system.affectstatus == "mdl" && (Number(effect.system.effectlevel) > 0))
for(let e of effects) {
for (let e of effects) {
meleeBonus += Number(e.system.effectlevel)
}
let weaponsMelee = this.items.filter( it => it.type == "weapon" && it.system.damagestatistic.toLowerCase() == "str")
let weaponsMelee = this.items.filter(it => it.type == "weapon" && it.system.damagestatistic.toLowerCase() == "str")
for (let w of weaponsMelee) {
let damage = Number(w.system.damage) + this.system.biodata.sizenum + this.system.biodata.sizebonus + this.system.statistics.str.value + this.system.statistics.str.bonuseffect + meleeBonus
if (damage != w.system.mdl ) {
if (damage != w.system.mdl) {
updates.push({ _id: w.id, "system.mdl": damage })
}
}
let rangedBonus = 0
effects = this.items.filter(effect => effect.type == "effect" && effect.system.affectstatus && effect.system.affectstatus == "rdl" && (Number(effect.system.effectlevel) > 0))
for(let e of effects) {
for (let e of effects) {
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) {
let damage = Number(w.system.damage) + rangedBonus
if (damage != w.system.rdl ) {
let damage = roleBonus + Number(w.system.damage) + rangedBonus
if (damage != w.system.rdl) {
updates.push({ _id: w.id, "system.rdl": damage })
}
}
let armorBonus = 0
effects = this.items.filter(effect => effect.type == "effect" && effect.system.affectstatus && effect.system.affectstatus == " adrl" && (Number(effect.system.effectlevel) > 0))
for(let e of effects) {
for (let e of effects) {
armorBonus += Number(e.system.effectlevel)
}
let armors = this.items.filter( it => it.type == "armor")
roleBonus = 0
if (role?.name?.toLowerCase() == "defender") { // Add defender bonus to ADRL
roleBonus = this.getRoleLevel()
}
let armors = this.items.filter(it => it.type == "armor")
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
if (adrl != a.system.adrl ) {
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) {
updates.push({ _id: a.id, "system.adrl": adrl })
}
}
@ -1693,7 +1702,7 @@ export class PegasusActor extends Actor {
async modStat(key, inc = 1) {
let stat = duplicate(this.system.statistics[key])
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()
let stat = duplicate(this.system.statistics[key])
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") {
let nrg = duplicate(this.system.nrg)
nrg.mod += parseInt(inc)
await this.update({ [`data.nrg`]: nrg })
await this.update({ [`system.nrg`]: nrg })
} else {
let status = duplicate(this.system.secondary[key])
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) {
let newQ = objetQ.system.quantity + incDec
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
}
}
}
@ -1774,14 +1783,14 @@ export class PegasusActor extends Actor {
ability.system = ability.data
}
if (ability.system.affectedstat != "notapplicable") {
if ( ability.system.affectedstat == "mr") {
if (ability.system.affectedstat == "mr") {
let stat = duplicate(this.system.mr)
stat.mod += Number(ability.system.statmodifier)
updates[`system.mr`] = stat
updates[`system.mr`] = stat
} else {
let stat = duplicate(this.system.statistics[ability.system.affectedstat])
stat.mod += Number(ability.system.statmodifier)
updates[`system.statistics.${ability.system.affectedstat}`] = stat
updates[`system.statistics.${ability.system.affectedstat}`] = stat
}
}
// manage status bonus
@ -1881,7 +1890,7 @@ export class PegasusActor extends Actor {
getIncreaseStatValue(updates, statKey) {
let stat = duplicate(this.system.statistics[statKey])
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) {
@ -1957,7 +2008,7 @@ export class PegasusActor extends Actor {
/* ROLL SECTION
/* -------------------------------------------- */
pushEffect(rollData, effect) {
if ( (this.getTraumaState() == "none" && !this.checkNoBonusDice()) || !effect.system.bonusdice) {
if ((this.getTraumaState() == "none" && !this.checkNoBonusDice()) || !effect.system.bonusdice) {
rollData.effectsList.push({ label: effect.name, type: "effect", applied: false, effect: effect, value: effect.system.effectlevel })
}
}
@ -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.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.dicePool = rollData.dicePool.concat(PegasusUtility.buildDicePool("effect-bonus-dice", this.getRoleLevel(), 0, "Defender Role Bonus"))
}
@ -2177,7 +2228,9 @@ export class PegasusActor extends Actor {
})
}
}
}
}
rollData.hindranceDices = this.computeCurrentHindrances()
this.processSizeBonus(rollData)
this.addEffects(rollData, isInit, isPower, subKey == "power-dmg")

View File

@ -72,9 +72,22 @@ export class PegasusUtility {
})
Handlebars.registerHelper('getStatusConfig', function (a) {
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]
})
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 diceList = diceKey.split(" ")
for (let myDice of diceList) {
myDice = myDice.trim()
let myDiceTrim = myDice.trim()
let newDice = {
name: name, key: myDice, level: PegasusUtility.getLevelFromDice(myDice), mod: mod, effect: effectName,
img: `systems/fvtt-pegasus-rpg/images/dice/${myDice}.webp`
name: name, key: myDiceTrim, level: PegasusUtility.getLevelFromDice(myDiceTrim), mod: mod, effect: effectName,
img: `systems/fvtt-pegasus-rpg/images/dice/${myDiceTrim}.webp`
}
dicePool.push(newDice)
mod = 0 // Only first dice has modifier
@ -151,10 +164,10 @@ export class PegasusUtility {
static updateEffectsBonusDice(rollData) {
let newDicePool = rollData.dicePool.filter(dice => dice.name != "effect-bonus-dice")
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))
}
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))
}
}
@ -165,7 +178,7 @@ export class PegasusUtility {
static updateHindranceBonusDice(rollData) {
let newDicePool = rollData.dicePool.filter(dice => dice.name != "effect-hindrance")
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)
newDicePool = newDicePool.concat(this.buildDicePool("effect-hindrance", (hindrance.value) ? hindrance.value : hindrance.effect.system.effectlevel, 0, hindrance.name))
console.log("Adding Hindrance 2", newDicePool)
@ -826,9 +839,19 @@ export class PegasusUtility {
let myRoll = rollData.roll
if (!myRoll || rollData.rerollHero || rollData.rerollMomentum) { // New rolls only of no rerolls
myRoll = new Roll(diceFormula).roll({ async: false })
await this.showDiceSoNice(myRoll, game.settings.get("core", "rollMode"))
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
rollData.finalScore = myRoll.total
@ -1048,7 +1071,7 @@ export class PegasusUtility {
}
//rollData.attackerId = this.id
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",
"url": "https://www.uberwald.me/data/files/fvtt-pegasus-rpg",
"version": "11.0.3",
"download": "https://www.uberwald.me/gitea/uberwald/fvtt-pegasus-rpg/archive/fvtt-pegasus-rpg-v11.0.3.zip",
"version": "11.0.4",
"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"
}

View File

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

View File

@ -26,7 +26,7 @@
</select>
</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 data.resistance}}
{{{optionsDiceList}}}

View File

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

View File

@ -87,7 +87,7 @@
<div class="flexrow dice-pool-stack">
{{#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"
src="{{dice.img}}"></a></span>
src="{{dice.img}}" alt="dices"></a></span>
{{/each}}
</div>
</div>
@ -100,10 +100,24 @@
<div class="flexrow">
{{#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"
src="{{dice.img}}"></a></span>
src="{{dice.img}}" alt="dices"></a></span>
{{/each}}
</div>
{{/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">