Automatisations de combats, WIP
This commit is contained in:
@@ -47,6 +47,12 @@ export class MournbladeActor extends Actor {
|
||||
return super.create(data, options);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
setModifier(name, type, value) {
|
||||
this.createEmbeddedDocuments("Item", [{ type: "modifier", name: name, system: { modifiertype: type, value: value } }])
|
||||
ui.notifications.info("Le modificateur " + name + " a été ajouté à " + this.name + ".")
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
prepareArme(arme) {
|
||||
arme = duplicate(arme)
|
||||
@@ -102,6 +108,20 @@ export class MournbladeActor extends Actor {
|
||||
return armes
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getModifiersForRoll() {
|
||||
let modifiers = []
|
||||
for (let mod of this.items) {
|
||||
if (mod.type == "modifier" && mod.system.modifiertype == "roll") {
|
||||
let modObj = mod.toObject()
|
||||
modObj .system.apply = true
|
||||
modifiers.push( modObj )
|
||||
}
|
||||
}
|
||||
MournbladeUtility.sortArrayObjectsByName(modifiers)
|
||||
return modifiers
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getItemSorted( types) {
|
||||
let items = this.items.filter(item => types.includes(item.type )) || []
|
||||
@@ -120,6 +140,9 @@ export class MournbladeActor extends Actor {
|
||||
getEquipments() {
|
||||
return this.getItemSorted(["equipement"])
|
||||
}
|
||||
getModifiers() {
|
||||
return this.getItemSorted(["modifier"])
|
||||
}
|
||||
getTraitsChaotiques() {
|
||||
return this.getItemSorted(["traitchaotique"])
|
||||
}
|
||||
@@ -165,6 +188,17 @@ export class MournbladeActor extends Actor {
|
||||
return comp
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getProtectionTotal() {
|
||||
let protection = 0
|
||||
for (let item of this.items) {
|
||||
if (item.type == "protection" && item.system.equipped) {
|
||||
protection += item.system.protection
|
||||
}
|
||||
}
|
||||
return protection
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getAspect() {
|
||||
return (this.system.balance.loi > this.system.balance.chaos) ? this.system.balance.loi : this.system.balance.chaos
|
||||
@@ -245,12 +279,31 @@ export class MournbladeActor extends Actor {
|
||||
/* -------------------------------------------- */
|
||||
async equipItem(itemId) {
|
||||
let item = this.items.find(item => item.id == itemId)
|
||||
if (item && item.system) {
|
||||
if (item?.system) {
|
||||
let update = { _id: item.id, "system.equipped": !item.system.equipped }
|
||||
await this.updateEmbeddedDocuments('Item', [update]); // Updates one EmbeddedEntity
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getStatusMalus() {
|
||||
let malusL = 0
|
||||
let malusNL = 0
|
||||
if (this.system.sante.base-this.system.sante.letaux < 10) {
|
||||
malusL = -2
|
||||
}
|
||||
if (this.system.sante.base-this.system.sante.letaux < 5) {
|
||||
malusL = -5
|
||||
}
|
||||
if (this.system.sante.base-this.system.sante.nonletaux < 10) {
|
||||
malusNL = -2
|
||||
}
|
||||
if (this.system.sante.base-this.system.sante.nonletaux < 5) {
|
||||
malusNL = -5
|
||||
}
|
||||
return Math.min(malusL, malusNL)
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
editItemField(itemId, itemType, itemField, dataType, value) {
|
||||
let item = this.items.find(item => item.id == itemId)
|
||||
@@ -266,6 +319,28 @@ export class MournbladeActor extends Actor {
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
incDecSante(type, value, applyArmure=true) {
|
||||
if (applyArmure) {
|
||||
let protection = this.getProtectionTotal()
|
||||
value -= protection
|
||||
value = Math.max(0, value)
|
||||
}
|
||||
if (value) {
|
||||
let newSante = duplicate(this.system.sante)
|
||||
newSante[type] += value
|
||||
if (newSante[type] > this.system.sante.base) {
|
||||
value -= this.system.sante.base - newSante[type]
|
||||
newSante[type] = this.system.sante.base
|
||||
}
|
||||
if (value && type == "nonletaux") {
|
||||
newSante["letaux"] += value
|
||||
}
|
||||
this.update({ 'system.sante': newSante })
|
||||
ui.notifications.info(this.name + "a subi " + value + " points de santé " + type + ".")
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getBonneAventure() {
|
||||
return this.system.bonneaventure.actuelle
|
||||
@@ -417,6 +492,8 @@ export class MournbladeActor extends Actor {
|
||||
rollData.doubleD20 = false
|
||||
rollData.attributs = MournbladeUtility.getAttributs()
|
||||
rollData.selectDifficulte = true
|
||||
rollData.malusSante = this.getStatusMalus() + this.system.sante.malusmanuel
|
||||
rollData.modifiers = this.getModifiersForRoll()
|
||||
|
||||
if (attrKey) {
|
||||
rollData.attrKey = attrKey
|
||||
|
||||
Reference in New Issue
Block a user