This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * @property array $reqPassed |
||
4 | * @property boolean $success |
||
5 | * @property integer $gained_xp |
||
6 | * @property integer $gained_dollar |
||
7 | * @property integer $gained_routine |
||
8 | * @property boolean $gained_visit |
||
9 | * @property Item $found_setpart |
||
10 | */ |
||
11 | class MissionAction extends CModel |
||
12 | { |
||
13 | private $mission; |
||
14 | private $reqPassed = []; |
||
15 | private $success; |
||
16 | private $gained_xp; |
||
17 | private $gained_dollar; |
||
18 | private $gained_routine; |
||
19 | private $gained_visit; |
||
20 | private $found_setpart; |
||
21 | |||
22 | public function getReqPassed() |
||
23 | { |
||
24 | return $this->reqPassed; |
||
25 | } |
||
26 | |||
27 | public function getSuccess() |
||
28 | { |
||
29 | return $this->success; |
||
30 | } |
||
31 | |||
32 | public function getGained_xp() |
||
33 | { |
||
34 | return (int)$this->gained_xp; |
||
35 | } |
||
36 | |||
37 | public function getGained_dollar() |
||
38 | { |
||
39 | return (int)$this->gained_dollar; |
||
40 | } |
||
41 | |||
42 | public function getGained_routine() |
||
43 | { |
||
44 | return (int)$this->gained_routine; |
||
45 | } |
||
46 | |||
47 | public function getGained_visit() |
||
48 | { |
||
49 | return (bool)$this->gained_visit; |
||
50 | } |
||
51 | |||
52 | public function getFound_setpart() |
||
53 | { |
||
54 | return $this->found_setpart; |
||
55 | } |
||
56 | |||
57 | public function setMission($mission) |
||
58 | { |
||
59 | $this->mission = $mission; |
||
60 | } |
||
61 | |||
62 | public function setGained_visit($visit) |
||
63 | { |
||
64 | $this->gained_visit = (bool)$visit; |
||
65 | $this->mission->gate_visited = (bool)$visit; |
||
66 | } |
||
67 | |||
68 | public function attributeNames() |
||
69 | { |
||
70 | return []; |
||
71 | } |
||
72 | |||
73 | public function complete() |
||
74 | { |
||
75 | if (!$this->requirementsOk()) { |
||
76 | return false; |
||
77 | } |
||
78 | |||
79 | if (!$this->doMission()) { |
||
80 | throw new CFlashException('A követelményeknek megfelelsz, mégsem sikerül teljesÃteni a megbÃzást mivel csak '. $this->mission->chance .'% esélyed volt rá.<br/> |
||
81 | Nagyobb szakértelemmel (több felszereléssel és csalival) ez növelhető.'); |
||
82 | } |
||
83 | $this->incrementRoutine(); |
||
84 | } |
||
85 | |||
86 | private function requirementsOk() |
||
87 | { |
||
88 | $player = Yii::app()->player->model; |
||
89 | |||
90 | //check if the mission is gate and the submissions are maxed out |
||
91 | if ($this->mission->gate) { |
||
92 | $this->reqPassed['routinesFull'] = $this->mission->locationRoutinesFull; |
||
93 | } |
||
94 | |||
95 | //check energy |
||
96 | $this->reqPassed['energy'] = ($player->energy >= $this->mission->req_energy); |
||
97 | |||
98 | //check baits |
||
99 | foreach ($this->mission->req_baits as $req) { |
||
100 | $this->reqPassed['bait_'.$req['item']->id] = $req['haveEnought']; |
||
101 | } |
||
102 | |||
103 | foreach ($this->reqPassed as $passed) { |
||
104 | if (!$passed) { |
||
105 | throw new CFlashException('Nem tudod elvégezni a megbÃzást, mert nem teljesÃted a követelményeket.'); |
||
106 | } |
||
107 | } |
||
108 | |||
109 | //routine full |
||
110 | if ($this->mission->routine >= 100) { |
||
111 | throw new CFlashException('Ezt a megbÃzást már 100% rutinnal végzed, ezért unalmas lenne ismételgetni.'); |
||
112 | } |
||
113 | |||
114 | return true; |
||
115 | } |
||
116 | |||
117 | private function doMission() |
||
118 | { |
||
119 | $incr = $decr = []; |
||
120 | |||
121 | //take requirements |
||
122 | $decr['energy'] = $this->mission->req_energy; |
||
123 | |||
124 | //complete |
||
125 | $this->success = $this->beatMission(); |
||
126 | |||
127 | //add awards |
||
128 | $incr['xp_all'] = $incr['xp_delta'] = $this->gainXP(); |
||
129 | $incr['dollar'] = $this->gainDollar(); |
||
130 | |||
131 | if ($this->success) { |
||
132 | if ($this->mission->gate && !$this->mission->gate_visited) { |
||
133 | $incr['gold'] = Yii::app()->params['goldPerGateMission']; |
||
134 | } |
||
135 | if ($this->mission->award_setpart) { |
||
136 | $this->addSetPart(); |
||
137 | } |
||
138 | } |
||
139 | |||
140 | Yii::app()->player->model->updateAttributes($incr, $decr); |
||
141 | |||
142 | //increment contest points |
||
143 | $contest = new Contest; |
||
144 | $contest->addPoints(Yii::app()->player->uid, Contest::ACT_MISSION, $decr['energy'], $incr['xp_all'], $incr['dollar']); |
||
145 | |||
146 | return $this->success; |
||
147 | } |
||
148 | |||
149 | private function incrementRoutine() |
||
150 | { |
||
151 | if ($this->mission->gate) { |
||
152 | return false; //do not increment for gate missions |
||
153 | } |
||
154 | if (!$this->success) { |
||
155 | return false; // do not increment on failed missions |
||
156 | } |
||
157 | |||
158 | $uid = Yii::app()->player->model->uid; |
||
159 | $routine = (int)$this->mission->routine_gain; |
||
160 | if ($routine<1) { |
||
161 | $routine = 1; |
||
162 | } |
||
163 | |||
164 | if ($this->mission->routine >= 100) { |
||
165 | $this->mission->routine_gain = 0; |
||
166 | return false; |
||
167 | } |
||
168 | |||
169 | $update = Yii::app()->db |
||
170 | ->createCommand("UPDATE users_missions SET routine=routine+:routine WHERE uid=:uid AND id=:id") |
||
0 ignored issues
–
show
|
|||
171 | ->bindValues([':uid'=>$uid, 'id'=>(int)$this->mission->id, ':routine'=>$routine]) |
||
172 | ->execute(); |
||
173 | |||
174 | View Code Duplication | if (!$update) { |
|
175 | Yii::app()->db->createCommand() |
||
176 | ->insert('users_missions', [ |
||
177 | 'uid'=>$uid, |
||
178 | 'id'=>(int)$this->mission->id, |
||
179 | 'water_id'=>(int)$this->mission->water_id, |
||
180 | 'routine'=>$routine |
||
181 | ]); |
||
182 | } |
||
183 | $this->mission->routine += $routine; |
||
184 | $this->gained_routine = $routine; |
||
185 | Yii::app()->badge->model->triggerRoutine($this->mission->routine); |
||
186 | } |
||
187 | |||
188 | private function beatMission() |
||
189 | { |
||
190 | $random = rand(1, 100); |
||
191 | $success = ($random <= $this->mission->chance); //win |
||
192 | |||
193 | //log mission counter |
||
194 | $cell = 'mission_' . ($this->mission->gate ? 'gate_' : '') . ($success ? 'success' : 'fail'); |
||
195 | |||
196 | $logger = new Logger; |
||
197 | $logger->uid = Yii::app()->player->model->uid; |
||
198 | $logger->level = Yii::app()->player->model->level; |
||
199 | $logger->increment($cell, 1); |
||
200 | |||
201 | return $success; |
||
202 | } |
||
203 | |||
204 | private function gainXP() |
||
205 | { |
||
206 | $xp = $this->mission->award_xp; |
||
207 | if (!$this->success) { |
||
208 | $xp = round($this->mission->award_xp / 10); |
||
209 | } |
||
210 | $this->gained_xp = $xp; |
||
211 | |||
212 | return $xp; |
||
213 | } |
||
214 | |||
215 | private function gainDollar() |
||
216 | { |
||
217 | $dollar = 0; |
||
218 | if ($this->success) { |
||
219 | $dollar = rand($this->mission->award_dollar_min, $this->mission->award_dollar_max); |
||
220 | } |
||
221 | $this->gained_dollar = $dollar; |
||
222 | |||
223 | return $dollar; |
||
224 | } |
||
225 | |||
226 | private function addSetPart() |
||
227 | { |
||
228 | $player = Yii::app()->player->model; |
||
229 | |||
230 | $logger = new Logger; |
||
231 | $logger->key = 'setitem:'.$player->uid; |
||
232 | $logger->addToSet('----start: '.date('Y.m.d. H:i:s').'----'); |
||
233 | |||
234 | $findChance = Yii::app()->params['setPartFindChanceInitial']; // Chance % to find something |
||
235 | $logger->addToSet('initialize variables'); |
||
236 | |||
237 | $now = time(); |
||
238 | if ($now - strtotime($player->found_setitem_time) < Yii::app()->params['setPartFindTimeLimit']) { |
||
239 | $findChance = Yii::app()->params['setPartFindChanceTimeLimit']; //decrease chance in last 24 hour |
||
240 | } |
||
241 | if ($player->xp_all - $player->found_setitem_xp < Yii::app()->params['setPartFindXpLimit']) { |
||
242 | $findChance = Yii::app()->params['setPartFindChanceXpLimit']; //decrease chance in last xp interval |
||
243 | } |
||
244 | |||
245 | $rnd = rand(1, 100); |
||
246 | $logger->addToSet('chance: '. $rnd .'/'.$findChance); |
||
247 | if ($rnd > $findChance) { |
||
248 | return false; |
||
249 | } |
||
250 | |||
251 | //select rnd setitem |
||
252 | $items = Yii::app()->db->createCommand() |
||
253 | ->select('id') |
||
254 | ->from('parts') |
||
255 | ->where('level < :minLevel', [':minLevel'=>$player->level+1]) |
||
256 | ->queryAll(); |
||
257 | |||
258 | $rnd = array_rand($items); |
||
259 | $logger->addToSet('items key: '.$rnd); |
||
260 | $itemId = isset($items[$rnd]) ? $items[$rnd]['id'] : false; |
||
261 | $logger->addToSet('itemId: '. $itemId); |
||
262 | if (!$itemId) { |
||
263 | return false; |
||
264 | } |
||
265 | |||
266 | $i = new Item; |
||
267 | $i->id = $itemId; |
||
268 | $i->item_type = Item::TYPE_PART; |
||
269 | $i->fetch(); |
||
270 | $logger->addToSet('item: '. $i->title); |
||
271 | |||
272 | //add to inventory |
||
273 | $i->buy(1); |
||
274 | $logger->addToSet('errors: '. CJSON::encode($i->errors)); |
||
275 | $logger->addToSet('price: '. $i->price); |
||
276 | $player->rewriteAttributes([ |
||
277 | 'found_setitem_time'=>date("Y-m-d H:i:s", $now), |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
Y-m-d H:i:s does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() |
|||
278 | 'found_setitem_xp'=>$player->xp_all, |
||
279 | ]); |
||
280 | $this->found_setpart = $i; |
||
281 | $logger->addToSet('item bought'); |
||
282 | |||
283 | //log found part |
||
284 | Yii::app()->gameLogger->log(['type'=>'setpart', 'found_setpart'=>$i->title]); |
||
285 | $logger->addToSet('---- end: '.date('Y.m.d. H:i:s').'----'); |
||
286 | |||
287 | //stat |
||
288 | $logger->uid = $player->uid; |
||
289 | $logger->level = $player->level; |
||
290 | $found = $logger->increment('found_part', 1); |
||
291 | Yii::app()->badge->model->triggerSetPart($found); |
||
292 | } |
||
293 | } |
||
294 |
PHP provides two ways to mark string literals. Either with single quotes
'literal'
or with double quotes"literal"
. The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (
\'
) and the backslash (\\
). Every other character is displayed as is.Double quoted string literals may contain other variables or more complex escape sequences.
will print an indented:
Single is Value
If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.
For more information on PHP string literals and available escape sequences see the PHP core documentation.