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
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -52,7 +52,7 @@ class Config
$c['https'] = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR . self::$hostname;
$c['img2'] = self::subdomain('img');
$c['lib'] = self::subdomain('lib');
$c['exit'] = '<script>top.location.href="' . $c['https'] . '";</script>';
$c['exit'] = "<script>window.location.replace('{$c['https']}');</script>";
$c['support'] = 'support@' . $c['host'];
+1 -1
View File
@@ -1483,7 +1483,7 @@ class Dungeon
{
$pd = array_fill(1, 28, 0);
global $pd;
//global $pd;
/* Генерируем изображение карты */
/* LEVEL 1 */
+2 -4
View File
@@ -83,7 +83,7 @@ class FightRequest
'select * from zayvki where btl_id = 0 and cancel = 0 and start = 0 and razdel in (4,5) order by id desc limit 22'
);
foreach ($sp as $pl) {
$uz = Db::getRow(
$uz = Db::getRows(
'select * from users left join stats on users.id = stats.id where zv = ?',
[$pl['id']]
);
@@ -244,7 +244,7 @@ class FightRequest
$z['timeout'],
$z['type'],
$z['invise'],
$z['travmChance'],
$z['travmChance'] ?? 0,
$z['exp'],
];
$q = 'insert into battle (
@@ -468,8 +468,6 @@ class FightRequest
'id' => $botInfo['id'],
'login' => $botInfo['login'],
'level' => $botInfo['level'],
'city' => $botInfo['city'],
'cityreg' => $botInfo['city'],
'name' => $botInfo['login'],
'sex' => $botInfo['sex'],
'hobby' => '',
+11 -2
View File
@@ -596,6 +596,7 @@ class User
$user = !empty($_SESSION['uid']) ? $_SESSION['uid'] : $_COOKIE['login'];
$this->info = self::getInfo($user);
unset($user);
Database::init(); // для всяких mysql_*
@@ -1097,6 +1098,14 @@ class User
left join room on users.room = room.id
where users.' . $cell . ' = ?';
$result = Db::getRow($query, [$user]);
$temp = Conversion::dataStringToArray($result['stats']);
$result['testStats'] = new User\UserStats(
$temp
);
$result['testStats2'] = new \User\UserCalculatedStats($result['testStats']);
return $result ?: [];
}
@@ -2014,7 +2023,7 @@ class User
Db::sql(
"insert into users (align, login, level, pass, city, cityreg, name, sex, timereg, obraz, bot_id, inTurnir) values (?,?,?,uuid(),'Неведомые земли','Неведомые земли',?,?,?,?,?,?)",
[
$clon['align'],
$clon['align'] ?? 0,
$clon['login'],
$clon['level'],
$clon['login'],
@@ -2022,7 +2031,7 @@ class User
$clon['time_reg'],
$clon['obraz'],
$id,
$clon['inTurnir'],
$clon['inTurnir'] ?? 0,
]
);
+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);
}
}