Completed
Push — master ( 29e2cf...033bf5 )
by Jakub
02:40
created

Heal   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 25%

Importance

Changes 0
Metric Value
wmc 7
eloc 17
dl 0
loc 28
ccs 4
cts 16
cp 0.25
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 2 1
A do() 0 15 3
A shouldUse() 0 2 2
A getPriority() 0 2 1
1
<?php
2
declare(strict_types=1);
3
4
namespace HeroesofAbenez\Combat\CombatActions;
5
6
use HeroesofAbenez\Combat\Character;
7
use HeroesofAbenez\Combat\CombatBase;
8
use HeroesofAbenez\Combat\CombatLogEntry;
9
use Nexendrie\Utils\Numbers;
10
11 1
final class Heal implements ICombatAction {
12
  public function getName(): string {
13 1
    return CombatLogEntry::ACTION_HEALING;
14
  }
15
16
  public function getPriority(): int {
17 1
    return 1000;
18
  }
19
20
  public function shouldUse(CombatBase $combat, Character $character): bool {
21 1
    return (in_array($character, $combat->findHealers()->toArray(), true) AND !is_null($combat->selectHealingTarget($character)));
0 ignored issues
show
introduced by
Line exceeds 120 characters; contains 130 characters
Loading history...
22
  }
23
24
  public function do(CombatBase $combat, Character $character): void {
25
    $result = [];
26
    /** @var Character $patient */
27
    $patient = $combat->selectHealingTarget($character);
28
    $result["result"] = $combat->successCalculator->hasHealed($character);
29
    $amount = ($result["result"]) ? (int) ($character->intelligence / 2) : 0;
30
    $result["amount"] = Numbers::range($amount, 0, $patient->maxHitpoints - $patient->hitpoints);
31
    if($result["amount"] > 0) {
32
      $patient->heal($result["amount"]);
33
    }
34
    $result["action"] = CombatLogEntry::ACTION_HEALING;
35
    $result["name"] = "";
36
    $result["character1"] = $character;
37
    $result["character2"] = $patient;
38
    $combat->log->log($result);
39
  }
40
}
41
?>