1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @property integer $state |
4
|
|
|
* @property integer $descriptionToShow |
5
|
|
|
* @property Location $location |
6
|
|
|
*/ |
7
|
|
|
class Tutorial extends CModel |
8
|
|
|
{ |
9
|
|
|
private $state; |
10
|
|
|
private $location; |
11
|
|
|
private $descriptionToShow; |
12
|
|
|
|
13
|
|
|
public function attributeNames() |
14
|
|
|
{ |
15
|
|
|
return []; |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
public function getState() |
19
|
|
|
{ |
20
|
|
|
return (int)$this->state; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function getDescriptionToShow() |
24
|
|
|
{ |
25
|
|
|
$this->update(); |
26
|
|
|
return (int)$this->descriptionToShow; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function setState($state) |
30
|
|
|
{ |
31
|
|
|
$this->state = (int)$state; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function setLocation($location) |
35
|
|
|
{ |
36
|
|
|
$this->location = $location; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
private function update() |
40
|
|
|
{ |
41
|
|
|
$player = Yii::app()->player->model; |
42
|
|
|
//check requirements of new state |
43
|
|
|
$advance = false; |
44
|
|
|
switch ($this->state) { |
45
|
|
View Code Duplication |
case 0: |
|
|
|
|
46
|
|
|
//teljesits 1 megbizast |
47
|
|
|
foreach ($this->location->missions as $mission) { |
|
|
|
|
48
|
|
|
if ($mission->routine > 0) { |
49
|
|
|
$advance = true; |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
break; |
53
|
|
|
case 1: |
54
|
|
|
if ($player->dollar >= 10) { |
55
|
|
|
$advance = true; |
56
|
|
|
} |
57
|
|
|
break; |
58
|
|
|
case 2: |
59
|
|
|
if ($player->skill_extended - $player->skill > 2) { |
60
|
|
|
$advance = true; |
61
|
|
|
} |
62
|
|
|
break; |
63
|
|
View Code Duplication |
case 3: |
|
|
|
|
64
|
|
|
//1 megbizasnal 100% rutin |
65
|
|
|
foreach ($this->location->missions as $mission) { |
|
|
|
|
66
|
|
|
if ($mission->routine >= 100) { |
67
|
|
|
$advance = true; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
break; |
71
|
|
|
case 4: |
72
|
|
|
$advance = true; |
73
|
|
View Code Duplication |
foreach ($this->location->missions as $mission) { |
|
|
|
|
74
|
|
|
if (!$mission->gate && $mission->routine < 100) { |
75
|
|
|
$advance = false; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
break; |
79
|
|
|
case 5: |
80
|
|
|
if ($this->location->routine > 0) { |
|
|
|
|
81
|
|
|
$advance = true; |
82
|
|
|
} |
83
|
|
|
break; |
84
|
|
|
case 6: |
85
|
|
|
//advance at first travel |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
//advance to new state |
89
|
|
|
if ($advance) { |
90
|
|
|
Yii::app()->player->model->updateAttributes(['tutorial_mission'=>1], []); |
91
|
|
|
$this->state++; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
//set description |
95
|
|
|
$this->descriptionToShow = $this->state < 7 ? $this->state+1 : 0; |
96
|
|
|
} |
97
|
|
|
} |
|
|
|
|
98
|
|
|
|
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.