Gestion des hordes et divers améliorations + traduction espagnole
This commit is contained in:
@@ -7,6 +7,35 @@ import { BoLUtility } from "../system/bol-utility.js";
|
||||
*/
|
||||
export class BoLActor extends Actor {
|
||||
|
||||
static async create(data, options) {
|
||||
|
||||
// Case of compendium global import
|
||||
if (data instanceof Array) {
|
||||
return super.create(data, options);
|
||||
}
|
||||
// If the created actor has items (only applicable to duplicated actors) bypass the new actor creation logic
|
||||
if (data.items) {
|
||||
let actor = super.create(data, options);
|
||||
return actor;
|
||||
}
|
||||
|
||||
if (data.type == 'horde') {
|
||||
let weapon = {
|
||||
name: game.i18n.localize("BOL.ui.hordeAttack"), type: "item",
|
||||
img: "ui/icons/attaque_melee.webp",
|
||||
system: foundry.utils.duplicate(game.bol.config.defaultNaturalWeapon)
|
||||
}
|
||||
weapon.system.properties.attackModifiers = 1
|
||||
weapon.system.properties.damage = "1d6M"
|
||||
data.items = [ weapon ]
|
||||
|
||||
data.img = "systems/bol/ui/icons/icon-horde-token.webp"
|
||||
data.prototypeToken = { texture: "systems/bol/ui/icons/icon-horde-token.webp" }
|
||||
}
|
||||
|
||||
return super.create(data, options);
|
||||
}
|
||||
|
||||
/** @override */
|
||||
prepareData() {
|
||||
|
||||
@@ -18,9 +47,31 @@ export class BoLActor extends Actor {
|
||||
this.chartype = 'tough'
|
||||
this.villainy = true
|
||||
}
|
||||
if (this.type == "horde") {
|
||||
let weapon = this.items.find(i => i.type === "item" && i.system.subtype === "weapon")
|
||||
// Check if the horde attack is inline with the hordesize
|
||||
if (weapon?.system?.properties?.attackModifiers != this.system.hordesize) {
|
||||
this.updateEmbeddedDocuments('Item', [{ _id: weapon.id, 'system.properties.attackModifiers': this.system.hordesize }])
|
||||
}
|
||||
}
|
||||
|
||||
super.prepareData()
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async _onCreateOperation(documents, operation, user) {
|
||||
await super._onCreateOperation(documents, operation, user);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getTokenSizeFromHordeSize(hordeSize) {
|
||||
hordeSize = hordeSize || this.system.hordesize
|
||||
// If size > 50 then max is 50
|
||||
let size = Math.min(hordeSize, 20)
|
||||
// Compute the size of the token from 1 to 5
|
||||
let tokenSize = Math.max((size / 4), 1) // Never below 1
|
||||
return tokenSize
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async _preCreate(data, options, user) {
|
||||
@@ -39,7 +90,7 @@ export class BoLActor extends Actor {
|
||||
if (this.type === 'character') {
|
||||
return true
|
||||
}
|
||||
return (this.type === 'encounter' && this.chartype == "adversary")
|
||||
return (this.type === 'encounter' && this.chartype == "adversary")
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@@ -205,7 +256,7 @@ export class BoLActor extends Actor {
|
||||
/* -------------------------------------------- */
|
||||
addXPLog(type, name, cost, value) {
|
||||
let xplog = {
|
||||
name: "XP : "+game.i18n.localize(type), type: "feature",
|
||||
name: "XP : " + game.i18n.localize(type), type: "feature",
|
||||
img: "icons/magic/symbols/chevron-elipse-circle-blue.webp",
|
||||
system: {
|
||||
subtype: "xplog", properties: {
|
||||
@@ -264,7 +315,7 @@ export class BoLActor extends Actor {
|
||||
xp.spent += nextXP
|
||||
this.update({ [`system.xp`]: xp })
|
||||
this.updateEmbeddedDocuments('Item', [{ _id: career._id, 'system.rank': career.system.rank + 1 }])
|
||||
this.addXPLog("career", career.name, nextXP, career.system.rank+1)
|
||||
this.addXPLog("career", career.name, nextXP, career.system.rank + 1)
|
||||
} else {
|
||||
ui.notifications.warn("Pas assez de points d'expérience !")
|
||||
}
|
||||
@@ -419,7 +470,7 @@ export class BoLActor extends Actor {
|
||||
}
|
||||
|
||||
isSorcerer() {
|
||||
return (this.careers.find(item => item.system.properties.sorcerer ))
|
||||
return (this.careers.find(item => item.system.properties.sorcerer))
|
||||
}
|
||||
isAlchemist() {
|
||||
return (this.careers.find(item => item.system.properties.alchemist))
|
||||
@@ -612,7 +663,7 @@ export class BoLActor extends Actor {
|
||||
}
|
||||
/*-------------------------------------------- */
|
||||
getSorcererBonus() {
|
||||
let sorcerer = this.careers.find(item => item.system.properties.sorcerer )
|
||||
let sorcerer = this.careers.find(item => item.system.properties.sorcerer)
|
||||
if (sorcerer) {
|
||||
return sorcerer.system.rank
|
||||
}
|
||||
@@ -799,7 +850,7 @@ export class BoLActor extends Actor {
|
||||
}
|
||||
if (this.system.resources.hp.value < -5 && !dead) {
|
||||
await this.createEmbeddedDocuments("ActiveEffect", [
|
||||
{ name: game.i18n.localize('EFFECT.StatusDead'), icon: 'icons/svg/skull.svg', statuses: 'dead' }
|
||||
{ name: game.i18n.localize('EFFECT.StatusDead'), icon: 'icons/svg/skull.svg', statuses: 'dead' }
|
||||
])
|
||||
}
|
||||
ChatMessage.create({
|
||||
@@ -896,6 +947,34 @@ export class BoLActor extends Actor {
|
||||
if (data.system?.resources) {
|
||||
this.checkNumeric(data.system.resources)
|
||||
}
|
||||
// Apply changes in Horde size to Token width/height
|
||||
if (this.type == "horde" ) {
|
||||
if (data?.system?.hordesize) { // If horde size is changed}
|
||||
let newHP = data.system.hordesize * this.system.hordebasehp
|
||||
if (newHP != this.system.resources.hp.value) {
|
||||
data.system.resources = { hp: { value: newHP, max: newHP } } // Update HP
|
||||
}
|
||||
let tokenSize = this.getTokenSizeFromHordeSize(data?.system?.hordesize)
|
||||
if (this.isToken && (tokenSize !== this.token.width)) {
|
||||
this.token.update({ width: tokenSize, height: tokenSize })
|
||||
} else {
|
||||
if (tokenSize && (tokenSize !== this.prototypeToken.width)) {
|
||||
if (!foundry.utils.hasProperty(data, "prototypeToken.width")) {
|
||||
data.prototypeToken ||= {};
|
||||
data.prototypeToken.height = tokenSize;
|
||||
data.prototypeToken.width = tokenSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (data?.system?.hordebasehp) {
|
||||
let newHP = this.system.hordesize * data.system.hordebasehp
|
||||
if (newHP != this.system.resources.hp.value) {
|
||||
data.system.resources = { hp: { value : newHP, max: newHP} }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
super._preUpdate(data, options, userId)
|
||||
}
|
||||
|
||||
@@ -966,8 +1045,15 @@ export class BoLActor extends Actor {
|
||||
}
|
||||
/*-------------------------------------------- */
|
||||
async sufferDamage(damage) {
|
||||
let updates = {}
|
||||
let newHP = this.system.resources.hp.value - damage
|
||||
await this.update({ 'system.resources.hp.value': newHP })
|
||||
updates['system.resources.hp.value'] = newHP
|
||||
if (this.type == "horde") {
|
||||
let newSize = Math.ceil(newHP / this.system.hordebasehp)
|
||||
updates['system.hordesize'] = newSize
|
||||
}
|
||||
await this.update(updates)
|
||||
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
Reference in New Issue
Block a user