-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDefenses.ts
135 lines (123 loc) · 3.58 KB
/
Defenses.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
import IUnits from "../interfaces/IUnits";
/**
* Represents a defenses-row in the database
*/
export default class Defenses implements IUnits {
/**
* The ID of the planet
*/
public planetID: number;
/**
* The current amount of rocketLauncher on the planet
*/
public rocketLauncher: number;
/**
* The current amount of lightLaser on the planet
*/
public lightLaser: number;
/**
* The current amount of heavyLaser on the planet
*/
public heavyLaser: number;
/**
* The current amount of ionCannon on the planet
*/
public ionCannon: number;
/**
* The current amount of gaussCannon on the planet
*/
public gaussCannon: number;
/**
* The current amount of plasmaTurret on the planet
*/
public plasmaTurret: number;
/**
* Is true, if the planet has a smallShieldDome
*/
public smallShieldDome: boolean;
/**
* Is true, if the planet has a largeShieldDome
*/
public largeShieldDome: boolean;
/**
* The current amount of antiBallisticMissile on the planet
*/
public antiBallisticMissile: number;
/**
* The current amount of interplanetaryMissile on the planet
*/
public interplanetaryMissile: number;
/**
* Returns, if the contains valid data or not
*/
public isValid(): boolean {
return (
0 <= this.planetID &&
0 <= this.rocketLauncher &&
0 <= this.lightLaser &&
0 <= this.heavyLaser &&
0 <= this.ionCannon &&
0 <= this.gaussCannon &&
0 <= this.plasmaTurret &&
0 <= this.antiBallisticMissile &&
0 <= this.interplanetaryMissile
);
}
// public save(): Promise<{}> {
// return new Promise((resolve, reject) => {
// const query = squel
// .update()
// .table("defenses")
// .set("rocketLauncher", this.rocketLauncher)
// .set("lightLaser", this.lightLaser)
// .set("heavyLaser", this.heavyLaser)
// .set("ionCannon", this.ionCannon)
// .set("gaussCannon", this.gaussCannon)
// .set("plasmaTurret", this.plasmaTurret)
// .set("smallShieldDome", this.smallShieldDome)
// .set("largeShieldDome", this.largeShieldDome)
// .set("antiBallisticMissile", this.antiBallisticMissile)
// .set("interplanetaryMissile", this.interplanetaryMissile)
// .where("planetID = ?", this.planetID)
// .toString();
//
// Database.query(query)
// .then(() => {
// return resolve(this);
// })
// .catch(error => {
// Logger.error(error);
// return reject(error);
// });
// });
// }
//
// public create(): Promise<{}> {
// return new Promise((resolve, reject) => {
// const query = squel
// .insert()
// .into("defenses")
// .set("planetID", this.planetID)
// .set("rocketLauncher", this.rocketLauncher)
// .set("lightLaser", this.lightLaser)
// .set("heavyLaser", this.heavyLaser)
// .set("ionCannon", this.ionCannon)
// .set("gaussCannon", this.gaussCannon)
// .set("plasmaTurret", this.plasmaTurret)
// .set("smallShieldDome", this.smallShieldDome)
// .set("largeShieldDome", this.largeShieldDome)
// .set("antiBallisticMissile", this.antiBallisticMissile)
// .set("interplanetaryMissile", this.interplanetaryMissile)
// .toString();
//
// Database.query(query)
// .then(() => {
// return resolve(this);
// })
// .catch(error => {
// Logger.error(error);
// return reject(error);
// });
// });
// }
}