Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
91.46% |
75 / 82 |
|
70.00% |
14 / 20 |
CRAP | |
0.00% |
0 / 1 |
| HeroPowers | |
91.46% |
75 / 82 |
|
70.00% |
14 / 20 |
50.49 | |
0.00% |
0 / 1 |
| render | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
2 | |||
| renderJavascript | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
6 | |||
| changeUserSoRejuvenationCanBeUsed | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| canUseRejuvanation | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| renderRejuvenation | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| changeUserSoIntuitionCanBeUsed | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| canUseIntuition | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| renderIntuition | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getRevelationUseCount | |
81.82% |
9 / 11 |
|
0.00% |
0 / 1 |
6.22 | |||
| canUseRevelation | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| remainingRevelationUseCount | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| renderRevelation | |
91.67% |
11 / 12 |
|
0.00% |
0 / 1 |
6.02 | |||
| changeUserSoSprintCanBeUsed | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| canUseSprint | |
80.00% |
4 / 5 |
|
0.00% |
0 / 1 |
3.07 | |||
| getSprintRemainingSeconds | |
88.89% |
8 / 9 |
|
0.00% |
0 / 1 |
3.01 | |||
| renderSprint | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isPotionActive | |
80.00% |
4 / 5 |
|
0.00% |
0 / 1 |
4.13 | |||
| canUseRefinement | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
3 | |||
| renderRefinement | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| renderPotion | |
50.00% |
1 / 2 |
|
0.00% |
0 / 1 |
2.50 | |||
| 1 | <?php |
| 2 | |
| 3 | class HeroPowers |
| 4 | { |
| 5 | public static $SPRINT_MINIMUM_LEVEL = 20; |
| 6 | public static $INTUITION_MINIMUM_LEVEL = 30; |
| 7 | public static $REJUVENATION_MINIMUM_LEVEL = 40; |
| 8 | public static $POTION_MINIMUM_LEVEL = 50; |
| 9 | public static $REVELATION_MINIMUM_LEVEL = 80; |
| 10 | public static $REFINEMENT_MINIMUM_LEVEL = 100; |
| 11 | |
| 12 | public static function render(): void |
| 13 | { |
| 14 | if (!Auth::isLoggedIn()) |
| 15 | return; |
| 16 | self::renderSprint(); |
| 17 | self::renderIntuition(); |
| 18 | self::renderRefinement(); |
| 19 | self::renderRejuvenation(); |
| 20 | self::renderRevelation(); |
| 21 | self::renderPotion(); |
| 22 | } |
| 23 | |
| 24 | public static function renderJavascript(): void |
| 25 | { |
| 26 | if (!Auth::isLoggedIn()) |
| 27 | return; |
| 28 | echo self::canUseIntuition() ? "enableIntuition();" : "disableIntuition();"; |
| 29 | echo self::canUseRejuvanation() ? "enableRejuvenation();" : "disableRejuvenation();"; |
| 30 | echo self::canUseSprint() ? "enableSprint();" : "disableSprint();"; |
| 31 | echo self::canUseRefinement() ? "enableRefinement();" : "disableRefinement();"; |
| 32 | } |
| 33 | |
| 34 | public static function changeUserSoRejuvenationCanBeUsed() |
| 35 | { |
| 36 | Auth::getUser()['level'] = self::$REJUVENATION_MINIMUM_LEVEL; |
| 37 | Auth::saveUser(); |
| 38 | } |
| 39 | |
| 40 | public static function canUseRejuvanation() |
| 41 | { |
| 42 | if (Auth::getWithDefault('level', 0) < self::$REJUVENATION_MINIMUM_LEVEL) |
| 43 | return false; |
| 44 | return !Auth::getUser()['used_rejuvenation']; |
| 45 | } |
| 46 | |
| 47 | public static function renderRejuvenation() |
| 48 | { |
| 49 | echo '<img id="rejuvenation" title="Rejuvenation (Level ' . self::$REJUVENATION_MINIMUM_LEVEL . '): Restores health, Intuition and locks.">'; |
| 50 | } |
| 51 | |
| 52 | public static function changeUserSoIntuitionCanBeUsed() |
| 53 | { |
| 54 | Auth::getUser()['level'] = self::$INTUITION_MINIMUM_LEVEL; |
| 55 | Auth::saveUser(); |
| 56 | } |
| 57 | |
| 58 | public static function canUseIntuition() |
| 59 | { |
| 60 | if (Auth::getWithDefault('level', 0) < self::$INTUITION_MINIMUM_LEVEL) |
| 61 | return false; |
| 62 | return !Auth::getUser()['used_intuition']; |
| 63 | } |
| 64 | |
| 65 | public static function renderIntuition() |
| 66 | { |
| 67 | echo '<img id="intuition" title="Intuition (Level ' . self::$INTUITION_MINIMUM_LEVEL . ') : Shows the first correct move." alt="Intuition">'; |
| 68 | } |
| 69 | |
| 70 | public static function getRevelationUseCount(): int |
| 71 | { |
| 72 | $result = 0; |
| 73 | if (Auth::isLoggedIn()) |
| 74 | $result++; |
| 75 | if (Auth::isAdmin()) |
| 76 | $result++; |
| 77 | if (Auth::getUser()['level'] >= self::$REVELATION_MINIMUM_LEVEL) |
| 78 | $result++; |
| 79 | if ($userContribution = ClassRegistry::init('UserContribution')->find('first', ['conditions' => ['user_id' => Auth::getUserID()]])) |
| 80 | if ($userContribution['UserContribution']['reward3']) |
| 81 | $result++; |
| 82 | return $result; |
| 83 | } |
| 84 | |
| 85 | public static function canUseRevelation(): bool |
| 86 | { |
| 87 | return self::remainingRevelationUseCount() > 0; |
| 88 | } |
| 89 | |
| 90 | public static function remainingRevelationUseCount(): int |
| 91 | { |
| 92 | if (!Auth::isLoggedIn()) |
| 93 | return 0; |
| 94 | return self::getRevelationUseCount() - Auth::getUser()['used_revelation']; |
| 95 | } |
| 96 | |
| 97 | public static function renderRevelation() |
| 98 | { |
| 99 | if (self::getRevelationUseCount() == 0) |
| 100 | return; |
| 101 | |
| 102 | $image = self::canUseRevelation() ? '/img/hp6.png' : '/img/hp6x.png'; |
| 103 | $hoveredImage = self::canUseRevelation() ? '/img/hp6h.png' : '/img/hp6x.png'; |
| 104 | echo '<img'; |
| 105 | echo ' id="revelation" title="Revelation (' . self::remainingRevelationUseCount() . '): Solves a problem, but you don\'t get any reward."'; |
| 106 | echo ' src="' . $image . '" '; |
| 107 | if (self::canUseRevelation()) |
| 108 | { |
| 109 | echo ' onmouseover="this.src = \'' . $hoveredImage . '\';"'; |
| 110 | echo ' onmouseout="this.src = \'' . $image . '\';"'; |
| 111 | echo ' onclick="revelation(); return false;"'; |
| 112 | } |
| 113 | echo ' style="cursor:' . (self::canUseRevelation() ? 'pointer' : 'auto') . '"></a>'; |
| 114 | } |
| 115 | |
| 116 | public static function changeUserSoSprintCanBeUsed() |
| 117 | { |
| 118 | Auth::getUser()['level'] = self::$SPRINT_MINIMUM_LEVEL; |
| 119 | Auth::getUser()['mode'] = Constants::$LEVEL_MODE; |
| 120 | Auth::saveUser(); |
| 121 | } |
| 122 | |
| 123 | public static function canUseSprint() |
| 124 | { |
| 125 | if (Auth::getWithDefault('level', 0) < self::$SPRINT_MINIMUM_LEVEL) |
| 126 | return false; |
| 127 | if (!Auth::isInLevelMode()) |
| 128 | return false; |
| 129 | return !Auth::getUser()['used_sprint']; |
| 130 | } |
| 131 | |
| 132 | public static function getSprintRemainingSeconds() |
| 133 | { |
| 134 | if (!Auth::isLoggedIn()) |
| 135 | return 0; |
| 136 | $value = Auth::getUser()['sprint_start']; |
| 137 | if (!$value) |
| 138 | return 0; |
| 139 | |
| 140 | $start = new DateTime($value); |
| 141 | $now = new DateTime('now'); |
| 142 | $x = Constants::$SPRINT_SECONDS - ($now->getTimestamp() - $start->getTimestamp()); |
| 143 | return max(0, Constants::$SPRINT_SECONDS - ($now->getTimestamp() - $start->getTimestamp())); |
| 144 | } |
| 145 | |
| 146 | public static function renderSprint() |
| 147 | { |
| 148 | echo '<img id="sprint" title="Sprint: Double XP for 2 minutes." alt="Sprint"></a>'; |
| 149 | } |
| 150 | |
| 151 | public static function isPotionActive() |
| 152 | { |
| 153 | if (!Auth::hasPremium() && Auth::getUser()['level'] < self::$POTION_MINIMUM_LEVEL) |
| 154 | return false; |
| 155 | if (!Auth::getUser()['used_potion']) |
| 156 | return false; |
| 157 | return Auth::getUser()['damage'] >= Util::getHealthBasedOnLevel(Auth::getUser()['level']); |
| 158 | } |
| 159 | |
| 160 | public static function canUseRefinement() |
| 161 | { |
| 162 | if (!Auth::hasPremium() && Auth::getWithDefault('level', 0) < self::$REFINEMENT_MINIMUM_LEVEL) |
| 163 | return false; |
| 164 | return !Auth::getUser()['used_refinement']; |
| 165 | } |
| 166 | |
| 167 | private static function renderRefinement() |
| 168 | { |
| 169 | echo '<img id="refinement" title="Refinement (Level ' . self::$REFINEMENT_MINIMUM_LEVEL . '): Gives you a chance to solve a golden tsumego. If you fail, it disappears.">'; |
| 170 | } |
| 171 | |
| 172 | private static function renderPotion() |
| 173 | { |
| 174 | if (self::isPotionActive()) |
| 175 | echo '<img id="potion" title="Potion (Passive): If you misplay and have no hearts left, you have a small chance to restore your health." src="/img/hp5.png">'; |
| 176 | } |
| 177 | } |