Mission::chanceOfPlayer()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 2
nop 0
1
<?php
2
/**
3
 * @property integer $id
4
 * @property integer $water_id
5
 * @property integer $gate
6
 * @property integer $req_energy
7
 * @property integer $req_bait_1
8
 * @property integer $req_bait_1_count
9
 * @property integer $req_bait_2
10
 * @property integer $req_bait_2_count
11
 * @property array $req_baits
12
 * @property integer $award_xp
13
 * @property integer $award_dollar_min
14
 * @property integer $award_dollar_max
15
 * @property integer $award_setpart
16
 * @property integer $routine_gain
17
 * @property integer $skill
18
 * @property string $title
19
 * @property string $txt
20
 * @property string $gate_name
21
 * @property boolean $gate_visited
22
 * @property string $award_dollar
23
 * @property integer $routine
24
 * @property integer $chance
25
 * @property integer $skill_extended_at_visit
26
 * @property integer $req_energy_expansion
27
 */
28
class Mission extends CModel
29
{
30
    private $id;
31
    private $action;
32
    private $water_id;
33
    private $gate;
34
    private $req_energy;
35
    private $req_energy_expansion = 0;
36
    private $req_bait_1;
37
    private $req_bait_1_count;
38
    private $req_bait_2;
39
    private $req_bait_2_count;
40
    private $req_baits; //list of item classes
41
    private $award_xp;
42
    private $award_dollar_min;
43
    private $award_dollar_max;
44
    private $award_setpart;
45
    private $routine_gain;
46
    private $routine_reduction = 0;
47
    private $skill;
48
    private $title;
49
    private $txt;
50
    private $gate_name;
51
    private $gate_visited;
52
    private $routine;
53
    private $chance;
54
    private $skill_extended_at_visit;
55
    private $locationRoutinesFull;
56
57
    public function attributeNames()
58
    {
59
        return [];
60
    }
61
62
    /* getters */
63
    public function getId()
64
    {
65
        return $this->id;
66
    }
67
68
    public function getAction()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
69
    {
70
        if (!$this->action) {
71
            $this->action = new MissionAction();
72
        }
73
        return $this->action;
74
    }
75
76
    public function getWater_id()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
77
    {
78
        return $this->water_id;
79
    }
80
81
    public function getGate()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
82
    {
83
        return $this->gate;
84
    }
85
86
    public function getReq_energy()
87
    {
88
        return $this->req_energy;
89
    }
90
91
    public function getReq_bait_1()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
92
    {
93
        return $this->req_bait_1;
94
    }
95
96
    public function getReq_bait_1_count()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
97
    {
98
        return $this->req_bait_1_count;
99
    }
100
101
    public function getReq_bait_2()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
102
    {
103
        return $this->req_bait_2;
104
    }
105
106
    public function getReq_bait_2_count()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
107
    {
108
        return $this->req_bait_2_count;
109
    }
110
111
    public function getReq_baits()
112
    {
113
        return $this->req_baits;
114
    }
115
116
    public function getAward_xp()
117
    {
118
        return $this->award_xp;
119
    }
120
121
    public function getAward_dollar_min()
122
    {
123
        return $this->award_dollar_min;
124
    }
125
126
    public function getAward_dollar_max()
127
    {
128
        return $this->award_dollar_max;
129
    }
130
131
    public function getAward_setpart()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
132
    {
133
        return $this->award_setpart;
134
    }
135
136
    public function getRoutine_gain()
137
    {
138
        return $this->routine_gain - $this->routine_reduction;
139
    }
140
141
    public function getRoutine_reduction()
142
    {
143
        return $this->routine_reduction;
144
    }
145
146
    public function getSkill()
147
    {
148
        return $this->skill;
149
    }
150
151
    public function getTitle()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
152
    {
153
        return $this->title;
154
    }
155
156
    public function getTxt()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
157
    {
158
        return $this->txt;
159
    }
160
161
    public function getGate_name()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
162
    {
163
        return $this->gate_name;
164
    }
165
166
    public function getGate_visited()
167
    {
168
        return $this->gate_visited;
169
    }
170
171
    public function getAward_dollar()
172
    {
173
        if ($this->award_dollar_min == $this->award_dollar_max) {
174
            return $this->award_dollar_min . '$';
175
        }
176
177
        return $this->award_dollar_min . '$ - ' . $this->award_dollar_max . '$';
178
    }
179
    public function getRoutine()
180
    {
181
        return $this->routine;
182
    }
183
184
    public function getChance()
185
    {
186
        return $this->chance;
187
    }
188
189
    public function getLocationRoutinesFull()
190
    {
191
        return $this->locationRoutinesFull;
192
    }
193
194
    /* setters */
195
    public function setId($id)
196
    {
197
        $this->id = (int)$id;
198
    }
199
200
    public function setGate_name($name)
201
    {
202
        $this->gate_name = $name;
203
    }
204
205
    public function setRoutine($routine)
206
    {
207
        $this->routine = (int)$routine;
208
    }
209
210
    public function setGate_visited($visited)
211
    {
212
        $this->gate_visited = (bool)$visited;
213
    }
214
215
    public function setRoutine_reduction($reduction)
216
    {
217
        $this->routine_reduction = (int)$reduction;
218
    }
219
220
    public function setReq_energy_expansion($exp)
221
    {
222
        $this->req_energy_expansion = (int)$exp;
223
    }
224
225
    public function setSkill_extended_at_visit($value)
226
    {
227
        $this->skill_extended_at_visit = (int)$value;
228
        if ($this->skill_extended_at_visit < 2) {
229
            $this->skill_extended_at_visit = 2; //min SEAV
230
        }
231
    }
232
233
    public function setLocationRoutinesFull($value)
234
    {
235
        $this->locationRoutinesFull = (bool)$value;
236
    }
237
238
    public function fetch()
239
    {
240
        if (!$this->id) {
241
            return false;
242
        }
243
244
        //read all from db
245
        $dependency = new CExpressionDependency('Yii::app()->params["missions_version"]');
246
        $res = Yii::app()->db->cache(Yii::app()->params['cacheDuration'], $dependency)->createCommand()
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 8 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
247
            ->select('*')
248
            ->from('missions')
249
            ->where('id=:id', [':id'=>$this->id])
250
            ->queryRow();
251
        foreach ($res as $k => $v) {
252
            $this->$k = $v;
253
        }
254
        $this->req_energy += $this->req_energy_expansion;
255
256
        $this->routine = $this->fetchRoutine();
257
        $this->skill = $this->missionSkill($this->chance);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
258
        $this->chance = $this->chanceOfPlayer(); //recalculate chance
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
259
260
        //dollar redurcion
261
        if (!$this->gate) {
262
            $this->award_dollar_min = ceil($this->award_dollar_min / 2);
263
            $this->award_dollar_max = ceil($this->award_dollar_max / 2);
264
        }
265
266
        $this->req_baits = $this->fetchBaits();
267
    }
268
269
    private function missionSkill($percent)
270
    {
271
        /* skillA = percentP * 100 / skillP */
272
        $skillM = 0;
273
        if ($this->skill_extended_at_visit && $percent) {
274
            $skillA = ($this->skill_extended_at_visit * 100) / $percent;
275
            $skillM = $skillA - $this->skill_extended_at_visit;
276
        }
277
        return $skillM;
278
    }
279
280
    public function complete()
281
    {
282
        $this->action = new MissionAction();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 10 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
283
        $this->action->mission = $this;
0 ignored issues
show
Bug introduced by
The property mission cannot be accessed from this context as it is declared private in class MissionAction.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
284
        $this->action->complete();
285
    }
286
287 View Code Duplication
    private function fetchRoutine()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
288
    {
289
        $res = Yii::app()->db->createCommand()
290
            ->select('routine')
291
            ->from('users_missions')
292
            ->where('uid=:uid AND id=:id', [':uid'=>Yii::app()->player->model->uid, ':id'=>(int)$this->id])
293
            ->queryScalar();
294
        return (int)$res;
295
    }
296
297
    private function fetchBaits()
298
    {
299
        $baits = [];
300
301
        for ($b=1; $b<=2; $b++) {
302
            $key = 'req_bait_'.$b;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
303
            $keyCount = 'req_bait_'.$b.'_count';
304
305
            if ($this->$key && $this->$keyCount) {
306
                $tmp = [];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 13 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
307
                $tmp['required'] = $this->$keyCount;
308
309
                $i = new Item();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 12 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
310
                $i->id = $this->$key;
0 ignored issues
show
Bug introduced by
The property id cannot be accessed from this context as it is declared private in class Item.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 8 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
311
                $i->item_type = Item::TYPE_BAIT;
0 ignored issues
show
Bug introduced by
The property item_type cannot be accessed from this context as it is declared private in class Item.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
312
                $i->fetch();
313
                $tmp['item'] = $i;
314
315
                $title = ($i->owned < $tmp['required'] ? $i->owned : $tmp['required']) . '/' . $tmp['required'] .' '. $i->title;
0 ignored issues
show
Bug introduced by
The property owned cannot be accessed from this context as it is declared private in class Item.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
Bug introduced by
The property title cannot be accessed from this context as it is declared private in class Item.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 14 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
316
                $tmp['linkTitle'] = $title;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
317
                $tmp['haveEnought'] = $i->owned >= $tmp['required'];
0 ignored issues
show
Bug introduced by
The property owned cannot be accessed from this context as it is declared private in class Item.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
318
319
                if ($i->title) {
0 ignored issues
show
Bug introduced by
The property title cannot be accessed from this context as it is declared private in class Item.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
320
                    //item found in shop, add to requirements
321
                    $baits[$b] = $tmp;
322
                }
323
            }
324
325
        }
326
        return $baits;
327
    }
328
329
    private function chanceOfPlayer()
330
    {
331
        $skillMission = $this->skill;
332
        $skillPlayer = Yii::app()->player->model->skill_extended;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
333
334
        $all = $skillMission + $skillPlayer;
335
336
        $percentPlayer = round($skillPlayer / ($all / 100), 1);
337
338
        if ($percentPlayer >= 90) {
339
            $percentPlayer = 100;
340
        }
341
        return $percentPlayer;
342
    }
343
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
344