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