refactor: distribution
This commit is contained in:
parent
fec717cbe1
commit
0cdabd0858
|
@ -208,18 +208,25 @@ export default class Inventory extends Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const {qty} = slots[slot];
|
const {qty} = slots[slot];
|
||||||
slots[slot].qty = 0;
|
slots[slot].qty -= qty;
|
||||||
for (let i = 0; i < qty; ++i) {
|
for (let i = 0; i < qty; ++i) {
|
||||||
const [entityId, destination] = destinations[i % destinations.length];
|
const [entityId, destination] = destinations[i % destinations.length];
|
||||||
const {Inventory} = ecs.get(entityId);
|
const {Inventory} = ecs.get(entityId);
|
||||||
const {slots} = Inventory;
|
const {slots} = Inventory;
|
||||||
slots[destination].qty += 1;
|
slots[destination].qty += 1;
|
||||||
}
|
}
|
||||||
if (!destinations.find(([entityId, destination]) => {
|
if (0 === slots[slot].qty) {
|
||||||
return entityId == this.entity && destination === slot;
|
|
||||||
})) {
|
|
||||||
this.clear(slot);
|
this.clear(slot);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
if (
|
||||||
|
!destinations.find(([entityId, destination]) => {
|
||||||
|
return entityId == this.entity && destination === slot;
|
||||||
|
})
|
||||||
|
) {
|
||||||
|
Component.markChange(this.entity, 'qtyUpdated', {[slot]: -qty});
|
||||||
|
}
|
||||||
|
}
|
||||||
for (const [entityId, destination] of given) {
|
for (const [entityId, destination] of given) {
|
||||||
const {Inventory} = ecs.get(entityId);
|
const {Inventory} = ecs.get(entityId);
|
||||||
const {slots} = Inventory;
|
const {slots} = Inventory;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user