game/_incl_data/class/User/UserCalculatedStats.php

73 lines
1.7 KiB
PHP

<?php
namespace User;
class UserCalculatedStats
{
public int $hpAll;
public int $mpAll;
public function __construct(
private readonly UserStats $us
) {
$this->hpAll = $this->hpAll();
$this->mpAll = $this->mpAll();
}
private function hpAll(): int
{
$hpAll = $this->us->s4 * 5;
$hpAll += match (true){
$this->us->s4 >= 200 => 850,
$this->us->s4 >= 175 => 600,
$this->us->s4 >= 150 => 450,
$this->us->s4 >= 125 => 400,
$this->us->s4 >= 100 => 250,
$this->us->s4 >= 75 => 175,
$this->us->s4 >= 50 => 100,
$this->us->s4 >= 25 => 50,
default => 0
};
return $hpAll;
}
private function mpAll():int
{
$mpAll = $this->us->s6 * 10;
$mpAll += match (true) {
$this->us->s6 >= 200 => 1500,
$this->us->s6 >= 175 => 900,
$this->us->s6 >= 150 => 700,
$this->us->s6 >= 125 => 500,
$this->us->s6 >= 100 => 350,
$this->us->s6 >= 75 => 250,
$this->us->s6 >= 50 => 150,
$this->us->s6 >= 25 => 50,
default => 0
};
return $mpAll;
}
public function __toString():string
{
$arr = [];
foreach ($this as $k=>$v) {
if (empty($v) || $k === 'us') {
continue;
}
$arr[$k] = $v;
}
return json_encode($arr);
}
public function __debugInfo()
{
$arr = [];
foreach ($this as $k=>$v) {
if ($k === 'us') {
continue;
}
$arr[$k] = $v;
}
return $arr;
}
}