-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathEvent.ts
78 lines (75 loc) · 2.23 KB
/
Event.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
import { Globals } from "../common/Globals";
import InputValidator from "../common/InputValidator";
import IUnits from "../interfaces/IUnits";
import PlanetType = Globals.PlanetType;
/**
* Represents a user-row in the database
*/
export default class Event implements IUnits {
public eventID: number;
public ownerID: number;
public mission: number;
public fleetlist: string;
public startID: number;
public startType: PlanetType;
public startTime: number;
public endID: number;
public endType: PlanetType;
public endTime: number;
public loadedMetal: number;
public loadedCrystal: number;
public loadedDeuterium: number;
public returning: boolean;
public inQueue: boolean;
public processed: boolean;
/**
* Returns, if the contains valid data or not
*/
public isValid(): boolean {
if (!InputValidator.isSet(this.eventID) || this.eventID <= 0) {
return false;
}
if (!InputValidator.isSet(this.ownerID) || this.ownerID < 0) {
return false;
}
if (!InputValidator.isSet(this.mission) || this.mission < 0) {
return false;
}
// TODO: validate against schema
if (!InputValidator.isSet(this.fleetlist) || this.fleetlist.length === 0) {
return false;
}
if (!InputValidator.isSet(this.startID) || this.startID < 0) {
return false;
}
if (
this.startType !== PlanetType.Planet &&
this.startType !== PlanetType.Moon &&
this.startType !== PlanetType.Debris
) {
return false;
}
if (!InputValidator.isSet(this.startTime) || this.startTime < 0) {
return false;
}
if (!InputValidator.isSet(this.endID) || this.endID < 0) {
return false;
}
if (this.endType !== PlanetType.Planet && this.endType !== PlanetType.Moon && this.endType !== PlanetType.Debris) {
return false;
}
if (!InputValidator.isSet(this.endTime) || this.endTime < 0) {
return false;
}
if (!InputValidator.isSet(this.loadedMetal) || this.loadedMetal < 0) {
return false;
}
if (!InputValidator.isSet(this.loadedCrystal) || this.loadedCrystal < 0) {
return false;
}
if (!InputValidator.isSet(this.loadedDeuterium) || this.loadedDeuterium < 0) {
return false;
}
return true;
}
}