Fiche acteur, WIP

This commit is contained in:
2023-01-18 16:16:18 +01:00
parent 3108c346f4
commit 54e397d6f0
15 changed files with 483 additions and 558 deletions

View File

@@ -38,40 +38,26 @@ export class HeritiersActor extends Actor {
}
if (data.type == 'personnage') {
const skills = await HeritiersUtility.loadCompendium("fvtt-les-heritiers.skills")
const skills = await HeritiersUtility.loadCompendium("fvtt-les-heritiers.competences")
data.items = skills.map(i => i.toObject())
}
if (data.type == 'creature') {
const skills = await HeritiersUtility.loadCompendium("fvtt-les-heritiers.skills-creatures")
data.items = skills.map(i => i.toObject())
data.items.push( { name: "Arme naturelle 1", type: 'arme', img: "systems/fvtt-les-heritiers/assets/icons/melee.webp", system: { typearme: "contact", bonusmaniementoff: 0, seuildefense: 0, degats: "0"} } )
data.items.push( { name: "Arme naturelle 2", type: 'arme', img: "systems/fvtt-les-heritiers/assets/icons/melee.webp", system: { typearme: "contact", bonusmaniementoff: 0, seuildefense: 0, degats: "0"} } )
data.items.push({ name: "Arme naturelle 1", type: 'arme', img: "systems/fvtt-les-heritiers/assets/icons/melee.webp", system: { typearme: "contact", bonusmaniementoff: 0, seuildefense: 0, degats: "0" } })
data.items.push({ name: "Arme naturelle 2", type: 'arme', img: "systems/fvtt-les-heritiers/assets/icons/melee.webp", system: { typearme: "contact", bonusmaniementoff: 0, seuildefense: 0, degats: "0" } })
}
return super.create(data, options);
}
/* -------------------------------------------- */
getBonusDefenseFromTalents() {
let talents = this.items.filter(item => item.type == "talent" && item.system.isautomated)
let bonus = 0
for (let talent of talents) {
for (let auto of talent.system.automations) {
if (auto.eventtype == "bonus-permanent" && auto.bonusname == "bonus-defensif") {
bonus += Number(auto.bonus || 0)
}
}
}
return bonus
}
/* -------------------------------------------- */
prepareArme(arme) {
arme = duplicate(arme)
let combat = this.getCombatValues()
if (arme.system.typearme == "contact" || arme.system.typearme == "contactjet") {
let bonusDefense = this.getBonusDefenseFromTalents()
arme.system.competence = duplicate(this.items.find(item => item.type == "competence" && item.name.toLowerCase() == "mêlée") )
let bonusDefense = 0
arme.system.competence = duplicate(this.items.find(item => item.type == "competence" && item.name.toLowerCase() == "mêlée"))
arme.system.attrKey = "pui"
arme.system.totalDegats = arme.system.degats + "+" + combat.bonusDegatsTotal
arme.system.totalOffensif = this.system.attributs.pui.value + arme.system.competence.system.niveau + arme.system.bonusmaniementoff
@@ -102,18 +88,18 @@ export class HeritiersActor extends Actor {
}
/* -------------------------------------------- */
getMonnaies() {
return this.items.filter( it => it.type == "monnaie")
return this.items.filter(it => it.type == "monnaie")
}
/* ----------------------- --------------------- */
addMember( actorId) {
addMember(actorId) {
let members = duplicate(this.system.members)
members.push( {id: actorId} )
this.update ({'system.members': members})
members.push({ id: actorId })
this.update({ 'system.members': members })
}
async removeMember(actorId) {
let members = this.system.members.filter(it => it.id != actorId )
this.update ({'system.members': members})
async removeMember(actorId) {
let members = this.system.members.filter(it => it.id != actorId)
this.update({ 'system.members': members })
}
/* ----------------------- --------------------- */
@@ -153,31 +139,39 @@ export class HeritiersActor extends Actor {
for (let item of this.items) {
item = duplicate(item)
if (item.type == "competence") {
item.system.attribut1total = item.system.niveau + (this.system.attributs[item.system.attribut1]?.value || 0)
item.system.attribut2total = item.system.niveau + (this.system.attributs[item.system.attribut2]?.value || 0)
item.system.attribut3total = item.system.niveau + (this.system.attributs[item.system.attribut3]?.value || 0)
if (item.system.niveau == 0) {
item.system.attribut1total -= 3
item.system.attribut2total -= 3
item.system.attribut3total -= 3
}
item.system.attribut1label = this.system.attributs[item.system.attribut1]?.label || ""
item.system.attribut2label = this.system.attributs[item.system.attribut2]?.label || ""
item.system.attribut3label = this.system.attributs[item.system.attribut3]?.label || ""
comp.push(item)
}
}
return comp.sort(function (a, b) {
let fa = a.name.toLowerCase(),
fb = b.name.toLowerCase();
if (fa < fb) {
return -1;
return HeritiersUtility.sortByName(comp)
}
/* -------------------------------------------- */
organizeUtileSkills() {
let comp = {}
for (let key in game.system.lesheritiers.config.competenceProfil) {
comp[key] = []
}
for (let item of this.items) {
if (item.type == "competence") {
if (item.system.categorie == "utile") {
comp[item.system.profil].push(item)
}
}
if (fa > fb) {
return 1;
}
return comp
}
/* -------------------------------------------- */
organizeFutileSkills() {
let comp = []
for (let item of this.items) {
if (item.type == "competence") {
if (item.system.categorie == "futile") {
comp.push(item)
}
}
return 0;
})
}
return HeritiersUtility.sortByName(comp)
}
/* -------------------------------------------- */
@@ -192,7 +186,7 @@ export class HeritiersActor extends Actor {
/* -------------------------------------------- */
getProtection() {
let equipProtection = 0
for(let armor in this.items) {
for (let armor in this.items) {
if (armor.type == "protection" && armor.system.equipped) {
equipProtection += Number(armor.system.protection)
}
@@ -206,15 +200,6 @@ export class HeritiersActor extends Actor {
/* -------------------------------------------- */
getCombatValues() {
let combat = {
initBase: this.system.attributs.adr.value,
initTotal: this.system.attributs.adr.value + this.system.combat.initbonus,
bonusDegats: this.getBonusDegats(),
bonusDegatsTotal: this.getBonusDegats() + this.system.combat.bonusdegats,
vitesseBase: this.getVitesseBase(),
vitesseTotal: this.getVitesseBase() + this.system.combat.vitessebonus,
defenseBase: this.getDefenseBase(),
protection : this.getProtection(),
defenseTotal: this.getDefenseBase() + this.system.combat.defensebonus + this.getProtection() - this.getTotalAdversite()
}
return combat
}
@@ -232,11 +217,6 @@ export class HeritiersActor extends Actor {
prepareDerivedData() {
if (this.type == 'personnage') {
let talentBonus = this.getVigueurBonus()
let vigueur = Math.floor((this.system.attributs.pui.value + this.system.attributs.tre.value) / 2) + talentBonus
if (vigueur != this.system.sante.vigueur) {
this.update({ 'system.sante.vigueur': vigueur })
}
}
super.prepareDerivedData()
@@ -380,13 +360,13 @@ export class HeritiersActor extends Actor {
}
/* -------------------------------------------- */
getAttribute(attrKey) {
return this.system.attributes[attrKey]
getCarac(attrKey) {
return duplicate(this.system.caracteristiques)
}
/* -------------------------------------------- */
getBonusDegats() {
return 0;
return 0;
}
/* -------------------------------------------- */
@@ -448,27 +428,27 @@ export class HeritiersActor extends Actor {
/* -------------------------------------------- */
computeRichesse() {
let valueSC = 0
for(let monnaie of this.items) {
for (let monnaie of this.items) {
if (monnaie.type == "monnaie") {
valueSC += Number(monnaie.system.prixsc) * Number(monnaie.system.quantite)
valueSC += Number(monnaie.system.prixsc) * Number(monnaie.system.quantite)
}
}
return HeritiersUtility.computeMonnaieDetails( valueSC)
return HeritiersUtility.computeMonnaieDetails(valueSC)
}
/* -------------------------------------------- */
computeValeurEquipement() {
let valueSC = 0
for(let equip of this.items) {
for (let equip of this.items) {
if (equip.type == "equipement" || equip.type == "arme" || equip.type == "protection") {
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
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
}
}
return HeritiersUtility.computeMonnaieDetails( valueSC)
return HeritiersUtility.computeMonnaieDetails(valueSC)
}
/* -------------------------------------------- */
getCompetence(compId) {
return this.items.get(compId)
@@ -494,7 +474,7 @@ export class HeritiersActor extends Actor {
let maxDef = 0
let bestArme
for (let arme of defenseList) {
if (arme.type == "arme" ) {
if (arme.type == "arme") {
arme = this.prepareArme(arme)
}
if (arme.system.totalDefensif > maxDef) {
@@ -532,32 +512,19 @@ export class HeritiersActor extends Actor {
}
/* -------------------------------------------- */
getCommonRollData(attrKey = undefined, compId = undefined, compName = undefined) {
getCommonRollData(compId = undefined, compName = undefined) {
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
rollData.attributs = HeritiersUtility.getAttributs()
rollData.maitriseId = "none"
rollData.nbEclat = this.system.eclat.value
rollData.nbBA = this.system.bonneaventure.actuelle
rollData.nbAdversites = this.getTotalAdversite()
rollData.talents = []
rollData.caracList = this.getCarac()
rollData.caracKey = "agi"
if (attrKey) {
rollData.attrKey = attrKey
if (attrKey != "tochoose") {
rollData.actionImg = "systems/fvtt-les-heritiers/assets/icons/" + this.system.attributs[attrKey].labelnorm + ".webp"
rollData.attr = duplicate(this.system.attributs[attrKey])
}
}
if (compId) {
rollData.competence = duplicate(this.items.get(compId) || {})
rollData.maitrises = rollData.competence.system.predilections.filter(p => p.maitrise)
rollData.actionImg = rollData.competence?.img
rollData.talents = this.searchRelevantTalents(rollData.competence)
}
if (compName) {
rollData.competence = duplicate(this.items.find(item => item.name.toLowerCase() == compName.toLowerCase()) || {})
@@ -568,16 +535,16 @@ export class HeritiersActor extends Actor {
/* -------------------------------------------- */
async rollAttribut(attrKey, isInit = false) {
let rollData = this.getCommonRollData(attrKey)
rollData.multiplier = (isInit)? 1 : 2
let rollData = this.getCommonRollData(attrKey)
rollData.multiplier = (isInit) ? 1 : 2
rollData.isInit = isInit
let rollDialog = await HeritiersRollDialog.create(this, rollData)
rollDialog.render(true)
}
/* -------------------------------------------- */
async rollCompetence(attrKey, compId) {
let rollData = this.getCommonRollData(attrKey, compId)
async rollCompetence(compId) {
let rollData = this.getCommonRollData(compId)
rollData.multiplier = 1 // Attr multiplier, always 1 in competence mode
console.log("RollDatra", rollData)
let rollDialog = await HeritiersRollDialog.create(this, rollData)
@@ -605,9 +572,9 @@ export class HeritiersActor extends Actor {
arme = this.prepareArme(arme)
}
console.log("DEGATS", arme)
let roll = new Roll( "1d10+"+arme.system.totalDegats).roll({ async: false })
let roll = new Roll("1d10+" + arme.system.totalDegats).roll({ async: false })
await HeritiersUtility.showDiceSoNice(roll, game.settings.get("core", "rollMode"));
let nbEtatPerdus = 0
let nbEtatPerdus = 0
if (targetVigueur) {
nbEtatPerdus = Math.floor(roll.total / targetVigueur)
}