-
Notifications
You must be signed in to change notification settings - Fork 71
/
EntityCreator.js
291 lines (269 loc) · 9.64 KB
/
EntityCreator.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
define([
'ash',
'game/constants/LogConstants',
'game/constants/PerkConstants',
'game/constants/ItemConstants',
'game/constants/PositionConstants',
'game/components/player/BagComponent',
'game/components/player/ExcursionComponent',
'game/components/player/VisionComponent',
'game/components/player/StaminaComponent',
'game/components/sector/ReputationComponent',
'game/components/player/RumoursComponent',
'game/components/player/EvidenceComponent',
'game/components/player/InsightComponent',
'game/components/player/HopeComponent',
'game/components/player/ExplorersComponent',
'game/components/player/ItemsComponent',
'game/components/player/PerksComponent',
'game/components/type/GangComponent',
'game/components/type/PlayerComponent',
'game/components/type/TribeComponent',
'game/components/type/LevelComponent',
'game/components/type/SectorComponent',
'game/components/common/PositionComponent',
'game/components/player/PlayerActionComponent',
'game/components/common/ResourcesComponent',
'game/components/common/CurrencyComponent',
'game/components/common/ResourceAccumulationComponent',
'game/components/common/VisitedComponent',
'game/components/common/RevealedComponent',
'game/components/common/LogMessagesComponent',
'game/components/common/SaveComponent',
'game/components/sector/improvements/BeaconComponent',
'game/components/sector/improvements/SectorImprovementsComponent',
'game/components/sector/improvements/SectorCollectorsComponent',
'game/components/sector/improvements/WorkshopComponent',
'game/components/sector/events/RecruitComponent',
'game/components/sector/events/TraderComponent',
'game/components/sector/SectorStatusComponent',
'game/components/sector/SectorControlComponent',
'game/components/sector/EnemiesComponent',
'game/components/sector/events/CampEventTimersComponent',
'game/components/sector/OutgoingCaravansComponent',
'game/components/sector/MovementOptionsComponent',
'game/components/sector/PassagesComponent',
'game/components/sector/SectorFeaturesComponent',
'game/components/sector/SectorLocalesComponent',
'game/components/sector/LastVisitedCampComponent',
'game/components/common/CampComponent',
'game/components/tribe/UpgradesComponent',
'game/components/level/LevelPassagesComponent',
'game/components/level/LevelStatusComponent'
], function (
Ash,
LogConstants,
PerkConstants,
ItemConstants,
PositionConstants,
BagComponent,
ExcursionComponent,
VisionComponent,
StaminaComponent,
ReputationComponent,
RumoursComponent,
EvidenceComponent,
InsightComponent,
HopeComponent,
ExplorersComponent,
ItemsComponent,
PerksComponent,
GangComponent,
PlayerComponent,
TribeComponent,
LevelComponent,
SectorComponent,
PositionComponent,
PlayerActionComponent,
ResourcesComponent,
CurrencyComponent,
ResourceAccumulationComponent,
VisitedComponent,
RevealedComponent,
LogMessagesComponent,
SaveComponent,
BeaconComponent,
SectorImprovementsComponent,
SectorCollectorsComponent,
WorkshopComponent,
RecruitComponent,
TraderComponent,
SectorStatusComponent,
SectorControlComponent,
EnemiesComponent,
CampEventTimersComponent,
OutgoingCaravansComponent,
MovementOptionsComponent,
PassagesComponent,
SectorFeaturesComponent,
SectorLocalesComponent,
LastVisitedCampComponent,
CampComponent,
UpgradesComponent,
LevelPassagesComponent,
LevelStatusComponent
) {
var EntityCreator = Ash.Class.extend({
engine: null,
constructor: function (engine) {
this.engine = engine;
},
destroyEntity: function (entity) {
this.engine.removeEntity(entity);
},
createPlayer: function (saveKey) {
var player = new Ash.Entity()
.add(new PlayerComponent())
.add(new BagComponent(0))
.add(new VisionComponent(0))
.add(new ItemsComponent())
.add(new ExplorersComponent())
.add(new PerksComponent())
.add(new StaminaComponent(1000))
.add(new ResourcesComponent("player", ItemConstants.PLAYER_DEFAULT_STORAGE))
.add(new CurrencyComponent(0))
.add(new ResourceAccumulationComponent(saveKey))
.add(new RumoursComponent())
.add(new EvidenceComponent())
.add(new HopeComponent())
.add(new InsightComponent())
.add(new PositionComponent(13, 0, 0, false))
.add(new LogMessagesComponent())
.add(new PlayerActionComponent())
.add(new SaveComponent(saveKey, [
ResourcesComponent,
CurrencyComponent,
VisionComponent,
ItemsComponent,
ExplorersComponent,
PerksComponent,
StaminaComponent,
PositionComponent,
RumoursComponent,
EvidenceComponent,
InsightComponent,
LogMessagesComponent,
PlayerActionComponent,
ExcursionComponent,
HopeComponent
]));
this.engine.addEntity(player);
return player;
},
createLevel: function (saveKey, pos, levelVO) {
var level = new Ash.Entity()
.add(new LevelComponent(pos, levelVO.isCampable, levelVO.isHard, levelVO.notCampableReason, levelVO.habitability, levelVO.raidDangerFactor, levelVO.minX, levelVO.maxX, levelVO.minY, levelVO.maxY))
.add(new PositionComponent(pos))
.add(new LevelPassagesComponent())
.add(new LevelStatusComponent())
.add(new SaveComponent(saveKey, [CampComponent, VisitedComponent, LevelStatusComponent]));
this.engine.addEntity(level);
return level;
},
createSector: function (saveKey, level, posX, posY, passageOptions, movementBlockers, sectorFeatures, locales, criticalPaths, enemies, hasRegularEnemies, localeEnemyNum) {
var sector = new Ash.Entity()
.add(new SectorComponent())
.add(new ResourcesComponent("sector", 0))
.add(new ResourceAccumulationComponent(saveKey))
.add(new EnemiesComponent(hasRegularEnemies, enemies))
.add(new SectorImprovementsComponent())
.add(new PositionComponent(level, posX, posY))
.add(new SectorControlComponent(localeEnemyNum))
.add(new MovementOptionsComponent())
.add(new SectorStatusComponent())
.add(new PassagesComponent(
passageOptions.passageUpType,
passageOptions.passageDownType,
movementBlockers))
.add(new SectorFeaturesComponent(level, sectorFeatures))
.add(new SectorLocalesComponent(locales))
.add(new SaveComponent(saveKey, [
ResourcesComponent,
CampComponent,
CurrencyComponent,
ReputationComponent,
OutgoingCaravansComponent,
CampEventTimersComponent,
SectorImprovementsComponent,
SectorStatusComponent,
SectorControlComponent,
RecruitComponent,
TraderComponent,
VisitedComponent,
RevealedComponent,
LastVisitedCampComponent
]));
if (sectorFeatures.hasWorkshop) {
sector.add(new WorkshopComponent(sectorFeatures.workshopResource, sectorFeatures.hasClearableWorkshop, sectorFeatures.hasBuildableWorkshop));
}
this.engine.addEntity(sector);
return sector;
},
createTribe: function (saveKey) {
var tribe = new Ash.Entity()
.add(new TribeComponent())
.add(new ResourcesComponent("tribe", 0))
.add(new CurrencyComponent(0))
.add(new UpgradesComponent())
.add(new ResourceAccumulationComponent(saveKey))
.add(new SaveComponent(saveKey, [UpgradesComponent, ResourcesComponent, CurrencyComponent]));
this.engine.addEntity(tribe);
return tribe;
},
createGang: function (saveKey, level, posX, posY, gangVO) {
var gang = new Ash.Entity()
.add(new PositionComponent(level, posX, posY))
.add(new GangComponent(gangVO))
.add(new SaveComponent(saveKey, [GangComponent]));
this.engine.addEntity(gang);
return gang;
},
initPlayer: function (entity, metaState) {
let perksComponent = entity.get(PerksComponent);
let defaultInjury = PerkConstants.perkDefinitions.injury[0].clone();
defaultInjury.startTimer = PerkConstants.TIMER_DISABLED;
defaultInjury.removeTimer = PerkConstants.TIMER_DISABLED;
perksComponent.addPerk(defaultInjury);
if (metaState.hasCompletedGame) {
perksComponent.addPerk(PerkConstants.getPerk(PerkConstants.perkIds.restartBonusCompletion));
} else if (metaState.maxCampOrdinalReached > 2) {
perksComponent.addPerk(PerkConstants.getPerk(PerkConstants.perkIds.restartBonusSmall));
}
perksComponent.addPerk(PerkConstants.getPerk(PerkConstants.perkIds.hunger));
perksComponent.addPerk(PerkConstants.getPerk(PerkConstants.perkIds.thirst));
entity.add(new ExcursionComponent());
let logComponent = entity.get(LogMessagesComponent);
let positionComponent = entity.get(PositionComponent);
let startMsg = "You are alone in a massive dark corridor, far below sunlight.";
logComponent.addMessage(LogConstants.MSG_ID_START, startMsg, null, null, positionComponent.getPosition(), LogConstants.MSG_VISIBILITY_DEFAULT, true);
},
syncPlayer: function (entity) {
var inCamp = entity.get(PositionComponent).inCamp;
if (!inCamp && !entity.has(ExcursionComponent)) {
entity.add(new ExcursionComponent());
}
},
syncSector: function (entity) {
if (entity.has(CampComponent) && !entity.has(CampEventTimersComponent)) {
entity.add(new CampEventTimersComponent());
}
if (entity.has(CampComponent) && !entity.has(ReputationComponent)) {
entity.add(new ReputationComponent());
}
if (entity.has(CampComponent) && !entity.has(CurrencyComponent)) {
entity.add(new CurrencyComponent(0));
}
if (entity.has(CampComponent) && !entity.has(OutgoingCaravansComponent)) {
entity.add(new OutgoingCaravansComponent());
}
let improvementsComponent = entity.get(SectorImprovementsComponent);
if (improvementsComponent.hasCollectors() && !entity.has(SectorCollectorsComponent)) {
entity.add(new SectorCollectorsComponent());
}
if (improvementsComponent.getCount(improvementNames.beacon) > 0 && !entity.has(BeaconComponent)) {
entity.add(new BeaconComponent);
}
},
});
return EntityCreator;
});