2023-12-11 20:11:10 +01:00
|
|
|
/* -------------------------------------------- */
|
2023-12-11 21:41:51 +01:00
|
|
|
import { TeDeumUtility } from "../common/tedeum-utility.js";
|
2024-05-31 09:23:01 +02:00
|
|
|
import { TeDeumRollDialog } from "../dialogs/tedeum-roll-dialog.js";
|
2023-12-11 20:11:10 +01:00
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/**
|
|
|
|
* Extend the base Actor entity by defining a custom roll data structure which is ideal for the Simple system.
|
|
|
|
* @extends {Actor}
|
|
|
|
*/
|
2023-12-11 21:41:51 +01:00
|
|
|
export class TeDeumActor extends Actor {
|
2023-12-11 20:11:10 +01:00
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/**
|
|
|
|
* Override the create() function to provide additional SoS functionality.
|
|
|
|
*
|
|
|
|
* This overrided create() function adds initial items
|
|
|
|
* Namely: Basic skills, money,
|
|
|
|
*
|
|
|
|
* @param {Object} data Barebones actor data which this function adds onto.
|
|
|
|
* @param {Object} options (Unused) Additional options which customize the creation workflow.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2024-06-06 17:16:40 +02:00
|
|
|
if (data.type == 'pj') {
|
|
|
|
const skills = await TeDeumUtility.loadCompendium("fvtt-te-deum.competences")
|
|
|
|
data.items = data.items || []
|
|
|
|
for (let skill of skills) {
|
|
|
|
if (skill.system.isBase || skill.system.score == 1) {
|
|
|
|
data.items.push(skill.toObject())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-11 20:11:10 +01:00
|
|
|
return super.create(data, options);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
async prepareData() {
|
|
|
|
super.prepareData()
|
2025-02-04 21:20:54 +01:00
|
|
|
|
|
|
|
let updates = []
|
|
|
|
let memoriser = this.items.find(item => item.type == "competence" && item.name.toLowerCase() == "mémoriser")
|
|
|
|
let newScore = this.getCommonBaseValue(this.system.caracteristiques.adresse.value)
|
|
|
|
if (memoriser && memoriser?.system.score != newScore) {
|
|
|
|
updates.push({ _id: memoriser.id, "system.score": Number(newScore) })
|
|
|
|
}
|
|
|
|
|
|
|
|
let perception = this.items.find(item => item.type == "competence" && item.name.toLowerCase() == "perception")
|
|
|
|
newScore = this.getCommonBaseValue(this.system.caracteristiques.sensibilite.value)
|
|
|
|
if (perception && perception.system.score != newScore) {
|
|
|
|
updates.push({ _id: perception.id, "system.score": Number(newScore) })
|
|
|
|
}
|
|
|
|
|
|
|
|
let charme = this.items.find(item => item.type == "competence" && item.name.toLowerCase() == "charme")
|
|
|
|
newScore = this.getCommonBaseValue(this.system.caracteristiques.entregent.value)
|
|
|
|
if (charme && charme?.system.score != newScore) {
|
|
|
|
updates.push({ _id: charme.id, "system.score": Number(newScore) })
|
|
|
|
}
|
|
|
|
|
|
|
|
let endurance = this.items.find(item => item.type == "competence" && item.name.toLowerCase() == "endurance")
|
|
|
|
newScore = this.getCommonBaseValue(this.system.caracteristiques.complexion.value)
|
|
|
|
if (endurance && endurance?.system.score != newScore) {
|
|
|
|
updates.push({ _id: endurance.id, "system.score": Number(newScore) })
|
|
|
|
}
|
|
|
|
|
|
|
|
let course = this.items.find(item => item.type == "competence" && item.name.toLowerCase() == "course")
|
|
|
|
newScore = this.getCommonBaseValue(this.system.caracteristiques.adresse.value)
|
|
|
|
if (course && course?.system.score != newScore) {
|
|
|
|
updates.push({ _id: course.id, "system.score": Number(newScore) })
|
|
|
|
}
|
|
|
|
|
|
|
|
let initiative = this.items.find(item => item.type == "competence" && item.name.toLowerCase() == "initiative")
|
|
|
|
newScore = this.getCommonBaseValue(this.system.caracteristiques.adresse.value)
|
|
|
|
if (initiative && initiative?.system.score != newScore) {
|
|
|
|
updates.push({ _id: initiative.id, "system.score": Number(newScore) })
|
|
|
|
}
|
|
|
|
|
|
|
|
let actionsTour = this.items.find(item => item.type == "competence" && item.name.toLowerCase() == "actions/tour")
|
|
|
|
newScore = this.getCommonBaseValue(this.system.caracteristiques.adresse.value)
|
|
|
|
if (actionsTour && actionsTour?.system.score != newScore) {
|
|
|
|
updates.push({ _id: actionsTour.id, "system.score": Number(newScore) })
|
|
|
|
}
|
|
|
|
|
|
|
|
let effort = this.items.find(item => item.type == "competence" && item.name.toLowerCase() == "effort")
|
|
|
|
newScore = this.getCommonBaseValue(this.system.caracteristiques.puissance.value)
|
|
|
|
if (effort && effort?.system.score != newScore) {
|
|
|
|
updates.push({ _id: effort.id, "system.score": Number(newScore) })
|
|
|
|
}
|
|
|
|
|
|
|
|
if (updates.length > 0) {
|
|
|
|
await this.updateEmbeddedDocuments('Item', updates)
|
|
|
|
}
|
|
|
|
|
2023-12-11 20:11:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
prepareDerivedData() {
|
|
|
|
super.prepareDerivedData();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
_preUpdate(changed, options, user) {
|
|
|
|
|
|
|
|
super._preUpdate(changed, options, user);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
async _preCreate(data, options, user) {
|
|
|
|
await super._preCreate(data, options, user);
|
|
|
|
|
|
|
|
// Configure prototype token settings
|
|
|
|
const prototypeToken = {};
|
2023-12-11 22:44:06 +01:00
|
|
|
if (this.type === "pj") Object.assign(prototypeToken, {
|
2023-12-11 20:11:10 +01:00
|
|
|
sight: { enabled: true }, actorLink: true, disposition: CONST.TOKEN_DISPOSITIONS.FRIENDLY
|
|
|
|
});
|
|
|
|
this.updateSource({ prototypeToken });
|
|
|
|
}
|
|
|
|
|
2025-02-04 21:20:54 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
getCommonBaseValue(value) {
|
|
|
|
return game.system.tedeum.config.COMMON_VALUE[value]?.value || 0
|
|
|
|
}
|
|
|
|
getInitiative() {
|
|
|
|
return game.system.tedeum.config.COMMON_VALUE[this.system.caracteristiques.adresse.value]?.value || 0
|
|
|
|
}
|
2023-12-11 20:11:10 +01:00
|
|
|
/* -------------------------------------------- */
|
2024-02-29 22:35:12 +01:00
|
|
|
getBonusDegats() {
|
|
|
|
return game.system.tedeum.config.BONUS_DEGATS[this.system.caracteristiques.puissance.value]
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
getNbArmures() {
|
|
|
|
return game.system.tedeum.config.MAX_ARMURES_LOURDES[this.system.caracteristiques.puissance.value]
|
|
|
|
}
|
|
|
|
getNbActions() {
|
|
|
|
return game.system.tedeum.config.ACTIONS_PAR_TOUR[this.system.caracteristiques.adresse.value]
|
|
|
|
}
|
2025-02-04 21:20:54 +01:00
|
|
|
getInitiative() {
|
|
|
|
return game.system.tedeum.config.ACTIONS_PAR_TOUR[this.system.caracteristiques.adresse.value]
|
|
|
|
}
|
2024-09-13 22:14:21 +02:00
|
|
|
getNbArmuresLourdesActuel() {
|
|
|
|
let armures = this.getArmures()
|
|
|
|
let nb = 0
|
|
|
|
for (let armure of armures) {
|
|
|
|
if (armure.system.equipe) {
|
|
|
|
nb += armure.system.coutArmureLourde
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nb
|
|
|
|
}
|
2023-12-11 20:11:10 +01:00
|
|
|
/* -------------------------------------------- */
|
2025-02-03 23:00:59 +01:00
|
|
|
getEducations() {
|
|
|
|
let educations = this.items.filter(item => item.type == 'education')
|
|
|
|
return educations
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
2023-12-11 22:44:06 +01:00
|
|
|
getCompetences() {
|
2024-07-08 07:54:53 +02:00
|
|
|
let comp = foundry.utils.duplicate(this.items.filter(item => item.type == 'competence') || [])
|
2023-12-11 22:44:06 +01:00
|
|
|
return comp;
|
2023-12-11 20:11:10 +01:00
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
2024-06-04 21:05:54 +02:00
|
|
|
getGraces() {
|
2024-07-08 07:54:53 +02:00
|
|
|
let comp = foundry.utils.duplicate(this.items.filter(item => item.type == 'grace') || [])
|
2024-06-04 21:05:54 +02:00
|
|
|
TeDeumUtility.sortArrayObjectsByName(comp)
|
|
|
|
return comp;
|
|
|
|
}
|
2023-12-11 22:44:06 +01:00
|
|
|
getArmes() {
|
2024-07-08 07:54:53 +02:00
|
|
|
let comp = foundry.utils.duplicate(this.items.filter(item => item.type == 'arme') || [])
|
2023-12-11 22:44:06 +01:00
|
|
|
TeDeumUtility.sortArrayObjectsByName(comp)
|
2023-12-11 20:11:10 +01:00
|
|
|
return comp;
|
|
|
|
}
|
2023-12-11 22:44:06 +01:00
|
|
|
getEquipements() {
|
2024-07-08 07:54:53 +02:00
|
|
|
let comp = foundry.utils.duplicate(this.items.filter(item => item.type == 'equipement') || [])
|
2023-12-11 22:44:06 +01:00
|
|
|
TeDeumUtility.sortArrayObjectsByName(comp)
|
2023-12-11 20:11:10 +01:00
|
|
|
return comp;
|
|
|
|
}
|
2023-12-11 22:44:06 +01:00
|
|
|
getArmures() {
|
2024-07-08 07:54:53 +02:00
|
|
|
let comp = foundry.utils.duplicate(this.items.filter(item => item.type == 'armure') || [])
|
|
|
|
TeDeumUtility.sortArrayObjectsByName(comp)
|
|
|
|
return comp;
|
|
|
|
}
|
|
|
|
getBlessures() {
|
|
|
|
let comp = foundry.utils.duplicate(this.items.filter(item => item.type == 'blessure') || [])
|
|
|
|
for (let c of comp) {
|
|
|
|
let blessDef = game.system.tedeum.config.blessures[c.system.typeBlessure]
|
|
|
|
c.malus = blessDef.modifier
|
|
|
|
}
|
|
|
|
TeDeumUtility.sortArrayObjectsByName(comp)
|
|
|
|
return comp;
|
|
|
|
}
|
|
|
|
getMaladies() {
|
|
|
|
let comp = foundry.utils.duplicate(this.items.filter(item => item.type == 'maladie') || [])
|
|
|
|
for (let c of comp) {
|
|
|
|
c.malus = "N/A"
|
|
|
|
if (c.system.appliquee) {
|
|
|
|
let malDef = game.system.tedeum.config.virulence[c.system.virulence]
|
|
|
|
c.malus = malDef.modifier
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TeDeumUtility.sortArrayObjectsByName(comp)
|
|
|
|
return comp;
|
|
|
|
}
|
|
|
|
getPoisons() {
|
|
|
|
let comp = foundry.utils.duplicate(this.items.filter(item => item.type == 'poison') || [])
|
|
|
|
for (let c of comp) {
|
|
|
|
c.malus = "N/A"
|
|
|
|
if (c.system.appliquee) {
|
|
|
|
let poisDef = game.system.tedeum.config.virulencePoison[c.system.virulence]
|
|
|
|
c.malus = poisDef.modifier
|
|
|
|
}
|
|
|
|
}
|
2023-12-11 22:44:06 +01:00
|
|
|
TeDeumUtility.sortArrayObjectsByName(comp)
|
2023-12-11 20:11:10 +01:00
|
|
|
return comp;
|
|
|
|
}
|
2024-05-31 09:23:01 +02:00
|
|
|
/* -------------------------------------------- */
|
2024-07-08 07:54:53 +02:00
|
|
|
getSanteModifier() {
|
|
|
|
let comp = foundry.utils.duplicate(this.items.filter(item => item.type == 'maladie') || [])
|
|
|
|
let modTotal = 0
|
|
|
|
for (let c of comp) {
|
|
|
|
if (c.system.appliquee) {
|
|
|
|
let maladieDef = game.system.tedeum.config.virulence[c.system.virulence]
|
|
|
|
modTotal += maladieDef.modifier
|
|
|
|
}
|
|
|
|
}
|
2024-09-13 22:14:21 +02:00
|
|
|
let simples = foundry.utils.duplicate(this.items.filter(item => item.type == 'simple') || [])
|
2024-07-08 07:54:53 +02:00
|
|
|
for (let c of simples) {
|
|
|
|
if (c.system.appliquee) {
|
|
|
|
let simpleDef = game.system.tedeum.config.virulencePoison[c.system.virulence]
|
|
|
|
modTotal += simpleDef.modifier
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let blessures = foundry.utils.duplicate(this.items.filter(item => item.type == 'blessure') || [])
|
|
|
|
for (let c of blessures) {
|
|
|
|
let blessDef = game.system.tedeum.config.blessures[c.system.typeBlessure]
|
|
|
|
modTotal += blessDef.modifier
|
2024-05-31 09:23:01 +02:00
|
|
|
}
|
|
|
|
// Si le nombre de blessures est supérieur au score d'endurance, alors malus supplémentaire
|
|
|
|
let endurance = this.items.find(item => item.type == "competence" && item.name.toLowerCase() == "endurance")
|
2024-09-13 22:14:21 +02:00
|
|
|
if (blessures.length > endurance.system.score) {
|
2024-07-08 07:54:53 +02:00
|
|
|
modTotal += -1
|
2024-09-13 22:14:21 +02:00
|
|
|
}
|
2024-07-08 07:54:53 +02:00
|
|
|
return modTotal
|
2024-05-31 09:23:01 +02:00
|
|
|
}
|
2024-09-13 22:14:21 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
async appliquerDegats(rollData) {
|
|
|
|
let combat = this.prepareCombat()
|
|
|
|
rollData.defenderName = this.name
|
|
|
|
let touche = combat[rollData.loc.id].touche
|
|
|
|
if (rollData.degats > 0 && rollData.degats > touche) {
|
|
|
|
let diff = rollData.degats - touche
|
|
|
|
for (let bId in game.system.tedeum.config.blessures) {
|
|
|
|
let blessure = game.system.tedeum.config.blessures[bId]
|
|
|
|
if (diff >= blessure.degatsMin && diff <= blessure.degatsMax) {
|
|
|
|
// Create a new blessure object
|
|
|
|
let blessureObj = {
|
|
|
|
name: blessure.label,
|
|
|
|
type: "blessure",
|
|
|
|
system: {
|
|
|
|
typeBlessure: bId,
|
|
|
|
localisation: rollData.loc.id,
|
|
|
|
appliquee: true,
|
|
|
|
description: "Blessure infligée par un coup de " + rollData.arme.name + " de " + rollData.alias,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rollData.blessure = blessureObj
|
|
|
|
this.createEmbeddedDocuments('Item', [blessureObj]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Display the relevant chat message
|
|
|
|
let msg = await TeDeumUtility.createChatWithRollMode(rollData.alias, {
|
|
|
|
content: await renderTemplate(`systems/fvtt-te-deum/templates/chat/chat-blessure-result.hbs`, rollData)
|
|
|
|
})
|
|
|
|
await msg.setFlag("world", "te-deum-rolldata", rollData)
|
|
|
|
}
|
2024-05-31 09:23:01 +02:00
|
|
|
|
2024-05-06 12:33:28 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
updateCarac(c, key) {
|
2024-05-31 09:23:01 +02:00
|
|
|
c.key = key
|
2024-05-06 12:33:28 +02:00
|
|
|
c.name = game.system.tedeum.config.caracteristiques[key].label
|
|
|
|
c.generalqualite = game.system.tedeum.config.descriptionValeur[c.value].qualite
|
|
|
|
c.qualite = game.system.tedeum.config.descriptionValeur[c.value][key]
|
|
|
|
c.dice = game.system.tedeum.config.descriptionValeur[c.value].dice
|
|
|
|
c.negativeDice = game.system.tedeum.config.descriptionValeur[c.value].negativeDice
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
prepareCaracteristiques() {
|
2024-09-13 22:14:21 +02:00
|
|
|
let carac = foundry.utils.deepClone(this.system.caracteristiques)
|
2024-05-06 12:33:28 +02:00
|
|
|
for (let key in carac) {
|
|
|
|
let c = carac[key]
|
|
|
|
this.updateCarac(c, key)
|
|
|
|
}
|
|
|
|
return carac
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
prepareProvidence() {
|
|
|
|
let providence = foundry.utils.deepClone(this.system.providence)
|
|
|
|
providence.name = "Providence"
|
2024-09-13 22:14:21 +02:00
|
|
|
providence.qualite = game.system.tedeum.config.providence[providence.value].labelM
|
2024-05-06 12:33:28 +02:00
|
|
|
providence.dice = game.system.tedeum.config.providence[providence.value].diceValue
|
|
|
|
return providence
|
|
|
|
}
|
2024-07-08 07:54:53 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
prepareCombat() {
|
|
|
|
let combatLoc = foundry.utils.deepClone(this.system.localisation)
|
|
|
|
for (let key in combatLoc) {
|
|
|
|
combatLoc[key] = foundry.utils.mergeObject(combatLoc[key], game.system.tedeum.config.LOCALISATION[key])
|
|
|
|
combatLoc[key].armures = []
|
2024-07-10 22:59:38 +02:00
|
|
|
combatLoc[key].blessures = []
|
2024-07-08 07:54:53 +02:00
|
|
|
combatLoc[key].protectionTotal = 0
|
|
|
|
let armures = this.getArmures()
|
|
|
|
for (let armure of armures) {
|
|
|
|
if (armure.system.equipe && armure.system.localisation[key].protege) {
|
|
|
|
combatLoc[key].armures.push(armure)
|
|
|
|
combatLoc[key].protectionTotal += armure.system.protection
|
|
|
|
}
|
|
|
|
}
|
2024-07-10 22:59:38 +02:00
|
|
|
let blessures = this.getBlessures()
|
|
|
|
for (let blessure of blessures) {
|
|
|
|
if (blessure.system.localisation == key) {
|
|
|
|
combatLoc[key].blessures.push(blessure)
|
|
|
|
}
|
|
|
|
}
|
2024-07-08 07:54:53 +02:00
|
|
|
let endurance = this.items.find(item => item.type == "competence" && item.name.toLowerCase() == "endurance")
|
|
|
|
combatLoc[key].endurance = endurance.system.score + game.system.tedeum.config.LOCALISATION[key].locMod
|
|
|
|
combatLoc[key].touche = combatLoc[key].endurance + combatLoc[key].protectionTotal
|
|
|
|
}
|
|
|
|
return combatLoc
|
|
|
|
}
|
2024-05-31 09:23:01 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
modifyProvidence(value) {
|
|
|
|
let providence = foundry.utils.duplicate(this.system.providence)
|
|
|
|
providence.value = Math.min(Math.max(providence.value + value, 0), 6)
|
2024-09-13 22:14:21 +02:00
|
|
|
this.update({ "system.providence": providence })
|
2024-05-31 09:23:01 +02:00
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
modifyXP(key, value) {
|
|
|
|
let xp = this.system.caracteristiques[key].experience
|
|
|
|
xp = Math.max(xp + value, 0)
|
2024-09-13 22:14:21 +02:00
|
|
|
this.update({ [`system.caracteristiques.${key}.experience`]: xp })
|
2024-05-31 09:23:01 +02:00
|
|
|
}
|
2024-05-06 12:33:28 +02:00
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
filterCompetencesByCarac(key) {
|
|
|
|
let comp = this.items.filter(item => item.type == 'competence' && item.system.caracteristique == key)
|
|
|
|
comp.forEach(c => {
|
|
|
|
if (c.system.isBase) {
|
|
|
|
c.system.score = this.system.caracteristiques[c.system.caracteristique].value
|
|
|
|
}
|
2024-05-31 09:23:01 +02:00
|
|
|
let caracDice = game.system.tedeum.config.descriptionValeur[this.system.caracteristiques[c.system.caracteristique].value].dice
|
|
|
|
c.system.formula = caracDice + "+" + c.system.score
|
2024-05-06 12:33:28 +02:00
|
|
|
})
|
2025-02-04 08:13:26 +01:00
|
|
|
comp = comp.sort((a, b) => a.name.localeCompare(b.name))
|
2024-09-13 22:14:21 +02:00
|
|
|
return foundry.utils.deepClone(comp || {})
|
2024-05-06 12:33:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
prepareArbreCompetences() {
|
|
|
|
let arbre = foundry.utils.deepClone(this.system.caracteristiques)
|
|
|
|
for (let key in arbre) {
|
|
|
|
let c = arbre[key]
|
|
|
|
this.updateCarac(c, key)
|
|
|
|
c.competences = this.filterCompetencesByCarac(key)
|
|
|
|
}
|
|
|
|
return arbre
|
|
|
|
}
|
|
|
|
|
2023-12-11 20:11:10 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
getItemById(id) {
|
|
|
|
let item = this.items.find(item => item.id == id);
|
|
|
|
if (item) {
|
2024-07-08 07:54:53 +02:00
|
|
|
item = foundry.utils.duplicate(item)
|
2023-12-11 20:11:10 +01:00
|
|
|
}
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
async equipItem(itemId) {
|
|
|
|
let item = this.items.find(item => item.id == itemId)
|
2024-09-13 22:14:21 +02:00
|
|
|
if (!this.checkArmure(item)) {
|
|
|
|
return
|
|
|
|
}
|
2024-07-10 22:59:38 +02:00
|
|
|
let update = { _id: item.id, "system.equipe": !item.system.equipe };
|
|
|
|
await this.updateEmbeddedDocuments('Item', [update]); // Updates one EmbeddedEntity
|
2023-12-11 20:11:10 +01:00
|
|
|
}
|
|
|
|
|
2024-09-13 22:14:21 +02:00
|
|
|
/* ------------------------------------------- */
|
|
|
|
checkArmure(item) {
|
|
|
|
if (item.type != "armure") {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if (item.system.equipe) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
let nbArmuresLourdes = this.getNbArmuresLourdesActuel()
|
|
|
|
if (nbArmuresLourdes + item.system.coutArmureLourde > this.getNbArmures().value) {
|
|
|
|
ui.notifications.warn("Impossible d'équiper cette armure, nombre d'armures lourdes maximum atteint")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Loop thru localisation
|
|
|
|
let armures = this.getArmures()
|
|
|
|
for (let loc in item.system.localisation) {
|
|
|
|
if (item.system.localisation[loc].protege) {
|
|
|
|
for (let armure of armures) {
|
|
|
|
if (armure.system.equipe && armure.system.localisation[loc].protege) {
|
|
|
|
let flag = true
|
|
|
|
//console.log("Check armure", armure, item)=
|
|
|
|
if (item.system.typeArmure == "cuir") {
|
|
|
|
flag = armure.system.superposableCuir
|
|
|
|
}
|
|
|
|
if (item.system.typeArmure == "maille") {
|
|
|
|
flag = armure.system.superposableMaille
|
|
|
|
}
|
|
|
|
if (item.system.typeArmure == "plate") {
|
|
|
|
flag = armure.system.superposablePlate
|
|
|
|
}
|
|
|
|
if (!flag) {
|
|
|
|
ui.notifications.warn("Impossible d'équiper cette armure, non superposable")
|
|
|
|
return flag
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-11 20:11:10 +01:00
|
|
|
/* ------------------------------------------- */
|
|
|
|
async buildContainerTree() {
|
2024-07-08 07:54:53 +02:00
|
|
|
let equipments = foundry.utils.duplicate(this.items.filter(item => item.type == "equipment") || [])
|
2023-12-11 20:11:10 +01:00
|
|
|
for (let equip1 of equipments) {
|
|
|
|
if (equip1.system.iscontainer) {
|
|
|
|
equip1.system.contents = []
|
|
|
|
equip1.system.contentsEnc = 0
|
|
|
|
for (let equip2 of equipments) {
|
|
|
|
if (equip1._id != equip2.id && equip2.system.containerid == equip1.id) {
|
|
|
|
equip1.system.contents.push(equip2)
|
|
|
|
let q = equip2.system.quantity ?? 1
|
|
|
|
equip1.system.contentsEnc += q * equip2.system.weight
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compute whole enc
|
|
|
|
let enc = 0
|
|
|
|
for (let item of equipments) {
|
2023-12-11 22:44:06 +01:00
|
|
|
//item.data.idrDice = TeDeumUtility.getDiceFromLevel(Number(item.data.idr))
|
2023-12-11 20:11:10 +01:00
|
|
|
if (item.system.equipped) {
|
|
|
|
if (item.system.iscontainer) {
|
|
|
|
enc += item.system.contentsEnc
|
|
|
|
} else if (item.system.containerid == "") {
|
|
|
|
let q = item.system.quantity ?? 1
|
|
|
|
enc += q * item.system.weight
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (let item of this.items) { // Process items/shields/armors
|
|
|
|
if ((item.type == "weapon" || item.type == "shield" || item.type == "armor") && item.system.equipped) {
|
|
|
|
let q = item.system.quantity ?? 1
|
|
|
|
enc += q * item.system.weight
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Store local values
|
|
|
|
this.encCurrent = enc
|
|
|
|
this.containersTree = equipments.filter(item => item.system.containerid == "") // Returns the root of equipements without container
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
async equipGear(equipmentId) {
|
|
|
|
let item = this.items.find(item => item.id == equipmentId);
|
|
|
|
if (item?.system) {
|
|
|
|
let update = { _id: item.id, "system.equipped": !item.system.equipped };
|
|
|
|
await this.updateEmbeddedDocuments('Item', [update]); // Updates one EmbeddedEntity
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
clearInitiative() {
|
|
|
|
this.getFlag("world", "initiative", -1)
|
|
|
|
}
|
2024-02-29 22:35:12 +01:00
|
|
|
|
2023-12-11 20:11:10 +01:00
|
|
|
/* -------------------------------------------- */
|
2024-07-08 07:54:53 +02:00
|
|
|
getInitiativeScore() {
|
2024-09-13 22:14:21 +02:00
|
|
|
let initiative = this.items.find(it => it.type == "competence" && it.name.toLowerCase() == "initiative")
|
|
|
|
if (initiative) {
|
2024-07-08 07:54:53 +02:00
|
|
|
return initiative.system.score
|
|
|
|
}
|
|
|
|
ui.notifications.warn("Impossible de trouver la compétence Initiative pour l'acteur " + this.name)
|
|
|
|
return -1;
|
2023-12-11 20:11:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
async deleteAllItemsByType(itemType) {
|
|
|
|
let items = this.items.filter(item => item.type == itemType);
|
|
|
|
await this.deleteEmbeddedDocuments('Item', items);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
async addItemWithoutDuplicate(newItem) {
|
|
|
|
let item = this.items.find(item => item.type == newItem.type && item.name.toLowerCase() == newItem.name.toLowerCase())
|
|
|
|
if (!item) {
|
|
|
|
await this.createEmbeddedDocuments('Item', [newItem]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
async incDecQuantity(objetId, incDec = 0) {
|
|
|
|
let objetQ = this.items.get(objetId)
|
|
|
|
if (objetQ) {
|
|
|
|
let newQ = objetQ.system.quantity + incDec
|
|
|
|
if (newQ >= 0) {
|
|
|
|
await this.updateEmbeddedDocuments('Item', [{ _id: objetQ.id, 'system.quantity': newQ }]) // pdates one EmbeddedEntity
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-09-13 22:14:21 +02:00
|
|
|
|
2023-12-11 20:11:10 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
getCommonRollData() {
|
2023-12-11 22:44:06 +01:00
|
|
|
let rollData = TeDeumUtility.getBasicRollData()
|
2023-12-11 20:11:10 +01:00
|
|
|
rollData.alias = this.name
|
|
|
|
rollData.actorImg = this.img
|
|
|
|
rollData.actorId = this.id
|
|
|
|
rollData.img = this.img
|
2024-05-31 09:23:01 +02:00
|
|
|
rollData.providence = this.prepareProvidence()
|
2024-07-08 07:54:53 +02:00
|
|
|
rollData.santeModifier = this.getSanteModifier()
|
2024-09-13 22:14:21 +02:00
|
|
|
|
2023-12-11 20:11:10 +01:00
|
|
|
return rollData
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2024-05-31 09:23:01 +02:00
|
|
|
getCommonCompetence(compId) {
|
2023-12-11 20:11:10 +01:00
|
|
|
let rollData = this.getCommonRollData()
|
2024-09-13 22:14:21 +02:00
|
|
|
|
|
|
|
let competence = foundry.utils.duplicate(this.items.find(it => it.type == "competence" && it.id == compId))
|
2023-12-11 20:11:10 +01:00
|
|
|
|
2023-12-11 22:44:06 +01:00
|
|
|
rollData.competence = competence
|
2024-05-31 09:23:01 +02:00
|
|
|
let c = foundry.utils.duplicate(this.system.caracteristiques[competence.system.caracteristique])
|
2024-09-13 22:14:21 +02:00
|
|
|
this.updateCarac(c, competence.system.caracteristique)
|
2024-05-31 09:23:01 +02:00
|
|
|
rollData.carac = c
|
2023-12-11 22:44:06 +01:00
|
|
|
rollData.img = competence.img
|
2023-12-11 20:11:10 +01:00
|
|
|
|
|
|
|
return rollData
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2024-05-31 09:23:01 +02:00
|
|
|
rollCompetence(compId) {
|
|
|
|
let rollData = this.getCommonCompetence(compId)
|
2023-12-11 22:44:06 +01:00
|
|
|
rollData.mode = "competence"
|
|
|
|
rollData.title = rollData.competence.name
|
2023-12-11 20:11:10 +01:00
|
|
|
this.startRoll(rollData).catch("Error on startRoll")
|
|
|
|
}
|
|
|
|
|
2025-02-04 21:20:54 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
async rollDegatsArme(armeId) {
|
|
|
|
let weapon = this.items.get(armeId)
|
|
|
|
if (weapon) {
|
2025-02-04 21:24:47 +01:00
|
|
|
let bDegats = 0
|
|
|
|
if ( weapon.system.typeArme == "melee" ) {
|
|
|
|
bDegats = this.getBonusDegats()
|
|
|
|
}
|
2025-02-04 21:20:54 +01:00
|
|
|
let formula = weapon.system.degats + "+" + bDegats.value
|
|
|
|
let degatsRoll = await new Roll(formula).roll()
|
|
|
|
await TeDeumUtility.showDiceSoNice(degatsRoll, game.settings.get("core", "rollMode") )
|
|
|
|
let rollData = this.getCommonRollData()
|
|
|
|
rollData.mode = "degats"
|
|
|
|
rollData.formula = formula
|
|
|
|
rollData.arme = foundry.utils.duplicate(weapon)
|
|
|
|
rollData.degatsRoll = foundry.utils.duplicate(degatsRoll)
|
|
|
|
rollData.degats = degatsRoll.total
|
|
|
|
|
|
|
|
let msg = await TeDeumUtility.createChatWithRollMode(rollData.alias, {
|
|
|
|
content: await renderTemplate(`systems/fvtt-te-deum/templates/chat/chat-degats-result.hbs`, rollData)
|
|
|
|
})
|
|
|
|
await msg.setFlag("world", "te-deum-rolldata", rollData)
|
|
|
|
console.log("Rolldata result", rollData)
|
|
|
|
}
|
|
|
|
}
|
2023-12-11 20:11:10 +01:00
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2024-07-08 07:54:53 +02:00
|
|
|
rollArme(armeId, compName = undefined) {
|
2023-12-11 22:44:06 +01:00
|
|
|
let weapon = this.items.get(armeId)
|
2023-12-11 20:11:10 +01:00
|
|
|
if (weapon) {
|
2024-07-08 07:54:53 +02:00
|
|
|
weapon = foundry.utils.duplicate(weapon)
|
2023-12-11 20:11:10 +01:00
|
|
|
let rollData = this.getCommonRollData()
|
2023-12-11 22:44:06 +01:00
|
|
|
rollData.mode = "arme"
|
2024-09-13 22:14:21 +02:00
|
|
|
rollData.isTir = weapon.system.typeArme == "tir"
|
2023-12-11 22:44:06 +01:00
|
|
|
rollData.arme = weapon
|
2023-12-11 20:11:10 +01:00
|
|
|
rollData.img = weapon.img
|
|
|
|
rollData.title = weapon.name
|
2024-09-13 22:14:21 +02:00
|
|
|
rollData.porteeTir = "courte"
|
|
|
|
rollData.porteeLabel = game.system.tedeum.config.ARME_PORTEES.courte.label
|
|
|
|
rollData.isViser = false
|
|
|
|
rollData.isMouvement = false
|
|
|
|
|
|
|
|
// Display warning if not target defined
|
|
|
|
if (!rollData.defenderTokenId) {
|
|
|
|
ui.notifications.warn("Vous attaquez avec une arme : afin de bénéficier des automatisations, il est conseillé de selectionner une cible")
|
|
|
|
}
|
|
|
|
|
2024-07-08 07:54:53 +02:00
|
|
|
// Setup competence + carac
|
|
|
|
if (!compName) {
|
|
|
|
compName = weapon.system.competence
|
2024-09-13 22:14:21 +02:00
|
|
|
}
|
|
|
|
let competence = this.items.find(item => item.type == "competence" && item.name.toLowerCase() == compName.toLowerCase())
|
|
|
|
if (competence) {
|
2024-07-08 07:54:53 +02:00
|
|
|
rollData.competence = competence
|
|
|
|
let c = foundry.utils.duplicate(this.system.caracteristiques[competence.system.caracteristique])
|
2024-09-13 22:14:21 +02:00
|
|
|
this.updateCarac(c, competence.system.caracteristique)
|
2024-07-08 07:54:53 +02:00
|
|
|
rollData.carac = c
|
|
|
|
} else {
|
2024-09-13 22:14:21 +02:00
|
|
|
ui.notifications.warn("Impossible de trouver la compétence " + compName)
|
2024-07-08 07:54:53 +02:00
|
|
|
return
|
|
|
|
}
|
2023-12-11 20:11:10 +01:00
|
|
|
this.startRoll(rollData).catch("Error on startRoll")
|
|
|
|
} else {
|
|
|
|
ui.notifications.warn("Impossible de trouver l'arme concernée ")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
async startRoll(rollData) {
|
2024-05-31 09:23:01 +02:00
|
|
|
console.log("startRoll", rollData)
|
|
|
|
let rollDialog = await TeDeumRollDialog.create(this, rollData)
|
2023-12-11 20:11:10 +01:00
|
|
|
rollDialog.render(true)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|