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 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") || []) |     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() { |   async buildContainerTree() { | ||||||
|     let equipments = duplicate(this.data.items.filter(item => item.type == "equipment") || []) |     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) { |         for (let equip2 of equipments) { | ||||||
|           if (equip1._id != equip2._id && equip2.data.containerid == equip1._id) { |           if (equip1._id != equip2._id && equip2.data.containerid == equip1._id) { | ||||||
|             equip1.data.contents.push(equip2) |             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) { |         if (item.data.iscontainer) { | ||||||
|           enc += item.data.contentsEnc |           enc += item.data.contentsEnc | ||||||
|         } else if (item.data.containerid == "") { |         } 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 |     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) { |       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) |       //console.log("UPD", updates, this.data.data.biodata) | ||||||
|       await this.update(updates) |       await this.update(updates) | ||||||
|  |  | ||||||
|  |       this.computeThreatLevel() | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     if (this.isOwner || game.user.isGM) { |     if (this.isOwner || game.user.isGM) { | ||||||
| @@ -875,8 +921,10 @@ export class PegasusActor extends Actor { | |||||||
|   async incDecQuantity(objetId, incDec = 0) { |   async incDecQuantity(objetId, incDec = 0) { | ||||||
|     let objetQ = this.data.items.get(objetId) |     let objetQ = this.data.items.get(objetId) | ||||||
|     if (objetQ) { |     if (objetQ) { | ||||||
|       let newQ = objetQ.data.data.quantity + incDec; |       let newQ = objetQ.data.data.quantity + incDec | ||||||
|       const updated = await this.updateEmbeddedDocuments('Item', [{ _id: objetQ.id, 'data.quantity': newQ }]); // pdates one EmbeddedEntity |       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) { |     Handlebars.registerHelper('count', function (list) { | ||||||
|       return list.length; |       return list.length; | ||||||
|     }); |     }) | ||||||
|     Handlebars.registerHelper('includes', function (array, val) { |     Handlebars.registerHelper('includes', function (array, val) { | ||||||
|       return array.includes(val); |       return array.includes(val); | ||||||
|     }); |     }) | ||||||
|     Handlebars.registerHelper('upper', function (text) { |     Handlebars.registerHelper('upper', function (text) { | ||||||
|       return text.toUpperCase(); |       return text.toUpperCase(); | ||||||
|     }); |     }) | ||||||
|     Handlebars.registerHelper('lower', function (text) { |     Handlebars.registerHelper('lower', function (text) { | ||||||
|       return text.toLowerCase() |       return text.toLowerCase() | ||||||
|     }); |     }) | ||||||
|     Handlebars.registerHelper('upperFirst', function (text) { |     Handlebars.registerHelper('upperFirst', function (text) { | ||||||
|       if (typeof text !== 'string') return text |       if (typeof text !== 'string') return text | ||||||
|       return text.charAt(0).toUpperCase() + text.slice(1) |       return text.charAt(0).toUpperCase() + text.slice(1) | ||||||
|     }); |     }) | ||||||
|     Handlebars.registerHelper('notEmpty', function (list) { |     Handlebars.registerHelper('notEmpty', function (list) { | ||||||
|       return list.length > 0; |       return list.length > 0; | ||||||
|     }); |     }) | ||||||
|  |     Handlebars.registerHelper('mul', function (a, b) { | ||||||
|  |       return parseInt(a) * parseInt(b); | ||||||
|  |     }) | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   /* -------------------------------------------- */ |   /* -------------------------------------------- */ | ||||||
|   | |||||||
| @@ -180,9 +180,9 @@ | |||||||
|   "styles": [ |   "styles": [ | ||||||
|     "styles/simple.css" |     "styles/simple.css" | ||||||
|   ], |   ], | ||||||
|   "templateVersion": 87, |   "templateVersion": 88, | ||||||
|   "title": "Pegasus RPG", |   "title": "Pegasus RPG", | ||||||
|   "url": "https://www.uberwald.me/data/files/fvtt-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" |   "background" : "./images/ui/pegasus_welcome_page.webp" | ||||||
| } | } | ||||||
|   | |||||||
| @@ -269,6 +269,7 @@ | |||||||
|       "powersource": "", |       "powersource": "", | ||||||
|       "powersactivated": false, |       "powersactivated": false, | ||||||
|       "powers": [], |       "powers": [], | ||||||
|  |       "isthreatlevel": false, | ||||||
|       "description": "" |       "description": "" | ||||||
|     }, |     }, | ||||||
|     "perk": { |     "perk": { | ||||||
| @@ -384,6 +385,7 @@ | |||||||
|       "iscontainer": false, |       "iscontainer": false, | ||||||
|       "containercapacity": 0, |       "containercapacity": 0, | ||||||
|       "containerid": "", |       "containerid": "", | ||||||
|  |       "threatlevel": 0, | ||||||
|       "description":"" |       "description":"" | ||||||
|     }, |     }, | ||||||
|     "money" : { |     "money" : { | ||||||
|   | |||||||
| @@ -526,7 +526,7 @@ | |||||||
|           <span class="item-field-label-short"> |           <span class="item-field-label-short"> | ||||||
|             <label class="short-label">DMG</label> |             <label class="short-label">DMG</label> | ||||||
|           </span> |           </span> | ||||||
|           <span class="item-field-label-medium"> |           <span class="item-field-label-long"> | ||||||
|             <label class="short-label">Ammo</label>                         |             <label class="short-label">Ammo</label>                         | ||||||
|           </span> |           </span> | ||||||
|           <span class="item-field-label-medium"> |           <span class="item-field-label-medium"> | ||||||
| @@ -548,11 +548,11 @@ | |||||||
|           <span class="item-field-label-short"><label>{{weapon.data.damageDice}}</label></span> |           <span class="item-field-label-short"><label>{{weapon.data.damageDice}}</label></span> | ||||||
|            |            | ||||||
|           {{#if (gt weapon.data.ammomax 0)}} |           {{#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>) |               (<a class="ammo-minus plus-minus-button"> -</a>/<a class="ammo-plus plus-minus-button">+</a>) | ||||||
|             </label></span> |             </label></span> | ||||||
|           {{else}} |           {{else}} | ||||||
|             <span class="item-field-label-medium"><label>-</label> |             <span class="item-field-label-long"><label>-</label> | ||||||
|             </span> |             </span> | ||||||
|           {{/if}} |           {{/if}} | ||||||
|  |  | ||||||
|   | |||||||
| @@ -66,6 +66,9 @@ | |||||||
|             <input type="text" class="input-numeric-short padd-right" name="data.containercapacity" value="{{data.containercapacity}}" data-dtype="Number"/> |             <input type="text" class="input-numeric-short padd-right" name="data.containercapacity" value="{{data.containercapacity}}" data-dtype="Number"/> | ||||||
|           </li> |           </li> | ||||||
|           {{/if}} |           {{/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> |           <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"/> |             <input type="text" class="input-numeric-short padd-right" name="data.cost" value="{{data.cost}}" data-dtype="Number"/> | ||||||
|           </li> |           </li> | ||||||
|   | |||||||
| @@ -53,6 +53,9 @@ | |||||||
|               </ul>               |               </ul>               | ||||||
|             </li> |             </li> | ||||||
|             {{/if}} |             {{/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> |           </ul> | ||||||
|         </div> |         </div> | ||||||
|     </section> |     </section> | ||||||
|   | |||||||
| @@ -27,7 +27,7 @@ | |||||||
|     {{#if equip.data.iscontainer}} |     {{#if equip.data.iscontainer}} | ||||||
|       {{equip.data.contentsEnc}} |       {{equip.data.contentsEnc}} | ||||||
|     {{else}} |     {{else}} | ||||||
|       N/A |       {{mul equip.data.weight equip.data.quantity}} | ||||||
|     {{/if}} |     {{/if}} | ||||||
|   </span> |   </span> | ||||||
|   <span class="item-field-label-medium"> |   <span class="item-field-label-medium"> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user