diff --git a/src/lostcity/engine/World.ts b/src/lostcity/engine/World.ts index 12835322a..7a5f881a6 100644 --- a/src/lostcity/engine/World.ts +++ b/src/lostcity/engine/World.ts @@ -1020,31 +1020,12 @@ class World { addObj(obj: Obj, receiver: Player | null, duration: number) { const zone = this.getZone(obj.x, obj.z, obj.level); - const existing = this.getObj(obj.x, obj.z, obj.level, obj.id); - if (existing && existing.id == obj.id) { - const type = ObjType.get(obj.type); - const nextCount = obj.count + existing.count; - if (type.stackable && nextCount <= Inventory.STACK_LIMIT) { - // if an obj of the same type exists and is stackable, then we merge them. - obj.count = nextCount; - zone.removeObj(existing, receiver); - } - } zone.addObj(obj, receiver, duration); - - obj.despawn = this.currentTick + duration; - obj.respawn = -1; } removeObj(obj: Obj, receiver: Player | null) { - // TODO - // stackable objs when they overflow are created into another slot on the floor - // currently when you pickup from a tile with multiple stackable objs - // you will pickup one of them and the other one disappears const zone = this.getZone(obj.x, obj.z, obj.level); - zone.removeObj(obj, receiver, -1); - obj.despawn = this.currentTick; - obj.respawn = this.currentTick + ObjType.get(obj.type).respawnrate; + zone.removeObj(obj, receiver); } // ---- diff --git a/src/lostcity/engine/script/handlers/LocOps.ts b/src/lostcity/engine/script/handlers/LocOps.ts index 7a9f99c7f..d934b25cc 100644 --- a/src/lostcity/engine/script/handlers/LocOps.ts +++ b/src/lostcity/engine/script/handlers/LocOps.ts @@ -105,7 +105,7 @@ const LocOps: CommandHandlers = { const pos = Position.unpackCoord(coord); const loc = World.getLoc(pos.x, pos.z, pos.level, locId); - if (!loc || loc.respawn !== -1) { + if (!loc) { state.pushInt(0); return; } diff --git a/src/lostcity/engine/zone/Zone.ts b/src/lostcity/engine/zone/Zone.ts index 9e9e98848..4615f17bc 100644 --- a/src/lostcity/engine/zone/Zone.ts +++ b/src/lostcity/engine/zone/Zone.ts @@ -15,6 +15,7 @@ export default class Zone { index = -1; // packed coord level = 0; buffer: Packet = new Packet(); + events: Packet[] = []; // zone entities players: Set = new Set(); // list of player uids @@ -24,18 +25,19 @@ export default class Zone { // loc info - bits 0-15 = type, bits 16-20 = shape, bits 21-23 = angle locs: Set = new Set(); locInfo: Map = new Map(); - - events: Packet[] = []; locDelEvent: Set = new Set(); locAddEvent: Set = new Set(); - locDelCached: Map = new Map(); locAddCached: Map = new Map(); - locDelTimer: Map = new Map(); locAddTimer: Map = new Map(); locChangeTimer: Map = new Map(); + staticObjs: Obj[] = []; // source of truth from map + staticObjAddCached: Packet[] = []; + staticObjDelCached: Packet[] = []; + objs: Obj[] = []; // objs actually in the zone + constructor(index: number, level: number) { this.index = index; this.level = level; @@ -90,6 +92,10 @@ export default class Zone { } } + for (const obj of this.objs) { + // + } + // respawn for (const [packed, timer] of this.locDelTimer) { if (timer - World.currentTick <= 0) { @@ -120,6 +126,10 @@ export default class Zone { } } + for (const obj of this.staticObjs) { + // + } + // shared events (this tick) this.computeSharedEvents(); } @@ -432,15 +442,27 @@ export default class Zone { // ---- addStaticObj(obj: Obj) { + this.staticObjs.push(obj); + this.addObj(Obj.clone(obj), null, -1); // temp + + const buf = Zone.write(ServerProt.OBJ_ADD, obj.x, obj.z, obj.type, obj.count); + this.staticObjAddCached.push(buf); } addObj(obj: Obj, receiver: Player | null, duration: number) { + this.objs.push(obj); } - removeObj(obj: Obj, receiver: Player | null, subtractTick: number = 0) { + removeObj(obj: Obj, receiver: Player | null) { } getObj(x: number, z: number, type: number): Obj | null { + for (const obj of this.objs) { + if (obj.x === x && obj.z === z && obj.type === type) { + return obj; + } + } + return null; } } diff --git a/src/lostcity/entity/Obj.ts b/src/lostcity/entity/Obj.ts index 0bb0db94f..7f9d3f6bd 100644 --- a/src/lostcity/entity/Obj.ts +++ b/src/lostcity/entity/Obj.ts @@ -11,6 +11,10 @@ export default class Obj extends NonPathingEntity { this.count = count; } + static clone(obj: Obj) { + return new Obj(obj.level, obj.x, obj.z, obj.type, obj.count); + } + get id() { return this.type; } diff --git a/src/lostcity/entity/Player.ts b/src/lostcity/entity/Player.ts index 71a4c94b4..73e3ee4e4 100644 --- a/src/lostcity/entity/Player.ts +++ b/src/lostcity/entity/Player.ts @@ -2666,7 +2666,7 @@ export default class Player extends PathingEntity { this.write(ServerProt.UPDATE_ZONE_FULL_FOLLOWS, x, z, this.loadedX, this.loadedZ); - const { locDelCached, locAddCached } = World.getZone(x << 3, z << 3, this.level); + const { locDelCached, locAddCached, staticObjAddCached, staticObjDelCached } = World.getZone(x << 3, z << 3, this.level); for (const [packed, buf] of locDelCached) { this.netOut.push(buf.copy()); @@ -2676,6 +2676,14 @@ export default class Player extends PathingEntity { this.netOut.push(buf.copy()); } + for (const buf of staticObjAddCached) { + this.netOut.push(buf.copy()); + } + + for (const buf of staticObjDelCached) { + this.netOut.push(buf.copy()); + } + if (locDelCached.size > 0 || locAddCached.size > 0) { World.getZone(x << 3, z << 3, this.level).debug(); } @@ -2686,6 +2694,8 @@ export default class Player extends PathingEntity { const z = zone >> 11; const { buffer, locAddTimer, locDelTimer, locChangeTimer } = World.getZone(x << 3, z << 3, this.level); + + // shared events if (buffer.length > 0) { this.write(ServerProt.UPDATE_ZONE_PARTIAL_ENCLOSED, x, z, this.loadedX, this.loadedZ, buffer); @@ -2693,9 +2703,9 @@ export default class Player extends PathingEntity { } else if (locAddTimer.size > 0 || locDelTimer.size > 0 || locChangeTimer.size > 0) { World.getZone(x << 3, z << 3, this.level).debug(); } - } - // todo: obj events + // local events + } } // ----