Fix encumbrance calculations
							parent
							
								
									7a548e55b5
								
							
						
					
					
						commit
						2606d577aa
					
				|  | @ -900,15 +900,6 @@ | ||||||
|   display: block; |   display: block; | ||||||
|   position: absolute; |   position: absolute; | ||||||
| } | } | ||||||
| .acks.sheet.actor.character .encumbrance .encumbrance-breakpoint.encumbrance-25 { |  | ||||||
|   left: 24.4%; |  | ||||||
| } |  | ||||||
| .acks.sheet.actor.character .encumbrance .encumbrance-breakpoint.encumbrance-35 { |  | ||||||
|   left: 34.4%; |  | ||||||
| } |  | ||||||
| .acks.sheet.actor.character .encumbrance .encumbrance-breakpoint.encumbrance-50 { |  | ||||||
|   left: 49.4%; |  | ||||||
| } |  | ||||||
| .acks.sheet.actor.character .encumbrance .arrow-up { | .acks.sheet.actor.character .encumbrance .arrow-up { | ||||||
|   bottom: 0; |   bottom: 0; | ||||||
|   width: 0; |   width: 0; | ||||||
|  |  | ||||||
|  | @ -50,7 +50,6 @@ export class AcksActorSheetCharacter extends AcksActorSheet { | ||||||
| 
 | 
 | ||||||
|     data.config.ascendingAC = game.settings.get("acks", "ascendingAC"); |     data.config.ascendingAC = game.settings.get("acks", "ascendingAC"); | ||||||
|     data.config.initiative = game.settings.get("acks", "initiative") != "group"; |     data.config.initiative = game.settings.get("acks", "initiative") != "group"; | ||||||
|     data.config.encumbrance = game.settings.get("acks", "encumbranceOption"); |  | ||||||
|     data.config.BHR = game.settings.get("acks", "bhr"); |     data.config.BHR = game.settings.get("acks", "bhr"); | ||||||
|     data.config.removeMagicBonus = game.settings.get("acks", "removeMagicBonus"); |     data.config.removeMagicBonus = game.settings.get("acks", "removeMagicBonus"); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -608,92 +608,67 @@ export class AcksActor extends Actor { | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   computeEncumbrance() { |   computeEncumbrance() { | ||||||
|     if (this.data.type != "character") { |     if (this.data.type !== "character") { | ||||||
|       return; |       return; | ||||||
|     } |     } | ||||||
|     const data = this.data.data; |  | ||||||
|     let option = game.settings.get("acks", "encumbranceOption"); |  | ||||||
| 
 | 
 | ||||||
|     // Compute encumbrance
 |     const option = game.settings.get("acks", "encumbranceOption"); | ||||||
|     let totalWeight = 0; |  | ||||||
|     let hasItems = false; |  | ||||||
|     Object.values(this.data.items).forEach((item) => { |  | ||||||
|       if (item.type == "item" && !item.data.treasure) { |  | ||||||
|         if (option === "detailed") totalWeight += 166.6; |  | ||||||
| 
 | 
 | ||||||
| //        hasItems = true;
 |     let totalEncumbrance = 0; | ||||||
|       } | 
 | ||||||
|       if ( |     this.data.items.forEach((item) => { | ||||||
|         item.type == "item" && |       if (item.type === "item") { | ||||||
|         (["complete", "disabled"].includes(option) || item.data.treasure) |         if (option === "detailed") { | ||||||
|       ) { |           if (item.data.data.treasure) { | ||||||
|         totalWeight += item.data.quantity.value * item.data.weight; |             totalEncumbrance += item.data.data.weight * item.data.data.quantity.value; | ||||||
|       } else if (option != "basic" && ["weapon", "armor"].includes(item.type)) { |           } else { | ||||||
|         totalWeight += item.data.weight; |             totalEncumbrance += item.data.data.weight; | ||||||
|  |           } | ||||||
|  |         } else { | ||||||
|  |           if (item.data.data.treasure) { | ||||||
|  |             totalEncumbrance += 1000 * item.data.data.quantity.value; | ||||||
|  |           } else { | ||||||
|  |             totalEncumbrance += 1000; | ||||||
|  |           } | ||||||
|  |         } | ||||||
|  |       } else if (["weapon", "armor"].includes(item.type)) { | ||||||
|  |         if (option === "detailed") { | ||||||
|  |           totalEncumbrance += item.data.data.weight; | ||||||
|  |         } else { | ||||||
|  |           totalEncumbrance += 1000; | ||||||
|  |         } | ||||||
|       } |       } | ||||||
|     }); |     }); | ||||||
| //    if (option === "detailed" && hasItems) totalWeight += 166.6;
 |  | ||||||
| 
 | 
 | ||||||
|     data.encumbrance = { |     const maxEncumbrance = 20000 + (this.data.data.scores.str.mod * 1000); | ||||||
|  | 
 | ||||||
|  |     this.data.data.encumbrance = { | ||||||
|       pct: Math.clamped( |       pct: Math.clamped( | ||||||
| //    To correct for percentage bar not lining up with movement rates.
 |         (totalEncumbrance / maxEncumbrance) * 100, | ||||||
| //        (100 * parseFloat(totalWeight)) / data.encumbrance.max,
 |  | ||||||
|         (100 * parseFloat(totalWeight)) / 20000, |  | ||||||
|         0, |         0, | ||||||
|         100 |         100 | ||||||
|       ), |       ), | ||||||
|       max: data.encumbrance.max, |       max: maxEncumbrance, | ||||||
|       encumbered: totalWeight > data.encumbrance.max, |       encumbered: totalEncumbrance > maxEncumbrance, | ||||||
|       value: Math.round(totalWeight), |       value: Math.round(totalEncumbrance), | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     if (data.config.movementAuto && option != "disabled") { |     if (this.data.data.config.movementAuto) { | ||||||
|       this._calculateMovement(); |       this._calculateMovement(); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   _calculateMovement() { |   _calculateMovement() { | ||||||
|     const data = this.data.data; |     if (this.data.data.encumbrance.value > this.data.data.encumbrance.max) { | ||||||
|     let option = game.settings.get("acks", "encumbranceOption"); |       this.data.data.movement.base = 0; | ||||||
|     let weight = data.encumbrance.value; |     } else if (this.data.data.encumbrance.value > 10000) { | ||||||
|     if (["detailed", "complete"].includes(option)) { |       this.data.data.movement.base = 30; | ||||||
|       if (weight > data.encumbrance.max) { |     } else if (this.data.data.encumbrance.value > 7000) { | ||||||
|         data.movement.base = 0; |       this.data.data.movement.base = 60; | ||||||
|       } else if (weight > 10000) { |     } else if (this.data.data.encumbrance.value > 5000) { | ||||||
|         data.movement.base = 30; |       this.data.data.movement.base = 90; | ||||||
|       } else if (weight > 7000) { |     } else { | ||||||
|         data.movement.base = 60; |       this.data.data.movement.base = 120; | ||||||
|       } else if (weight > 5000) { |  | ||||||
|         data.movement.base = 90; |  | ||||||
|       } else { |  | ||||||
|         data.movement.base = 120; |  | ||||||
|       } |  | ||||||
|     } else if (option == "basic") { |  | ||||||
|       const armors = this.data.items.filter((i) => i.type == "armor"); |  | ||||||
|       let heaviest = 0; |  | ||||||
|       armors.forEach((a) => { |  | ||||||
|         if (a.data.equipped) { |  | ||||||
|           if (a.data.type == "light" && heaviest == 0) { |  | ||||||
|             heaviest = 1; |  | ||||||
|           } else if (a.data.type == "heavy") { |  | ||||||
|             heaviest = 2; |  | ||||||
|           } |  | ||||||
|         } |  | ||||||
|       }); |  | ||||||
|       switch (heaviest) { |  | ||||||
|         case 0: |  | ||||||
|           data.movement.base = 120; |  | ||||||
|           break; |  | ||||||
|         case 1: |  | ||||||
|           data.movement.base = 90; |  | ||||||
|           break; |  | ||||||
|         case 2: |  | ||||||
|           data.movement.base = 60; |  | ||||||
|           break; |  | ||||||
|       } |  | ||||||
|       if (weight > game.settings.get("acks", "significantTreasure")) { |  | ||||||
|         data.movement.base -= 30; |  | ||||||
|       } |  | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -23,13 +23,21 @@ export const registerHelpers = async function () { | ||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
|   Handlebars.registerHelper("subtract", function (lh, rh) { |   Handlebars.registerHelper("subtract", function (lh, rh) { | ||||||
|     return parseInt(rh) - parseInt(lh); |     return parseInt(lh) - parseInt(rh); | ||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
|  |   Handlebars.registerHelper("fsubtract", (lh, rh) => { | ||||||
|  |     return parseFloat(lh) - parseFloat(rh); | ||||||
|  |   }) | ||||||
|  | 
 | ||||||
|   Handlebars.registerHelper("divide", function (lh, rh) { |   Handlebars.registerHelper("divide", function (lh, rh) { | ||||||
|     return Math.floor(parseFloat(lh) / parseFloat(rh)); |     return Math.floor(parseFloat(lh) / parseFloat(rh)); | ||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
|  |   Handlebars.registerHelper("fdivide", (lh, rh) => { | ||||||
|  |     return parseFloat(lh) / parseFloat(rh); | ||||||
|  |   }); | ||||||
|  | 
 | ||||||
|   Handlebars.registerHelper("mult", function (lh, rh) { |   Handlebars.registerHelper("mult", function (lh, rh) { | ||||||
|     return parseFloat(lh) * parseFloat(rh); |     return parseFloat(lh) * parseFloat(rh); | ||||||
|   }); |   }); | ||||||
|  |  | ||||||
|  | @ -35,7 +35,7 @@ | ||||||
|             {{/each}} |             {{/each}} | ||||||
|           </div> |           </div> | ||||||
|           <div class="field-short"> |           <div class="field-short"> | ||||||
|             {{#if (eq @root.config.encumbrance "basic")}}_{{else}}{{item.data.weight}}{{/if}} |             {{#if (eq @root.config.encumbrance "detailed")}}{{item.data.weight}}{{else}}_{{/if}} | ||||||
|           </div> |           </div> | ||||||
|           <div class="item-controls"> |           <div class="item-controls"> | ||||||
|             {{#if ../owner}} |             {{#if ../owner}} | ||||||
|  | @ -87,7 +87,7 @@ | ||||||
|             {{/if}} |             {{/if}} | ||||||
|           </div> |           </div> | ||||||
|           <div class="field-short"> |           <div class="field-short"> | ||||||
|             {{#if (eq @root.config.encumbrance "basic")}}_{{else}}{{item.data.weight}}{{/if}} |             {{#if (eq @root.config.encumbrance "detailed")}}{{item.data.weight}}{{else}}_{{/if}} | ||||||
|           </div> |           </div> | ||||||
|           <div class="item-controls"> |           <div class="item-controls"> | ||||||
|             {{#if ../owner}} |             {{#if ../owner}} | ||||||
|  | @ -134,7 +134,7 @@ | ||||||
|               placeholder="0" />{{#if item.data.quantity.max}}<span>/{{item.data.quantity.max}}</span>{{/if}} |               placeholder="0" />{{#if item.data.quantity.max}}<span>/{{item.data.quantity.max}}</span>{{/if}} | ||||||
|           </div> |           </div> | ||||||
|           <div class="field-short"> |           <div class="field-short"> | ||||||
|             {{#if (eq @root.config.encumbrance "basic")}}_{{else if (eq @root.config.encumbrance "detailed")}}_{{else}}{{item.data.weight}}{{/if}} |             {{#if (eq @root.config.encumbrance "detailed")}}{{item.data.weight}}{{else}}_{{/if}} | ||||||
|           </div> |           </div> | ||||||
|           <div class="item-controls"> |           <div class="item-controls"> | ||||||
|             {{#if ../owner}} |             {{#if ../owner}} | ||||||
|  | @ -157,7 +157,7 @@ | ||||||
|       <div class="field-short"><i class="fas fa-hashtag"></i></div> |       <div class="field-short"><i class="fas fa-hashtag"></i></div> | ||||||
|       <div class="field-short"><i class="fas fa-weight-hanging"></i></div> |       <div class="field-short"><i class="fas fa-weight-hanging"></i></div> | ||||||
|       <div class="item-controls"> |       <div class="item-controls"> | ||||||
|         <a class="item-control item-create" data-type="item" data-treasure="true" title="{{localize 'ACKS.Add'}}"><i |         <a class="item-control item-create" data-type="item" data-treasure="true" data-weight=1000 title="{{localize 'ACKS.Add'}}"><i | ||||||
|             class="fa fa-plus"></i></a> |             class="fa fa-plus"></i></a> | ||||||
|       </div> |       </div> | ||||||
|     </li> |     </li> | ||||||
|  | @ -180,7 +180,7 @@ | ||||||
|               placeholder="0" />{{#if item.data.quantity.max}}<span>/{{item.data.quantity.max}}</span>{{/if}} |               placeholder="0" />{{#if item.data.quantity.max}}<span>/{{item.data.quantity.max}}</span>{{/if}} | ||||||
|           </div> |           </div> | ||||||
|           <div class="field-short"> |           <div class="field-short"> | ||||||
|             {{mult item.data.quantity.value item.data.weight}} |             {{#if (eq @root.config.encumbrance "detailed")}}{{mult item.data.quantity.value item.data.weight}}{{else}}_{{/if}} | ||||||
|           </div> |           </div> | ||||||
|           <div class="item-controls"> |           <div class="item-controls"> | ||||||
|             {{#if ../owner}} |             {{#if ../owner}} | ||||||
|  | @ -200,12 +200,12 @@ | ||||||
|   <div class="encumbrance {{#if encumbered}}encumbered{{/if}}"> |   <div class="encumbrance {{#if encumbered}}encumbered{{/if}}"> | ||||||
|     <span class="encumbrance-bar" style="width:{{pct}}%"></span> |     <span class="encumbrance-bar" style="width:{{pct}}%"></span> | ||||||
|     <span class="encumbrance-label">{{value}} / {{max}}</span> |     <span class="encumbrance-label">{{value}} / {{max}}</span> | ||||||
|     <i class="encumbrance-breakpoint encumbrance-25 arrow-up"></i> |     <i class="encumbrance-breakpoint arrow-up" style="left: {{fsubtract (mult (fdivide 5000 max) 100) 1}}%"></i> | ||||||
|     <i class="encumbrance-breakpoint encumbrance-25 arrow-down"></i> |     <i class="encumbrance-breakpoint arrow-down" style="left: {{fsubtract (mult (fdivide 5000 max) 100) 1}}%"></i> | ||||||
|     <i class="encumbrance-breakpoint encumbrance-35 arrow-up"></i> |     <i class="encumbrance-breakpoint arrow-up" style="left: {{fsubtract (mult (fdivide 7000 max) 100) 1}}%"></i> | ||||||
|     <i class="encumbrance-breakpoint encumbrance-35 arrow-down"></i> |     <i class="encumbrance-breakpoint arrow-down" style="left: {{fsubtract (mult (fdivide 7000 max) 100) 1}}%"></i> | ||||||
|     <i class="encumbrance-breakpoint encumbrance-50 arrow-up"></i> |     <i class="encumbrance-breakpoint arrow-up" style="left: {{fsubtract (mult (fdivide 10000 max) 100) 1}}%"></i> | ||||||
|     <i class="encumbrance-breakpoint encumbrance-50 arrow-down"></i> |     <i class="encumbrance-breakpoint arrow-down" style="left: {{fsubtract (mult (fdivide 10000 max) 100) 1}}%"></i> | ||||||
|     {{/with}} |     {{/with}} | ||||||
|   </div> |   </div> | ||||||
| </section> | </section> | ||||||
		Loading…
	
		Reference in New Issue