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

RandomSuccessCalculator::hasHit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
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 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
?>