|
1
|
|
|
<?php |
|
2
|
|
|
class DuelBadgeActivator extends BadgeActivator |
|
3
|
|
|
{ |
|
4
|
|
|
/** |
|
5
|
|
|
* @param boolean $role |
|
6
|
|
|
* @param string $winner |
|
7
|
|
|
*/ |
|
8
|
|
|
public function triggerDuelFirstWin($role, $winner) |
|
9
|
|
|
{ |
|
10
|
|
|
if ($role == 'caller' && $winner == 'caller') { |
|
11
|
|
|
$this->activate('first_duel_win'); |
|
12
|
|
|
} |
|
13
|
|
|
} |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @param integer $cnt |
|
17
|
|
|
*/ |
|
18
|
|
|
public function triggerDuelSuccess($cnt) |
|
19
|
|
|
{ |
|
20
|
|
|
if ($cnt >= 100) { |
|
21
|
|
|
$this->activate('duel_success_100'); |
|
22
|
|
|
} |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @param integer $cnt |
|
27
|
|
|
*/ |
|
28
|
|
|
public function triggerDuelFail($cnt) |
|
29
|
|
|
{ |
|
30
|
|
|
if ($cnt >= 100) { |
|
31
|
|
|
$this->activate('duel_fail_100'); |
|
32
|
|
|
} |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @param integer $cntSuccess |
|
37
|
|
|
* @param integer $cntFail |
|
38
|
|
|
*/ |
|
39
|
|
|
public function triggerDuelRate($cntSuccess, $cntFail) |
|
40
|
|
|
{ |
|
41
|
|
|
$mapMax = [ |
|
42
|
|
|
['limit'=>100, 'percent'=>40], |
|
43
|
|
|
['limit'=>300, 'percent'=>25], |
|
44
|
|
|
['limit'=>600, 'percent'=>10], |
|
45
|
|
|
]; |
|
46
|
|
View Code Duplication |
foreach ($mapMax as $params) { |
|
|
|
|
|
|
47
|
|
|
if ($this->getSuccessRate($params['limit'], $cntSuccess, $cntFail) <= $params['percent']) { |
|
48
|
|
|
$this->activate('duel_rate_' . $params['percent']); |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
$mapMin = [ |
|
53
|
|
|
['limit'=>100, 'percent'=>60], |
|
54
|
|
|
['limit'=>300, 'percent'=>75], |
|
55
|
|
|
['limit'=>900, 'percent'=>90], |
|
56
|
|
|
]; |
|
57
|
|
View Code Duplication |
foreach ($mapMin as $params) { |
|
|
|
|
|
|
58
|
|
|
if ($this->getSuccessRate($params['limit'], $cntSuccess, $cntFail) >= $params['percent']) { |
|
59
|
|
|
$this->activate('duel_rate_' . $params['percent']); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @param integer $dollar |
|
66
|
|
|
*/ |
|
67
|
|
|
public function triggerDuelMoney($dollar) |
|
68
|
|
|
{ |
|
69
|
|
|
foreach ([100, 1000] as $limit) { |
|
70
|
|
|
if ($dollar >= $limit) { |
|
71
|
|
|
$this->activate('duel_money_' . $limit); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @param boolean $isWinner |
|
78
|
|
|
*/ |
|
79
|
|
View Code Duplication |
public function triggerDuelWinChance($isWinner, $chance) |
|
|
|
|
|
|
80
|
|
|
{ |
|
81
|
|
|
if (!$isWinner) { |
|
82
|
|
|
return false; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
foreach ([35, 20, 5] as $limit) { |
|
86
|
|
|
if ($chance <= $limit) { |
|
87
|
|
|
$this->activate('duel_win_chance' . $limit); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @param boolean $isWinner |
|
94
|
|
|
*/ |
|
95
|
|
View Code Duplication |
public function triggerDuelLoseChance($isWinner, $chance) |
|
|
|
|
|
|
96
|
|
|
{ |
|
97
|
|
|
if ($isWinner) { |
|
98
|
|
|
return false; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
foreach ([65, 80, 95] as $limit) { |
|
102
|
|
|
if ($chance >= $limit) { |
|
103
|
|
|
$this->activate('duel_lose_chance' . $limit); |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @param string $role |
|
110
|
|
|
*/ |
|
111
|
|
|
public function triggerDuel2h($role) |
|
112
|
|
|
{ |
|
113
|
|
|
if ($role == 'caller' && date('G') == 2) { |
|
114
|
|
|
$this->activate('duel_2h'); |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* @param integer $limit |
|
120
|
|
|
* @param integer $cntSuccess |
|
121
|
|
|
* @param integer $cntFail |
|
122
|
|
|
*/ |
|
123
|
|
|
private function getSuccessRate($limit, $cntSuccess, $cntFail) |
|
124
|
|
|
{ |
|
125
|
|
|
$rate = 50; |
|
126
|
|
|
if ($cntSuccess + $cntFail >= $limit) { |
|
127
|
|
|
$rate = round($cntSuccess / (($cntSuccess + $cntFail)/100), 1); |
|
128
|
|
|
} |
|
129
|
|
|
return $rate; |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
|
|
|
|
|
132
|
|
|
|
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.