-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathresources.php
72 lines (56 loc) · 2.49 KB
/
resources.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
<?php
defined('INSIDE') OR exit('No direct script access allowed');
class M_Resources implements I_Model {
/**
* updates the production levels for each ressource-producing building
* @param $planetID the current planet id
* @param $levels the level of the building (or the amount of a unit)
* @throws InvalidArgumentException
*/
public static function updateProductionLevels($planetID, $levels) {
$query_values = '';
foreach ($levels as $k => $v) {
// illegal values
if ($v > 100 || $v < 0 || $v == null || !is_numeric($v) || $v % 10 != 0) {
throw new InvalidArgumentException('updateProductionLevels only accepts integers');
} else {
$query_values .= $k . '_percent = \'' . $v . '\', ';
}
}
// update the planet
$dbConnection = connectToDB();
$dbConnection->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
$dbConnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $dbConnection->prepare('UPDATE planets SET ' . rtrim($query_values,
', ') . ' WHERE planetID = :planetid');
$stmt->bindParam(':planetid', $planetID);
$stmt->execute();
}
/**
* 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'] . '/resources.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;
}
}