Skip to content
This repository was archived by the owner on Oct 5, 2024. It is now read-only.

Commit 75ecb94

Browse files
committed
1 parent 2d4ba88 commit 75ecb94

12 files changed

Lines changed: 85 additions & 13 deletions

src/Area.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class Area extends GameEntity {
8787
* @fires Area#roomRemoved
8888
*/
8989
removeRoom(room) {
90+
this.removeRoomFromMap(room);
9091
this.rooms.delete(room.id);
9192

9293
/**
@@ -115,6 +116,26 @@ class Area extends GameEntity {
115116
floor.addRoom(x, y, room);
116117
}
117118

119+
/**
120+
* Remove a room from the map
121+
* @param {Room} room
122+
* @throws Error
123+
*/
124+
removeRoomFromMap(room) {
125+
if (!room.coordinates) {
126+
throw new Error('Room does not have coordinates');
127+
}
128+
129+
const {x, y, z} = room.coordinates;
130+
131+
if (!this.map.has(z)) {
132+
throw new Error(`That floor doesn't exist`);
133+
}
134+
135+
const floor = this.map.get(z);
136+
floor.removeRoom(x, y);
137+
}
138+
118139
/**
119140
* find a room at the given coordinates for this area
120141
* @param {number} x
@@ -144,7 +165,7 @@ class Area extends GameEntity {
144165

145166
/**
146167
* This method is automatically called every N milliseconds where N is defined in the
147-
* `setInterval` call to `GameState.AreaMAnager.tickAll` in the `ranvier` executable. It, in turn,
168+
* `setInterval` call to `GameState.AreaManager.tickAll` in the `ranvier` executable. It, in turn,
148169
* will fire the `updateTick` event on all its rooms and npcs
149170
*
150171
* @param {GameState} state

src/Attribute.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* safely. Where safely means without being destructive to the base value.
66
*
77
* An attribute on its own cannot be raised above its base value. To raise attributes above their
8-
* base temporarily see the {@link http://ranviermud.com/extending/effects|Effect guide}.
8+
* base temporarily see the {@link https://ranviermud.com/coding/effects/|Effect guide}.
99
*
1010
* @property {string} name
1111
* @property {number} base

src/CommandQueue.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ class CommandQueue {
100100
/**
101101
* For a given command index find how many seconds until it will run
102102
* @param {number} commandIndex
103-
* @param {boolean} milliseconds
104103
* @return {number}
105104
*/
106105
getTimeTilRun(commandIndex) {

src/Effect.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,27 +146,29 @@ class Effect extends EventEmitter {
146146
}
147147

148148
this.startedAt = Date.now() - this.elapsed;
149+
this.active = true;
150+
149151
/**
150152
* @event Effect#effectActivated
151153
*/
152154
this.emit('effectActivated');
153-
this.active = true;
154155
}
155156

156157
/**
157-
* Set this effect active
158+
* Deactivate this effect
158159
* @fires Effect#effectDeactivated
159160
*/
160161
deactivate() {
161162
if (!this.active) {
162163
return;
163164
}
164165

166+
this.active = false;
167+
165168
/**
166169
* @event Effect#effectDeactivated
167170
*/
168171
this.emit('effectDeactivated');
169-
this.active = false;
170172
}
171173

172174
/**

src/EffectFactory.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ class EffectFactory {
3939
this.effects.set(id, { definition, eventManager });
4040
}
4141

42+
/**
43+
* @see Map#has
44+
*/
4245
has(id) {
4346
return this.effects.has(id);
4447
}
@@ -49,7 +52,8 @@ class EffectFactory {
4952
* @return {object}
5053
*/
5154
get(id) {
52-
return this.get(id);
55+
const entry = this.effects.get(id);
56+
if (entry) return entry.definition;
5357
}
5458

5559
/**

src/EffectList.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class EffectList {
156156
/**
157157
* @event Character#effectRemoved
158158
*/
159-
this.target.emit('effectRemoved');
159+
this.target.emit('effectRemoved', effect);
160160
}
161161

162162
/**

src/Inventory.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ class Inventory extends Map {
105105
newItem.hydrate(state, def);
106106
this.set(uuid, newItem);
107107
state.ItemManager.add(newItem);
108+
/**
109+
* @event Item#spawn
110+
*/
111+
newItem.emit('spawn');
108112
}
109113
}
110114
}

src/Item.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,11 @@ class Item extends GameEntity {
208208
Logger.warn('Attempted to hydrate already hydrated item.');
209209
return false;
210210
}
211+
this.__manager = state.ItemManager;
211212

212-
// perform deep copy if behaviors is set to prevent sharing of the object between
213-
// item instances
213+
state.ItemManager.add(this);
214+
215+
// deep copy behaviors to prevent sharing of the object between item instances
214216
if (serialized.behaviors) {
215217
const behaviors = JSON.parse(JSON.stringify(serialized.behaviors));
216218
this.behaviors = new Map(Object.entries(behaviors));
@@ -241,6 +243,10 @@ class Item extends GameEntity {
241243
newItem.hydrate(state);
242244
state.ItemManager.add(newItem);
243245
this.addItem(newItem);
246+
/**
247+
* @event Item#spawn
248+
*/
249+
newItem.emit('spawn');
244250
});
245251
}
246252

src/MobManager.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,26 @@ class MobManager {
2121
*/
2222
removeMob(mob) {
2323
mob.effects.clear();
24+
25+
const sourceRoom = mob.sourceRoom;
26+
if (sourceRoom) {
27+
sourceRoom.area.removeNpc(mob);
28+
sourceRoom.removeNpc(mob, true);
29+
}
30+
2431
const room = mob.room;
25-
if (room) {
26-
room.area.removeNpc(mob);
27-
room.removeNpc(mob, true);
32+
if (room && room !== sourceRoom) {
33+
room.removeNpc(mob);
2834
}
35+
36+
if (mob.equipment && mob.equipment.size) {
37+
mob.equipment.forEach((item, slot) => mob.unequip(slot));
38+
}
39+
40+
if (mob.inventory && mob.inventory.size) {
41+
mob.inventory.forEach(item => item.__manager.remove(item));
42+
}
43+
2944
mob.__pruned = true;
3045
mob.removeAllListeners();
3146
this.mobs.delete(mob.uuid);

src/Npc.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ class Npc extends Scriptable(Character) {
9191
newItem.hydrate(state);
9292
state.ItemManager.add(newItem);
9393
this.addItem(newItem);
94+
/**
95+
* @event Item#spawn
96+
*/
97+
newItem.emit('spawn');
9498
}
9599

96100
for (let [slot, defaultEqId] of Object.entries(this.defaultEquipment)) {
@@ -99,6 +103,10 @@ class Npc extends Scriptable(Character) {
99103
newItem.hydrate(state);
100104
state.ItemManager.add(newItem);
101105
this.equip(newItem, slot);
106+
/**
107+
* @event Item#spawn
108+
*/
109+
newItem.emit('spawn');
102110
}
103111
}
104112

0 commit comments

Comments
 (0)