import { ISystem, System, Component, Components } from '../engine/system'; import { IEntity, State, DoSet, IAction } from '../engine/state'; import { IHudWindow } from '../../client/engine/ui'; import { IOverlapAction } from './ammo-physics'; interface IStatsComponent { name: string; current: number; min: number; max: number; regen: number; } export interface IPickupAction extends IAction { type: 'PICKUP'; targetId: string; slot: string; itemId: string; equipObj: string; } const DoPickup = (targetId: string, item: IEntity): IPickupAction => { return { type: 'PICKUP', targetId, slot: item.slot, itemId: item.id, equipObj: item.equipped, }; }; @Components('item') export class Items extends System { add(entity: IEntity) { super.add(entity); // item already includes 'body' ? // this.dispatch(DoCreateGhost(entity, entity.position, entity.rotation, entity.item.size, ["player"])); } tick(delta) { this.actions({ OVERLAP: this.HandleOverlap }); } private HandleOverlap(a: IOverlapAction) { const item = this.entities[a.instigatorId]; if (!item) return; if (!item.equipped) return; this.dispatch(DoPickup(a.targetId, item), true); } }