fvtt-les-heritiers/modules/heritiers-actor.js

922 lines
30 KiB
JavaScript
Raw Normal View History

2022-12-26 00:33:13 +01:00
/* -------------------------------------------- */
import { HeritiersUtility } from "./heritiers-utility.js";
import { HeritiersRollDialog } from "./heritiers-roll-dialog.js";
/* -------------------------------------------- */
const __degatsBonus = [-2, -2, -1, -1, 0, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 8, 8, 9, 9, 10, 10]
const __vitesseBonus = [-2, -2, -1, -1, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8]
/* -------------------------------------------- */
/**
* Extend the base Actor entity by defining a custom roll data structure which is ideal for the Simple system.
* @extends {Actor}
*/
export class HeritiersActor extends Actor {
/* -------------------------------------------- */
/**
* 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;
}
if (data.type == 'personnage') {
2023-01-18 16:16:18 +01:00
const skills = await HeritiersUtility.loadCompendium("fvtt-les-heritiers.competences")
2023-03-08 23:44:19 +01:00
data.items = []
for (let skill of skills) {
2024-11-17 22:45:48 +01:00
if (skill.system.categorie == "utile" && skill.system.profil != "magie") {
2023-03-09 13:16:19 +01:00
data.items.push(skill.toObject())
}
2023-03-08 23:44:19 +01:00
}
2022-12-26 00:33:13 +01:00
}
2023-03-13 09:00:49 +01:00
if (data.type == 'pnj') {
2022-12-26 00:33:13 +01:00
}
return super.create(data, options);
}
/* -------------------------------------------- */
prepareArme(arme) {
2024-05-23 11:25:51 +02:00
arme = foundry.utils.duplicate(arme)
2023-04-09 21:45:46 +02:00
arme.system.isMelee = HeritiersUtility.isArmeMelee(arme)
2022-12-26 00:33:13 +01:00
return arme
}
/* -------------------------------------------- */
getWeapons() {
let armes = []
for (let arme of this.items) {
if (arme.type == "arme") {
armes.push(this.prepareArme(arme))
}
}
return armes
}
/* -------------------------------------------- */
2023-04-11 13:26:51 +02:00
getOtherMeleeWeapons(excludeArme) {
let armes = []
for (let arme of this.items) {
if (HeritiersUtility.isArmeMelee(arme) && arme.id != excludeArme._id) {
2023-04-11 13:26:51 +02:00
armes.push(this.prepareArme(arme))
}
}
return armes
}
/* -------------------------------------------- */
2022-12-26 00:33:13 +01:00
getMonnaies() {
2023-01-18 16:16:18 +01:00
return this.items.filter(it => it.type == "monnaie")
2022-12-26 00:33:13 +01:00
}
/* ----------------------- --------------------- */
2023-01-18 16:16:18 +01:00
addMember(actorId) {
2024-05-23 11:25:51 +02:00
let members = foundry.utils.duplicate(this.system.members)
2023-01-18 16:16:18 +01:00
members.push({ id: actorId })
this.update({ 'system.members': members })
2022-12-26 00:33:13 +01:00
}
2023-01-18 16:16:18 +01:00
async removeMember(actorId) {
let members = this.system.members.filter(it => it.id != actorId)
this.update({ 'system.members': members })
2022-12-26 00:33:13 +01:00
}
/* ----------------------- --------------------- */
2023-04-09 21:45:46 +02:00
getItemSorted(types) {
let items = this.items.filter(item => types.includes(item.type)) || []
2023-03-10 13:21:06 +01:00
HeritiersUtility.sortArrayObjectsByName(items)
return items
}
2022-12-26 00:33:13 +01:00
getEquipments() {
2023-04-09 21:45:46 +02:00
return this.getItemSorted(["equipement", "accessoire"])
2022-12-26 00:33:13 +01:00
}
2023-01-20 15:19:04 +01:00
getAvantages() {
2023-04-09 21:45:46 +02:00
return this.getItemSorted(["avantage"])
2023-01-20 15:19:04 +01:00
}
getDesavantages() {
2023-04-09 21:45:46 +02:00
return this.getItemSorted(["desavantage"])
2022-12-26 00:33:13 +01:00
}
getMonnaies() {
2023-04-09 21:45:46 +02:00
return this.getItemSorted(["monnaie"])
2022-12-26 00:33:13 +01:00
}
getArmors() {
2023-04-09 21:45:46 +02:00
return this.getItemSorted(["protection"])
2022-12-26 00:33:13 +01:00
}
getTalents() {
2023-04-09 21:45:46 +02:00
return this.getItemSorted(["talent"])
2022-12-26 00:33:13 +01:00
}
getContacts() {
2023-04-09 21:45:46 +02:00
return this.getItemSorted(["contact"])
2022-12-26 00:33:13 +01:00
}
2023-01-20 15:19:04 +01:00
getAtouts() {
2023-04-09 21:45:46 +02:00
return this.getItemSorted(["atoutfeerique"])
2023-01-20 15:19:04 +01:00
}
getCapacites() {
2023-04-09 21:45:46 +02:00
return this.getItemSorted(["capacitenaturelle"])
2023-01-20 15:19:04 +01:00
}
2023-03-07 19:33:12 +01:00
getFee() {
2023-04-09 21:45:46 +02:00
return this.items.find(item => item.type == "fee")
2023-03-07 19:33:12 +01:00
}
2023-03-08 16:58:11 +01:00
getProfils() {
2023-04-09 21:45:46 +02:00
return this.getItemSorted(["profil"])
2023-03-08 16:58:11 +01:00
}
2023-03-08 23:44:19 +01:00
getPouvoirs() {
2024-03-23 11:37:15 +01:00
let pouvoirs = []
for (let item of this.items) {
if (item.type == "pouvoir") {
2024-05-23 11:25:51 +02:00
let itemObj = foundry.utils.duplicate(item)
2024-03-23 11:37:15 +01:00
itemObj.maxUsage = this.getPouvoirUsageMax(item)
pouvoirs.push(itemObj)
}
}
HeritiersUtility.sortArrayObjectsByName(pouvoirs)
return pouvoirs
2023-03-08 23:44:19 +01:00
}
2024-11-17 22:45:48 +01:00
getSorts() {
return this.getItemSorted(["sort"])
}
getCompetencesMagie() {
let comp = []
for (let item of this.items) {
if (item.type == "competence" && item.system.profil == "magie") {
let itemObj = foundry.utils.duplicate(item)
comp.push(itemObj)
}
}
HeritiersUtility.sortArrayObjectsByName(comp)
return comp
}
prepareMagie() {
let magieList = []
for (let item of this.items) {
if (item.type == "competence" && item.system.profil == "magie") {
let magie = {}
magie.name = item.name
magie.competence = foundry.utils.duplicate(item)
magie.sorts = []
for (let sort of this.items) {
if (sort.type == "sort" && sort.system.competence == item.name) {
magie.sorts.push(sort)
}
}
magieList.push(magie)
}
}
return magieList
}
2024-03-23 11:37:15 +01:00
2022-12-26 00:33:13 +01:00
/* -------------------------------------------- */
getSkills() {
let comp = []
for (let item of this.items) {
2024-05-23 11:25:51 +02:00
item = foundry.utils.duplicate(item)
2022-12-26 00:33:13 +01:00
if (item.type == "competence") {
comp.push(item)
}
}
2023-01-18 16:16:18 +01:00
return HeritiersUtility.sortByName(comp)
}
2023-03-08 16:58:11 +01:00
/* -------------------------------------------- */
prepareUtileSkill(item) {
let specList = []
if (item?.system?.categorie == "utile") {
2023-03-09 13:16:19 +01:00
for (let spec of item.system.specialites) {
2023-03-08 16:58:11 +01:00
specList.push(spec.name)
}
}
item.nbSpec = specList.length
item.specList = specList.toString()
}
2023-01-18 16:16:18 +01:00
/* -------------------------------------------- */
2023-03-11 12:11:27 +01:00
organizeUtileSkills(kind = "mental") {
2023-01-18 16:16:18 +01:00
let comp = {}
for (let key in game.system.lesheritiers.config.competenceProfil) {
2023-04-09 21:45:46 +02:00
if (game.system.lesheritiers.config.competenceProfil[key].kind == kind)
comp[key] = { skills: [], niveau: this.system.competences[key].niveau }
2023-01-18 16:16:18 +01:00
}
for (let item of this.items) {
if (item.type == "competence") {
2023-03-11 12:11:27 +01:00
if (item.system.categorie == "utile" && comp[item.system.profil]) {
2023-03-08 16:58:11 +01:00
this.prepareUtileSkill(item)
2023-03-13 09:00:49 +01:00
comp[item.system.profil].skills.push(item)
2023-01-18 16:16:18 +01:00
}
2022-12-26 00:33:13 +01:00
}
2023-01-18 16:16:18 +01:00
}
2023-03-11 12:11:27 +01:00
2023-03-09 00:26:52 +01:00
for (let key in comp) {
2023-03-13 09:00:49 +01:00
HeritiersUtility.sortArrayObjectsByName(comp[key].skills)
2023-03-09 00:26:52 +01:00
}
2023-03-11 12:11:27 +01:00
return Object.fromEntries(Object.entries(comp).sort())
2023-01-18 16:16:18 +01:00
}
2023-03-08 16:58:11 +01:00
/* -------------------------------------------- */
2023-03-09 13:16:19 +01:00
organizeContacts() {
2023-03-08 16:58:11 +01:00
let contactList = {}
for (let item of this.items) {
if (item.type == "contact") {
let c = contactList[item.system.contacttype] || { label: game.system.lesheritiers.config.contactType[item.system.contacttype], list: [] }
2023-03-09 13:16:19 +01:00
c.list.push(item)
2023-03-08 16:58:11 +01:00
contactList[item.system.contacttype] = c
}
}
2023-03-10 13:21:06 +01:00
for (let key in contactList) {
HeritiersUtility.sortArrayObjectsByName(contactList[key].list)
}
2023-03-08 16:58:11 +01:00
return contactList
}
2023-01-18 16:16:18 +01:00
/* -------------------------------------------- */
organizeFutileSkills() {
let comp = []
for (let item of this.items) {
if (item.type == "competence") {
if (item.system.categorie == "futile") {
comp.push(item)
}
2022-12-26 00:33:13 +01:00
}
2023-01-18 16:16:18 +01:00
}
2023-03-09 00:04:23 +01:00
HeritiersUtility.sortArrayObjectsByName(comp)
2023-01-18 16:16:18 +01:00
return HeritiersUtility.sortByName(comp)
2022-12-26 00:33:13 +01:00
}
/* -------------------------------------------- */
getDefenseBase() {
return Math.max(this.system.attributs.tre.value, this.system.attributs.pui.value)
}
/* -------------------------------------------- */
getVitesseBase() {
return 5 + __vitesseBonus[this.system.attributs.adr.value]
}
/* -------------------------------------------- */
getProtection() {
let equipProtection = 0
2023-01-18 16:16:18 +01:00
for (let armor in this.items) {
2022-12-26 00:33:13 +01:00
if (armor.type == "protection" && armor.system.equipped) {
equipProtection += Number(armor.system.protection)
}
}
if (equipProtection < 4) {
return 4 + equipProtection // Cas des boucliers + sans armure
}
return equipProtection // Uniquement la protection des armures + boucliers
}
/* -------------------------------------------- */
getCombatValues() {
let combat = {
}
return combat
}
/* -------------------------------------------- */
prepareBaseData() {
}
/* -------------------------------------------- */
async prepareData() {
2024-04-11 12:36:50 +02:00
let pvMax = (this.system.caracteristiques.con.rang * 3) + 9 + this.system.pv.mod
if (this.system.pv.max != pvMax) {
this.update({ 'system.pv.max': pvMax })
}
2024-11-17 22:45:48 +01:00
if (this.system.biodata.magie || this.type == "pnj") {
let pointsAmes = this.system.caracteristiques.esp.rang + this.system.caracteristiques.san.rang + this.getMaxRangMagie()
if (this.system.magie.pointsame.max != pointsAmes) {
this.update({ 'system.magie.pointsame.max': pointsAmes })
}
}
super.prepareData();
}
/* -------------------------------------------- */
getMaxRangMagie() {
let niv = 0
let bestMagie
for (let comp of this.items) {
if (comp.type == "competence" && comp.system.profil == "magie") {
if (comp.system.niveau > niv) {
bestMagie = comp
niv = comp.system.niveau
}
}
}
if (bestMagie) {
return Math.round(bestMagie.system.niveau / 2)
}
return 0
2022-12-26 00:33:13 +01:00
}
/* -------------------------------------------- */
prepareDerivedData() {
if (this.type == 'personnage') {
}
super.prepareDerivedData()
}
/* -------------------------------------------- */
_preUpdate(changed, options, user) {
super._preUpdate(changed, options, user);
}
/* -------------------------------------------- */
getItemById(id) {
let item = this.items.find(item => item.id == id);
if (item) {
2024-05-23 11:25:51 +02:00
item = foundry.utils.duplicate(item)
2022-12-26 00:33:13 +01:00
}
return item;
}
/* -------------------------------------------- */
async equipItem(itemId) {
let item = this.items.find(item => item.id == itemId)
if (item?.system) {
2022-12-26 00:33:13 +01:00
let update = { _id: item.id, "system.equipped": !item.system.equipped }
await this.updateEmbeddedDocuments('Item', [update]); // Updates one EmbeddedEntity
}
}
/* -------------------------------------------- */
editItemField(itemId, itemType, itemField, dataType, value) {
let item = this.items.find(item => item.id == itemId)
if (item) {
console.log("Item ", item, itemField, dataType, value)
2023-04-09 21:45:46 +02:00
if (dataType) {
2023-03-10 09:08:10 +01:00
if (dataType.toLowerCase() == "number") {
value = Number(value)
} else {
value = String(value)
}
2022-12-26 00:33:13 +01:00
}
let update = { _id: item.id, [`system.${itemField}`]: value };
this.updateEmbeddedDocuments("Item", [update])
}
}
/* -------------------------------------------- */
2023-01-20 15:19:04 +01:00
getPvMalus() {
if (this.system.pv.value > 0) {
if (this.system.pv.value < 5) {
2023-04-09 21:45:46 +02:00
return { name: "Santé", value: -2 }
2022-12-26 00:33:13 +01:00
}
2023-04-23 23:13:31 +02:00
if (this.system.pv.value < this.system.pv.max / 2) {
return { name: "Santé", value: -1 }
}
2023-04-09 21:45:46 +02:00
return { name: "Santé", value: 0 }
2022-12-26 00:33:13 +01:00
}
2023-04-09 21:45:46 +02:00
return { name: "Moribond(e)", value: -50 }
2022-12-26 00:33:13 +01:00
}
/* -------------------------------------------- */
compareName(a, b) {
if (a.name < b.name) {
return -1;
}
if (a.name > b.name) {
return 1;
}
return 0;
}
/* -------------------------------------------- */
2023-01-18 16:16:18 +01:00
getCarac(attrKey) {
2024-05-23 11:25:51 +02:00
return foundry.utils.duplicate(this.system.caracteristiques)
2022-12-26 00:33:13 +01:00
}
/* -------------------------------------------- */
getBonusDegats() {
2023-01-18 16:16:18 +01:00
return 0;
2022-12-26 00:33:13 +01:00
}
/* -------------------------------------------- */
async equipGear(equipmentId) {
let item = this.items.find(item => item.id == equipmentId);
if (item?.system) {
2022-12-26 00:33:13 +01:00
let update = { _id: item.id, "system.equipped": !item.system.equipped };
await this.updateEmbeddedDocuments('Item', [update]); // Updates one EmbeddedEntity
}
}
/* -------------------------------------------- */
getSubActors() {
let subActors = [];
for (let id of this.system.subactors) {
2024-05-23 11:25:51 +02:00
subActors.push(foundry.utils.duplicate(game.actors.get(id)));
2022-12-26 00:33:13 +01:00
}
return subActors;
}
/* -------------------------------------------- */
async addSubActor(subActorId) {
2024-05-23 11:25:51 +02:00
let subActors = foundry.utils.duplicate(this.system.subactors);
2022-12-26 00:33:13 +01:00
subActors.push(subActorId);
await this.update({ 'system.subactors': subActors });
}
/* -------------------------------------------- */
async delSubActor(subActorId) {
let newArray = [];
for (let id of this.system.subactors) {
if (id != subActorId) {
newArray.push(id);
}
}
await this.update({ 'system.subactors': newArray });
}
/* -------------------------------------------- */
getTotalAdversite() {
return this.system.adversite.bleue + this.system.adversite.rouge + this.system.adversite.noire
}
/* -------------------------------------------- */
async incDecAdversite(adv, incDec = 0) {
2024-05-23 11:25:51 +02:00
let adversite = foundry.utils.duplicate(this.system.adversite)
2022-12-26 00:33:13 +01:00
adversite[adv] += Number(incDec)
adversite[adv] = Math.max(adversite[adv], 0)
this.update({ 'system.adversite': adversite })
}
/* -------------------------------------------- */
async incDecQuantity(objetId, incDec = 0) {
let objetQ = this.items.get(objetId)
if (objetQ) {
let newQ = objetQ.system.quantite + incDec
newQ = Math.max(newQ, 0)
const updated = await this.updateEmbeddedDocuments('Item', [{ _id: objetQ.id, 'system.quantite': newQ }]); // pdates one EmbeddedEntity
}
}
/* -------------------------------------------- */
computeRichesse() {
let valueSC = 0
2023-01-18 16:16:18 +01:00
for (let monnaie of this.items) {
2022-12-26 00:33:13 +01:00
if (monnaie.type == "monnaie") {
2023-01-18 16:16:18 +01:00
valueSC += Number(monnaie.system.prixsc) * Number(monnaie.system.quantite)
2022-12-26 00:33:13 +01:00
}
}
2023-01-18 16:16:18 +01:00
return HeritiersUtility.computeMonnaieDetails(valueSC)
2022-12-26 00:33:13 +01:00
}
/* -------------------------------------------- */
computeValeurEquipement() {
let valueSC = 0
2023-01-18 16:16:18 +01:00
for (let equip of this.items) {
2022-12-26 00:33:13 +01:00
if (equip.type == "equipement" || equip.type == "arme" || equip.type == "protection") {
2023-01-18 16:16:18 +01:00
valueSC += Number(equip.system.prixsc) * Number(equip.system.quantite ?? 1)
valueSC += (Number(equip.system.prixca) * Number(equip.system.quantite ?? 1)) * 20
valueSC += (Number(equip.system.prixpo) * Number(equip.system.quantite ?? 1)) * 400
2022-12-26 00:33:13 +01:00
}
}
2023-01-18 16:16:18 +01:00
return HeritiersUtility.computeMonnaieDetails(valueSC)
2022-12-26 00:33:13 +01:00
}
2023-01-18 16:16:18 +01:00
2022-12-26 00:33:13 +01:00
/* -------------------------------------------- */
getCompetence(compId) {
return this.items.get(compId)
}
/* -------------------------------------------- */
async setPredilectionUsed(compId, predIdx) {
let comp = this.items.get(compId)
2024-05-23 11:25:51 +02:00
let pred = foundry.utils.duplicate(comp.system.predilections)
2022-12-26 00:33:13 +01:00
pred[predIdx].used = true
await this.updateEmbeddedDocuments('Item', [{ _id: compId, 'system.predilections': pred }])
}
/* -------------------------------------------- */
getInitiativeScore() {
let init = this.getFlag("world", "last-initiative")
return init || -1
}
/* -------------------------------------------- */
getBestDefenseValue() {
let defenseList = this.items.filter(item => (item.type == "arme") && item.system.equipped)
let maxDef = 0
let bestArme
for (let arme of defenseList) {
2023-01-18 16:16:18 +01:00
if (arme.type == "arme") {
2022-12-26 00:33:13 +01:00
arme = this.prepareArme(arme)
}
if (arme.system.totalDefensif > maxDef) {
maxDef = arme.system.totalDefensif
2024-05-23 11:25:51 +02:00
bestArme = foundry.utils.duplicate(arme)
2022-12-26 00:33:13 +01:00
}
}
return bestArme
}
/* -------------------------------------------- */
searchRelevantTalents(competence) {
let talents = []
for (let talent of this.items) {
if (talent.type == "talent" && talent.system.isautomated && talent.system.automations.length > 0) {
for (let auto of talent.system.automations) {
if (auto.eventtype === "prepare-roll") {
if (auto.competence.toLowerCase() == competence.name.toLowerCase()) {
2024-05-23 11:25:51 +02:00
talent = foundry.utils.duplicate(talent)
2022-12-26 00:33:13 +01:00
talent.system.bonus = auto.bonus
talent.system.baCost = auto.baCost
talents.push(talent)
}
}
}
}
}
return talents
}
2023-04-08 18:49:54 +02:00
/* -------------------------------------------- */
getCurrentParade() {
2023-04-09 21:45:46 +02:00
if (this.system.statutmasque == "masque") {
2023-04-08 18:49:54 +02:00
return this.system.combat.parade.masquee
}
return this.system.combat.parade.demasquee
}
/* -------------------------------------------- */
getCurrentEsquive() {
2023-04-09 21:45:46 +02:00
if (this.system.statutmasque == "masque") {
2023-04-08 18:49:54 +02:00
return this.system.combat.esquive.masquee
}
return this.system.combat.esquive.demasquee
}
2023-04-09 21:45:46 +02:00
getCurrentResistancePhysique() {
return this.system.combat.resistancephysique.value
}
2022-12-26 00:33:13 +01:00
/* -------------------------------------------- */
2023-01-18 21:08:32 +01:00
getTricherie() {
return this.system.rang.tricherie.value
}
/* -------------------------------------------- */
getHeritages() {
return this.system.rang.heritage.value
2022-12-26 00:33:13 +01:00
}
2023-01-20 15:19:04 +01:00
/* -------------------------------------------- */
incDecTricherie(value) {
let tricherie = this.system.rang.tricherie
tricherie.value += value
if (tricherie.value < 0 || tricherie.value > tricherie.max) {
ui.notifications.warn("Pas assez de points de Tricherie !")
return false
}
2023-01-20 15:19:04 +01:00
tricherie.value = Math.max(tricherie.value, 0)
tricherie.value = Math.min(tricherie.value, tricherie.max)
this.update({ 'system.rang.tricherie': tricherie })
return true
2023-01-20 15:19:04 +01:00
}
2023-04-09 21:45:46 +02:00
/* -------------------------------------------- */
getPireCompetence(compName1, compName2) {
let comp1 = this.items.find(it => it.name == compName1)
let comp2 = this.items.find(it => it.name == compName2)
if (comp1 && comp2) {
2023-04-09 21:45:46 +02:00
if (comp1.system.niveau > comp2.system.niveau) {
return comp1
} else {
return comp2
}
}
return undefined
}
2024-04-11 12:36:50 +02:00
2022-12-26 00:33:13 +01:00
/* -------------------------------------------- */
2023-01-18 16:16:18 +01:00
getCommonRollData(compId = undefined, compName = undefined) {
2022-12-26 00:33:13 +01:00
let rollData = HeritiersUtility.getBasicRollData()
rollData.alias = this.name
rollData.actorImg = this.img
rollData.actorId = this.id
rollData.tokenId = this.token?.id
rollData.img = this.img
2023-01-18 16:16:18 +01:00
rollData.caracList = this.getCarac()
rollData.caracKey = "agi"
2023-01-18 21:08:32 +01:00
rollData.tricherie = this.getTricherie()
rollData.heritage = this.getHeritages()
rollData.useTricherie = false
2023-03-08 16:58:11 +01:00
rollData.useSpecialite = false
2023-01-18 21:08:32 +01:00
rollData.useHeritage = false
2024-03-23 11:37:15 +01:00
rollData.pouvoirPointsUsage = 1
2023-04-09 21:45:46 +02:00
rollData.rulesMalus.push(this.getPvMalus())
2023-01-18 16:16:18 +01:00
2022-12-26 00:33:13 +01:00
if (compId) {
2024-05-23 11:25:51 +02:00
rollData.competence = foundry.utils.duplicate(this.items.get(compId) || {})
2023-03-08 16:58:11 +01:00
this.prepareUtileSkill(rollData.competence)
2022-12-26 00:33:13 +01:00
rollData.actionImg = rollData.competence?.img
}
if (compName) {
2024-05-23 11:25:51 +02:00
rollData.competence = foundry.utils.duplicate(this.items.find(item => item.name.toLowerCase() == compName.toLowerCase()) || {})
if (rollData.competence?.name) {
2023-04-08 18:49:54 +02:00
this.prepareUtileSkill(rollData.competence)
2023-04-09 21:45:46 +02:00
rollData.actionImg = rollData.competence?.img
2023-04-08 18:49:54 +02:00
} else {
rollData.competence = undefined
}
2022-12-26 00:33:13 +01:00
}
2023-04-08 18:49:54 +02:00
HeritiersUtility.updateWithTarget(rollData)
2022-12-26 00:33:13 +01:00
return rollData
}
2023-03-01 22:12:27 +01:00
/* -------------------------------------------- */
async rollInitiative() {
let rollData = this.getCommonRollData(undefined, "Art de la guerre")
2023-03-09 13:16:19 +01:00
rollData.mode = "init"
2023-03-01 22:12:27 +01:00
if (this.system.caracteristiques["san"].value > this.system.caracteristiques["per"].value) {
rollData.caracKey = "san"
} else {
rollData.caracKey = "per"
}
rollData.carac = this.system.caracteristiques[rollData.caracKey]
let rollDialog = await HeritiersRollDialog.create(this, rollData)
rollDialog.render(true)
}
2023-03-09 13:16:19 +01:00
2022-12-26 00:33:13 +01:00
/* -------------------------------------------- */
2023-01-20 15:19:04 +01:00
async rollCarac(key, isInit = false) {
let rollData = this.getCommonRollData()
2023-03-09 13:16:19 +01:00
rollData.mode = "carac"
2023-01-20 15:19:04 +01:00
rollData.carac = this.system.caracteristiques[key]
rollData.caracKey = key
2022-12-26 00:33:13 +01:00
let rollDialog = await HeritiersRollDialog.create(this, rollData)
rollDialog.render(true)
}
2023-03-11 12:11:27 +01:00
/* -------------------------------------------- */
async rollRang(key, isInit = false) {
let rollData = this.getCommonRollData()
rollData.mode = "rang"
rollData.rang = this.system.rang[key]
rollData.rangKey = key
let rollDialog = await HeritiersRollDialog.create(this, rollData)
rollDialog.render(true)
}
2023-03-13 09:00:49 +01:00
/* -------------------------------------------- */
async rollRootCompetence(compKey) {
let rollData = this.getCommonRollData()
rollData.mode = "competence"
2023-04-09 21:45:46 +02:00
rollData.competence = { name: this.system.competences[compKey].label, system: { niveau: this.system.competences[compKey].niveau } }
2023-03-13 09:00:49 +01:00
console.log("RollDatra", rollData)
let rollDialog = await HeritiersRollDialog.create(this, rollData)
rollDialog.render(true)
}
2023-03-11 12:11:27 +01:00
2022-12-26 00:33:13 +01:00
/* -------------------------------------------- */
2023-01-18 16:16:18 +01:00
async rollCompetence(compId) {
let rollData = this.getCommonRollData(compId)
2023-01-20 15:19:04 +01:00
rollData.mode = "competence"
2022-12-26 00:33:13 +01:00
console.log("RollDatra", rollData)
let rollDialog = await HeritiersRollDialog.create(this, rollData)
rollDialog.render(true)
}
2023-04-09 21:45:46 +02:00
2024-11-17 22:45:48 +01:00
/* -------------------------------------------- */
async rollSort(sortId) {
let sort = this.items.get(sortId)
let comp = this.items.find(it => it.type =="competence" && it.name.toLowerCase() == sort.system.competence.toLowerCase())
if (!comp) {
ui.notifications.warn("Compétence de magie associée non trouvée !")
return
}
let rollData = this.getCommonRollData(comp.id)
rollData.mode = "sort"
rollData.sort = foundry.utils.duplicate(sort)
rollData.sdValue = HeritiersUtility.getSDSortValue(sort.system.niveau)
rollData.sortPointsAme = sort.system.niveau
rollData.caracKey = sort.system.carac
console.log("RollData", rollData)
let rollDialog = await HeritiersRollDialog.create(this, rollData)
rollDialog.render(true)
}
2023-03-09 00:26:52 +01:00
/* -------------------------------------------- */
async rollAttaqueArme(armeId) {
let arme = this.items.get(armeId)
if (arme) {
2024-05-23 11:25:51 +02:00
arme = foundry.utils.duplicate(arme)
2023-04-10 14:11:47 +02:00
arme.system.isMelee = HeritiersUtility.isArmeMelee(arme)
2023-03-09 00:26:52 +01:00
let competenceName = "Tir"
let key = "prec"
if (arme.system.isMelee) {
2023-03-09 00:26:52 +01:00
competenceName = "Mêlée"
key = "agi"
}
2023-03-09 13:16:19 +01:00
let rollData = this.getCommonRollData(undefined, competenceName)
2023-03-09 00:26:52 +01:00
rollData.carac = this.system.caracteristiques[key]
rollData.caracKey = key
2023-04-10 14:11:47 +02:00
rollData.arme = arme
2023-03-09 00:26:52 +01:00
rollData.mode = "arme"
2023-04-11 13:26:51 +02:00
rollData.armes = this.getOtherMeleeWeapons(arme)
if (rollData.defenderTokenId && arme.system.isMelee) {
2023-04-09 21:45:46 +02:00
rollData.cacheDifficulte = true
}
2023-04-10 14:11:47 +02:00
console.log(">>>> ARME", rollData)
2023-03-09 00:26:52 +01:00
let rollDialog = await HeritiersRollDialog.create(this, rollData)
rollDialog.render(true)
2023-03-09 13:16:19 +01:00
}
}
2023-04-09 21:45:46 +02:00
/* -------------------------------------------- */
async rollAttaqueBrutaleArme(armeId) {
let arme = this.items.get(armeId)
if (arme) {
let key = "for"
let competenceName = "Mêlée"
2023-04-10 14:11:47 +02:00
arme.system.isMelee = HeritiersUtility.isArmeMelee(arme)
2023-04-09 21:45:46 +02:00
let rollData = this.getCommonRollData(undefined, competenceName)
rollData.carac = this.system.caracteristiques[key]
rollData.caracKey = key
2024-05-23 11:25:51 +02:00
rollData.arme = foundry.utils.duplicate(arme)
2023-04-09 21:45:46 +02:00
rollData.mode = "attaquebrutale"
2023-04-11 13:26:51 +02:00
rollData.armes = this.getOtherMeleeWeapons(arme)
rollData.rulesMalus.push({ name: "Attaque brutale", value: -2 })
2023-04-09 21:45:46 +02:00
let rollDialog = await HeritiersRollDialog.create(this, rollData)
rollDialog.render(true)
}
}
/* -------------------------------------------- */
async rollAttaqueChargeArme(armeId) {
let arme = this.items.get(armeId)
if (arme) {
let key = "agi"
2023-04-10 14:11:47 +02:00
arme.system.isMelee = HeritiersUtility.isArmeMelee(arme)
2023-04-09 21:45:46 +02:00
let pireCompetence = this.getPireCompetence("Mêlée", "Mouvement")
let rollData = this.getCommonRollData(undefined, pireCompetence.name)
rollData.carac = this.system.caracteristiques[key]
rollData.caracKey = key
2024-05-23 11:25:51 +02:00
rollData.arme = foundry.utils.duplicate(arme)
2023-04-11 13:26:51 +02:00
rollData.armes = this.getOtherMeleeWeapons(arme)
2023-04-09 21:45:46 +02:00
rollData.mode = "attaquecharge"
let rollDialog = await HeritiersRollDialog.create(this, rollData)
rollDialog.render(true)
}
}
2023-04-09 21:45:46 +02:00
/* -------------------------------------------- */
async rollAssomerArme(armeId) {
let arme = this.items.get(armeId)
if (arme) {
let competenceName = "Mêlée"
2023-04-10 14:11:47 +02:00
//arme.system.isMelee = HeritiersUtility.isArmeMelee(arme)
2023-04-09 21:45:46 +02:00
let rollData = this.getCommonRollData(undefined, competenceName)
rollData.carac = this.system.caracteristiques["agi"]
rollData.caracKey = "agi"
2024-05-23 11:25:51 +02:00
rollData.arme = foundry.utils.duplicate(arme)
2023-04-09 21:45:46 +02:00
rollData.mode = "assommer"
if (rollData.defenderTokenId) {
rollData.cacheDifficulte = true
}
let rollDialog = await HeritiersRollDialog.create(this, rollData)
rollDialog.render(true)
}
}
2024-04-11 12:36:50 +02:00
/* -------------------------------------------- */
pouvoirPassifDialog(pouvoir) {
let rollData = this.getCommonRollData()
rollData.pouvoir = pouvoir
rollData.mode = "pouvoirpassif"
rollData.pouvoirPointsUsage = 0
rollData.noRoll = true
let d = new Dialog({
title: "Activer le pouvoir passif " + pouvoir.name,
content: "<p>Choisissez le nombre de Points d'Usage</p>",
buttons: {
one: {
icon: '<i class="fas fa-check"></i>',
label: "1 Point d'Usage",
callback: () => {
rollData.pouvoirPointsUsage = 1;
HeritiersUtility.rollHeritiers(rollData);
2024-11-17 22:45:48 +01:00
}
2024-04-11 12:36:50 +02:00
},
two: {
icon: '<i class="fas fa-check"></i>',
label: "2 Points d'Usage",
callback: () => {
rollData.pouvoirPointsUsage = 2;
HeritiersUtility.rollHeritiers(rollData);
2024-11-17 22:45:48 +01:00
}
2024-04-11 12:36:50 +02:00
},
three: {
icon: '<i class="fas fa-check"></i>',
label: "3 Points d'Usage",
callback: () => {
rollData.pouvoirPointsUsage = 3;
HeritiersUtility.rollHeritiers(rollData);
2024-11-17 22:45:48 +01:00
}
2024-04-11 12:36:50 +02:00
},
four: {
icon: '<i class="fas fa-check"></i>',
label: "4 Points d'Usage",
callback: () => {
rollData.pouvoirPointsUsage = 4;
HeritiersUtility.rollHeritiers(rollData);
2024-11-17 22:45:48 +01:00
}
2024-04-11 12:36:50 +02:00
},
close: {
icon: '<i class="fas fa-times"></i>',
label: "Annuler",
callback: () => {
2024-11-17 22:45:48 +01:00
}
2024-04-11 12:36:50 +02:00
}
},
default: "one",
render: html => console.log("Pouvoir passif"),
close: html => console.log("No option")
});
d.render(true);
}
2024-11-17 22:45:48 +01:00
2023-03-09 13:16:19 +01:00
/* -------------------------------------------- */
async rollPouvoir(pouvoirId) {
let pouvoir = this.items.get(pouvoirId)
if (pouvoir) {
2024-04-11 12:36:50 +02:00
if (pouvoir.system.pouvoirtype == "passif") {
this.pouvoirPassifDialog(pouvoir)
return
}
2023-03-09 13:16:19 +01:00
let rollData = this.getCommonRollData(undefined, undefined)
rollData.pouvoirMaxUsage = this.getPouvoirUsageMax(pouvoir)
rollData.pouvoir = foundry.utils.duplicate(pouvoir)
rollData.mode = "pouvoir"
2023-04-09 21:45:46 +02:00
if (pouvoir.system.feeriemasque != "autre") {
2024-05-23 11:25:51 +02:00
rollData.pouvoirBase = foundry.utils.duplicate(this.system.rang[pouvoir.system.feeriemasque.toLowerCase()])
2023-03-09 13:16:19 +01:00
rollData.pouvoirBase.label = "Féerie"
if (pouvoir.system.istest && !pouvoir.system.carac) {
ui.notifications.warn("Le pouvoir actif " + pouvoir.name + " n'a pas de caractéristique associée")
}
2024-11-17 22:45:48 +01:00
if (pouvoir.system.istest) {
rollData.carac = foundry.utils.duplicate(this.system.caracteristiques[pouvoir.system.carac])
rollData.caracKey = pouvoir.system.carac
} else {
rollData.noRoll = true
HeritiersUtility.rollHeritiers(rollData);
return;
//this.incDecPointsUsage(pouvoir.id, -rollData.pouvoirPointsUsage)
//ui.notifications.warn("Le pouvoir actif " + pouvoir.name + " a été utilisé, dépense de " + pouvoirPointsUsage + " points d'usage")
}
2023-03-09 00:26:52 +01:00
}
2023-03-09 13:16:19 +01:00
let rollDialog = await HeritiersRollDialog.create(this, rollData)
rollDialog.render(true)
}
2023-03-09 00:26:52 +01:00
}
2024-03-23 11:37:15 +01:00
/* -------------------------------------------- */
incDecPointsUsage(pouvoirId, value) {
let pouvoir = this.items.get(pouvoirId)
let newValue = pouvoir.system.pointsusagecourant + value
newValue = Math.max(newValue, 0)
newValue = Math.min(newValue, this.getPouvoirUsageMax(pouvoir))
this.updateEmbeddedDocuments('Item', [{ _id: pouvoirId, 'system.pointsusagecourant': newValue }])
}
/* -------------------------------------------- */
getPouvoirUsage(pouvoirId) {
let pouvoir = this.items.get(pouvoirId)
return pouvoir.system.pointsusagecourant
}
/* -------------------------------------------- */
getPouvoirUsageMax(pouvoir) {
if (pouvoir.system.masquetype == "masque") {
return this.system.rang.masque.value
}
return this.system.rang.feerie.value
}
/* -------------------------------------------- */
recupUsage(value) {
let updates = []
for (let pouvoir of this.items) {
if (pouvoir.type == "pouvoir") {
let newValue = pouvoir.system.pointsusagecourant + value
newValue = Math.max(newValue, 0)
newValue = Math.min(newValue, this.getPouvoirUsageMax(pouvoir))
updates.push({ _id: pouvoir.id, 'system.pointsusagecourant': newValue })
}
}
2024-04-11 12:36:50 +02:00
if (updates.length > 0) {
2024-03-23 11:37:15 +01:00
this.updateEmbeddedDocuments('Item', updates)
}
}
2022-12-26 00:33:13 +01:00
}