-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathActorTickExpander.js
52 lines (42 loc) · 1.14 KB
/
ActorTickExpander.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"use strict";
const ActorWithMemory = require('ActorWithMemory');
const NO_CONTROLLER_IN_ROOM = -1;
module.exports = class ActorTickExpander extends ActorWithMemory
{
constructor(locator)
{
super(locator);
this.events = locator.getService(SERVICE_NAMES.EVENTS);
}
initiateActor()
{
super.initiateActor();
this.events.subscribe("everyTick", this.actorId, "onEveryTick");
this.memoryObject =
{ roomLevels: {}
};
}
removeActor()
{
this.events.unsubscribe("everyTick", this.actorId);
super.removeActor();
}
onEveryTick(event)
{
let tick = Game.time;
let counter = 1;
for(let mod=2; tick % mod === 0; mod *= 2)
this.events.frontLoadEvent("tick2pow" + counter++);
for(let roomName in Game.rooms)
{
let oldRoomLevel = this.memoryObject.roomLevels[roomName];
let room = Game.rooms[roomName];
let currentRoomLevel = room.controller ? room.controller.level : NO_CONTROLLER_IN_ROOM;
if(typeof oldRoomLevel === UNDEFINED || oldRoomLevel !== currentRoomLevel)
{
this.memoryObject.roomLevels[roomName] = currentRoomLevel;
this.events.frontLoadEvent(EVENTS.ROOM_LEVEL_CHANGED + roomName);
}
}
}
};