-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPlanet.ts
252 lines (216 loc) · 5.51 KB
/
Planet.ts
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
import Config from "../common/Config";
import { Globals } from "../common/Globals";
import IUnits from "../interfaces/IUnits";
/**
* Represents a planet-row in the database
*/
export default class Planet implements IUnits {
/**
* The ID of the planet
*/
public planetID: number;
/**
* The ID of the owner
*/
public ownerID: number;
/**
* The name of the planet
*/
public name: string;
/**
* The galaxy-position in the universe
*/
public posGalaxy: number;
/**
* The system-position in the universe
*/
public posSystem: number;
/**
* the planet-position in the universe
*/
public posPlanet: number;
/**
* The unix-timestamp the planet was last updated
*/
public lastUpdate: number;
/**
* The type of the planet
*/
public planetType: Globals.PlanetType;
/**
* The image of the planet
*/
public image: string;
/**
* The diameter of the planet
*/
public diameter: number;
/**
* The currently populated fields on the planet
*/
public fieldsCurrent: number;
/**
* The maximum fields on the planet
*/
public fieldsMax: number;
/**
* The minimum temperature on the planet
*/
public tempMin: number;
/**
* The maximum temperature on the planet
*/
public tempMax: number;
/**
* The current amount of metal on the planet
*/
public metal: number;
/**
* The current amount of crystal on the planet
*/
public crystal: number;
/**
* The current amount of deuterium on the planet
*/
public deuterium: number;
/**
* The current amount of energy used on the planet
*/
public energyUsed: number;
/**
* The maximum amount of energy on the planet
*/
public energyMax: number;
/**
* The percentage of production metal-mine
*/
public metalMinePercent: number;
/**
* The percentage of production of the crystal-mine
*/
public crystalMinePercent: number;
/**
* The percentage of production deuterium-synthesizer
*/
public deuteriumSynthesizerPercent: number;
/**
* The percentage of production solar-planet
*/
public solarPlantPercent: number;
/**
* The percentage of production fusion-reactor
*/
public fusionReactorPercent: number;
/**
* The percentage of production solar-sattelite
*/
public solarSatellitePercent: number;
/**
* The ID of the building currently upgrading.
* This value is 0 if no building is currently upgrading.
*/
public bBuildingId: number;
/**
* The time, at which the upgrade will be completed
*/
public bBuildingEndTime: number;
/**
* True, if the current build-order is a demolition job
*/
public bBuildingDemolition: boolean;
/**
* The curreny queue of the hangar
*/
public bHangarQueue: string;
/**
* The time, the queue was started
*/
public bHangarStartTime: number;
// TODO: obsolete?
/**
* True, if the hangar is currently upgraded
*/
public bHangarPlus: boolean;
/**
* Indicates, if the planet is destroyed
*/
public destroyed: boolean;
/**
* Checks, if the planet is currently upgrading a building
*/
public isUpgradingBuilding(): boolean {
return this.bBuildingId > 0 && this.bBuildingEndTime > 0;
}
/**
* Checks, if the planet is currently upgrading its hangar
*/
public isUpgradingHangar(): boolean {
return this.bHangarPlus;
}
/**
* Checks, if the planet is currently upgrading the research-lab
*/
public isUpgradingResearchLab(): boolean {
return this.bBuildingId === Globals.Buildings.RESEARCH_LAB && this.bBuildingEndTime > 0;
}
/**
* Checks, if the planet is currently building units
*/
public isBuildingUnits(): boolean {
return (
this.bHangarQueue !== undefined &&
this.bHangarQueue !== null &&
this.bHangarQueue.length > 0 &&
this.bHangarStartTime > 0
);
}
/**
* Returns, if the contains valid data or not
*/
public isValid(): boolean {
return (
0 < this.planetID &&
0 < this.ownerID &&
5 <= this.name.length &&
this.name.length < 45 &&
0 < this.posGalaxy &&
this.posGalaxy <= Config.getGameConfig().posGalaxyMax &&
0 < this.posSystem &&
this.posSystem <= Config.getGameConfig().posSystemMax &&
0 < this.posPlanet &&
this.posPlanet <= Config.getGameConfig().posPlanetMax &&
0 < this.lastUpdate &&
0 < this.diameter &&
0 <= this.fieldsCurrent &&
0 < this.fieldsMax &&
this.fieldsCurrent <= this.fieldsMax &&
this.tempMin <= this.tempMax &&
0 <= this.metal &&
0 <= this.crystal &&
0 <= this.deuterium &&
0 <= this.energyUsed &&
0 <= this.energyMax &&
0 <= this.metalMinePercent &&
this.metalMinePercent <= 100 &&
this.metalMinePercent % 10 === 0 &&
0 <= this.crystalMinePercent &&
this.crystalMinePercent <= 100 &&
this.crystalMinePercent % 10 === 0 &&
0 <= this.deuteriumSynthesizerPercent &&
this.deuteriumSynthesizerPercent <= 100 &&
this.deuteriumSynthesizerPercent % 10 === 0 &&
0 <= this.solarPlantPercent &&
this.solarPlantPercent <= 100 &&
this.solarPlantPercent % 10 === 0 &&
0 <= this.fusionReactorPercent &&
this.fusionReactorPercent <= 100 &&
this.fusionReactorPercent % 10 === 0 &&
0 <= this.solarSatellitePercent &&
this.solarSatellitePercent <= 100 &&
this.solarSatellitePercent % 10 === 0 &&
0 <= this.bBuildingId &&
0 <= this.bBuildingEndTime &&
0 <= this.bHangarStartTime
);
}
}