Scrap !!
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import type { ServerContext } from "cubi/server";
|
||||
|
||||
// scrap lies around as this entity (see its items' "entity"), holding the item, and is picked up by right clicking it
|
||||
export const SCRAP = "dangerous_business:scrap";
|
||||
|
||||
// the inventory slots scrap can be picked up into, the hotbar for now
|
||||
const LOOT_SLOTS = [0, 1, 2, 3, 4, 5, 6, 7, 8];
|
||||
|
||||
export function register_scrap(ctx: ServerContext) {
|
||||
ctx.events.before.entity_interact.subscribe((event) => {
|
||||
if (event.entity.type !== SCRAP) return;
|
||||
// clicking scrap never uses what's held, picked up or not
|
||||
event.cancel = true;
|
||||
const item = event.entity.get_item();
|
||||
const inventory = event.player.inventory;
|
||||
const slot = LOOT_SLOTS.find((slot) => inventory.get(slot) === undefined);
|
||||
// with no free loot slot it stays where it is
|
||||
if (!item || slot === undefined) return;
|
||||
inventory.set(slot, item);
|
||||
event.entity.remove();
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user