Skip to content

Commit ea8e381

Browse files
committed
Merge pull request #21 from JRizzle88/master
fixed percentThroughLevel to return the correct value
2 parents e04dca0 + 3fb901a commit ea8e381

File tree

1 file changed

+2
-16
lines changed
  • src/Syntax/SteamApi/Containers/Player

1 file changed

+2
-16
lines changed

src/Syntax/SteamApi/Containers/Player/Level.php

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,8 @@ public function __construct($levelDetails)
2525
$this->currentLevelFloor = $this->xpForCurrentLevel;
2626
$this->currentLevelCeiling = $this->playerXp + $this->xpToLevelUp;
2727

28-
$levelRange = $this->currentLevelCeiling - $this->currentLevelFloor;
29-
30-
$this->percentThroughLevel = $this->percent($this->xpToLevelUp, $levelRange);
31-
}
32-
33-
private function percent ($num_amount, $num_total)
34-
{
35-
if($num_amount == 0 || $num_total == 0){
36-
return 0;
37-
}
38-
else {
39-
$count1 = $num_amount / $num_total;
40-
$count2 = $count1 * 100;
41-
$count = number_format($count2, 0);
42-
return $count;
43-
}
28+
// arbitrary range formula. n = value in the middle ( n - min ) / ( max - min ) * 100
29+
$this->percentThroughLevel = ( $this->playerXp - $this->currentLevelFloor ) / ( $this->currentLevelCeiling - $this->currentLevelFloor ) * 100;
4430
}
4531

4632
}

0 commit comments

Comments
 (0)