WIP: removing User::class public array $items for Stat()::class.

This commit is contained in:
2024-01-08 03:33:20 +02:00
parent 4a7535d67d
commit bd8761f240
22 changed files with 812 additions and 971 deletions
+79 -130
View File
@@ -11,6 +11,7 @@ use Core\Config;
use Core\Db;
use DTO\BattlePriem;
use Helper\Conversion;
use Model\Constant\Stat;
use User\Effects;
use User\ItemsModel;
use User\Login;
@@ -58,62 +59,7 @@ class Battle
/**Отображаем главное окно (1 - можно бить, 2 - ожидаем ход противника, 3 - Проиграли. Ожидаем завершения поединка)*/
public int $mainStatus = 1;
/**Информация о поединке
* array (size=51)
* 'id' => int 466012
* 'city' => string 'capitalcity' (length=11)
* 'time_start' => int 1704495486
* 'testfinish' => int 0
* 'players' => string '' (length=0)
* 'timeout' => int 60
* 'type' => int 0
* 'status' => int 0
* 'kulak' => int 0
* 'invis' => int 0
* 'noinc' => int 0
* 'travmChance' => int 0
* 'typeBattle' => int 0
* 'addExp' => float 0
* 'money' => float 0
* 'money3' => float 0
* 'time_over' => int 0
* 'team_win' => int -1
* 'dungeon' => string '0' (length=1)
* 'razdel' => int 5
* 'dn_id' => int 0
* 'x' => int 0
* 'y' => int 0
* 'fDate' => string '' (length=0)
* 'izlom' => int 0
* 'izlomLvl' => int 0
* 'izlomRound' => int 0
* 'start1' => int 1704495496
* 'start2' => int 1704495496
* 'izlomRoundSee' => int 0
* 'izlomObr' => int 0
* 'izlomObrNow' => int 0
* 'turnir' => int 0
* 'inTurnir' => int 0
* 'clone' => int 0
* 'players_c' => int 0
* 'fastfight' => int 0
* 'nobot' => null
* 'kingfight' => null
* 'arand' => null
* 'noatack' => null
* 'noeff' => null
* 'smert' => null
* 'noart' => null
* 'zarad' => int 0
* 'priz' => int 0
* 'otmorozok' => int 0
* 'otmorozok_use' => int 0
* 'hod' => int 0
* 'clan1' => int 0
* 'clan2' => int 0
* */
public array $info = [];
/** Информация о поединке.*/
public Info $i;
/**Информация о пользователях в этом бою*/
@@ -172,7 +118,7 @@ class Battle
private Finish $finish;
public function __construct()
public function __construct(private Stat $statnames = new Stat())
{
ignore_user_abort(true);
$this->finish = new Finish($this);
@@ -316,6 +262,13 @@ class Battle
public function initRefresh(User $user): bool
{
$this->i = new Info($user->info['battle']);
$this->hodID = Db::getValue('select id_hod from battle_logs where battle = ? order by id desc limit 1', [$this->i->id]);
if (!$this->hodID) {
$this->hodID = 0;
}
return !empty($this->i->id);
}
@@ -528,7 +481,7 @@ class Battle
$ur['id'] != 0 && $this->stats[$this->uids[$ur['id']]]['seeAllEff'] != 1
) {
$nseef = 1;
if ($eff[$i]['v1'] == 'priem') {
if (isset($eff[$i]['v1']) && $eff[$i]['v1'] == 'priem') {
$eff[$i]['priem'] = Db::getRow('select * from priems where id = ?', [$eff[$i]['v2']]);
}
@@ -587,22 +540,24 @@ class Battle
//Действие эффекта
$tr = '';
$ti = $u->items['add'];
$statBonusNames = $this->statnames->getBonusNames();
$statSysBonusNames = array_keys($statBonusNames);
$x = 0;
$ed = Conversion::dataStringToArray($eff[$i]['data']);
while ($x < count($ti)) {
$n = $ti[$x];
if (isset($ed['add_' . $n], $u->is[$n]) && $n != 'pog') {
while ($x < count($statSysBonusNames)) {
$n = $statSysBonusNames[$x];
if (isset($ed['add_' . $n]) && $n != 'pog') {
$z = '';
if ($ed['add_' . $n] > 0) {
$z = '+';
}
$tr .= '<br>' . $u->is[$n] . ': ' . $z . $ed['add_' . $n];
$tr .= '<br>' . $statBonusNames[$n] . ': ' . $z . $ed['add_' . $n];
}
$x++;
}
if ($ed['add_mib1'] != 0) {
if (isset($ed['add_mib1']) && $ed['add_mib1'] != 0) {
if ($ed['add_mab1'] != 0) {
$tr .= $armor1 . $ed['add_mib1'] . '-' . $ed['add_mab1'];
} else {
@@ -613,7 +568,7 @@ class Battle
$tr .= $armor1 . $m1l;
}
}
if ($ed['add_mib2'] != 0) {
if (isset($ed['add_mib2']) && $ed['add_mib2'] != 0) {
if ($ed['add_mab2'] != 0) {
$tr .= $armor2 . $ed['add_mib2'] . '-' . $ed['add_mab2'];
} else {
@@ -624,7 +579,7 @@ class Battle
$tr .= $armor2 . $m1l;
}
}
if ($ed['add_mib3'] != 0) {
if (isset($ed['add_mib3']) && $ed['add_mib3'] != 0) {
if ($ed['add_mab3'] != 0) {
$tr .= $armor3 . $ed['add_mib3'] . '-' . $ed['add_mab3'];
} else {
@@ -635,7 +590,7 @@ class Battle
$tr .= $armor3 . $m1l;
}
}
if ($ed['add_mib4'] != 0) {
if (isset($ed['add_mib4']) && $ed['add_mib4'] != 0) {
if ($ed['add_mab4'] != 0) {
$tr .= $armor4 . $ed['add_mib4'] . '-' . $ed['add_mab4'];
} else {
@@ -768,14 +723,14 @@ JS;
$td = Conversion::dataStringToArray($itm[$i]['data']);
$lvar = '';
if ($td['add_hpAll'] > 0) {
if (isset($td['add_hpAll']) && $td['add_hpAll'] > 0) {
$td['add_hpAll'] = '+' . $td['add_hpAll'];
$lvar .= '<br>Уровень жизни: ' . $td['add_hpAll'];
}
if ($td['sv_yron_max'] > 0 || $td['sv_yron_min'] > 0) {
if (isset($td['sv_yron_max']) && $td['sv_yron_max'] > 0 || isset($td['sv_yron_min']) && $td['sv_yron_min'] > 0) {
$lvar .= '<br>Урон: ' . (0 + $td['sv_yron_min']) . '-' . (0 + $td['sv_yron_max']);
}
if ($td['add_mab1'] > 0) {
if (isset($td['add_mab1']) && $td['add_mab1'] > 0) {
if ($td['add_mib1'] == $td['add_mab1']) {
$m1l = '+';
$lvar .= $armor1 . $m1l . (0 + $td['add_mab1']);
@@ -783,7 +738,7 @@ JS;
$lvar .= $armor1 . (0 + $td['add_mib1']) . '-' . (0 + $td['add_mab1']);
}
}
if ($td['add_mab2'] > 0) {
if (isset($td['add_mab2']) && $td['add_mab2'] > 0) {
if ($td['add_mib2'] == $td['add_mab2']) {
$m1l = '+';
$lvar .= $armor2 . $m1l . (0 + $td['add_mab2']);
@@ -791,7 +746,7 @@ JS;
$lvar .= $armor2 . (0 + $td['add_mib2']) . '-' . (0 + $td['add_mab2']);
}
}
if ($td['add_mab3'] > 0) {
if (isset($td['add_mab3']) && $td['add_mab3'] > 0) {
if ($td['add_mib3'] == $td['add_mab3']) {
$m1l = '+';
$lvar .= $armor3 . $m1l . (0 + $td['add_mab3']);
@@ -799,7 +754,7 @@ JS;
$lvar .= $armor3 . (0 + $td['add_mib3']) . '-' . (0 + $td['add_mab3']);
}
}
if ($td['add_mab4'] > 0) {
if (isset($td['add_mab4']) && $td['add_mab4'] > 0) {
if ($td['add_mib4'] == $td['add_mab4']) {
$m1l = '+';
$lvar .= $armor4 . $m1l . (0 + $td['add_mab4']);
@@ -807,8 +762,8 @@ JS;
$lvar .= $armor4 . (0 + $td['add_mib4']) . '-' . (0 + $td['add_mab4']);
}
}
if ($itm[$i]['iznosMAX'] > 0) {
if ($itm[$i]['iznosMAXi'] == 999999999) {
if (isset($itm[$i]['iznosMAX']) && $itm[$i]['iznosMAX'] > 0) {
if (isset($itm[$i]['iznosMAXi']) && $itm[$i]['iznosMAXi'] == 999999999) {
$lvar .= '<br>Долговечность: <span style="color: brown;">неразрушимо</span>';
} else {
$lvar .= '<br>Долговечность: ' . floor($itm[$i]['iznosNOW']) . '/' . floor($itm[$i]['iznosMAX']);
@@ -817,7 +772,7 @@ JS;
$ttl .= $lvar;
$ccv = '';
if ($itm[$i]['magic_inci'] != '' || $itm[$i]['magic_inc'] != '') {
if (isset($itm[$i]['magic_inci']) && $itm[$i]['magic_inci'] != '' || isset($itm[$i]['magic_inc']) && $itm[$i]['magic_inc'] != '') {
if ($itm[$i]['magic_inc'] == '') {
$itm[$i]['magic_inc'] = $itm[$i]['magic_inci'];
}
@@ -1945,6 +1900,7 @@ JS;
$this->stats[$this->uids[$bot]]['pass'] != 'saintlucia'
) { //Тут проверка на бота saintlucia
$j = 0;
while ($j < count($this->users)) {
if ($this->i->razdel == 0) {
$tnbot = time() + rand(1, 1);
@@ -1952,24 +1908,24 @@ JS;
$tnbot = time() + rand(1, 2);
}
if (
$this->users[$j]['timeGo'] < time() &&
$this->users[$this->uids[$bot]]['timeGo'] < time() &&
$this->users[$j]['hpNow'] >= 1 &&
$this->users[$this->uids[$bot]]['hpNow'] >= 1 &&
$this->users[$j]['timego'] < time() &&
$this->users[$this->uids[$bot]]['timego'] < time() &&
$this->users[$j]['hpnow'] >= 1 &&
$this->users[$this->uids[$bot]]['hpnow'] >= 1 &&
$this->users[$this->uids[$bot]]['team'] != $this->users[$j]['team']
) {
if (
isset($this->users[$j]) &&
$this->stats[$j]['hpNow'] >= 1 &&
$this->stats[$this->uids[$bot]]['hpNow'] >= 1 &&
$this->stats[$j]['hpnow'] >= 1 &&
$this->stats[$this->uids[$bot]]['hpnow'] >= 1 &&
!isset($this->ga[$bot][$this->users[$j]['id']]) &&
!isset($this->ag[$bot][$this->users[$j]['id']]) &&
$this->users[$j]['id'] != $bot &&
$this->users[$j]['team'] != $this->users[$this->uids[$bot]]['team']
) {
if (
$this->users[$j]['timeGo'] < time() &&
$this->users[$this->uids[$bot]]['timeGo'] < time()
$this->users[$j]['timego'] < time() &&
$this->users[$this->uids[$bot]]['timego'] < time()
) {
$this->botAtack($this->users[$j]['id'], $bot, 1);
mysql_query(
@@ -1979,19 +1935,19 @@ JS;
} elseif (
isset($this->users[$i]) &&
$this->users[$i]['bot'] > 0 &&
$this->stats[$i]['hpNow'] >= 1 &&
$this->stats[$this->uids[$bot]]['hpNow'] >= 1 &&
$this->stats[$i]['hpnow'] >= 1 &&
$this->stats[$this->uids[$bot]]['hpnow'] >= 1 &&
$this->users[$i]['id'] != $bot &&
$this->users[$i]['team'] != $this->users[$this->uids[$bot]]['team']
) {
if (
$this->users[$j]['timeGo'] < time() &&
$this->users[$this->uids[$bot]]['timeGo'] < time() &&
$this->users[$j]['timego'] < time() &&
$this->users[$this->uids[$bot]]['timego'] < time() &&
$this->botAct($bot)
) {
if (
!isset($this->ga[$bot][$this->users[$i]['id']]) &&
$this->users[$this->uids[$bot]]['timeGo'] < time() &&
$this->users[$this->uids[$bot]]['timego'] < time() &&
!isset($this->ag[$bot][$this->users[$i]['id']])
) {
$this->botAtack($this->users[$i]['id'], $bot, 1);
@@ -2001,7 +1957,7 @@ JS;
} elseif (
!isset($this->ag[$bot][$this->users[$i]['id']]) &&
isset($this->ga[$bot][$this->users[$i]['id']]) &&
$this->users[$this->uids[$bot]]['timeGo'] < time()
$this->users[$this->uids[$bot]]['timego'] < time()
) {
$this->botAtack($bot, $this->users[$i]['id'], 1);
mysql_query(
@@ -2012,10 +1968,10 @@ JS;
} else {
//Удары между ботами
if (
$this->users[$j]['timeGo'] < time() &&
$this->users[$this->uids[$bot]]['timeGo'] < time() &&
$this->users[$j]['hpNow'] >= 1 &&
$this->users[$this->uids[$bot]]['hpNow'] >= 1
$this->users[$j]['timego'] < time() &&
$this->users[$this->uids[$bot]]['timego'] < time() &&
$this->users[$j]['hpnow'] >= 1 &&
$this->users[$this->uids[$bot]]['hpnow'] >= 1
) {
$this->atacks[$this->ga[$bot][$this->users[$j]['id']]]['a1'] =
rand(1, 5) . '' . rand(1, 5) . rand(1, 5) . rand(1, 5) . rand(1, 5);
@@ -2042,15 +1998,15 @@ JS;
$this->users[$j]['bot'] > 0
) {
if (
$this->users[$j]['timeGo'] < time() &&
$this->users[$this->uids[$bot]]['timeGo'] < time()
$this->users[$j]['timego'] < time() &&
$this->users[$this->uids[$bot]]['timego'] < time()
) {
$tnbot = time() + rand(3, 7);
if ($this->i->type == 329) { // тестовый бой
$tnbot = time() - 1;
}
$this->startAtack($this->ga[$bot][$this->users[$j]['id']]);
$this->users[$this->uids[$bot]]['timeGo'] = $tnbot;
$this->users[$this->uids[$bot]]['timego'] = $tnbot;
mysql_query(
'UPDATE `stats` SET `timeGo` = "' . $tnbot . '" WHERE `id` = "' . $this->users[$this->uids[$bot]]['id'] . '" LIMIT 1'
);
@@ -2060,15 +2016,15 @@ JS;
$this->users[$j]['bot'] > 0
) {
if (
$this->users[$this->uids[$bot]]['timeGo'] < time() &&
$this->users[$j]['timeGo'] < time()
$this->users[$this->uids[$bot]]['timego'] < time() &&
$this->users[$j]['timego'] < time()
) {
$this->startAtack($this->ag[$bot][$this->users[$j]['id']]);
$tnbot = time() + rand(3, 7);
if ($this->i->type == 329) { // тестовый бой
$tnbot = time() - 1;
}
$this->users[$this->uids[$bot]]['timeGo'] = $tnbot;
$this->users[$this->uids[$bot]]['timego'] = $tnbot;
mysql_query(
'UPDATE `stats` SET `timeGo` = "' . $tnbot . '" WHERE `id` = "' . $this->users[$this->uids[$bot]]['id'] . '" LIMIT 1'
);
@@ -2277,7 +2233,7 @@ JS;
// Заносим в логи + записываем статистику боя
$this->addlogRazmen($id, $at);
var_dump($at);
//Запускаем магию предметов
$this->magicItems($this->atacks[$id]['uid1'], $this->atacks[$id]['uid2'], $id);
$this->magicItems($this->atacks[$id]['uid2'], $this->atacks[$id]['uid1'], $id);
@@ -4447,6 +4403,7 @@ JS;
$this->add_log($mas);
$j++;
}
var_dump($at);
}
//Добавляем статистику + записываем в баттл_юзерс НР игроков
@@ -4910,42 +4867,33 @@ JS;
}
//проверка блока (Визуальная)
public function battleInfo($id): array
{
$b = self::get($id);
if (!isset($b['id'])) {
return [];
}
$this->hodID = Db::getValue('select id_hod from battle_logs where battle = ? order by id desc limit 1', [$b['id']]);
$this->hodID = $this->hodID['id_hod'] ?? 0;
return $b;
}
//проверка блока
public function addAtack(): void
{
global $js;
if (!isset($_POST['atack'], $_POST['block'])) {
if ($_POST['atack'] === '0_0_0_0_0' || $_POST['block'] === '0') {
$this->e = 'Выберите зоны удара и блока';
return;
}
//atack: '3_2_0_0_0' (length=9)
//block: '5' (length=1)
$na = ['a' => [1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0]];
$a = explode('_', $_POST['atack']);
$na['id'] = time();
array_unshift($a, 0);
for ($i = 1; $i <= 5; $i++) {
if (!isset($a[$i - 1])) {
if (!isset($a[$i])) {
continue;
}
$a[$i - 1] = intval(round($a[$i - 1]));
if ($a[$i - 1] >= 1 && $a[$i - 1] <= 5) {
$na['a'][$i] = $a[$i - 1];
$a[$i] = intval(round($a[$i]));
if ($a[$i] >= 1 && $a[$i] <= 5) {
$na['a'][$i] = $a[$i];
} else {
$na['a'][$i] = 0;
}
@@ -4995,7 +4943,7 @@ JS;
foreach ($usersInBattle as $user) {
//записываем данные
$this->fighters[] = new Fighter();
//$this->fighters[] = new Fighter();
$this->users[$i] = $user;
$this->uids[$user['id']] = $i;
@@ -5007,7 +4955,7 @@ JS;
//записываем статы
$stats = new Stats($u);
$this->stats[$i] = $stats->getStats(btl_cache: $this->cached);
$this->stats[$i] = $stats->getStats(uid: $user['id'], btl_cache: $this->cached);
//Заносим старт
if ($this->i->getStart2() == 0) {
@@ -5036,7 +4984,7 @@ JS;
}
// Бафф Зверя animal_bonus
$this->addAnimalBuff($i, $u);
$this->addAnimalBuff($i);
Db::sql(
'update stats set last_hp = 0, tactic1 = 0, tactic2 = 0, tactic3 = 0, tactic4 = 0, tactic5 = 0, tactic6 = 0, tactic7 = ? where id = ?',
@@ -5220,7 +5168,7 @@ JS;
if ($this->users[$i]['lider'] == $this->i->id) {
$ldr = '<img width=24 height=15 title=Лидер&nbsp;группы src=//img.new-combats.tech/i/lead' . $this->users[$i]['team'] . '.gif \>';
}
$teams[$this->users[$i]['team']] .= ', ' . $ldr . '<span ' . $a1ms . ' class=\"CSSteam' . $this->users[$i]['team'] . '\" onClick=\"top.chat.addto(\'' . $this->users[$i]['login2'] . '\',\'to\'); return false;\" oncontextmenu=\"top.infoMenu(\'' . $this->users[$i]['login2'] . '\',event,\'main\'); return false;\">' . $this->users[$i]['login2'] . '</span><small> [' . floor(
$teams[$this->users[$i]['team']] .= ', ' . $ldr . '<span ' . $a1ms . ' class=\"CSSteam' . $this->users[$i]['team'] . '\" onClick=\"chat.addto(\'' . $this->users[$i]['login2'] . '\',\'to\'); return false;\" oncontextmenu=\"top.infoMenu(\'' . $this->users[$i]['login2'] . '\',event,\'main\'); return false;\">' . $this->users[$i]['login2'] . '</span><small> [' . floor(
$this->stats[$i]['hpNow']
) . '/' . $this->stats[$i]['hpAll'] . ']</small>';
}
@@ -5232,7 +5180,7 @@ JS;
while ($i < count($tms)) {
$teams[$tms[$i]] = ltrim($teams[$tms[$i]], ', ');
if ($teams[$tms[$i]] != '') {
$teams[$tms[$i]] = '<img src=\"//img.new-combats.tech/i/lock3.gif\" style=\"cursor:pointer\" width=\"20\" height=\"15\" onClick=\"top.chat.addto(\'team' . $tms[$i] . '\',\'private\'); return false;\"> ' . $teams[$tms[$i]];
$teams[$tms[$i]] = '<img src=\"//img.new-combats.tech/i/lock3.gif\" style=\"cursor:pointer\" width=\"20\" height=\"15\" onClick=\"chat.addto(\'team' . $tms[$i] . '\',\'private\'); return false;\"> ' . $teams[$tms[$i]];
$ret .= $teams[$tms[$i]];
if (count($tms) > $i + 1) {
$ret .= ' <span class=\"CSSvs\">&nbsp; против &nbsp;</span> ';
@@ -5250,10 +5198,9 @@ JS;
/**
* @param int $i
* @param User $u
* @return void
*/
private function addAnimalBuff(int $i, User $u): void
private function addAnimalBuff(int $i): void
{
if ($this->users[$i]['animal'] <= 0) {
return;
@@ -5319,8 +5266,10 @@ JS;
$animalBonusData = Conversion::dataStringToArray($animalBonusDataString);
$bonusString = '';
$statBonusNames = $this->statnames->getBonusNames();
$statBonusSysNames = array_keys($statBonusNames);
foreach ($u->items['add'] as $itemBonusSysName) {
foreach ($statBonusSysNames as $itemBonusSysName) {
if (
!isset($animalBonusData['add_' . $itemBonusSysName]) ||
$animalBonusData['add_' . $itemBonusSysName] <= 0
@@ -5333,7 +5282,7 @@ JS;
'mib2' => 'Броня корпуса: +' . $animalBonusData['add_' . $itemBonusSysName] . ', ',
'mib3' => 'Броня пояса: +' . $animalBonusData['add_' . $itemBonusSysName] . ', ',
'mib4' => 'Броня ног: +' . $animalBonusData['add_' . $itemBonusSysName] . ', ',
default => $u->is[$itemBonusSysName] . ': +' . $animalBonusData['add_' . $itemBonusSysName] . ', ',
default => $statBonusNames[$itemBonusSysName] . ': +' . $animalBonusData['add_' . $itemBonusSysName] . ', ',
};
}