Compute threat level
This commit is contained in:
parent
ec860b9f12
commit
27f81e2e9d
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
|
@ -31,24 +31,26 @@ export class PegasusUtility {
|
||||
|
||||
Handlebars.registerHelper('count', function (list) {
|
||||
return list.length;
|
||||
});
|
||||
})
|
||||
Handlebars.registerHelper('includes', function (array, val) {
|
||||
return array.includes(val);
|
||||
});
|
||||
})
|
||||
Handlebars.registerHelper('upper', function (text) {
|
||||
return text.toUpperCase();
|
||||
});
|
||||
})
|
||||
Handlebars.registerHelper('lower', function (text) {
|
||||
return text.toLowerCase()
|
||||
});
|
||||
})
|
||||
Handlebars.registerHelper('upperFirst', function (text) {
|
||||
if (typeof text !== 'string') return text
|
||||
return text.charAt(0).toUpperCase() + text.slice(1)
|
||||
});
|
||||
})
|
||||
Handlebars.registerHelper('notEmpty', function (list) {
|
||||
return list.length > 0;
|
||||
});
|
||||
|
||||
})
|
||||
Handlebars.registerHelper('mul', function (a, b) {
|
||||
return parseInt(a) * parseInt(b);
|
||||
})
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
@ -180,9 +180,9 @@
|
||||
"styles": [
|
||||
"styles/simple.css"
|
||||
],
|
||||
"templateVersion": 87,
|
||||
"templateVersion": 88,
|
||||
"title": "Pegasus RPG",
|
||||
"url": "https://www.uberwald.me/data/files/fvtt-pegasus-rpg",
|
||||
"version": "0.5.6",
|
||||
"version": "0.5.7",
|
||||
"background" : "./images/ui/pegasus_welcome_page.webp"
|
||||
}
|
||||
|
@ -269,6 +269,7 @@
|
||||
"powersource": "",
|
||||
"powersactivated": false,
|
||||
"powers": [],
|
||||
"isthreatlevel": false,
|
||||
"description": ""
|
||||
},
|
||||
"perk": {
|
||||
@ -384,6 +385,7 @@
|
||||
"iscontainer": false,
|
||||
"containercapacity": 0,
|
||||
"containerid": "",
|
||||
"threatlevel": 0,
|
||||
"description":""
|
||||
},
|
||||
"money" : {
|
||||
|
@ -526,7 +526,7 @@
|
||||
<span class="item-field-label-short">
|
||||
<label class="short-label">DMG</label>
|
||||
</span>
|
||||
<span class="item-field-label-medium">
|
||||
<span class="item-field-label-long">
|
||||
<label class="short-label">Ammo</label>
|
||||
</span>
|
||||
<span class="item-field-label-medium">
|
||||
@ -548,11 +548,11 @@
|
||||
<span class="item-field-label-short"><label>{{weapon.data.damageDice}}</label></span>
|
||||
|
||||
{{#if (gt weapon.data.ammomax 0)}}
|
||||
<span class="item-field-label-medium"><label>{{weapon.data.ammocurrent}}/{{weapon.data.ammomax}}
|
||||
<span class="item-field-label-long"><label>{{weapon.data.ammocurrent}}/{{weapon.data.ammomax}}
|
||||
(<a class="ammo-minus plus-minus-button"> -</a>/<a class="ammo-plus plus-minus-button">+</a>)
|
||||
</label></span>
|
||||
{{else}}
|
||||
<span class="item-field-label-medium"><label>-</label>
|
||||
<span class="item-field-label-long"><label>-</label>
|
||||
</span>
|
||||
{{/if}}
|
||||
|
||||
|
@ -66,6 +66,9 @@
|
||||
<input type="text" class="input-numeric-short padd-right" name="data.containercapacity" value="{{data.containercapacity}}" data-dtype="Number"/>
|
||||
</li>
|
||||
{{/if}}
|
||||
<li class="flexrow"><label class="generic-label">Threat Level Value</label>
|
||||
<input type="text" class="input-numeric-short padd-right" name="data.threatlevel" value="{{data.threatlevel}}" data-dtype="Number"/>
|
||||
</li>
|
||||
<li class="flexrow"><label class="generic-label">Cost</label>
|
||||
<input type="text" class="input-numeric-short padd-right" name="data.cost" value="{{data.cost}}" data-dtype="Number"/>
|
||||
</li>
|
||||
|
@ -53,6 +53,9 @@
|
||||
</ul>
|
||||
</li>
|
||||
{{/if}}
|
||||
<li class="flexrow"><label class="generic-label">Use for Threat Level ?</label>
|
||||
<label class="attribute-value checkbox"><input type="checkbox" name="data.isthreatlevel" {{checked data.isthreatlevel}}/></label>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</section>
|
||||
|
@ -27,7 +27,7 @@
|
||||
{{#if equip.data.iscontainer}}
|
||||
{{equip.data.contentsEnc}}
|
||||
{{else}}
|
||||
N/A
|
||||
{{mul equip.data.weight equip.data.quantity}}
|
||||
{{/if}}
|
||||
</span>
|
||||
<span class="item-field-label-medium">
|
||||
|
Loading…
Reference in New Issue
Block a user