Fixed inventory calculation to include item quantities

This commit is contained in:
Stefan Zermatten
2022-03-03 15:53:58 +02:00
parent 473a9f0253
commit 4edfe1bcb9
2 changed files with 21 additions and 14 deletions

View File

@@ -43,18 +43,26 @@ export default function aggregateInventory({node, linkedNode, link}){
}
}
function quantity(prop){
if (typeof prop.quantity === 'number'){
return prop.quantity;
} else {
return 1;
}
}
function weight(prop){
return (prop.weight || 0) + (prop.contentsWeight || 0);
return (prop.weight || 0) * quantity(prop) + (prop.contentsWeight || 0);
}
function carriedWeight(prop){
return (prop.weight || 0) + (prop.carriedWeight || 0);
return (prop.weight || 0) * quantity(prop) + (prop.carriedWeight || 0);
}
function value (prop){
return (prop.value || 0) + (prop.contentsValue || 0);
return (prop.value || 0) * quantity(prop) + (prop.contentsValue || 0);
}
function carriedValue (prop){
return (prop.value || 0) + (prop.carriedValue || 0);
return (prop.value || 0) * quantity(prop) + (prop.carriedValue || 0);
}

View File

@@ -14,16 +14,14 @@ export default function(){
assert.equal(scope('itemsAttuned'), 1);
assert.equal(prop('childContainerId').carriedWeight, 23);
assert.equal(prop('childContainerId').contentsWeight, 23);
assert.equal(prop('childContainerId').carriedWeight, 69);
assert.equal(prop('childContainerId').contentsWeight, 69);
assert.equal(scope('weightCarried'), 58);
assert.equal(scope('weightCarried'), 104);
assert.equal(scope('valueCarried'), 129);
assert.equal(scope('weightCarried'), 58);
assert.equal(scope('valueCarried'), 71);
assert.equal(scope('weightTotal'), 58);
assert.equal(scope('valueTotal'), 71);
assert.equal(scope('weightTotal'), 104);
assert.equal(scope('valueTotal'), 129);
}
var testProperties = [
@@ -62,8 +60,9 @@ var testProperties = [
clean({
_id: 'grandchildItemId',
type: 'item',
weight: 23,
value: 29,
weight: 23, // 69 total
value: 29, // 87 total
quantity: 3,
ancestors: [{id: 'charId'}, {id: 'containerId'}, {id: 'childContainerId'}],
}),
];