refactor and custom user entities

This commit is contained in:
2023-11-06 02:40:12 +02:00
parent ce2691971b
commit 1645f58a63
14 changed files with 828 additions and 587 deletions
+2 -2
View File
@@ -735,7 +735,7 @@ class InfoBox
}
$x++;
}
if ($pl['2h'] == 1) {
if (isset($pl['2h']) && $pl['2h'] == 1) {
$lvar .= '<br>• Двуручное оружие';
}
if (isset($po['zonb'])) {
@@ -766,7 +766,7 @@ class InfoBox
}
if ($pl['iznosMAX'] > 0) {
if (isset($pl['iznosMAX']) && $pl['iznosMAX'] > 0) {
$lvar .= '<br>Долговечность: ' . floor($pl['iznosNOW']) . DIRECTORY_SEPARATOR . ceil($pl['iznosMAX']);
}
@@ -0,0 +1,73 @@
<?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;
}
}
+97
View File
@@ -0,0 +1,97 @@
<?php
namespace User;
readonly class UserStats
{
public int $s1;
public int $s2;
public int $s3;
public int $s4;
public int $s5;
public int $s6;
public int $s7;
public int $a1;
public int $a2;
public int $a3;
public int $a4;
public int $a5;
public int $mg1;
public int $mg2;
public int $mg3;
public int $mg4;
public int $mg7;
//public int $hpAll;
//public int $mpAll;
public function __construct(
array $a
)
{
$this->s1 = $a['s1'] ?? 0;
$this->s2 = $a['s2'] ?? 0;
$this->s3 = $a['s3'] ?? 0;
$this->s4 = $a['s4'] ?? 0;
$this->s5 = $a['s5'] ?? 0;
$this->s6 = $a['s6'] ?? 0;
$this->s7 = $a['s7'] ?? 0;
$this->a1 = max($a['a1'] ?? 0, $a['aall'] ?? 0);
$this->a2 = max($a['a2'] ?? 0, $a['aall'] ?? 0);
$this->a3 = max($a['a3'] ?? 0, $a['aall'] ?? 0);
$this->a4 = max($a['a4'] ?? 0, $a['aall'] ?? 0);
$this->a5 = max($a['a5'] ?? 0, $a['aall'] ?? 0);
$this->mg1 = max($a['mg1'] ?? 0, $a['mall'] ?? 0);
$this->mg2 = max($a['mg2'] ?? 0, $a['mall'] ?? 0);
$this->mg3 = max($a['mg3'] ?? 0, $a['mall'] ?? 0);
$this->mg4 = max($a['mg4'] ?? 0, $a['mall'] ?? 0);
$this->mg7 = $a['mg7'] ?? 0;
//$this->hpAll = $this->hpAll();
//$this->mpAll = $this->mpAll();
}
/*private function hpAll(): int
{
$hpAll = $this->s4 * 5;
$hpAll += match (true){
$this->s4 >= 200 => 850,
$this->s4 >= 175 => 600,
$this->s4 >= 150 => 450,
$this->s4 >= 125 => 400,
$this->s4 >= 100 => 250,
$this->s4 >= 75 => 175,
$this->s4 >= 50 => 100,
$this->s4 >= 25 => 50,
default => 0
};
return $hpAll;
}
private function mpAll():int
{
$mpAll = $this->s6 * 10;
$mpAll += match (true) {
$this->s6 >= 200 => 1500,
$this->s6 >= 175 => 900,
$this->s6 >= 150 => 700,
$this->s6 >= 125 => 500,
$this->s6 >= 100 => 350,
$this->s6 >= 75 => 250,
$this->s6 >= 50 => 150,
$this->s6 >= 25 => 50,
default => 0
};
return $mpAll;
}*/
public function __toString():string
{
$arr = [];
foreach ($this as $k=>$v) {
if (empty($v)) {
continue;
}
$arr[$k] = $v;
}
return json_encode($arr);
}
}