Completed
Push — master ( d10f8a...114a35 )
by Jakub
03:42
created

RandomSuccessCalculator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 17
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A calculateHealingSuccessChance() 0 2 1
A hasHit() 0 3 1
A calculateHitChance() 0 7 2
1
<?php
2
declare(strict_types=1);
3
4
namespace HeroesofAbenez\Combat;
5
6
use Nexendrie\Utils\Numbers;
7
8
/**
9
 * RandomSuccessCalculator
10
 *
11
 * @author Jakub Konečný
12
 */
13 1
final class RandomSuccessCalculator implements ISuccessCalculator {
14
  public function calculateHitChance(Character $character1, Character $character2, ?CharacterAttackSkill $skill = NULL): int {
0 ignored issues
show
introduced by
Line exceeds 120 characters; contains 126 characters
Loading history...
15 1
    $hitRate = $character1->hit;
16 1
    $dodgeRate = $character2->dodge;
17 1
    if(!is_null($skill)) {
18 1
      $hitRate = $hitRate / 100 * $skill->hitRate;
19
    }
20 1
    return Numbers::range((int) ($hitRate - $dodgeRate), 15, 100);
21
  }
22
  
23
  public function calculateHealingSuccessChance(Character $healer): int {
24 1
    return $healer->intelligence * (int) round($healer->level / 5) + 30;
25
  }
26
  
27
  public function hasHit(int $hitChance): bool {
28 1
    $roll = rand(0, 100);
29 1
    return ($roll <= $hitChance);
30
  }
31
}
32
?>