Update sheet

This commit is contained in:
2023-01-20 15:19:04 +01:00
parent d294d6aed1
commit aefdb54c85
8 changed files with 200 additions and 240 deletions

View File

@ -43,12 +43,13 @@ export class HeritiersActorSheet extends ActorSheet {
armes: duplicate(this.actor.getWeapons()),
monnaies: duplicate(this.actor.getMonnaies()),
protections: duplicate(this.actor.getArmors()),
profils: duplicate(this.actor.getProfils() || []),
combat: this.actor.getCombatValues(),
equipements: duplicate(this.actor.getEquipments()),
monnaies: duplicate(this.actor.getMonnaies()),
richesse: this.actor.computeRichesse(),
valeurEquipement: this.actor.computeValeurEquipement(),
avantages: duplicate(this.actor.getAvantages()),
atouts: duplicate(this.actor.getAtouts()),
capacites: duplicate(this.actor.getCapacites()),
desavantages: duplicate(this.actor.getDesavantages()),
pvMalus: this.actor.getPvMalus(),
initiative: this.actor.getFlag("world", "last-initiative") || -1,
description: await TextEditor.enrichHTML(this.object.system.biodata.description, {async: true}),
habitat: await TextEditor.enrichHTML(this.object.system.biodata.habitat, {async: true}),
@ -124,26 +125,15 @@ export class HeritiersActorSheet extends ActorSheet {
this.actor.rollAttribut("pre", true)
})
html.find('.roll-attribut').click((event) => {
const li = $(event.currentTarget).parents(".item")
let attrKey = li.data("attr-key")
this.actor.rollAttribut(attrKey, false)
html.find('.roll-carac').click((event) => {
const key = $(event.currentTarget).data("key")
this.actor.rollCarac(key, false)
})
html.find('.roll-competence').click((event) => {
const li = $(event.currentTarget).parents(".item")
let compId = li.data("item-id")
this.actor.rollCompetence(compId)
})
html.find('.roll-arme-offensif').click((event) => {
const li = $(event.currentTarget).parents(".item")
let armeId = li.data("item-id")
this.actor.rollArmeOffensif(armeId)
})
html.find('.roll-arme-degats').click((event) => {
const li = $(event.currentTarget).parents(".item")
let armeId = li.data("item-id")
this.actor.rollArmeDegats(armeId)
})
html.find('.item-add').click((event) => {
const itemType = $(event.currentTarget).data("type")
@ -173,19 +163,14 @@ export class HeritiersActorSheet extends ActorSheet {
}
/* -------------------------------------------- */
async _onDropItem(event, dragData) {
/*async _onDropItem(event, dragData) {
let data = event.dataTransfer.getData('text/plain')
let dataItem = JSON.parse( data)
let item = fromUuidSync(dataItem.uuid)
if (item.pack) {
item = await HeritiersUtility.searchItem(item)
}
let autoresult = HeritiersAutomation.processAutomations("on-drop", item, this.actor)
if ( autoresult.isValid ) {
super._onDropItem(event, dragData)
} else {
ui.notifications.warn( autoresult.warningMessage)
}
}
super._onDropItem(event, dragData)
}*/
}

View File

@ -106,33 +106,30 @@ export class HeritiersActor extends Actor {
getEquipments() {
return this.items.filter(item => item.type == "equipement")
}
/* ----------------------- --------------------- */
getArtefacts() {
return this.items.filter(item => item.type == "artefact")
getAvantages() {
return this.items.filter(item => item.type == "avantage")
}
getDesavantages() {
return this.items.filter(item => item.type == "desavantage")
}
/* ----------------------- --------------------- */
getMonnaies() {
return this.items.filter(item => item.type == "monnaie")
}
/* -------------------------------------------- */
getArmors() {
return this.items.filter(item => item.type == "protection")
}
getHistoriques() {
return this.items.filter(item => item.type == "historique")
}
getProfils() {
return this.items.filter(item => item.type == "profil")
}
getTalents() {
return this.items.filter(item => item.type == "talent")
}
getRessources() {
return this.items.filter(item => item.type == "ressource")
}
getContacts() {
return this.items.filter(item => item.type == "contact")
}
getAtouts() {
return this.items.filter(item => item.type == "atoutfeerique")
}
getCapacites() {
return this.items.filter(item => item.type == "capacitenaturelle")
}
/* -------------------------------------------- */
getSkills() {
let comp = []
@ -262,90 +259,17 @@ export class HeritiersActor extends Actor {
}
/* -------------------------------------------- */
checkAttribut(attribut, minLevel) {
let attr = this.system.attributs.find(at => at.labelnorm == attribut.toLowerCase())
if (attr && attr.value >= minLevel) {
return { isValid: true, attr: duplicate(attr) }
}
return { isValid: false }
}
/* -------------------------------------------- */
checkAttributOrCompetenceLevel(compName, minLevel) {
let comp = this.items.find(i => i.type == "competence" && i.name.toLowerCase() == compName.toLowerCase() && i.system.niveau >= minLevel)
if (comp) {
return { isValid: true, item: duplicate(comp) }
} else {
for (let attrKey in this.system.attributs) {
if (this.system.attributs[attrKey].label.toLowerCase() == compName.toLowerCase() && this.system.attributs[attrKey].value >= minLevel) {
return { isValid: true, item: duplicate(this.system.attributs[attrKey]) }
}
getPvMalus() {
if (this.system.pv.value > 0) {
if (this.system.pv.value < this.system.pv.max / 2) {
return -1
}
}
return { isValid: false, warningMessage: `Prérequis insuffisant : la compétence/attribut ${compName} doit être de niveau ${minLevel} au minimum` }
}
/* -------------------------------------------- */
addCompetenceBonus(compName, bonus, baCost) {
let comp = this.items.find(i => i.type == "competence" && i.name.toLowerCase() == compName.toLowerCase())
if (comp) {
comp = duplicate(comp)
comp.system.bonus = bonus
comp.system.baCost = baCost
return { isValid: true, item: comp }
}
return { isValid: false, warningMessage: `Compétence ${compName} non trouvée` }
}
/* -------------------------------------------- */
checkIfCompetence(compName) {
let comp = this.items.find(i => i.type == "competence" && i.name.toLowerCase() == compName.toLowerCase())
if (comp) {
return { isValid: true, item: comp }
}
return { isValid: false }
}
/* -------------------------------------------- */
getVigueur() {
return this.system.sante.vigueur
}
/* -------------------------------------------- */
getVigueurBonus() {
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 == "vigueur") {
bonus += Number(auto.bonus || 0)
}
if (this.system.pv.value < 5) {
return -2
}
return 0
}
return bonus
}
/* -------------------------------------------- */
getBonneAventure() {
return this.system.bonneaventure.actuelle
}
/* -------------------------------------------- */
checkBonneAventure(cost) {
return (this.system.bonneaventure.actuelle >= cost)
}
/* -------------------------------------------- */
changeBonneAventure(value) {
let newBA = this.system.bonneaventure.actuelle
newBA += value
this.update({ 'system.bonneaventure.actuelle': newBA })
}
/* -------------------------------------------- */
getEclat() {
return this.system.eclat.value
}
/* -------------------------------------------- */
changeEclat(value) {
let newE = this.system.eclat.value
newE += value
this.update({ 'system.eclat.value': newE })
return "Moribond(e)"
}
/* -------------------------------------------- */
@ -514,6 +438,14 @@ export class HeritiersActor extends Actor {
getHeritages() {
return this.system.rang.heritage.value
}
/* -------------------------------------------- */
incDecTricherie(value) {
let tricherie = this.system.rang.tricherie
tricherie.value += value
tricherie.value = Math.max(tricherie.value, 0)
tricherie.value = Math.min(tricherie.value, tricherie.max)
this.update({ 'system.rang.tricherie': tricherie })
}
/* -------------------------------------------- */
getCommonRollData(compId = undefined, compName = undefined) {
@ -529,6 +461,7 @@ export class HeritiersActor extends Actor {
rollData.heritage = this.getHeritages()
rollData.useTricherie = false
rollData.useHeritage = false
rollData.pvMalus = this.getPvMalus()
if (compId) {
rollData.competence = duplicate(this.items.get(compId) || {})
@ -542,10 +475,11 @@ export class HeritiersActor extends Actor {
}
/* -------------------------------------------- */
async rollAttribut(attrKey, isInit = false) {
let rollData = this.getCommonRollData(attrKey)
rollData.multiplier = (isInit) ? 1 : 2
rollData.isInit = isInit
async rollCarac(key, isInit = false) {
let rollData = this.getCommonRollData()
rollData.mode = "carac"
rollData.carac = this.system.caracteristiques[key]
rollData.caracKey = key
let rollDialog = await HeritiersRollDialog.create(this, rollData)
rollDialog.render(true)
}
@ -553,7 +487,7 @@ export class HeritiersActor extends Actor {
/* -------------------------------------------- */
async rollCompetence(compId) {
let rollData = this.getCommonRollData(compId)
rollData.multiplier = 1 // Attr multiplier, always 1 in competence mode
rollData.mode = "competence"
console.log("RollDatra", rollData)
let rollDialog = await HeritiersRollDialog.create(this, rollData)
rollDialog.render(true)

View File

@ -57,7 +57,6 @@ export class HeritiersItemSheet extends ItemSheet {
name: objectData.name,
editable: this.isEditable,
cssClass: this.isEditable ? "editable" : "locked",
attributs: HeritiersUtility.getAttributs(),
system: objectData.system,
limited: this.object.limited,
options: this.options,

View File

@ -16,7 +16,8 @@ export class HeritiersRollDialog extends Dialog {
let conf = {
title: "Test de Capacité",
content: html,
buttons: {
buttons:
{
rolld8: {
icon: '<i class="fas fa-check"></i>',
label: "Lancer 1d8",
@ -40,7 +41,21 @@ export class HeritiersRollDialog extends Dialog {
},
close: close
}
// Overwrite in case of carac only -> 1d10
if (rollData.mode == "carac") {
conf.buttons = {
rolld8: {
icon: '<i class="fas fa-check"></i>',
label: "Lancer 1d8",
callback: () => { this.roll("d8") }
},
cancel: {
icon: '<i class="fas fa-times"></i>',
label: "Annuler",
callback: () => { this.close() }
}
}
}
super(conf, options);
this.actor = actor
@ -77,6 +92,6 @@ export class HeritiersRollDialog extends Dialog {
})
html.find('#useHeritage').change((event) => {
this.rollData.useHeritage = event.currentTarget.checked
})
})
}
}

View File

@ -277,27 +277,55 @@ export class HeritiersUtility {
}
/* -------------------------------------------- */
static computeResult(rollData) {
static incDecHeritage() {
}
/* -------------------------------------------- */
static computeResult(actor, rollData) {
rollData.diceResult = -1
let resTab = []
for ( let res of rollData.roll.terms[0].results) {
rollData.diceResult = Math.max(res.result, rollData.diceResult)
resTab.push(res.result)
}
let isFailure = false
if (rollData.mainDice.includes("d10")) {
if ( rollData.diceResult == 1) {
rollData.finalResult -= 3
isFailure = true
}
}
if (rollData.mainDice.includes("d12")) {
if ( rollData.diceResult == 1 || rollData.diceResult == 2) {
rollData.finalResult -= 5
isFailure = true
}
}
if (rollData.useHeritage || rollData.useTricherie) {
// Heritage/Tricherie management
rollData.marge = 0
if (!isFailure && (rollData.useHeritage || rollData.useTricherie)) {
resTab = resTab.sort()
if ( (resTab[0] == resTab[1]) && (resTab[1] == resTab[2])) {
rollData.marge = 7
rollData.isSuccess = true
rollData.isCriticalSuccess = true
}
if ((resTab[0]+1 == resTab[1]) && (resTab[1]+1 == resTab[2]) ) {
rollData.marge = 7
rollData.isSuccess = true
rollData.isCriticalSuccess = true
}
if ( rollData.useTricherie) {
actor.incDecTricherie(-1)
}
if ( rollData.useHeritage) {
this.incDecHeritage()
}
}
//rollData.finalResult = Math.max(rollData.finalResult, 0)
//console.log("Result : ", rollData)
if (rollData.sdValue > 0 ) {
if (rollData.marge == 0 && rollData.sdValue > 0 ) {
rollData.marge = rollData.finalResult - rollData.sdValue
rollData.isSuccess = (rollData.finalResult >= rollData.sdValue)
rollData.isCriticalSuccess = ((rollData.finalResult - rollData.sdValue) >= 7)
@ -319,8 +347,9 @@ export class HeritiersUtility {
let compmod = (rollData.competence.system.niveau == 0) ? -3 : 0
rollData.diceFormula += `+${rollData.carac.value}+${rollData.competence.system.niveau}+${rollData.bonusMalusContext}+${compmod}`
} else {
rollData.diceFormula += `+${rollData.attr.value}*${rollData.multiplier}+${rollData.modificateur}+${rollData.bonusMalusContext}`
rollData.diceFormula += `+${rollData.carac.value}+${rollData.bonusMalusContext}`
}
rollData.diceFormula += `+${rollData.pvMalus}`
if (rollData.arme && rollData.arme.type == "arme") {
rollData.diceFormula += `+${rollData.arme.system.bonusmaniementoff}`
@ -332,7 +361,7 @@ export class HeritiersUtility {
console.log(">>>> ", myRoll)
rollData.finalResult = myRoll.total
this.computeResult(rollData)
this.computeResult(actor, rollData)
if (rollData.isInit) {
actor.setFlag("world", "last-initiative", rollData.finalResult)
}