-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoolClass.php
165 lines (157 loc) · 5.81 KB
/
toolClass.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
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
<?php
require_once("buildingClass.php");
require_once("userDetailsClass.php");
class Tool {
private $userid;
private $db;
public static $FISH_AXE = 10;
public static $WOODEN_AXE = 11;
public static $STONE_AXE = 12;
public static $FISH_PICKAXE = 13;
public static $WOODEN_PICKAXE = 14;
public static $STONE_PICKAXE = 15;
function __construct($db,$userid) {
$this->db = $db;
$this->userid = $userid;
}
/**
* Lekérdezi az eszközhöz szükséges nyersanyagokat
* @param $type
* @return mixed
*/
function getToolResources($type) {
$sql = "SELECT ".$GLOBALS["table_toolresources_resources"]." FROM ".$GLOBALS["table_toolresources_title"]." WHERE ".$GLOBALS["table_toolresources_toolid"]." = ?";
$stmt = $this->db->prepare($sql);
$stmt->execute(array($type));
$resultArray = $stmt->fetch(PDO::FETCH_ASSOC);
$result = json_decode($resultArray[$GLOBALS["table_toolresources_resources"]]);
return $result;
}
/**
* Lekérdezi az eszközhöz szükséges intelligenciapontokat
* @param $type
* @return mixed
*/
function getToolIpo($type) {
$sql = "SELECT ".$GLOBALS["table_toolresources_ipo"]." FROM ".$GLOBALS["table_toolresources_title"]." WHERE ".$GLOBALS["table_toolresources_toolid"]." = ?";
$stmt = $this->db->prepare($sql);
$stmt->execute(array($type));
$resultArray = $stmt->fetch(PDO::FETCH_ASSOC);
$result = $resultArray[$GLOBALS["table_toolresources_ipo"]];
return $result;
}
/**
* Lekérdezi az összes kifejleszthető eszközt
* @return array
*/
public function getAllDevelopableTools() {
$building = new Building($this->db,$this->userid);
$toolStationLevel = $building->getToolStationLevel();
$sql = "SELECT * FROM ".$GLOBALS["table_toolresources_title"]." WHERE ".$GLOBALS["table_toolresources_minlevel"]." <= ?";
$stmt = $this->db->prepare($sql);
$stmt->execute(array($toolStationLevel));
$resultArray = $stmt->fetchAll(PDO::FETCH_ASSOC);
$userdetails = new UserDetails($this->db,$this->userid);
$tResources = array();
foreach($resultArray as $buildingResource) {
if(!$userdetails->isToolDeveloped($buildingResource[$GLOBALS["table_toolresources_toolid"]])) {
$buildingResource[$GLOBALS["table_toolresources_resources"]] = json_decode($buildingResource[$GLOBALS["table_toolresources_resources"]]);
array_push($tResources,$buildingResource);
}
}
return $tResources;
}
/**
* Elkezdi kifejleszteni az adott eszközt
* @param $toolid
* @return array
*/
public function developTool($toolid) {
$neededResources = $this->getToolResources($toolid);
if($neededResources == null) {
$result["hibaid"] = "5";
$result["hiba"] = Exceptions::getMessage(5);
return $result;
}
$userdetails = new UserDetails($this->db,$this->userid);
foreach($neededResources as $restype=>$resamount) {
$stored = $userdetails->getStorageResource($this->userid,$restype);
if($stored < $resamount) {
$result["hibaid"] = "6";
$result["hiba"] = Exceptions::getMessage(6);
return $result;
}
}
$ipoNeeded = $this->getToolIpo($toolid);
$myIpo = $userdetails->getIpo();
if($myIpo < $ipoNeeded) {
$result["hibaid"] = "8";
$result["hiba"] = Exceptions::getMessage(8);
return $result;
}
foreach($neededResources as $restype=>$resamount) {
$stored = $userdetails->getStorageResource($this->userid,$restype);
$userdetails->setStorageResource($this->userid,$restype,$stored-$resamount);
}
$userdetails->setIpo($myIpo-$ipoNeeded);
$timedAction = new TimedAction($this->db,$this->userid);
$timeArray = $timedAction->setDevelopTool($toolid);
return $timeArray;
}
/**
* Lekérdezi, hogy menyni ideig tart kitermelni egy nyersanyagot
* @param $type
* @return float|int
*/
public function getMiningTime($type) {
$userdetails = new UserDetails($this->db,$this->userid);
$time = 10;
if($type == UserDetails::$WOOD) {
$time = 10;
if($userdetails->isToolDeveloped(Tool::$STONE_AXE)) {
$time /= 4;
}
else if($userdetails->isToolDeveloped(Tool::$WOODEN_AXE)) {
$time /= 2;
}
else if($userdetails->isToolDeveloped(Tool::$FISH_AXE)) {
$time /= 1.2;
}
}
else if($type == UserDetails::$TWIG) {
$time = 10;
if($userdetails->isToolDeveloped(Tool::$STONE_AXE)) {
$time /= 4;
}
else if($userdetails->isToolDeveloped(Tool::$WOODEN_AXE)) {
$time /= 2;
}
else if($userdetails->isToolDeveloped(Tool::$FISH_AXE)) {
$time /= 1.2;
}
}
else if($type == UserDetails::$MEAT) {
$time = 10;
}
else if($type == UserDetails::$BERRY) {
$time = 10;
}
else if($type == UserDetails::$STONE) {
$time = 10;
if($userdetails->isToolDeveloped(Tool::$STONE_PICKAXE)) {
$time /= 4;
}
else if($userdetails->isToolDeveloped(Tool::$WOODEN_PICKAXE)) {
$time /= 2;
}
else if($userdetails->isToolDeveloped(Tool::$FISH_PICKAXE)) {
$time /= 1.2;
}
}
else if($type == UserDetails::$FISH) {
$time = 10;
}
return $time;
}
}
?>