Actor sheet v1

This commit is contained in:
2022-12-30 22:27:38 +01:00
parent 83119a2b82
commit 580b044c77
13 changed files with 313 additions and 874 deletions

View File

@@ -64,26 +64,30 @@ export class DarkStarsActor extends Actor {
/* -------------------------------------------- */
computeHitPoints() {
if (this.type == "character") {
let hp = duplicate(this.system.secondary.hp)
let max = (this.system.abilities.str.value + this.system.abilities.con.value) * 6
if (max != hp.max || hp.value > max) {
hp.max = max
hp.value = max // Init case
this.update({ 'system.secondary.hp': hp })
}
}
}
/* -------------------------------------------- */
computeEffortPoints() {
if (this.type == "character") {
let effort = duplicate(this.system.secondary.effort)
let max = (this.system.abilities.con.value + this.system.abilities.int.value) * 6
if (max != effort.max || effort.value > max) {
effort.max = max
effort.value = max // Init case
this.update({ 'system.secondary.effort': effort })
}
}
computeDerivated() {
let attr = this.system.attributes
let deriv = this.system.derivated
let secondary = this.system.secondary
deriv.csb.value = Math.round((attr.dex.value + attr.sel.value) / 2) + deriv.csb.bonus
deriv.asb.value = Math.round((attr.int.value + attr.edu.value) / 2) + deriv.asb.bonus
deriv.ssb.value = Math.round((attr.cha.value + attr.emp.value + attr.att.value) / 3) + deriv.ssb.bonus
deriv.msb.value = Math.round((attr.con.value + attr.str.value ) / 2) + deriv.msb.bonus
deriv.psb.value = Math.round((attr.str.value + attr.dex.value + attr.con.value) / 3) + deriv.psb.bonus
deriv.ego.value = attr.str.value + attr.cha.value + attr.sel.value + attr.emp.value + deriv.ego.bonus
deriv.hup.value = (attr.emp.value * 10) + deriv.hup.bonus
deriv.ss.value = (attr.edu.value * 10) + (attr.int.value * 10) + 250 + deriv.ss.bonus
deriv.mcdb.value = Math.round( (attr.str.value + attr.siz.value) / 4) + deriv.mcdb.bonus
deriv.si.value = Math.round( ((attr.dex.value + attr.sel.value) / 5) + 0.5) + deriv.si.bonus
secondary.hp.max = ((attr.con.value + attr.siz.value ) * 2) + secondary.hp.bonus
secondary.fp.max = 10 + attr.str.value + attr.con.value + secondary.fp.bonus
}
/* -------------------------------------------- */
@@ -91,6 +95,7 @@ export class DarkStarsActor extends Actor {
if (this.type == 'character' || game.user.isGM) {
this.system.encCapacity = this.getEncumbranceCapacity()
this.computeDerivated()
this.buildContainerTree()
this.computeHitPoints()
this.computeEffortPoints()
@@ -110,35 +115,6 @@ export class DarkStarsActor extends Actor {
return 1;
}
/* -------------------------------------------- */
getMoneys() {
let comp = this.items.filter(item => item.type == 'money');
DarkStarsUtility.sortArrayObjectsByName(comp)
return comp;
}
/* -------------------------------------------- */
getFeats() {
let comp = duplicate(this.items.filter(item => item.type == 'feat') || []);
DarkStarsUtility.sortArrayObjectsByName(comp)
return comp;
}
/* -------------------------------------------- */
getFeatsWithDie() {
let comp = duplicate(this.items.filter(item => item.type == 'feat' && item.system.isfeatdie) || []);
DarkStarsUtility.sortArrayObjectsByName(comp)
return comp;
}
getFeatsWithSL() {
let comp = duplicate(this.items.filter(item => item.type == 'feat' && item.system.issl) || []);
DarkStarsUtility.sortArrayObjectsByName(comp)
return comp;
}
/* -------------------------------------------- */
getLore() {
let comp = duplicate(this.items.filter(item => item.type == 'spell') || []);
DarkStarsUtility.sortArrayObjectsByName(comp)
return comp;
}
getEquippedWeapons() {
let comp = duplicate(this.items.filter(item => item.type == 'weapon' && item.system.equipped) || []);
DarkStarsUtility.sortArrayObjectsByName(comp)
@@ -171,11 +147,6 @@ export class DarkStarsActor extends Actor {
return undefined
}
/* -------------------------------------------- */
getRace() {
let race = this.items.filter(item => item.type == 'race')
return race[0] ?? [];
}
/* -------------------------------------------- */
checkAndPrepareEquipment(item) {
}
@@ -208,23 +179,23 @@ export class DarkStarsActor extends Actor {
return item;
}
/* -------------------------------------------- */
updateSkill(skill) {
skill.derivated = duplicate(this.system.derivated[skill.system.base])
skill.total = skill.derivated.value + skill.system.bonus
}
/* -------------------------------------------- */
getSkills() {
this.computeDerivated()
let comp = duplicate(this.items.filter(item => item.type == 'skill') || [])
for (let skill of comp) {
DarkStarsUtility.updateSkill(skill)
this.updateSkill(skill)
}
DarkStarsUtility.sortArrayObjectsByName(comp)
return comp
}
/* -------------------------------------------- */
getRelevantAbility(statKey) {
let comp = duplicate(this.items.filter(item => item.type == 'skill' && item.system.ability == ability) || []);
return comp;
}
/* -------------------------------------------- */
async equipItem(itemId) {
let item = this.items.find(item => item.id == itemId)
@@ -343,7 +314,7 @@ export class DarkStarsActor extends Actor {
/* -------------------------------------------- */
async incDecHP(formula) {
let dmgRoll = new Roll(formula+"[dark-starsorange]").roll({ async: false })
let dmgRoll = new Roll(formula + "[dark-starsorange]").roll({ async: false })
await DarkStarsUtility.showDiceSoNice(dmgRoll, game.settings.get("core", "rollMode"))
let hp = duplicate(this.system.secondary.hp)
hp.value = Number(hp.value) + Number(dmgRoll.total)
@@ -428,12 +399,6 @@ export class DarkStarsActor extends Actor {
await this.update({ 'system.subactors': newArray });
}
/* -------------------------------------------- */
syncRoll(rollData) {
this.lastRollId = rollData.rollId;
DarkStarsUtility.saveRollData(rollData);
}
/* -------------------------------------------- */
getOneSkill(skillId) {
let skill = this.items.find(item => item.type == 'skill' && item.id == skillId)
@@ -545,20 +510,8 @@ export class DarkStarsActor extends Actor {
rollData.actorImg = this.img
rollData.actorId = this.id
rollData.img = this.img
rollData.featsDie = this.getFeatsWithDie()
rollData.featsSL = this.getFeatsWithSL()
rollData.armors = this.getArmors()
rollData.conditions = this.getConditions()
rollData.featDieName = "none"
rollData.featSLName = "none"
rollData.rollAdvantage = "none"
rollData.advantage = "none"
rollData.disadvantage = "none"
rollData.forceAdvantage = this.isForcedAdvantage()
rollData.forceDisadvantage = this.isForcedDisadvantage()
rollData.forceRollAdvantage = this.isForcedRollAdvantage()
rollData.forceRollDisadvantage = this.isForcedRollDisadvantage()
rollData.noAdvantage = this.isNoAdvantage()
if (rollData.defenderTokenId) {
let defenderToken = game.canvas.tokens.get(rollData.defenderTokenId)
let defender = defenderToken.actor
@@ -612,10 +565,10 @@ export class DarkStarsActor extends Actor {
return
}
skill = duplicate(skill)
DarkStarsUtility.updateSkill(skill)
let abilityKey = skill.system.ability
let rollData = this.getCommonRollData(abilityKey)
this.updateSkill(skill)
let rollData = this.getCommonRollData()
rollData.mode = "skill"
rollData.title = "Skill " + skill.name
rollData.skill = skill
rollData.img = skill.img
if (rollData.target) {
@@ -655,152 +608,8 @@ export class DarkStarsActor extends Actor {
}
}
/* -------------------------------------------- */
rollDefenseMelee(attackRollData) {
let weapon = this.items.get(attackRollData.defenseWeaponId)
if (weapon) {
weapon = duplicate(weapon)
let skill = this.items.find(item => item.name.toLowerCase() == weapon.system.skill.toLowerCase())
if (skill) {
skill = duplicate(skill)
DarkStarsUtility.updateSkill(skill)
let abilityKey = skill.system.ability
let rollData = this.getCommonRollData(abilityKey)
rollData.defenderTokenId = undefined // Cleanup
rollData.mode = "weapondefense"
rollData.shield = this.getEquippedShield()
rollData.attackRollData = duplicate(attackRollData)
rollData.skill = skill
rollData.weapon = weapon
rollData.img = weapon.img
if (!rollData.forceDisadvantage) { // This is an attack, check if disadvantaged
rollData.forceDisadvantage = this.isDefenseDisadvantage()
}
this.startRoll(rollData)
} else {
ui.notifications.warn("Unable to find the relevant skill for weapon " + weapon.name)
}
} else {
ui.notifications.warn("Weapon not found ! ")
}
}
/* -------------------------------------------- */
rollDefenseRanged(attackRollData) {
let rollData = this.getCommonRollData()
rollData.defenderTokenId = undefined // Cleanup
rollData.mode = "rangeddefense"
if ( attackRollData) {
rollData.attackRollData = duplicate(attackRollData)
rollData.effectiveRange = DarkStarsUtility.getWeaponRange(attackRollData.weapon)
rollData.tokensDistance = attackRollData.tokensDistance // QoL copy
}
rollData.sizeDice = DarkStarsUtility.getSizeDice(this.system.biodata.size)
rollData.distanceBonusDice = 0 //Math.max(0, Math.floor((rollData.tokensDistance - rollData.effectiveRange) + 0.5))
rollData.hasCover = "none"
rollData.situational = "none"
rollData.useshield = false
rollData.shield = this.getEquippedShield()
this.startRoll(rollData)
}
/* -------------------------------------------- */
rollShieldDie() {
let shield = this.getEquippedShield()
if (shield) {
shield = duplicate(shield)
let rollData = this.getCommonRollData()
rollData.mode = "shield"
rollData.shield = shield
rollData.useshield = true
rollData.img = shield.img
this.startRoll(rollData)
}
}
/* -------------------------------------------- */
async rollArmorDie(rollData = undefined) {
let armor = this.getEquippedArmor()
if (armor) {
armor = duplicate(armor)
let reduce = 0
let multiply = 1
let disadvantage = false
let advantage = false
let messages = ["Armor applied"]
if (rollData) {
if (DarkStarsUtility.isArmorLight(armor) && DarkStarsUtility.isWeaponPenetrating(rollData.attackRollData.weapon)) {
return { armorIgnored: true, nbSuccess: 0, messages: ["Armor ignored : Penetrating weapons ignore Light Armors."] }
}
if (DarkStarsUtility.isWeaponPenetrating(rollData.attackRollData.weapon)) {
messages.push("Armor reduced by 1 (Penetrating weapon)")
reduce = 1
}
if (DarkStarsUtility.isWeaponLight(rollData.attackRollData.weapon)) {
messages.push("Armor with advantage (Light weapon)")
advantage = true
}
if (DarkStarsUtility.isWeaponHeavy(rollData.attackRollData.weapon)) {
messages.push("Armor with disadvantage (Heavy weapon)")
disadvantage = true
}
if (DarkStarsUtility.isWeaponHack(rollData.attackRollData.weapon)) {
messages.push("Armor reduced by 1 (Hack weapon)")
reduce = 1
}
if (DarkStarsUtility.isWeaponUndamaging(rollData.attackRollData.weapon)) {
messages.push("Armor multiplied by 2 (Undamaging weapon)")
multiply = 2
}
}
let diceColor = armor.system.absorprionroll
let armorResult = await DarkStarsUtility.getRollTableFromDiceColor(diceColor, false)
console.log("Armor log", armorResult)
let armorValue = Math.max(0, (Number(armorResult.text) + reduce) * multiply)
if (advantage || disadvantage) {
let armorResult2 = await DarkStarsUtility.getRollTableFromDiceColor(diceColor, false)
let armorValue2 = Math.max(0, (Number(armorResult2.text) + reduce) * multiply)
if (advantage) {
armorValue = (armorValue2 > armorValue) ? armorValue2 : armorValue
messages.push(`Armor advantage - Roll 1 = ${armorValue} - Roll 2 = ${armorValue2}`)
}
if (disadvantage) {
armorValue = (armorValue2 < armorValue) ? armorValue2 : armorValue
messages.push(`Armor disadvantage - Roll 1 = ${armorValue} - Roll 2 = ${armorValue2}`)
}
}
armorResult.armorValue = armorValue
if (!rollData) {
ChatMessage.create({ content: "Armor result : " + armorValue })
}
messages.push("Armor result : " + armorValue)
return { armorIgnored: false, nbSuccess: armorValue, rawArmor: armorResult.text, messages: messages }
}
return { armorIgnored: true, nbSuccess: 0, messages: ["No armor equipped."] }
}
/* -------------------------------------------- */
rollSave(saveKey) {
let saves = this.getSaveRoll()
let save = saves[saveKey]
if (save) {
save = duplicate(save)
let rollData = this.getCommonRollData()
rollData.mode = "save"
rollData.save = save
if (rollData.target) {
ui.notifications.warn("You are targetting a token with a save roll - Not authorized.")
return
}
this.startRoll(rollData)
}
}
/* -------------------------------------------- */
async startRoll(rollData) {
this.syncRoll(rollData)
let rollDialog = await DarkStarsRollDialog.create(this, rollData)
rollDialog.render(true)
}