Completed
Push — master ( b2206c...5f69d8 )
by Jakub
02:25
created

RandomSuccessCalculator::hasHealed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
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 hasHit(Character $character1, Character $character2, ?CharacterAttackSkill $skill = null): bool {
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
    $hitChance = Numbers::range((int) ($hitRate - $dodgeRate), 15, static::MAX_HIT_CHANCE);
21 1
    $roll = rand(0, 100);
22 1
    return ($roll <= $hitChance);
23
  }
24
  
25
  public function hasHealed(Character $healer): bool {
26 1
    $chance = $healer->intelligence * (int) round($healer->level / 5) + 30;
27 1
    $roll = rand(0, 100);
28 1
    return ($roll <= $chance);
29
  }
30
}
31
?>