-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathshipyard.php
98 lines (76 loc) · 3.77 KB
/
shipyard.php
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
<?php
defined('INSIDE') OR exit('No direct script access allowed');
class M_Shipyard implements I_Model {
/**
* loads the required language files
* @return array the loaded language-array
* @throws FileNotFoundException
*/
public function loadLanguage() {
global $lang;
$file = Config::$pathConfig['language'] . Config::$gameConfig['language'] . '/shipyard.php';
if (file_exists($file)) {
require $file;
} else {
throw new FileNotFoundException('File \'' . $file . '\' not found');
}
$file = Config::$pathConfig['language'] . Config::$gameConfig['language'] . '/units.php';
if (file_exists($file)) {
require $file;
} else {
throw new FileNotFoundException('File \'' . $file . '\' not found');
}
$file = Config::$pathConfig['language'] . Config::$gameConfig['language'] . '/menu.php';
if (file_exists($file)) {
require $file;
} else {
throw new FileNotFoundException('File \'' . $file . '\' not found');
}
return $lang;
}
public function build(int $planetID, array $buildingQueue, int $costMetal, int $costCrystal,
int $costDeuterium) {
global $debug;
if (Loader::getUser()
->getCurrentPlanet() != $planetID || $costMetal < 0 || $costCrystal < 0 || $costDeuterium < 0) {
throw new InvalidArgumentException('Passed arguments are not valid');
//break;
}
try {
// append to current queue
if (Loader::getPlanet()->getBHangarId() !== "0") {
$buildingString = Loader::getPlanet()->getBHangarId();
}
foreach ($buildingQueue as $k => $v) {
$key = key($v);
$buildingString .= $key . "," . $v[$key] . ";";
}
$params = array(
':b_hangar_start_time' => time(),
':b_hangar_id' => $buildingString,
':metal' => Loader::getPlanet()->getMetal() - $costMetal,
':crystal' => Loader::getPlanet()->getCrystal() - $costCrystal,
':deuterium' => Loader::getPlanet()->getDeuterium() - $costDeuterium,
':planetID' => $planetID
);
$dbConnection = new Database();
$stmt = $dbConnection->prepare('UPDATE planets SET
b_hangar_start_time = :b_hangar_start_time,
b_hangar_id = :b_hangar_id,
metal = :metal,
crystal = :crystal,
deuterium = :deuterium
WHERE planetID = :planetID;');
$stmt->execute($params);
Loader::getPlanet()->setMetal(Loader::getPlanet()->getMetal() - $costMetal);
Loader::getPlanet()->setCrystal(Loader::getPlanet()->getCrystal() - $costCrystal);
Loader::getPlanet()->setDeuterium(Loader::getPlanet()->getDeuterium() - $costDeuterium);
} catch (PDOException $e) {
if (DEBUG) {
$debug->addLog(self::class, __FUNCTION__, __LINE__, get_class($e), $e->getMessage());
} else {
$debug->saveError(self::class, __FUNCTION__, __LINE__, get_class($e), $e->getMessage());
}
}
}
}