bol/module/actor/actor.js

613 lines
19 KiB
JavaScript
Raw Normal View History

2022-01-16 22:06:49 +01:00
import { BoLDefaultRoll } from "../controllers/bol-rolls.js";
2022-02-18 22:15:46 +01:00
import { BoLUtility } from "../system/bol-utility.js";
2022-01-16 22:06:49 +01:00
2021-07-08 10:12:12 +02:00
/**
* Extend the base Actor entity by defining a custom roll data structure which is ideal for the Simple system.
* @extends {Actor}
*/
export class BoLActor extends Actor {
2022-03-21 23:21:05 +01:00
2021-07-08 10:12:12 +02:00
/** @override */
prepareData() {
const actorData = this.data;
2022-02-23 20:39:58 +01:00
2021-11-01 22:23:43 +01:00
if (actorData.type === 'character') {
2022-01-08 23:28:16 +01:00
actorData.type = 'player';
actorData.villainy = false;
}
if (actorData.type === 'encounter') {
actorData.type = 'tough';
actorData.villainy = true;
2021-11-01 22:23:43 +01:00
}
2022-01-03 00:09:27 +01:00
super.prepareData();
2021-07-08 10:12:12 +02:00
}
2022-01-03 00:09:27 +01:00
/* -------------------------------------------- */
2022-03-21 23:21:05 +01:00
updateResourcesData() {
if (this.type == 'character') {
2022-01-08 23:28:16 +01:00
let newVitality = 10 + this.data.data.attributes.vigor.value + this.data.data.resources.hp.bonus
2022-03-21 23:21:05 +01:00
if (this.data.data.resources.hp.max != newVitality) {
this.update({ 'data.resources.hp.max': newVitality });
2022-01-08 23:28:16 +01:00
}
let newPower = 10 + this.data.data.attributes.mind.value + this.data.data.resources.power.bonus
2022-03-21 23:21:05 +01:00
if (this.data.data.resources.power.max != newPower) {
this.update({ 'data.resources.power.max': newPower });
2022-01-08 23:28:16 +01:00
}
2021-11-01 22:23:43 +01:00
}
}
2021-12-29 19:15:06 +01:00
/* -------------------------------------------- */
2022-01-03 00:09:27 +01:00
prepareDerivedData() {
super.prepareDerivedData()
this.updateResourcesData()
this.manageHealthState();
2021-12-29 19:15:06 +01:00
}
2022-01-03 00:09:27 +01:00
2021-11-01 00:28:42 +01:00
/* -------------------------------------------- */
2022-03-21 23:21:05 +01:00
get itemData() {
2022-03-10 21:05:53 +01:00
return Array.from(this.data.items.values()).map(i => i.data)
2021-11-01 00:28:42 +01:00
}
2021-11-08 14:40:29 +01:00
get details() {
2022-03-10 21:05:53 +01:00
return this.data.data.details
2021-11-01 00:28:42 +01:00
}
2021-11-08 14:40:29 +01:00
get attributes() {
2022-03-10 21:05:53 +01:00
return Object.values(this.data.data.attributes)
2021-11-08 14:40:29 +01:00
}
get aptitudes() {
2022-03-10 21:05:53 +01:00
return Object.values(this.data.data.aptitudes)
2021-11-08 14:40:29 +01:00
}
2022-03-10 21:39:12 +01:00
/* -------------------------------------------- */
2022-03-21 23:21:05 +01:00
clearRoundModifiers() { // Process data/items that are finished at end of a round
2022-03-10 21:39:12 +01:00
let foList = this.fightoptions
2022-03-21 23:21:05 +01:00
for (let fo of foList) {
2022-03-10 21:39:12 +01:00
if (fo.data.properties.used) {
2022-03-21 23:21:05 +01:00
this.updateEmbeddedDocuments("Item", [{ _id: fo._id, 'data.properties.used': false }])
2022-03-10 21:39:12 +01:00
}
}
}
2022-03-10 21:05:53 +01:00
/* -------------------------------------------- */
2021-12-25 23:26:27 +01:00
get defenseValue() {
2022-03-10 21:05:53 +01:00
let defMod = 0
let fo = this.getActiveFightOption()
2022-03-21 23:21:05 +01:00
if (fo && fo.data.properties.fightoptiontype == "intrepid") {
2022-03-10 21:05:53 +01:00
defMod += -2
}
2022-03-21 23:21:05 +01:00
if (fo && fo.data.properties.fightoptiontype == "fulldefense") {
2022-03-10 21:05:53 +01:00
defMod += 2
}
if (fo && fo.data.properties.fightoptiontype == "twoweaponsdef" && !fo.data.properties.used) {
defMod += 1
2022-03-21 23:21:05 +01:00
this.updateEmbeddedDocuments("Item", [{ _id: fo._id, 'data.properties.used': true }])
2022-03-10 21:05:53 +01:00
}
2022-03-21 23:21:05 +01:00
if (fo && fo.data.properties.fightoptiontype == "defense") {
2022-03-10 21:05:53 +01:00
defMod += 1
}
2022-03-21 23:21:05 +01:00
if (fo && fo.data.properties.fightoptiontype == "attack") {
2022-03-10 21:05:53 +01:00
defMod += -1
}
return this.data.data.aptitudes.def.value + defMod
2021-12-25 23:26:27 +01:00
}
2022-03-10 21:05:53 +01:00
/* -------------------------------------------- */
2022-03-21 23:21:05 +01:00
getActiveFightOption() {
2022-03-10 21:05:53 +01:00
let it = this.itemData.find(i => i.type === "feature" && i.data.subtype === "fightoption" && i.data.properties.activated)
if (it) {
return duplicate(it)
}
return undefined
}
2022-03-20 23:17:52 +01:00
/* -------------------------------------------- */
2022-03-21 23:21:05 +01:00
incAttributeXP(key) {
2022-03-20 23:17:52 +01:00
let attr = duplicate(this.data.data.attributes[key])
if (attr) {
2022-03-21 23:21:05 +01:00
let nextXP = (attr.value == -1) ? 2 : attr.value + (attr.value + 1)
2022-03-20 23:17:52 +01:00
let xp = duplicate(this.data.data.xp)
2022-03-21 23:21:05 +01:00
if (xp.total - xp.spent >= nextXP) {
2022-03-20 23:17:52 +01:00
attr.value += 1
xp.spent += nextXP
2022-03-21 23:21:05 +01:00
this.update({ [`data.attributes.${key}`]: attr, [`data.xp`]: xp })
2022-03-20 23:17:52 +01:00
} else {
ui.notifications.warn("Pas assez de points d'expérience !")
}
}
}
/* -------------------------------------------- */
2022-03-21 23:21:05 +01:00
incAptitudeXP(key) {
2022-03-20 23:17:52 +01:00
let apt = duplicate(this.data.data.aptitudes[key])
if (apt) {
let nextXP = (apt.value == -1) ? 1 : apt.value + 2
let xp = duplicate(this.data.data.xp)
2022-03-21 23:21:05 +01:00
if (xp.total - xp.spent >= nextXP) {
2022-03-20 23:17:52 +01:00
apt.value += 1
xp.spent += nextXP
2022-03-21 23:21:05 +01:00
this.update({ [`data.aptitudes.${key}`]: apt, [`data.xp`]: xp })
2022-03-20 23:17:52 +01:00
} else {
ui.notifications.warn("Pas assez de points d'expérience !")
}
}
}
/* -------------------------------------------- */
2022-03-21 23:21:05 +01:00
incCareerXP(itemId) {
let career = this.data.items.get(itemId)
2022-03-20 23:17:52 +01:00
if (career) {
career = duplicate(career)
let nextXP = career.data.rank + 1
let xp = duplicate(this.data.data.xp)
2022-03-21 23:21:05 +01:00
if (xp.total - xp.spent >= nextXP) {
2022-03-20 23:17:52 +01:00
xp.spent += nextXP
2022-03-21 23:21:05 +01:00
this.update({ [`data.xp`]: xp })
this.updateEmbeddedDocuments('Item', [{ _id: career._id, 'data.rank': career.data.rank + 1 }])
2022-03-20 23:17:52 +01:00
} else {
ui.notifications.warn("Pas assez de points d'expérience !")
}
}
}
2022-03-10 21:05:53 +01:00
/* -------------------------------------------- */
2022-03-21 23:21:05 +01:00
async toggleFightOption(itemId) {
2022-03-10 21:05:53 +01:00
let fightOption = this.data.items.get(itemId)
let state
let updates = []
2022-03-21 23:21:05 +01:00
if (fightOption) {
2022-03-10 21:05:53 +01:00
fightOption = duplicate(fightOption)
if (fightOption.data.properties.activated) {
state = false
} else {
state = true
}
2022-03-21 23:21:05 +01:00
updates.push({ _id: fightOption._id, 'data.properties.activated': state }) // Update the selected one
2022-03-10 21:05:53 +01:00
await this.updateEmbeddedDocuments("Item", updates) // Apply all changes
// Then notify
ChatMessage.create({
alias: this.name,
whisper: BoLUtility.getWhisperRecipientsAndGMs(this.name),
2022-03-21 23:21:05 +01:00
content: await renderTemplate('systems/bol/templates/chat/chat-activate-fight-option.hbs', { name: this.name, img: fightOption.img, foName: fightOption.name, state: state })
2022-03-10 21:05:53 +01:00
})
}
}
/*-------------------------------------------- */
2022-03-10 21:05:53 +01:00
get armorMalusValue() { // used for Fight Options
2022-03-21 23:21:05 +01:00
for (let armor of this.armors) {
if (armor.data.properties.armorQuality.includes("light")) {
2022-03-10 21:05:53 +01:00
return 1
}
2022-03-21 23:21:05 +01:00
if (armor.data.properties.armorQuality.includes("medium")) {
2022-03-10 21:05:53 +01:00
return 2
}
2022-03-21 23:21:05 +01:00
if (armor.data.properties.armorQuality.includes("heavy")) {
2022-03-10 21:05:53 +01:00
return 3
}
}
return 0
}
2021-11-08 14:40:29 +01:00
get resources() {
2022-03-10 21:05:53 +01:00
return Object.values(this.data.data.resources)
2021-11-08 14:40:29 +01:00
}
get boons() {
return this.itemData.filter(i => i.type === "feature" && i.data.subtype === "boon");
}
get flaws() {
return this.itemData.filter(i => i.type === "feature" && i.data.subtype === "flaw");
}
get careers() {
return this.itemData.filter(i => i.type === "feature" && i.data.subtype === "career");
}
get origins() {
return this.itemData.filter(i => i.type === "feature" && i.data.subtype === "origin");
}
get races() {
return this.itemData.filter(i => i.type === "feature" && i.data.subtype === "race");
}
get languages() {
2022-03-10 21:05:53 +01:00
return this.itemData.filter(i => i.type === "feature" && i.data.subtype === "language")
}
get fightoptions() {
return this.itemData.filter(i => i.type === "feature" && i.data.subtype === "fightoption")
2021-11-08 14:40:29 +01:00
}
get features() {
2022-03-10 21:05:53 +01:00
return this.itemData.filter(i => i.type === "feature")
2021-11-08 14:40:29 +01:00
}
get equipment() {
2022-03-10 21:05:53 +01:00
return this.itemData.filter(i => i.type === "item")
2021-11-08 14:40:29 +01:00
}
get armors() {
2022-03-21 23:21:05 +01:00
return this.itemData.filter(i => i.type === "item" && i.data.category === "equipment" && i.data.subtype === "armor");
2021-11-08 14:40:29 +01:00
}
get helms() {
return this.itemData.filter(i => i.type === "item" && i.data.category === "equipment" && i.data.subtype === "helm");
2021-11-08 14:40:29 +01:00
}
get shields() {
return this.itemData.filter(i => i.type === "item" && i.data.category === "equipment" && i.data.subtype === "shield");
}
2022-03-21 23:21:05 +01:00
get weapons() {
return this.itemData.filter(i => i.type === "item" && i.data.category === "equipment" && i.data.subtype === "weapon");
2021-11-08 14:40:29 +01:00
}
get protections() {
return this.armors.concat(this.helms).concat(this.shields)
2021-11-08 14:40:29 +01:00
}
2022-01-23 09:25:09 +01:00
get spells() {
2022-03-21 23:21:05 +01:00
return this.itemData.filter(i => i.type === "item" && i.data.category === "spell");
2022-01-23 09:25:09 +01:00
}
get alchemy() {
2022-03-21 23:21:05 +01:00
return this.itemData.filter(i => i.type === "item" && i.data.category === "alchemy");
2022-01-23 09:25:09 +01:00
}
2021-11-08 14:40:29 +01:00
get melee() {
return this.weapons.filter(i => i.data.properties.melee === true);
2021-11-08 14:40:29 +01:00
}
get ranged() {
return this.weapons.filter(i => i.data.properties.ranged === true);
}
get containers() {
return this.itemData.filter(i => i.type === "item" && i.data.category === "equipment" && i.data.subtype === "container");
2021-11-08 14:40:29 +01:00
}
get treasure() {
return this.itemData.filter(i => i.type === "item" && i.data.category === "equipment" && i.data.subtype === "currency");
}
get vehicles() {
return this.itemData.filter(i => i.type === "item" && i.data.category === "vehicle");
}
get ammos() {
return this.itemData.filter(i => i.type === "item" && i.data.category === "equipment" && i.data.subtype === "ammunition");
}
get misc() {
2022-03-21 23:21:05 +01:00
return this.itemData.filter(i => i.type === "item" && i.data.category === "equipment" && (i.data.subtype === "other" || i.data.subtype === "container" || i.data.subtype === "scroll" || i.data.subtype === "jewel"));
}
2022-03-21 23:21:05 +01:00
2022-02-18 21:58:53 +01:00
get bonusBoons() {
return this.itemData.filter(i => i.type === "feature" && i.data.subtype === "boon" && i.data.properties.isbonusdice);
}
get malusFlaws() {
return this.itemData.filter(i => i.type === "feature" && i.data.subtype === "flaw" && i.data.properties.ismalusdice);
}
2022-03-21 23:21:05 +01:00
isSorcerer() {
if (this.careers.find(item => item.data.properties.sorcerer == true))
2022-01-23 09:25:09 +01:00
return true
return false
}
2022-03-21 23:21:05 +01:00
isAlchemist() {
if (this.careers.find(item => item.data.properties.alchemist == true))
2022-01-23 09:25:09 +01:00
return true
return false
}
2022-03-21 23:21:05 +01:00
isPriest() {
if (this.careers.find(item => item.data.properties.priest == true))
2022-01-23 09:25:09 +01:00
return true
return false
}
/*-------------------------------------------- */
getPPCostArmor() {
let armors = this.armors
let ppCostArmor = 0
for (let armor of armors) {
if (armor.data.worn) {
ppCostArmor += Number(armor.data.properties.modifiers.powercost) || 0
}
}
return ppCostArmor
}
/*-------------------------------------------- */
getArmorAgiMalus() {
let malusAgi = 0
for (let armor of this.armors) {
if (armor.data.worn) {
malusAgi += Number(armor.data.properties.modifiers.agility) || 0
}
}
for (let shield of this.shields) {
if (shield.data.worn) {
malusAgi += Number(shield.data.properties.modifiers.agility) || 0
}
}
return malusAgi
}
/*-------------------------------------------- */
getArmorInitMalus() {
let armors = this.armors
let malusInit = 0
for (let armor of armors) {
if (armor.data.worn) {
malusInit += Number(armor.data.properties.modifiers.init) || 0
}
}
return malusInit
}
/*-------------------------------------------- */
2022-03-21 23:21:05 +01:00
spendPowerPoint(ppCost) {
2022-01-23 09:25:09 +01:00
let newPP = this.data.data.resources.power.value - ppCost
2022-03-21 23:21:05 +01:00
newPP = (newPP < 0) ? 0 : newPP
this.update({ 'data.resources.power.value': newPP })
2022-01-23 09:25:09 +01:00
}
/*-------------------------------------------- */
2022-03-21 23:21:05 +01:00
resetAlchemyStatus(alchemyId) {
let alchemy = this.data.items.get(alchemyId)
2022-01-23 09:25:09 +01:00
if (alchemy) {
2022-03-21 23:21:05 +01:00
this.updateEmbeddedDocuments('Item', [{ _id: alchemy.id, 'data.properties.pccurrent': 0 }])
2022-01-23 09:25:09 +01:00
}
}
/*-------------------------------------------- */
2022-03-21 23:21:05 +01:00
async spendAlchemyPoint(alchemyId, pcCost) {
let alchemy = this.data.items.get(alchemyId)
2022-01-23 09:25:09 +01:00
if (alchemy) {
2022-03-21 23:21:05 +01:00
pcCost = Number(pcCost) ?? 0
if (this.data.data.resources.alchemypoints.value >= pcCost) {
2022-01-23 09:25:09 +01:00
let newPC = this.data.data.resources.alchemypoints.value - pcCost
2022-03-21 23:21:05 +01:00
newPC = (newPC < 0) ? 0 : newPC
this.update({ 'data.resources.alchemypoints.value': newPC })
2022-01-23 09:25:09 +01:00
newPC = alchemy.data.data.properties.pccurrent + pcCost
2022-03-21 23:21:05 +01:00
await this.updateEmbeddedDocuments('Item', [{ _id: alchemy.id, 'data.properties.pccurrent': newPC }])
2022-01-23 09:25:09 +01:00
} else {
ui.notifications.warn("Plus assez de Points de Création !")
}
}
2022-03-21 23:21:05 +01:00
}
2022-01-23 09:25:09 +01:00
getAlchemistBonus() {
2022-03-21 23:21:05 +01:00
let sorcerer = this.careers.find(item => item.data.properties.alchemist == true)
2022-01-23 09:25:09 +01:00
if (sorcerer) {
return sorcerer.data.rank
}
return 0;
}
getSorcererBonus() {
2022-03-21 23:21:05 +01:00
let sorcerer = this.careers.find(item => item.data.properties.sorcerer == true)
2022-01-23 09:25:09 +01:00
if (sorcerer) {
return sorcerer.data.rank
}
return 0;
}
2022-03-21 23:21:05 +01:00
heroReroll() {
2022-01-09 13:23:20 +01:00
if (this.type == 'character') {
return this.data.data.resources.hero.value > 0;
} else {
if (this.data.data.type == 'adversary') {
return this.data.data.resources.hero.value > 0;
}
}
return false
}
2022-01-08 23:28:16 +01:00
getResourcesFromType() {
let resources = {};
if (this.type == 'encounter') {
resources['hp'] = this.data.data.resources.hp;
if (this.data.data.type != 'base') {
resources['faith'] = this.data.data.resources.faith
resources['power'] = this.data.data.resources.power
}
if (this.data.data.type == 'adversary') {
resources['hero'] = duplicate(this.data.data.resources.hero)
resources['hero'].label = "BOL.resources.villainy"
}
} else {
resources = this.data.data.resources;
}
return resources
}
2022-03-21 23:21:05 +01:00
buildFeatures() {
2021-11-08 14:40:29 +01:00
return {
"careers": {
"label": "BOL.featureCategory.careers",
"ranked": true,
"items": this.careers
},
"origins": {
"label": "BOL.featureCategory.origins",
"ranked": false,
"items": this.origins
},
"races": {
"label": "BOL.featureCategory.races",
"ranked": false,
"items": this.races
},
"boons": {
"label": "BOL.featureCategory.boons",
"ranked": false,
"items": this.boons
},
"flaws": {
"label": "BOL.featureCategory.flaws",
"ranked": false,
"items": this.flaws
},
"languages": {
"label": "BOL.featureCategory.languages",
"ranked": false,
"items": this.languages
2022-03-10 21:05:53 +01:00
},
"fightoptions": {
"label": "BOL.featureCategory.fightoptions",
"ranked": false,
"items": this.fightoptions
2021-11-08 14:40:29 +01:00
}
2022-03-10 21:05:53 +01:00
}
2021-11-08 14:40:29 +01:00
}
2022-03-21 23:21:05 +01:00
buildCombat() {
2021-11-08 14:40:29 +01:00
return {
2022-03-21 23:21:05 +01:00
"melee": {
"label": "BOL.combatCategory.melee",
"weapon": true,
"protection": false,
"blocking": false,
"ranged": false,
2022-03-10 21:05:53 +01:00
"options": false,
2022-03-21 23:21:05 +01:00
"items": this.melee
2021-11-08 14:40:29 +01:00
},
2022-03-21 23:21:05 +01:00
"ranged": {
"label": "BOL.combatCategory.ranged",
"weapon": true,
"protection": false,
"blocking": false,
"ranged": true,
2022-03-10 21:05:53 +01:00
"options": false,
2022-03-21 23:21:05 +01:00
"items": this.ranged
2021-11-08 14:40:29 +01:00
},
2022-03-21 23:21:05 +01:00
"protections": {
"label": "BOL.combatCategory.protections",
"weapon": false,
"protection": true,
"blocking": false,
"ranged": false,
2022-03-10 21:05:53 +01:00
"options": false,
2022-03-21 23:21:05 +01:00
"items": this.protections
2021-11-08 14:40:29 +01:00
},
2022-03-21 23:21:05 +01:00
"shields": {
"label": "BOL.combatCategory.shields",
"weapon": false,
"protection": false,
"blocking": true,
"ranged": false,
2022-03-10 21:05:53 +01:00
"options": false,
2022-03-21 23:21:05 +01:00
"items": this.shields
2022-03-10 21:05:53 +01:00
},
2022-03-21 23:21:05 +01:00
"fightoptions": {
"label": "BOL.combatCategory.fightOptions",
"weapon": false,
"protection": false,
"blocking": false,
"ranged": false,
2022-03-10 21:05:53 +01:00
"options": true,
2022-03-21 23:21:05 +01:00
"items": this.fightoptions
2021-11-08 14:40:29 +01:00
}
2022-03-10 21:05:53 +01:00
}
2021-11-01 00:28:42 +01:00
}
2021-12-29 19:15:06 +01:00
2022-03-21 23:21:05 +01:00
/*-------------------------------------------- */
buildRollList() {
let rolls = []
for (let key in this.data.data.attributes) {
2022-03-21 23:21:05 +01:00
let attr = this.data.data.attributes[key]
rolls.push({ key: key, value: attr.value, name: attr.label, type: "attribute" })
2022-03-21 23:21:05 +01:00
}
for (let key in this.data.data.aptitudes) {
if (key != "def") {
2022-03-21 23:21:05 +01:00
let apt = this.data.data.aptitudes[key]
rolls.push({ key: key, value: apt.value, name: apt.label, type: "aptitude" })
2022-03-21 23:21:05 +01:00
}
}
return rolls
}
/*-------------------------------------------- */
buildListeActions() {
return this.melee.concat(this.ranged)
}
2021-12-29 19:15:06 +01:00
/*-------------------------------------------- */
2022-02-18 22:15:46 +01:00
async manageHealthState() {
2022-03-21 23:21:05 +01:00
let hpID = "lastHP" + this.id
let lastHP = await this.getFlag("world", hpID)
if (lastHP != this.data.data.resources.hp.value) {
2022-03-21 13:28:27 +01:00
await this.setFlag("world", hpID, this.data.data.resources.hp.value)
2022-03-21 23:21:05 +01:00
if (this.data.data.resources.hp.value <= 0) {
2022-02-20 10:12:25 +01:00
ChatMessage.create({
alias: this.name,
whisper: BoLUtility.getWhisperRecipientsAndGMs(this.name),
2022-03-21 23:21:05 +01:00
content: await renderTemplate('systems/bol/templates/chat/chat-vitality-zero.hbs', { name: this.name, img: this.img, hp: this.data.data.resources.hp.value })
2022-02-20 10:12:25 +01:00
})
}
2021-12-29 19:15:06 +01:00
}
}
2022-01-16 22:53:41 +01:00
/*-------------------------------------------- */
registerInit(initScore, isCritical, isFumble) {
2022-03-21 23:21:05 +01:00
this.update({ 'data.combat.lastinit': initScore, 'data.combat.iscritical': isCritical, 'data.combat.isfumble': isFumble })
2022-01-16 22:53:41 +01:00
}
/*-------------------------------------------- */
getLastInitData() {
return this.data.data.combat
}
2021-12-29 19:15:06 +01:00
/*-------------------------------------------- */
2022-03-21 23:21:05 +01:00
async subHeroPoints(nb) {
2021-12-29 19:15:06 +01:00
let newHeroP = this.data.data.resources.hero.value - nb;
2022-03-21 23:21:05 +01:00
newHeroP = (newHeroP < 0) ? 0 : newHeroP;
await this.update({ 'data.resources.hero.value': newHeroP });
2021-12-29 19:15:06 +01:00
}
/*-------------------------------------------- */
2022-03-21 23:21:05 +01:00
async sufferDamage(damage) {
2021-12-29 19:15:06 +01:00
let newHP = this.data.data.resources.hp.value - damage;
2022-03-21 23:21:05 +01:00
await this.update({ 'data.resources.hp.value': newHP });
2021-12-29 19:15:06 +01:00
}
/* -------------------------------------------- */
2022-03-21 23:21:05 +01:00
getArmorFormula() {
let protectWorn = this.protections.filter(item => item.data.worn)
2021-12-29 19:15:06 +01:00
let formula = ""
for (let protect of protectWorn) {
2022-03-21 23:21:05 +01:00
if (protect.data.subtype == 'helm') {
formula += "+1"
} else if (protect.data.subtype == 'armor') {
if (BoLUtility.getRollArmor()) {
if (!protect.data.properties.soak.formula || protect.data.properties.soak.formula == "") {
ui.notifications.warn(`L'armure ${protect.name} n'a pas de formule pour la protection !`)
} else {
2022-02-23 20:39:58 +01:00
formula += "+" + protect.data.properties.soak.formula
}
2022-03-21 23:21:05 +01:00
} else {
if (protect.data.properties.soak.value == undefined) {
ui.notifications.warn(`L'armure ${protect.name} n'a pas de valeur fixe pour la protection !`)
} else {
formula += "+ " + protect.data.properties.soak.value
2022-02-23 20:39:58 +01:00
}
}
2021-12-29 19:15:06 +01:00
}
}
console.log("Protect Formula", formula)
2022-03-21 23:21:05 +01:00
return (formula == "") ? "0" : formula;
2021-12-29 19:15:06 +01:00
}
2022-01-16 22:06:49 +01:00
/* -------------------------------------------- */
2022-03-21 23:21:05 +01:00
rollProtection(itemId) {
let armor = this.data.items.get(itemId)
if (armor) {
let armorFormula = armor.data.data.properties.soak.formula;
2022-01-16 22:06:49 +01:00
let rollArmor = new Roll(armorFormula)
2022-03-21 23:21:05 +01:00
rollArmor.roll({ async: false }).toMessage();
2022-01-16 22:06:49 +01:00
}
}
/* -------------------------------------------- */
2022-03-21 23:21:05 +01:00
rollWeaponDamage(itemId) {
let weapon = this.data.items.get(itemId)
if (weapon) {
let r = new BoLDefaultRoll({ id: randomID(16), isSuccess: true, mode: "weapon", weapon: weapon, actor: this })
2022-01-16 22:06:49 +01:00
r.setSuccess(true)
2022-02-02 09:35:32 +01:00
r.rollDamage()
2022-01-16 22:06:49 +01:00
}
}
2021-11-01 00:28:42 +01:00
/* -------------------------------------------- */
toggleEquipItem(item) {
const equipable = item.data.data.properties.equipable;
2022-03-21 23:21:05 +01:00
if (equipable) {
let itemData = duplicate(item.data);
itemData.data.worn = !itemData.data.worn;
return item.update(itemData);
}
}
2021-07-08 10:12:12 +02:00
}