bol/module/actor/actor.js

660 lines
20 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() {
2022-02-23 20:39:58 +01:00
2022-07-01 15:48:54 +02:00
if (this.type === 'character') {
2022-07-01 16:30:21 +02:00
this.chartype = 'player'
this.villainy = false
2022-01-08 23:28:16 +01:00
}
2022-07-01 15:48:54 +02:00
if (this.type === 'encounter') {
2022-07-01 16:30:21 +02:00
this.chartype = 'tough'
this.villainy = true
2021-11-01 22:23:43 +01:00
}
2022-07-01 16:30:21 +02:00
super.prepareData()
}
/* -------------------------------------------- */
getCharType() {
if (this.type === 'character') {
return 'player'
}
return 'tough'
}
/* -------------------------------------------- */
getVillainy() {
if (this.type === 'character') {
return false
}
return true
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-07-01 15:48:54 +02:00
let newVitality = 10 + this.system.attributes.vigor.value + this.system.resources.hp.bonus
if (this.system.resources.hp.max != newVitality) {
this.update({ 'system.resources.hp.max': newVitality })
2022-01-08 23:28:16 +01:00
}
2022-07-01 15:48:54 +02:00
let newPower = 10 + this.system.attributes.mind.value + this.system.resources.power.bonus
if (this.system.resources.power.max != newPower) {
this.update({ 'system.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
/* -------------------------------------------- */
2021-11-08 14:40:29 +01:00
get details() {
2022-07-01 15:48:54 +02:00
return this.system.details
2021-11-01 00:28:42 +01:00
}
2021-11-08 14:40:29 +01:00
get attributes() {
2022-07-01 15:48:54 +02:00
return Object.values(this.system.attributes)
2021-11-08 14:40:29 +01:00
}
get aptitudes() {
2022-07-01 15:48:54 +02:00
return Object.values(this.system.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-07-01 15:48:54 +02:00
if (fo.system.properties.used) {
this.updateEmbeddedDocuments("Item", [{ _id: fo._id, 'system.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-07-01 15:48:54 +02:00
if (fo && fo.system.properties.fightoptiontype == "intrepid") {
2022-03-10 21:05:53 +01:00
defMod += -2
}
2022-07-01 15:48:54 +02:00
if (fo && fo.system.properties.fightoptiontype == "fulldefense") {
2022-03-10 21:05:53 +01:00
defMod += 2
}
2022-07-01 15:48:54 +02:00
if (fo && fo.system.properties.fightoptiontype == "twoweaponsdef" && !fo.system.properties.used) {
2022-03-10 21:05:53 +01:00
defMod += 1
2022-07-01 15:48:54 +02:00
this.updateEmbeddedDocuments("Item", [{ _id: fo._id, 'system.properties.used': true }])
2022-03-10 21:05:53 +01:00
}
2022-07-01 15:48:54 +02:00
if (fo && fo.system.properties.fightoptiontype == "defense") {
2022-03-10 21:05:53 +01:00
defMod += 1
}
2022-07-01 15:48:54 +02:00
if (fo && fo.system.properties.fightoptiontype == "attack") {
2022-03-10 21:05:53 +01:00
defMod += -1
}
2022-07-01 15:48:54 +02:00
return this.system.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-07-01 15:48:54 +02:00
let it = this.items.find(i => i.type === "feature" && i.system.subtype === "fightoption" && i.system.properties.activated)
2022-03-10 21:05:53 +01:00
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-07-01 15:48:54 +02:00
let attr = duplicate(this.system.attributes[key])
2022-03-20 23:17:52 +01:00
if (attr) {
2022-03-21 23:21:05 +01:00
let nextXP = (attr.value == -1) ? 2 : attr.value + (attr.value + 1)
2022-07-01 15:48:54 +02:00
let xp = duplicate(this.system.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-07-01 15:48:54 +02:00
this.update({ [`system.attributes.${key}`]: attr, [`system.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-07-01 15:48:54 +02:00
let apt = duplicate(this.system.aptitudes[key])
2022-03-20 23:17:52 +01:00
if (apt) {
let nextXP = (apt.value == -1) ? 1 : apt.value + 2
2022-07-01 15:48:54 +02:00
let xp = duplicate(this.system.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-07-01 15:48:54 +02:00
this.update({ [`system.aptitudes.${key}`]: apt, [`system.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) {
2022-07-01 15:48:54 +02:00
let career = this.items.get(itemId)
2022-03-20 23:17:52 +01:00
if (career) {
career = duplicate(career)
2022-07-01 15:48:54 +02:00
let nextXP = career.system.rank + 1
let xp = duplicate(this.system.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-07-01 15:48:54 +02:00
this.update({ [`system.xp`]: xp })
this.updateEmbeddedDocuments('Item', [{ _id: career._id, 'system.rank': career.system.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-07-01 15:48:54 +02:00
let fightOption = this.items.get(itemId)
2022-03-10 21:05:53 +01:00
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)
2022-07-01 15:48:54 +02:00
if (fightOption.system.properties.activated) {
2022-03-10 21:05:53 +01:00
state = false
} else {
state = true
}
2022-07-01 15:48:54 +02:00
updates.push({ _id: fightOption._id, 'system.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) {
2022-07-01 15:48:54 +02:00
if (armor.system.properties.armorQuality.includes("light")) {
2022-03-10 21:05:53 +01:00
return 1
}
2022-07-01 15:48:54 +02:00
if (armor.system.properties.armorQuality.includes("medium")) {
2022-03-10 21:05:53 +01:00
return 2
}
2022-07-01 15:48:54 +02:00
if (armor.system.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-07-01 15:48:54 +02:00
return Object.values(this.system.resources)
2021-11-08 14:40:29 +01:00
}
get boons() {
2022-07-07 13:33:31 +02:00
return duplicate(this.items.filter(i => i.type === "feature" && i.system.subtype === "boon") || []);
2021-11-08 14:40:29 +01:00
}
get flaws() {
2022-07-07 13:33:31 +02:00
return duplicate(this.items.filter(i => i.type === "feature" && i.system.subtype === "flaw") || []);
2021-11-08 14:40:29 +01:00
}
get careers() {
2022-07-01 15:48:54 +02:00
return duplicate( this.items.filter(i => i.type === "feature" && i.system.subtype === "career") || [])
2021-11-08 14:40:29 +01:00
}
get origins() {
2022-07-01 15:48:54 +02:00
return this.items.filter(i => i.type === "feature" && i.system.subtype === "origin");
2021-11-08 14:40:29 +01:00
}
get races() {
2022-07-01 15:48:54 +02:00
return this.items.filter(i => i.type === "feature" && i.system.subtype === "race");
2021-11-08 14:40:29 +01:00
}
get languages() {
2022-07-01 15:48:54 +02:00
return this.items.filter(i => i.type === "feature" && i.system.subtype === "language")
2022-03-10 21:05:53 +01:00
}
get fightoptions() {
2022-07-01 15:48:54 +02:00
return this.items.filter(i => i.type === "feature" && i.system.subtype === "fightoption")
2021-11-08 14:40:29 +01:00
}
2022-05-23 18:38:51 +02:00
get godsfaith() {
2022-07-01 15:48:54 +02:00
return this.items.filter(i => i.type === "feature" && i.system.subtype === "godsfaith")
2022-05-23 18:38:51 +02:00
}
2021-11-08 14:40:29 +01:00
get features() {
2022-07-01 15:48:54 +02:00
return this.items.filter(i => i.type === "feature")
2021-11-08 14:40:29 +01:00
}
get equipment() {
2022-07-01 15:48:54 +02:00
return this.items.filter(i => i.type === "item")
2021-11-08 14:40:29 +01:00
}
2022-04-10 16:38:09 +02:00
get equipmentCreature() {
2022-07-01 15:48:54 +02:00
return this.items.filter(i => i.type === "item" && i.system.category === "equipment" && (( i.system.subtype === "weapon" && i.system.properties.natural === true) || (i.system.subtype === "armor")) )
2022-04-10 16:38:09 +02:00
}
2021-11-08 14:40:29 +01:00
get armors() {
2022-07-01 15:48:54 +02:00
return this.items.filter(i => i.type === "item" && i.system.category === "equipment" && i.system.subtype === "armor");
2021-11-08 14:40:29 +01:00
}
get helms() {
2022-07-01 15:48:54 +02:00
return this.items.filter(i => i.type === "item" && i.system.category === "equipment" && i.system.subtype === "helm");
2021-11-08 14:40:29 +01:00
}
get shields() {
2022-07-01 15:48:54 +02:00
return this.items.filter(i => i.type === "item" && i.system.category === "equipment" && i.system.subtype === "shield");
}
2022-03-21 23:21:05 +01:00
get weapons() {
2022-07-01 15:48:54 +02:00
return this.items.filter(i => i.type === "item" && i.system.category === "equipment" && i.system.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-07-01 15:48:54 +02:00
return this.items.filter(i => i.type === "item" && i.system.category === "spell");
2022-01-23 09:25:09 +01:00
}
get alchemy() {
2022-07-01 15:48:54 +02:00
return this.items.filter(i => i.type === "item" && i.system.category === "alchemy");
2022-01-23 09:25:09 +01:00
}
2021-11-08 14:40:29 +01:00
get melee() {
2022-07-01 15:48:54 +02:00
return this.weapons.filter(i => i.system.properties.melee === true);
2021-11-08 14:40:29 +01:00
}
2022-04-10 16:38:09 +02:00
get natural() {
2022-07-01 15:48:54 +02:00
return this.weapons.filter(i => i.system.properties.natural === true);
2022-04-10 16:38:09 +02:00
}
2021-11-08 14:40:29 +01:00
get ranged() {
2022-07-01 15:48:54 +02:00
return this.weapons.filter(i => i.system.properties.ranged === true);
}
get containers() {
2022-07-01 15:48:54 +02:00
return this.items.filter(i => i.type === "item" && i.system.category === "equipment" && i.system.subtype === "container");
2021-11-08 14:40:29 +01:00
}
get treasure() {
2022-07-01 15:48:54 +02:00
return this.items.filter(i => i.type === "item" && i.system.category === "equipment" && i.system.subtype === "currency");
}
get vehicles() {
2022-07-01 15:48:54 +02:00
return this.items.filter(i => i.type === "item" && i.system.category === "vehicle");
}
get ammos() {
2022-07-01 15:48:54 +02:00
return this.items.filter(i => i.type === "item" && i.system.category === "equipment" && i.system.subtype === "ammunition");
}
get misc() {
2022-07-01 15:48:54 +02:00
return this.items.filter(i => i.type === "item" && i.system.category === "equipment" && (i.system.subtype === "other" || i.system.subtype === "container" || i.system.subtype === "scroll" || i.system.subtype === "jewel"));
}
2022-03-21 23:21:05 +01:00
2022-02-18 21:58:53 +01:00
get bonusBoons() {
2022-07-07 13:33:31 +02:00
let boons = this.items.filter(i => i.type === "feature" && i.system.subtype === "boon" && i.system.properties.isbonusdice)
return duplicate( boons || [])
2022-02-18 21:58:53 +01:00
}
get malusFlaws() {
2022-07-07 13:33:31 +02:00
return duplicate( this.items.filter(i => i.type === "feature" && i.system.subtype === "flaw" && i.system.properties.ismalusdice) || []);
2022-02-18 21:58:53 +01:00
}
2022-03-21 23:21:05 +01:00
isSorcerer() {
2022-07-01 15:48:54 +02:00
if (this.careers.find(item => item.system.properties.sorcerer == true))
2022-01-23 09:25:09 +01:00
return true
return false
}
2022-03-21 23:21:05 +01:00
isAlchemist() {
2022-07-01 15:48:54 +02:00
if (this.careers.find(item => item.system.properties.alchemist == true))
2022-01-23 09:25:09 +01:00
return true
return false
}
2022-03-21 23:21:05 +01:00
isPriest() {
2022-07-01 15:48:54 +02:00
if (this.careers.find(item => item.system.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) {
2022-07-01 15:48:54 +02:00
if (armor.system.worn) {
ppCostArmor += Number(armor.system.properties.modifiers.powercost) || 0
}
}
return ppCostArmor
}
/*-------------------------------------------- */
getArmorAgiMalus() {
let malusAgi = 0
2022-03-27 22:56:43 +02:00
for (let armor of this.protections) {
2022-07-01 15:48:54 +02:00
if (armor.system.worn) {
malusAgi += Number(armor.system.properties.modifiers.agility) || 0
}
}
return malusAgi
}
/*-------------------------------------------- */
getArmorInitMalus() {
let malusInit = 0
2022-03-27 22:56:43 +02:00
for (let armor of this.protections) {
2022-07-01 15:48:54 +02:00
if (armor.system.worn) {
malusInit += Number(armor.system.properties.modifiers.init) || 0
}
}
return malusInit
}
/*-------------------------------------------- */
2022-03-21 23:21:05 +01:00
spendPowerPoint(ppCost) {
2022-07-01 15:48:54 +02:00
let newPP = this.system.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-06-11 20:56:35 +02:00
return newPP
2022-01-23 09:25:09 +01:00
}
/*-------------------------------------------- */
2022-03-21 23:21:05 +01:00
resetAlchemyStatus(alchemyId) {
2022-07-01 15:48:54 +02:00
let alchemy = this.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) {
2022-07-01 15:48:54 +02:00
let alchemy = this.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
2022-07-01 15:48:54 +02:00
if (this.system.resources.alchemypoints.value >= pcCost) {
let newPC = this.system.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-07-01 15:48:54 +02:00
newPC = alchemy.system.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
2022-06-11 10:21:18 +02:00
/*-------------------------------------------- */
2022-01-23 09:25:09 +01:00
getAlchemistBonus() {
2022-07-01 15:48:54 +02:00
let sorcerer = this.careers.find(item => item.system.properties.alchemist == true)
2022-01-23 09:25:09 +01:00
if (sorcerer) {
2022-07-01 15:48:54 +02:00
return sorcerer.system.rank
2022-01-23 09:25:09 +01:00
}
return 0;
}
2022-06-11 10:21:18 +02:00
/*-------------------------------------------- */
2022-01-23 09:25:09 +01:00
getSorcererBonus() {
2022-07-01 15:48:54 +02:00
let sorcerer = this.careers.find(item => item.system.properties.sorcerer == true)
2022-01-23 09:25:09 +01:00
if (sorcerer) {
2022-07-01 15:48:54 +02:00
return sorcerer.system.rank
2022-01-23 09:25:09 +01:00
}
return 0;
}
2022-06-11 10:21:18 +02:00
/*-------------------------------------------- */
2022-03-21 23:21:05 +01:00
heroReroll() {
2022-01-09 13:23:20 +01:00
if (this.type == 'character') {
2022-07-01 15:48:54 +02:00
return this.system.resources.hero.value > 0;
2022-01-09 13:23:20 +01:00
} else {
2022-07-01 15:48:54 +02:00
if (this.system.type == 'adversary') {
return this.system.resources.hero.value > 0;
2022-01-09 13:23:20 +01:00
}
}
return false
}
2022-01-08 23:28:16 +01:00
getResourcesFromType() {
let resources = {};
if (this.type == 'encounter') {
2022-07-01 15:48:54 +02:00
resources['hp'] = this.system.resources.hp;
if (this.system.type != 'base') {
resources['faith'] = this.system.resources.faith
resources['power'] = this.system.resources.power
2022-01-08 23:28:16 +01:00
}
2022-07-01 15:48:54 +02:00
if (this.system.type == 'adversary') {
resources['hero'] = duplicate(this.system.resources.hero)
2022-01-08 23:28:16 +01:00
resources['hero'].label = "BOL.resources.villainy"
}
} else {
2022-07-01 15:48:54 +02:00
resources = this.system.resources;
2022-01-08 23:28:16 +01:00
}
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
2022-05-23 18:38:51 +02:00
},
"godsfaith": {
"label": "BOL.featureSubtypes.gods",
"ranked": false,
"items": this.godsfaith
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-04-10 16:38:09 +02:00
buildCombatCreature() {
return {
"natural": {
"label": "BOL.combatCategory.natural",
"weapon": true,
"protection": false,
"blocking": false,
"ranged": false,
"options": false,
"items": this.natural
},
"protections": {
"label": "BOL.combatCategory.protections",
"weapon": false,
"protection": true,
"blocking": false,
"ranged": false,
"options": false,
"items": this.protections
},
}
}
2022-03-21 23:21:05 +01:00
/*-------------------------------------------- */
buildRollList() {
let rolls = []
2022-07-01 15:48:54 +02:00
for (let key in this.system.attributes) {
let attr = this.system.attributes[key]
rolls.push({ key: key, value: attr.value, name: attr.label, type: "attribute" })
2022-03-21 23:21:05 +01:00
}
2022-07-01 15:48:54 +02:00
for (let key in this.system.aptitudes) {
if (key != "def") {
2022-07-01 15:48:54 +02:00
let apt = this.system.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() {
2022-05-23 18:38:51 +02:00
return this.melee.concat(this.ranged).concat(this.natural)
2022-03-21 23:21:05 +01:00
}
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)
2022-07-01 15:48:54 +02:00
if (lastHP != this.system.resources.hp.value && game.user.isGM ) { // Only GM sends this
await this.setFlag("world", hpID, this.system.resources.hp.value)
if (this.system.resources.hp.value <= 0) {
2022-02-20 10:12:25 +01:00
ChatMessage.create({
alias: this.name,
whisper: BoLUtility.getWhisperRecipientsAndGMs(this.name),
2022-07-01 15:48:54 +02:00
content: await renderTemplate('systems/bol/templates/chat/chat-vitality-zero.hbs', { name: this.name, img: this.img, hp: this.system.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-07-01 15:48:54 +02:00
this.update({ 'system.combat.lastinit': initScore, 'system.combat.iscritical': isCritical, 'system.combat.isfumble': isFumble })
2022-01-16 22:53:41 +01:00
}
/*-------------------------------------------- */
getLastInitData() {
2022-07-01 15:48:54 +02:00
return this.system.combat
2022-01-16 22:53:41 +01:00
}
2021-12-29 19:15:06 +01:00
/*-------------------------------------------- */
2022-03-21 23:21:05 +01:00
async subHeroPoints(nb) {
2022-07-01 15:48:54 +02:00
let newHeroP = this.system.resources.hero.value - nb;
2022-03-21 23:21:05 +01:00
newHeroP = (newHeroP < 0) ? 0 : newHeroP;
2022-07-01 15:48:54 +02:00
await this.update({ 'system.resources.hero.value': newHeroP });
2021-12-29 19:15:06 +01:00
}
/*-------------------------------------------- */
2022-03-21 23:21:05 +01:00
async sufferDamage(damage) {
2022-07-01 15:48:54 +02:00
let newHP = this.system.resources.hp.value - damage
await this.update({ 'system.resources.hp.value': newHP })
2021-12-29 19:15:06 +01:00
}
/* -------------------------------------------- */
2022-03-21 23:21:05 +01:00
getArmorFormula() {
2022-07-01 15:48:54 +02:00
let protectWorn = this.protections.filter(item => item.system.worn)
2021-12-29 19:15:06 +01:00
let formula = ""
for (let protect of protectWorn) {
2022-07-01 15:48:54 +02:00
if (protect.system.subtype == 'helm') {
2022-03-21 23:21:05 +01:00
formula += "+1"
2022-07-01 15:48:54 +02:00
} else if (protect.system.subtype == 'armor') {
2022-03-21 23:21:05 +01:00
if (BoLUtility.getRollArmor()) {
2022-07-01 15:48:54 +02:00
if (!protect.system.properties.soak.formula || protect.system.properties.soak.formula == "") {
2022-03-21 23:21:05 +01:00
ui.notifications.warn(`L'armure ${protect.name} n'a pas de formule pour la protection !`)
} else {
2022-07-01 15:48:54 +02:00
formula += "+" + " max(" + protect.system.properties.soak.formula +",0)"
2022-02-23 20:39:58 +01:00
}
2022-03-21 23:21:05 +01:00
} else {
2022-07-01 15:48:54 +02:00
if (protect.system.properties.soak.value == undefined) {
2022-03-21 23:21:05 +01:00
ui.notifications.warn(`L'armure ${protect.name} n'a pas de valeur fixe pour la protection !`)
} else {
2022-07-01 15:48:54 +02:00
formula += "+ " + protect.system.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) {
2022-07-01 15:48:54 +02:00
let armor = duplicate(this.items.get(itemId))
2022-03-21 23:21:05 +01:00
if (armor) {
2022-07-01 15:48:54 +02:00
let armorFormula = "max("+armor.system.properties.soak.formula + ", 0)"
2022-01-16 22:06:49 +01:00
let rollArmor = new Roll(armorFormula)
2022-05-10 23:04:04 +02:00
rollArmor.roll({ async: false }).toMessage()
2022-01-16 22:06:49 +01:00
}
}
/* -------------------------------------------- */
2022-03-21 23:21:05 +01:00
rollWeaponDamage(itemId) {
2022-07-01 16:00:49 +02:00
let weapon = duplicate(this.items.get(itemId))
2022-03-21 23:21:05 +01:00
if (weapon) {
2022-05-10 23:04:04 +02:00
let r = new BoLDefaultRoll({ id: randomID(16), isSuccess: true, mode: "weapon", weapon: weapon, actorId: this.id, 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) {
2022-07-01 15:48:54 +02:00
const equipable = item.system.properties.equipable;
2022-03-21 23:21:05 +01:00
if (equipable) {
2022-07-01 15:48:54 +02:00
let itemData = duplicate(item);
itemData.system.worn = !itemData.system.worn;
return item.update(itemData);
}
}
2021-07-08 10:12:12 +02:00
}