Manage weapons

This commit is contained in:
LeRatierBretonnien 2023-01-22 20:27:22 +01:00
parent 17e8fb4aa6
commit 8f9ecff285
5 changed files with 81 additions and 43 deletions

View File

@ -62,8 +62,8 @@ export class Avd12Actor extends Actor {
/* -------------------------------------------- */ /* -------------------------------------------- */
rebuildSkills() { rebuildSkills() {
let armorPenalties = Avd12Utility.getArmorPenalty( this.items.find( item => item.type == "armor") ) let armorPenalties = Avd12Utility.getArmorPenalty(this.items.find(item => item.type == "armor"))
let shieldPenalties = Avd12Utility.getArmorPenalty( this.items.find( item => item.type == "shield") ) let shieldPenalties = Avd12Utility.getArmorPenalty(this.items.find(item => item.type == "shield"))
for (let attrKey in this.system.attributes) { for (let attrKey in this.system.attributes) {
let attr = this.system.attributes[attrKey] let attr = this.system.attributes[attrKey]
@ -76,17 +76,17 @@ export class Avd12Actor extends Actor {
skill.modifier += Number(trait.system.bonusvalue) skill.modifier += Number(trait.system.bonusvalue)
} }
// Apply armor penalties // Apply armor penalties
if ( armorPenalties[skillKey]) { if (armorPenalties[skillKey]) {
console.log("Found armor penalties : ", armorPenalties, skillKey) console.log("Found armor penalties : ", armorPenalties, skillKey)
skill.modifier += Number(armorPenalties[skillKey]) skill.modifier += Number(armorPenalties[skillKey])
} }
// Apply shield penalties // Apply shield penalties
if ( shieldPenalties[skillKey]) { if (shieldPenalties[skillKey]) {
console.log("Found shield penalties : ", shieldPenalties, skillKey) console.log("Found shield penalties : ", shieldPenalties, skillKey)
skill.modifier += Number(shieldPenalties[skillKey]) skill.modifier += Number(shieldPenalties[skillKey])
} }
// Process additionnal bonuses // Process additionnal bonuses
for(let item of this.items) { for (let item of this.items) {
if (item.system.bonus && item.system.bonus[skillKey]) { if (item.system.bonus && item.system.bonus[skillKey]) {
skill.modifier += Number(item.system.bonus[skillKey].value) skill.modifier += Number(item.system.bonus[skillKey].value)
} }
@ -100,14 +100,27 @@ export class Avd12Actor extends Actor {
rebuildMitigations() { rebuildMitigations() {
for (let mitiKey in this.system.mitigation) { for (let mitiKey in this.system.mitigation) {
let mitigation = this.system.mitigation[mitiKey] let mitigation = this.system.mitigation[mitiKey]
for(let item of this.items) { for (let item of this.items) {
if (item.system.mitigation && item.system.mitigation[mitiKey]) { if (item.system.mitigation && item.system.mitigation[mitiKey]) {
mitigation.value += Number(item.system.mitigation[mitiKey].value) mitigation.value += Number(item.system.mitigation[mitiKey].value)
} }
} }
} }
} }
/* -------------------------------------------- */
rebuildBonus() {
for (let bonusKey in this.system.bonus) {
let bonus = this.system.bonus[bonusKey]
for (let content in bonus) {
let dataPath = bonusKey + "." + content
//console.log("Parsing", bonusKey, content, dataPath)
let availableTraits = this.items.filter(t => t.type == "trait" && t.system.computebonus && t.system.bonusdata == dataPath)
for (let trait of availableTraits) {
bonus[content] += Number(trait.system.bonusvalue)
}
}
}
}
/* -------------------------------------------- */ /* -------------------------------------------- */
prepareDerivedData() { prepareDerivedData() {
@ -118,6 +131,7 @@ export class Avd12Actor extends Actor {
this.rebuildSkills() this.rebuildSkills()
this.rebuildMitigations() this.rebuildMitigations()
this.rebuildBonus()
} }
super.prepareDerivedData(); super.prepareDerivedData();
@ -146,10 +160,23 @@ export class Avd12Actor extends Actor {
return comp; return comp;
} }
getEquippedWeapons() { getEquippedWeapons() {
let comp = duplicate(this.items.filter(item => item.type == 'weapon' && item.system.equipped) || []); let comp = duplicate(this.items.filter(item => item.type == 'weapon' && item.system.equipped) || [])
comp.forEach(item => {
this.prepareWeapon(item)
})
Avd12Utility.sortArrayObjectsByName(comp) Avd12Utility.sortArrayObjectsByName(comp)
return comp; return comp;
} }
/* -------------------------------------------- */
getWeapons() {
let comp = duplicate(this.items.filter(item => item.type == 'weapon') || [])
comp.forEach(item => {
this.prepareWeapon(item)
})
Avd12Utility.sortArrayObjectsByName(comp)
return comp;
}
/* -------------------------------------------- */ /* -------------------------------------------- */
getArmors() { getArmors() {
let comp = duplicate(this.items.filter(item => item.type == 'armor') || []); let comp = duplicate(this.items.filter(item => item.type == 'armor') || []);
@ -199,29 +226,29 @@ export class Avd12Actor extends Actor {
return comp; return comp;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
addDamages( damage) { addDamages(damage, bonusDamage) {
//console.log(damage) //console.log(damage)
if ( damage.damagetype != "none" && damage.dice ) { if (damage.damagetype != "none" && damage.dice) {
damage.normal = damage.dice + '+' + damage.bonus let fullBonus = Number(bonusDamage) + Number(damage.bonus)
damage.critical = damage.dice + '+' + Number(damage.bonus)*2 damage.normal = damage.dice + '+' + fullBonus
damage.critical = damage.dice + '+' + Number(fullBonus) * 2
let parser = damage.dice.match(/(\d+)(d\d+)/) let parser = damage.dice.match(/(\d+)(d\d+)/)
let nbDice = 2 let nbDice = 2
if (parser && parser[1]) { if (parser && parser[1]) {
nbDice = Number(parser[1]) * 2 nbDice = Number(parser[1]) * 2
} }
damage.brutal = nbDice + parser[2] + "+" + Number(damage.bonus)*2 damage.brutal = nbDice + parser[2] + "+" + Number(fullBonus) * 2
} }
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
getWeapons() { prepareWeapon(weapon) {
let comp = duplicate(this.items.filter(item => item.type == 'weapon') || []) weapon.attackBonus = this.system.bonus.weapon.attack + this.system.bonus[weapon.system.weapontype].attack
comp.forEach(item => { let bonusDamage = this.system.bonus.weapon.damage + this.system.bonus[weapon.system.weapontype].damage
this.addDamages(item.system.damages.primary) this.addDamages(weapon.system.damages.primary, bonusDamage)
this.addDamages(item.system.damages.secondary) bonusDamage = this.system.bonus.weapon.damage + this.system.bonus[weapon.system.weapontype].crits
this.addDamages(item.system.damages.tertiary) this.addDamages(weapon.system.damages.secondary, bonusDamage)
}) bonusDamage = this.system.bonus.weapon.damage + this.system.bonus[weapon.system.weapontype].brutals
Avd12Utility.sortArrayObjectsByName(comp) this.addDamages(weapon.system.damages.tertiary + bonusDamage)
return comp;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
getItemById(id) { getItemById(id) {
@ -403,7 +430,7 @@ export class Avd12Actor extends Actor {
/* -------------------------------------------- */ /* -------------------------------------------- */
async preprocessItem(event, item, onDrop = false) { async preprocessItem(event, item, onDrop = false) {
//console.log('ITEM', item) //console.log('ITEM', item)
if ( item.system.focus && item.system.focus?.isfocus) { if (item.system.focus && item.system.focus?.isfocus) {
let focusItem = this.items.find(it => it.system.focus?.isfocus) let focusItem = this.items.find(it => it.system.focus?.isfocus)
if (focusItem) { if (focusItem) {
ui.notifications.warn("You already have a Focus Item in your equipment.") ui.notifications.warn("You already have a Focus Item in your equipment.")
@ -421,22 +448,22 @@ export class Avd12Actor extends Actor {
let focus = this.items.find(it => it.system.focus?.isfocus) let focus = this.items.find(it => it.system.focus?.isfocus)
if (focus) { if (focus) {
let focusData = Avd12Utility.computeFocusData(focus.system.focus) let focusData = Avd12Utility.computeFocusData(focus.system.focus)
let focusBonus = this.items.filter( it => it.system.focuspointsbonus > 0).reduce((sum, item2) => sum = item2.system.focuspointsbonus, 0) let focusBonus = this.items.filter(it => it.system.focuspointsbonus > 0).reduce((sum, item2) => sum = item2.system.focuspointsbonus, 0)
let focusregenbonus = this.items.filter( it => it.system.focusregenbonus > 0).reduce((sum, item2) => sum = item2.system.focusregenbonus, 0) let focusregenbonus = this.items.filter(it => it.system.focusregenbonus > 0).reduce((sum, item2) => sum = item2.system.focusregenbonus, 0)
let burnchancebonus = this.items.filter( it => it.system.burnchancebonus > 0).reduce((sum, item2) => sum = item2.system.burnchancebonus, 0) let burnchancebonus = this.items.filter(it => it.system.burnchancebonus > 0).reduce((sum, item2) => sum = item2.system.burnchancebonus, 0)
let focusPoints = focusData.focusPoints + focusBonus let focusPoints = focusData.focusPoints + focusBonus
let focusRegen = focusData.focusRegen + focusregenbonus let focusRegen = focusData.focusRegen + focusregenbonus
//console.log("Update focus", focusPoints, focusRegen) //console.log("Update focus", focusPoints, focusRegen)
if ( focusPoints != this.system.focus.focuspoints || focusRegen != this.system.focus.focusregen) { if (focusPoints != this.system.focus.focuspoints || focusRegen != this.system.focus.focusregen) {
let focusData = duplicate(this.system.focus) let focusData = duplicate(this.system.focus)
focusData.focuspoints = focusPoints focusData.focuspoints = focusPoints
focusData.focusregen = focusRegen focusData.focusregen = focusRegen
this.update( {'system.focus': focusData}) this.update({ 'system.focus': focusData })
} }
//console.log("FINAL BONUS", focusBonus, focusregenbonus, burnchancebonus) //console.log("FINAL BONUS", focusBonus, focusregenbonus, burnchancebonus)
return { return {
focusPoints : focusPoints, focusPoints: focusPoints,
burnChance: focusData.burnChance + burnchancebonus, burnChance: focusData.burnChance + burnchancebonus,
focusRegen: focusRegen, focusRegen: focusRegen,
spellAttackBonus: focusData.spellAttackBonus, spellAttackBonus: focusData.spellAttackBonus,
@ -445,7 +472,7 @@ export class Avd12Actor extends Actor {
} }
} }
return { return {
focusPoints : 0, focusPoints: 0,
burnChance: 0, burnChance: 0,
focusRegen: 0, focusRegen: 0,
spellAttackBonus: 0, spellAttackBonus: 0,
@ -657,7 +684,7 @@ export class Avd12Actor extends Actor {
if (spell.system.spelltype != "utility") { if (spell.system.spelltype != "utility") {
this.startRoll(rollData) this.startRoll(rollData)
} else { } else {
this.spentFocusPoints( spell ) this.spentFocusPoints(spell)
let msg = await Avd12Utility.createChatWithRollMode(rollData.alias, { let msg = await Avd12Utility.createChatWithRollMode(rollData.alias, {
content: await renderTemplate(`systems/fvtt-avd12/templates/chat/chat-utility-spell.hbs`, rollData) content: await renderTemplate(`systems/fvtt-avd12/templates/chat/chat-utility-spell.hbs`, rollData)
}) })
@ -669,13 +696,13 @@ export class Avd12Actor extends Actor {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
spentFocusPoints( spell) { spentFocusPoints(spell) {
let spellCost = Avd12Utility.getSpellCost(spell) let spellCost = Avd12Utility.getSpellCost(spell)
let focusData = duplicate(this.system.focus) let focusData = duplicate(this.system.focus)
focusData.currentfocuspoints -= spellCost focusData.currentfocuspoints -= spellCost
focusData.currentfocuspoints = Math.max(focusData.currentfocuspoints, 0) focusData.currentfocuspoints = Math.max(focusData.currentfocuspoints, 0)
console.log("New fovcus", this.system, focusData) console.log("New fovcus", this.system, focusData)
this.update({'system.focus': focusData}) this.update({ 'system.focus': focusData })
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -683,6 +710,7 @@ export class Avd12Actor extends Actor {
let weapon = this.items.get(weaponId) let weapon = this.items.get(weaponId)
if (weapon) { if (weapon) {
weapon = duplicate(weapon) weapon = duplicate(weapon)
this.prepareWeapon(weapon)
let rollData = this.getCommonRollData() let rollData = this.getCommonRollData()
rollData.modifier = this.system.bonus[weapon.system.weapontype] rollData.modifier = this.system.bonus[weapon.system.weapontype]
rollData.mode = "weapon" rollData.mode = "weapon"
@ -698,7 +726,7 @@ export class Avd12Actor extends Actor {
let weapon = this.items.get(weaponId) let weapon = this.items.get(weaponId)
if (weapon) { if (weapon) {
weapon = duplicate(weapon) weapon = duplicate(weapon)
this.addDamages(weapon.system.damages.primary) this.prepareWeapon(weapon)
let rollData = this.getCommonRollData() let rollData = this.getCommonRollData()
rollData.damageFormula = weapon.system.damages.primary[damageType] rollData.damageFormula = weapon.system.damages.primary[damageType]
rollData.mode = "weapon-damage" rollData.mode = "weapon-damage"

View File

@ -536,6 +536,9 @@ export class Avd12Utility {
if (rollData.skill && rollData.skill.good) { if (rollData.skill && rollData.skill.good) {
diceFormula += "+1d4" diceFormula += "+1d4"
} }
if (rollData.weapon ) {
diceFormula += "+" + rollData.weapon.attackBonus
}
rollData.diceFormula = diceFormula rollData.diceFormula = diceFormula
// Performs roll // Performs roll

View File

@ -64,7 +64,7 @@
], ],
"title": "AnyVenture D12 RPG", "title": "AnyVenture D12 RPG",
"url": "https://www.uberwald.me/gitea/public/fvtt-avd12", "url": "https://www.uberwald.me/gitea/public/fvtt-avd12",
"version": "10.0.17", "version": "10.0.18",
"download": "https://www.uberwald.me/gitea/public/fvtt-avd12/archive/fvtt-avd12-v10.0.17.zip", "download": "https://www.uberwald.me/gitea/public/fvtt-avd12/archive/fvtt-avd12-v10.0.18.zip",
"background": "systems/fvtt-avd12/images/ui/avd12_welcome_page.webp" "background": "systems/fvtt-avd12/images/ui/avd12_welcome_page.webp"
} }

View File

@ -212,7 +212,7 @@
<label class="short-label">Brutal</label> <label class="short-label">Brutal</label>
</span> </span>
</li> </li>
{{#each weapons as |weapon key|}} {{#each equippedWeapons as |weapon key|}}
<li class="item flexrow list-item list-item-shadow" data-item-id="{{weapon._id}}"> <li class="item flexrow list-item list-item-shadow" data-item-id="{{weapon._id}}">
<a class="item-edit item-name-img" title="Edit Item"><img class="sheet-competence-img" <a class="item-edit item-name-img" title="Edit Item"><img class="sheet-competence-img"
src="{{weapon.img}}" /></a> src="{{weapon.img}}" /></a>

View File

@ -15,6 +15,13 @@
</div> </div>
{{/if}} {{/if}}
{{#if weapon}}
<div class="flexrow">
<span class="roll-dialog-label">Weapon Attack Bonus : </span>
<span class="roll-dialog-label">{{weapon.attackBonus}}</span>
</div>
{{/if}}
{{#if spell}} {{#if spell}}
<div class="flexrow"> <div class="flexrow">
<span class="roll-dialog-label">Spell : </span> <span class="roll-dialog-label">Spell : </span>