Compute threat level
This commit is contained in:
@ -4,7 +4,7 @@ import { PegasusRollDialog } from "./pegasus-roll-dialog.js";
|
||||
|
||||
/* -------------------------------------------- */
|
||||
const coverBonusTable = { "nocover": 0, "lightcover": 2, "heavycover": 4, "entrenchedcover": 6 };
|
||||
|
||||
const statThreatLevel = [ "agi", "str", "phy", "com", "def", "per" ]
|
||||
/* -------------------------------------------- */
|
||||
/* -------------------------------------------- */
|
||||
/**
|
||||
@ -295,6 +295,47 @@ export class PegasusActor extends Actor {
|
||||
return duplicate(this.data.items.filter(item => item.type == "equipment") || [])
|
||||
}
|
||||
|
||||
/* ------------------------------------------- */
|
||||
computeThreatLevel() {
|
||||
let tl = 0
|
||||
for(let key of statThreatLevel) { // Init with concerned stats
|
||||
tl += PegasusUtility.getDiceValue( this.data.data.statistics[key].value )
|
||||
}
|
||||
let powers = this.getPowers()
|
||||
if ( powers && powers.length > 0 ) { // Then add some mental ones of powers
|
||||
tl += PegasusUtility.getDiceValue( this.data.data.statistics.foc.value )
|
||||
tl += PegasusUtility.getDiceValue( this.data.data.statistics.mnd.value )
|
||||
}
|
||||
tl += PegasusUtility.getDiceValue( this.data.data.mr.value )
|
||||
let specThreat = this.data.items.filter( it => it.type == "specialisation" && it.data.data.isthreatlevel) || []
|
||||
for (let spec of specThreat) {
|
||||
tl += PegasusUtility.getDiceValue( spec.data.data.level )
|
||||
}
|
||||
tl += this.data.data.nrg.absolutemax + this.data.data.secondary.health.max + this.data.data.secondary.delirium.max
|
||||
tl += this.getPerks().length * 5
|
||||
|
||||
let weapons = this.getWeapons()
|
||||
for(let weapon of weapons) {
|
||||
tl += PegasusUtility.getDiceValue(weapon.data.damage)
|
||||
}
|
||||
let armors = this.getArmors()
|
||||
for(let armor of armors) {
|
||||
tl += PegasusUtility.getDiceValue(armor.data.resistance)
|
||||
}
|
||||
let shields = this.getShields()
|
||||
for(let shield of shields) {
|
||||
tl += PegasusUtility.getDiceValue(shield.data.level)
|
||||
}
|
||||
|
||||
let equipments = this.getEquipmentsOnly()
|
||||
for (let equip of equipments) {
|
||||
tl += equip.data.threatlevel
|
||||
}
|
||||
if ( tl != this.data.data.biodata.threatlevel) {
|
||||
this.update( {'data.biodata.threatlevel': tl} )
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------- */
|
||||
async buildContainerTree() {
|
||||
let equipments = duplicate(this.data.items.filter(item => item.type == "equipment") || [])
|
||||
@ -305,7 +346,8 @@ export class PegasusActor extends Actor {
|
||||
for (let equip2 of equipments) {
|
||||
if (equip1._id != equip2._id && equip2.data.containerid == equip1._id) {
|
||||
equip1.data.contents.push(equip2)
|
||||
equip1.data.contentsEnc += equip2.data.weight
|
||||
let q = equip2.data.quantity ?? 1
|
||||
equip1.data.contentsEnc += q *equip2.data.weight
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -319,13 +361,15 @@ export class PegasusActor extends Actor {
|
||||
if (item.data.iscontainer) {
|
||||
enc += item.data.contentsEnc
|
||||
} else if (item.data.containerid == "") {
|
||||
enc += item.data.weight
|
||||
let q = item.data.quantity ?? 1
|
||||
enc += q * item.data.weight
|
||||
}
|
||||
}
|
||||
}
|
||||
for (let item of this.data.items) { // Process items/shields/armors
|
||||
if ((item.type == "weapon" || item.type == "shield" || item.type == "armor") && item.data.data.equipped) {
|
||||
enc += item.data.data.weight
|
||||
let q = item.data.data.quantity ?? 1
|
||||
enc += q * item.data.data.weight
|
||||
}
|
||||
}
|
||||
|
||||
@ -826,6 +870,8 @@ export class PegasusActor extends Actor {
|
||||
}
|
||||
//console.log("UPD", updates, this.data.data.biodata)
|
||||
await this.update(updates)
|
||||
|
||||
this.computeThreatLevel()
|
||||
}
|
||||
|
||||
if (this.isOwner || game.user.isGM) {
|
||||
@ -875,8 +921,10 @@ export class PegasusActor extends Actor {
|
||||
async incDecQuantity(objetId, incDec = 0) {
|
||||
let objetQ = this.data.items.get(objetId)
|
||||
if (objetQ) {
|
||||
let newQ = objetQ.data.data.quantity + incDec;
|
||||
const updated = await this.updateEmbeddedDocuments('Item', [{ _id: objetQ.id, 'data.quantity': newQ }]); // pdates one EmbeddedEntity
|
||||
let newQ = objetQ.data.data.quantity + incDec
|
||||
if (newQ >= 0) {
|
||||
const updated = await this.updateEmbeddedDocuments('Item', [{ _id: objetQ.id, 'data.quantity': newQ }]) // pdates one EmbeddedEntity
|
||||
}
|
||||
}
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
|
Reference in New Issue
Block a user