|
1
|
|
|
<?php |
|
2
|
|
|
class DuelController extends GameController |
|
3
|
|
|
{ |
|
4
|
|
|
protected function beforeAction($action) |
|
5
|
|
|
{ |
|
6
|
|
|
parent::beforeAction($action); |
|
7
|
|
|
|
|
8
|
|
|
if (Yii::app()->player->model->level < Yii::app()->params['duelLevelRequirement']) { |
|
9
|
|
|
$this->render('lowlevel', [ |
|
10
|
|
|
'levelRequirement' => Yii::app()->params['duelLevelRequirement'] |
|
11
|
|
|
]); |
|
12
|
|
|
return false; |
|
13
|
|
|
} |
|
14
|
|
|
return true; |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
public function actionIndex($page = 0) |
|
19
|
|
|
{ |
|
20
|
|
|
$duelList = new DuelList(); |
|
|
|
|
|
|
21
|
|
|
$duelList->page = $page; |
|
|
|
|
|
|
22
|
|
|
$duelList->fetchOpponents(); |
|
23
|
|
|
|
|
24
|
|
|
$this->render('index', [ |
|
25
|
|
|
'list'=>$duelList->opponents, |
|
|
|
|
|
|
26
|
|
|
'pagination' => $duelList->pagination, |
|
|
|
|
|
|
27
|
|
|
'count' => $duelList->count, |
|
|
|
|
|
|
28
|
|
|
'page_size' => Yii::app()->params['listPerPage'], |
|
29
|
|
|
'page'=>$page, |
|
30
|
|
|
]); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function actionCommon() |
|
34
|
|
|
{ |
|
35
|
|
|
$duelList = new DuelList(); |
|
36
|
|
|
$duelList->fetchCommonRivals(); |
|
37
|
|
|
|
|
38
|
|
|
$this->render('commonrivals', [ |
|
39
|
|
|
'list'=>$duelList->opponents, |
|
|
|
|
|
|
40
|
|
|
]); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function actionHistory() |
|
44
|
|
|
{ |
|
45
|
|
|
$duelList = new DuelList(); |
|
46
|
|
|
$duelList->fetchLastRivals(); |
|
47
|
|
|
|
|
48
|
|
|
$this->render('history', [ |
|
49
|
|
|
'list'=>$duelList->opponents, |
|
|
|
|
|
|
50
|
|
|
]); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function actionGo($opponentId = 0) |
|
54
|
|
|
{ |
|
55
|
|
|
$duel = new Duel(); |
|
|
|
|
|
|
56
|
|
|
$duel->caller = Yii::app()->player->uid; |
|
|
|
|
|
|
57
|
|
|
$duel->opponent = $opponentId; |
|
|
|
|
|
|
58
|
|
|
$duel->fetchClubChallengeState(); |
|
59
|
|
|
|
|
60
|
|
|
try { |
|
61
|
|
|
if ($duel->validateDuel()) { |
|
62
|
|
|
$duel->play(); |
|
63
|
|
|
} |
|
64
|
|
|
} catch (CFlashException $e) { |
|
65
|
|
|
Yii::app()->user->setFlash('error', $e->getMessage()); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
$this->render('go', [ |
|
69
|
|
|
'duel'=>$duel, |
|
70
|
|
|
]); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function actionReplay($id) |
|
74
|
|
|
{ |
|
75
|
|
|
$duel = new Duel; |
|
76
|
|
|
try { |
|
77
|
|
|
$duel->replay((int)$id); |
|
78
|
|
|
} catch (CFlashException $e) { |
|
79
|
|
|
Yii::app()->user->setFlash('error', $e->getMessage()); |
|
80
|
|
|
$this->redirect('/duel'); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
$this->render('replay', [ |
|
84
|
|
|
'duel'=>$duel, |
|
85
|
|
|
]); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
|
|
|
|
|
88
|
|
|
|
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
will produce issues in the first and second line, while this second example
will produce no issues.