|
@@ -1,10 +1,11 @@
|
|
-import { Types, defineComponent, addComponent, removeComponent, removeEntity } from './ecs';
|
|
|
|
-import { playerQuery } from './components';
|
|
|
|
|
|
+import { Types, defineComponent, addComponent, removeComponent, removeEntity, type IWorld, type Entity } from './ecs';
|
|
import { log } from './log';
|
|
import { log } from './log';
|
|
import { describe } from '$lib';
|
|
import { describe } from '$lib';
|
|
-import { getPos2, placeOnMap, removeFromMap } from './pos2';
|
|
|
|
import { Clock } from './clock';
|
|
import { Clock } from './clock';
|
|
import { registerAction } from './actions';
|
|
import { registerAction } from './actions';
|
|
|
|
+import { registerCorpseDrop } from './death';
|
|
|
|
+import { getPos3, hasPos3, placeOnMap, removeFromMap } from './pos3';
|
|
|
|
+import { logVisible } from './render3';
|
|
|
|
|
|
const MAX_INVENTORY = 64;
|
|
const MAX_INVENTORY = 64;
|
|
|
|
|
|
@@ -18,7 +19,7 @@ export const Stored = defineComponent('Stored', {
|
|
parent: Types.eid,
|
|
parent: Types.eid,
|
|
});
|
|
});
|
|
|
|
|
|
-export const getInventory = (world, char) => {
|
|
|
|
|
|
+export const getInventory = (world: IWorld, char: Entity) => {
|
|
const sz = Inventory.count[char];
|
|
const sz = Inventory.count[char];
|
|
let res = [];
|
|
let res = [];
|
|
for (let i = 0; i < sz; ++i) {
|
|
for (let i = 0; i < sz; ++i) {
|
|
@@ -29,8 +30,8 @@ export const getInventory = (world, char) => {
|
|
|
|
|
|
export const PickupAction = (item) => (world, e) => {
|
|
export const PickupAction = (item) => (world, e) => {
|
|
let error = false;
|
|
let error = false;
|
|
- const epos = getPos2(e);
|
|
|
|
- const ipos = getPos2(item);
|
|
|
|
|
|
+ const epos = getPos3(e);
|
|
|
|
+ const ipos = getPos3(item);
|
|
if (epos.x !== ipos.x || epos.y !== ipos.y) {
|
|
if (epos.x !== ipos.x || epos.y !== ipos.y) {
|
|
error = "Cannot pick up remotely";
|
|
error = "Cannot pick up remotely";
|
|
}
|
|
}
|
|
@@ -48,7 +49,7 @@ export const PickupAction = (item) => (world, e) => {
|
|
removeFromMap(world, item);
|
|
removeFromMap(world, item);
|
|
addComponent(world, Stored, item);
|
|
addComponent(world, Stored, item);
|
|
Stored.parent[item] = e;
|
|
Stored.parent[item] = e;
|
|
- log(`${describe(world, e)} picks up ${describe(world, item)}`);
|
|
|
|
|
|
+ logVisible(e, `${describe(world, e)} picks up ${describe(world, item)}`);
|
|
},
|
|
},
|
|
};
|
|
};
|
|
};
|
|
};
|
|
@@ -64,9 +65,9 @@ export const DropAction = (item) => (world, e) => {
|
|
log('DROPPING ITEM NOT IN INVENTORY!');
|
|
log('DROPPING ITEM NOT IN INVENTORY!');
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- const { x, y } = getPos2(e);
|
|
|
|
- placeOnMap(world, item, x, y);
|
|
|
|
- log(`${describe(world, e)} drops ${describe(world, item)}`);
|
|
|
|
|
|
+ const { x, y, z } = getPos3(e);
|
|
|
|
+ placeOnMap(world, item, x, y, z);
|
|
|
|
+ logVisible(e, `${describe(world, e)} drops ${describe(world, item)}`);
|
|
},
|
|
},
|
|
};
|
|
};
|
|
};
|
|
};
|
|
@@ -104,3 +105,18 @@ export const purgeInventory = (world, e) => {
|
|
}
|
|
}
|
|
Inventory.count[e] = 0;
|
|
Inventory.count[e] = 0;
|
|
};
|
|
};
|
|
|
|
+
|
|
|
|
+registerCorpseDrop({
|
|
|
|
+ target: Inventory,
|
|
|
|
+ drop: (world, e) => {
|
|
|
|
+ // TODO: configurable pos component
|
|
|
|
+ if (hasPos3(world, e)) {
|
|
|
|
+ const {x, y, z} = getPos3(e);
|
|
|
|
+ for (let item of getInventory(world, e)) {
|
|
|
|
+ placeOnMap(world, item, x, y, z);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ console.warn("Dead creature had inventory, but no Pos3, inventory items lost");
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+});
|