Optimising Stat()::class.
This commit is contained in:
parent
68ef35d14a
commit
7dc27047b6
@ -118,9 +118,10 @@ class Battle
|
||||
|
||||
private Finish $finish;
|
||||
|
||||
public function __construct(private Stat $statnames = new Stat())
|
||||
public function __construct(private readonly Stat $statnames = new Stat())
|
||||
{
|
||||
ignore_user_abort(true);
|
||||
$this->statnames->getBonus();
|
||||
$this->finish = new Finish($this);
|
||||
|
||||
$this->prm = [1 => new BattlePriem(act:1, typeOf:5),
|
||||
@ -540,19 +541,17 @@ class Battle
|
||||
|
||||
//Действие эффекта
|
||||
$tr = '';
|
||||
$statBonusNames = $this->statnames->getBonusNames();
|
||||
$statSysBonusNames = array_keys($statBonusNames);
|
||||
|
||||
$x = 0;
|
||||
$ed = Conversion::dataStringToArray($eff[$i]['data']);
|
||||
while ($x < count($statSysBonusNames)) {
|
||||
$n = $statSysBonusNames[$x];
|
||||
while ($x < count($this->statnames->sysBonusNames)) {
|
||||
$n = $this->statnames->sysBonusNames[$x];
|
||||
if (isset($ed['add_' . $n]) && $n != 'pog') {
|
||||
$z = '';
|
||||
if ($ed['add_' . $n] > 0) {
|
||||
$z = '+';
|
||||
}
|
||||
$tr .= '<br>' . $statBonusNames[$n] . ': ' . $z . $ed['add_' . $n];
|
||||
$tr .= '<br>' . $this->statnames->bonusNames[$n] . ': ' . $z . $ed['add_' . $n];
|
||||
}
|
||||
$x++;
|
||||
}
|
||||
@ -5266,10 +5265,8 @@ JS;
|
||||
$animalBonusData = Conversion::dataStringToArray($animalBonusDataString);
|
||||
|
||||
$bonusString = '';
|
||||
$statBonusNames = $this->statnames->getBonusNames();
|
||||
$statBonusSysNames = array_keys($statBonusNames);
|
||||
|
||||
foreach ($statBonusSysNames as $itemBonusSysName) {
|
||||
foreach ($this->statnames->sysBonusNames as $itemBonusSysName) {
|
||||
if (
|
||||
!isset($animalBonusData['add_' . $itemBonusSysName]) ||
|
||||
$animalBonusData['add_' . $itemBonusSysName] <= 0
|
||||
@ -5282,7 +5279,7 @@ JS;
|
||||
'mib2' => 'Броня корпуса: +' . $animalBonusData['add_' . $itemBonusSysName] . ', ',
|
||||
'mib3' => 'Броня пояса: +' . $animalBonusData['add_' . $itemBonusSysName] . ', ',
|
||||
'mib4' => 'Броня ног: +' . $animalBonusData['add_' . $itemBonusSysName] . ', ',
|
||||
default => $statBonusNames[$itemBonusSysName] . ': +' . $animalBonusData['add_' . $itemBonusSysName] . ', ',
|
||||
default => $this->statnames->bonusNames[$itemBonusSysName] . ': +' . $animalBonusData['add_' . $itemBonusSysName] . ', ',
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -108,6 +108,7 @@ class BotPriemLogic
|
||||
global $u;
|
||||
$notr = 0;
|
||||
$statnames = new Stat();
|
||||
$statnames->getRequirement();
|
||||
$tr = Conversion::dataStringToArray($pl['tr']);
|
||||
$d2 = Conversion::dataStringToArray($pl['date2']);
|
||||
|
||||
@ -130,13 +131,10 @@ class BotPriemLogic
|
||||
}
|
||||
}
|
||||
|
||||
$statRequirementNames = $statnames->getRequirementNames();
|
||||
$statSysRequirementNames = array_keys($statRequirementNames);
|
||||
|
||||
$x = 0;
|
||||
|
||||
while ($x < count($statSysRequirementNames)) {
|
||||
$n = $statSysRequirementNames[$x];
|
||||
while ($x < count($statnames->sysRequirementNames)) {
|
||||
$n = $statnames->sysRequirementNames[$x];
|
||||
if (isset($tr['tr_' . $n])) {
|
||||
if ($n == 'lvl') {
|
||||
if ($tr['tr_' . $n] > BotLogic::$bot['level']) {
|
||||
|
@ -12,13 +12,14 @@ class Bonuses
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$this->stat = new Stat();
|
||||
$this->stat->getBonus();
|
||||
|
||||
foreach ($data as $bonusName => $value) {
|
||||
if (!$this->stat->getBonusNames()[$bonusName]) {
|
||||
if (!$this->stat->bonusNames[$bonusName]) {
|
||||
$this->result[$bonusName] = $value; //fixme на период отладки для отлова забытых
|
||||
//continue;
|
||||
}
|
||||
$this->result[$this->stat->getBonusNames()[$bonusName]] = $value;
|
||||
$this->result[$this->stat->bonusNames[$bonusName]] = $value;
|
||||
}
|
||||
$this->armor($data);
|
||||
}
|
||||
@ -58,10 +59,10 @@ class Bonuses
|
||||
|
||||
public function addZonb(): void
|
||||
{
|
||||
if (isset($this->result[$this->stat->getBonusNames()['zonb']])) {
|
||||
$this->result[$this->stat->getBonusNames()['zonb']]++;
|
||||
if (isset($this->result[$this->stat->bonusNames['zonb']])) {
|
||||
$this->result[$this->stat->bonusNames['zonb']]++;
|
||||
} else {
|
||||
$this->result[$this->stat->getBonusNames()['zonb']] = 1;
|
||||
$this->result[$this->stat->bonusNames['zonb']] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,13 +20,13 @@ class Requirements
|
||||
private int $alignValue = 0;
|
||||
|
||||
private array $result = [];
|
||||
private Stat $stat;
|
||||
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$this->stat = new Stat();
|
||||
$statnames = new Stat();
|
||||
$statnames->getRequirement();
|
||||
foreach ($data as $requirementName => $value) {
|
||||
if (!$this->stat->getRequirementNames()[$requirementName]) {
|
||||
if (!$statnames->requirementNames[$requirementName]) {
|
||||
$this->result[$requirementName] = $value; //fixme на период отладки для отлова забытых
|
||||
//continue;
|
||||
}
|
||||
@ -49,7 +49,7 @@ class Requirements
|
||||
//$this->result[$this->stat->getRequirementNames()[$requirementName]] = $value;
|
||||
|
||||
$this->result[$requirementName] = [
|
||||
'name' => $this->stat->getRequirementNames()[$requirementName],
|
||||
'name' => $statnames->requirementNames[$requirementName],
|
||||
'value' => $value,
|
||||
];
|
||||
}
|
||||
|
@ -17,13 +17,6 @@ class Stat extends Constant
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getBonusNames(): array
|
||||
{
|
||||
$filtered = $this->filterByCell(StatFilterCellName::Bonus);
|
||||
$this->sysBonusNames = array_keys($filtered);
|
||||
return $filtered;
|
||||
}
|
||||
|
||||
private function filterByCell(StatFilterCellName $cellName): array
|
||||
{
|
||||
$result = [];
|
||||
@ -36,13 +29,6 @@ class Stat extends Constant
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getRequirementNames(): array
|
||||
{
|
||||
$filtered = $this->filterByCell(StatFilterCellName::Requirement);
|
||||
$this->sysRequirementNames = array_keys($filtered);
|
||||
return $filtered;
|
||||
}
|
||||
|
||||
/**
|
||||
* Создаёт и заполняет массивы bonusNames и sysBonusNames.
|
||||
* @return void
|
||||
|
@ -18,6 +18,7 @@ class InfoBox
|
||||
public function __construct(private readonly User $user, private readonly Stat $statname = new Stat())
|
||||
{
|
||||
$this->info = $user->info;
|
||||
$this->statname->getBonus();
|
||||
}
|
||||
|
||||
public function getInfoPers($uid, $i1, $sn = 0, $ivv = 0): array
|
||||
@ -384,17 +385,16 @@ class InfoBox
|
||||
|
||||
//Действие эффекта
|
||||
$tr = '';
|
||||
$t = array_keys($this->statname->getBonusNames());
|
||||
$x = 0;
|
||||
$ed = Conversion::dataStringToArray($e['data']);
|
||||
while ($x < count($t)) {
|
||||
$n = $t[$x];
|
||||
while ($x < count($this->statname->sysBonusNames)) {
|
||||
$n = $this->statname->sysBonusNames[$x];
|
||||
if (isset($ed['add_' . $n])) {
|
||||
$z = '';
|
||||
if ($ed['add_' . $n] > 0) {
|
||||
$z = '+';
|
||||
}
|
||||
$tr .= '<br>' . $this->statname->getBonusNames()[$n] . ': ' . $z . $ed['add_' . $n];
|
||||
$tr .= '<br>' . $this->statname->bonusNames[$n] . ': ' . $z . $ed['add_' . $n];
|
||||
}
|
||||
$x++;
|
||||
}
|
||||
@ -708,16 +708,15 @@ class InfoBox
|
||||
$lvar .= '<br>Урон: ' . $po['sv_yron_min'] . '-' . $po['sv_yron_max'];
|
||||
}
|
||||
|
||||
$t = array_keys($this->statname->getBonusNames());
|
||||
$x = 0;
|
||||
while ($x < count($t)) {
|
||||
$n = $t[$x];
|
||||
while ($x < count($this->statname->sysBonusNames)) {
|
||||
$n = $this->statname->sysBonusNames[$x];
|
||||
if (isset($po['add_' . $n])) {
|
||||
$z = '+';
|
||||
if ($po['add_' . $n] < 0) {
|
||||
$z = '';
|
||||
}
|
||||
$lvar .= '<br>' . $this->statname->getBonusNames()[$n] . ': ' . $z . $po['add_' . $n];
|
||||
$lvar .= '<br>' . $this->statname->bonusNames[$n] . ': ' . $z . $po['add_' . $n];
|
||||
}
|
||||
$x++;
|
||||
}
|
||||
|
@ -31,8 +31,9 @@ class Item
|
||||
] = $item;
|
||||
$this->durability = $iMax - $iNow;
|
||||
$stat = new Stat();
|
||||
$stat->getBonus();
|
||||
$dataArr = Conversion::dataStringToArray(strtolower($this->data));
|
||||
foreach (array_keys($stat->getBonusNames()) as $bonusName) {
|
||||
foreach ($stat->sysBonusNames as $bonusName) {
|
||||
if (!isset($dataArr["add_$bonusName"])) {
|
||||
continue;
|
||||
}
|
||||
|
@ -14,16 +14,17 @@ class Stats
|
||||
private User $u;
|
||||
|
||||
/** Список разрешённых для бонусов системных названий статов
|
||||
* @var array
|
||||
* @var Stat
|
||||
*/
|
||||
private array $sysNames;
|
||||
private Stat $sysNames;
|
||||
|
||||
private array $statsKeys = [];
|
||||
|
||||
public function __construct(User $user)
|
||||
{
|
||||
$this->u = $user;
|
||||
$this->sysNames = (new Stat())->getBonusNames();
|
||||
$this->sysNames = new Stat();
|
||||
$this->sysNames->getBonus();
|
||||
|
||||
}
|
||||
|
||||
@ -137,7 +138,8 @@ class Stats
|
||||
}
|
||||
|
||||
// Как? Нахуя 4 переменные разные для одного и того же?
|
||||
$st = array_fill_keys(array_keys($this->sysNames), 0);
|
||||
|
||||
$st = array_fill_keys($this->sysNames->sysBonusNames, 0);
|
||||
$sti = $st;
|
||||
$s_v = $st;
|
||||
$s_vi = $st;
|
||||
@ -310,7 +312,7 @@ class Stats
|
||||
}
|
||||
|
||||
$sti = Conversion::dataStringToArray($com);
|
||||
foreach ($this->sysNames as $stat) {
|
||||
foreach ($this->sysNames->sysBonusNames as $stat) {
|
||||
if (!isset($sti[$stat])) {
|
||||
continue;
|
||||
}
|
||||
@ -596,7 +598,7 @@ class Stats
|
||||
|
||||
//Добавляем статы от данного предмета
|
||||
if (!isset($data['restart_stats'])) {
|
||||
foreach ($this->sysNames as $stat) {
|
||||
foreach ($this->sysNames->sysBonusNames as $stat) {
|
||||
if (!isset($data['add_' . $stat])) {
|
||||
continue;
|
||||
}
|
||||
@ -605,13 +607,6 @@ class Stats
|
||||
} else {
|
||||
$reitm[] = $data;
|
||||
}
|
||||
|
||||
foreach ($this->sysNames as $stat) {
|
||||
if (!isset($data['sv_' . $stat])) {
|
||||
continue;
|
||||
}
|
||||
$s_v[$stat] += (int)$data['sv_' . $stat];
|
||||
}
|
||||
}
|
||||
|
||||
//Сохраненные хар-ки и умения
|
||||
@ -662,7 +657,7 @@ class Stats
|
||||
foreach ($efs as $data) {
|
||||
$sts = Conversion::dataStringToArray($data);
|
||||
foreach ($sts as $paramName => $value) {
|
||||
if (!in_array($paramName, $this->sysNames, true)) { // есть ли параметр в разрешенных?
|
||||
if (!in_array($paramName, $this->sysNames->sysBonusNames, true)) { // есть ли параметр в разрешенных?
|
||||
continue;
|
||||
}
|
||||
$st[$paramName] += $value;
|
||||
@ -672,7 +667,7 @@ class Stats
|
||||
|
||||
private function addValuesToAllArrays(array $sts, array &$st, array &$sti, array &$s_v, array &$s_vi): void
|
||||
{
|
||||
foreach ($this->sysNames as $stat) {
|
||||
foreach ($this->sysNames->sysBonusNames as $stat) {
|
||||
if (!isset($sts['add_' . $stat])) {
|
||||
continue;
|
||||
}
|
||||
|
7
inf.php
7
inf.php
@ -27,7 +27,8 @@ $c['inf'] = true;
|
||||
|
||||
include_once('_incl_data/class/__db_connect.php');
|
||||
$u = User::start();
|
||||
$bonusstatnames = (new Stat())->getBonusNames();
|
||||
$statnames = new Stat();
|
||||
$statnames->getBonus();
|
||||
|
||||
const LOWERCASE = 3;
|
||||
const UPPERCASE = 1;
|
||||
@ -349,7 +350,7 @@ if (isset($uer)) {
|
||||
<small>
|
||||
<?php
|
||||
|
||||
foreach (array_keys($bonusstatnames) as $stat) {
|
||||
foreach ($statnames->sysBonusNames as $stat) {
|
||||
if (empty($st[$stat]) || empty($u->is[$stat])) {
|
||||
continue;
|
||||
}
|
||||
@ -357,7 +358,7 @@ if (isset($uer)) {
|
||||
$st[$stat] = '+' . $st[$stat];
|
||||
}
|
||||
|
||||
echo '• ' . $bonusstatnames[$stat] . ': ' . $st[$stat] . ' <br>';
|
||||
echo '• ' . $statnames->bonusNames[$stat] . ': ' . $st[$stat] . ' <br>';
|
||||
}
|
||||
?>
|
||||
</small>
|
||||
|
Loading…
Reference in New Issue
Block a user