Сloses #54; Метод [getMaxWeight()] вместо конструкции из метода и математики [getStrength() * 4]; Очистка неиспользуемых методов класса.

This commit is contained in:
Igor Barkov (iwork) 2022-01-25 18:16:09 +02:00
parent a1ea3a0a8c
commit cd80c56f93
5 changed files with 84 additions and 92 deletions

View File

@ -55,13 +55,14 @@ IMG;
private function dressStatsChecks(): ?string private function dressStatsChecks(): ?string
{ {
$checkStats = new UserStats($this->owner_id); $checkStats = new UserStats($this->owner_id);
$stat = $checkStats->getFullStats();
return return
$this->need_strength > $checkStats->getFullStats()->strength $this->need_strength > $stat->strength
|| $this->need_dexterity > $checkStats->getFullStats()->dexterity || $this->need_dexterity > $stat->dexterity
|| $this->need_intuition > $checkStats->getFullStats()->intuition || $this->need_intuition > $stat->intuition
|| $this->need_endurance > $checkStats->getFullStats()->endurance || $this->need_endurance > $stat->endurance
|| $this->need_intelligence > $checkStats->getFullStats()->intelligence || $this->need_intelligence > $stat->intelligence
|| $this->need_wisdom > $checkStats->getFullStats()->wisdom || $this->need_wisdom > $stat->wisdom
? true : null; ? true : null;
} }

View File

@ -60,6 +60,7 @@ class UserInfo extends UserStats
private function ttz() private function ttz()
{ {
$stat = $this->getFullStats();
$arr = [ $arr = [
'Уровень' => $this->level, 'Уровень' => $this->level,
'Сила' => $this->printStat('strength'), 'Сила' => $this->printStat('strength'),
@ -68,10 +69,10 @@ class UserInfo extends UserStats
'Выносливость' => $this->printStat('endurance'), 'Выносливость' => $this->printStat('endurance'),
'Интеллект' => $this->printStat('intelligence'), 'Интеллект' => $this->printStat('intelligence'),
'Мудрость' => $this->printStat('wisdom'), 'Мудрость' => $this->printStat('wisdom'),
'Уворот' => $this->getFullStats()->evasion, 'Уворот' => $stat->evasion,
'Точность' => $this->getFullStats()->accuracy, 'Точность' => $stat->accuracy,
'Шанс крита' => $this->getFullStats()->criticals, 'Шанс крита' => $stat->criticals,
'Урон' => $this->getFullStats()->min_physical_damage . ' - ' . $this->getFullStats()->max_physical_damage, 'Урон' => $stat->min_physical_damage . ' - ' . $stat->max_physical_damage,
'Локация' => Rooms::$roomNames[$this->room], 'Локация' => Rooms::$roomNames[$this->room],
]; ];
@ -93,21 +94,23 @@ class UserInfo extends UserStats
private function printStat($statName): string private function printStat($statName): string
{ {
return $this->getFreeStatPoints() ? $this->getStat($statName, 1) . '(' . $this->getFullStats()->$statName . ')' : $this->getFullStats()->$statName; $stat = $this->getFullStats();
return $this->getFreeStatPoints() ? $this->getStat($statName, 1) . '(' . $stat->$statName . ')' : $stat->$statName;
} }
//TODO вызывать из main.php //TODO вызывать из main.php
private function UserInfoStats($isMainWindow = 0) private function UserInfoStats($isMainWindow = 0)
{ {
$stat = $this->getFullStats();
$captions = 'Уровень:<br>Сила:<br>Ловкость:<br>Интуиция:<br>Выносливость:<br>Интеллект:<br>Мудрость:<br>Местонахождение:'; $captions = 'Уровень:<br>Сила:<br>Ловкость:<br>Интуиция:<br>Выносливость:<br>Интеллект:<br>Мудрость:<br>Местонахождение:';
$variables = $variables =
$this->level . '<br>' . $this->level . '<br>' .
parent::getFullStats()->strength . '<br>' . $stat->strength . '<br>' .
parent::getFullStats()->dexterity . '<br>' . $stat->dexterity . '<br>' .
parent::getFullStats()->intuition . '<br>' . $stat->intuition . '<br>' .
parent::getFullStats()->endurance . '<br>' . $stat->endurance . '<br>' .
parent::getFullStats()->intelligence . '<br>' . $stat->intelligence . '<br>' .
parent::getFullStats()->wisdom . '<br>' . $stat->wisdom . '<br>' .
Rooms::$roomNames[$this->room]; Rooms::$roomNames[$this->room];
if ($isMainWindow) { if ($isMainWindow) {
$captions = 'Уровень:<br>Здоровье:<br>Сила:<br>Ловкость:<br>Интуиция:<br>Выносливость:<br>Интеллект:<br>Мудрость:<br>Опыт:<br>Очки характеристик:<br>Деньги:<br>Деньги в банке:'; $captions = 'Уровень:<br>Здоровье:<br>Сила:<br>Ловкость:<br>Интуиция:<br>Выносливость:<br>Интеллект:<br>Мудрость:<br>Опыт:<br>Очки характеристик:<br>Деньги:<br>Деньги в банке:';

View File

@ -90,52 +90,9 @@ class UserStats extends User
} }
} }
/** public function getMaxWeight(): int
* @return mixed
*/
public function getStrength()
{ {
return $this->strength; return $this->strength * 4;
}
/**
* @return mixed
*/
public function getDexterity()
{
return $this->dexterity;
}
/**
* @return mixed
*/
public function getIntuition()
{
return $this->intuition;
}
/**
* @return mixed
*/
public function getEndurance()
{
return $this->endurance;
}
/**
* @return mixed
*/
public function getIntelligence()
{
return $this->intelligence;
}
/**
* @return mixed
*/
public function getWisdom()
{
return $this->wisdom;
} }
/** /**
@ -202,23 +159,53 @@ class UserStats extends User
return $this->legArmor; return $this->legArmor;
} }
public function getFullStats() public function getFullStats(): object
{ {
$query = " $stats = self::$db->ofetch("
select select
sum(greatest(strength + (ifnull((select sum(add_strength) from inventory where dressed_slot != 0 and owner_id = $this->id), 0)) + (ifnull((select sum(mod_strength) from users_effects where owner_id = $this->id), 0)), 0)) as strength, strength,
sum(greatest(dexterity + (ifnull((select sum(add_dexterity) from inventory where dressed_slot != 0 and owner_id = $this->id), 0)) + (ifnull((select sum(mod_dexterity) from users_effects where owner_id = $this->id), 0)), 0)) as dexterity, dexterity,
sum(greatest(intuition + (ifnull((select sum(add_intuition) from inventory where dressed_slot != 0 and owner_id = $this->id), 0)) + (ifnull((select sum(mod_intuition) from users_effects where owner_id = $this->id), 0)), 0)) as intuition, intuition,
sum(greatest(endurance + (ifnull((select sum(add_endurance) from inventory where dressed_slot != 0 and owner_id = $this->id), 0)) + (ifnull((select sum(mod_endurance) from users_effects where owner_id = $this->id), 0)), 0)) as endurance, endurance,
sum(greatest(intelligence + (ifnull((select sum(add_intelligence) from inventory where dressed_slot != 0 and owner_id = $this->id), 0)) + (ifnull((select sum(mod_intelligence) from users_effects where owner_id = $this->id), 0)), 0)) as intelligence, intelligence,
sum(greatest(wisdom + (ifnull((select sum(add_wisdom) from inventory where dressed_slot != 0 and owner_id = $this->id), 0)) + (ifnull((select sum(mod_wisdom) from users_effects where owner_id = $this->id), 0)), 0)) as wisdom, wisdom
ifnull((select sum(add_accuracy) from inventory where dressed_slot != 0 and owner_id = $this->id), 0) as accuracy, from users where id = $this->id");
ifnull((select sum(add_evasion) from inventory where dressed_slot != 0 and owner_id = $this->id), 0) as evasion, $itemBonuses = self::$db->ofetch("
ifnull((select sum(add_criticals) from inventory where dressed_slot != 0 and owner_id = $this->id), 0) as criticals, select
sum(greatest($this->minDamage + (ifnull((select sum(add_min_physical_damage) from inventory where dressed_slot != 0 and owner_id = $this->id), 0)), 0)) as min_physical_damage, sum(add_strength) as item_strength,
sum(greatest($this->maxDamage + (ifnull((select sum(add_max_physical_damage) from inventory where dressed_slot != 0 and owner_id = $this->id), 0)), 0)) as max_physical_damage sum(add_dexterity) as item_dexterity,
from users where id = $this->id"; sum(add_intuition) as item_intuition,
return self::$db->ofetch($query); sum(add_endurance) as item_endurance,
sum(add_intelligence) as item_intelligence,
sum(add_wisdom) as item_wisdom,
sum(add_accuracy) as item_accuracy,
sum(add_evasion) as item_evasion,
sum(add_criticals) as item_criticals,
sum(add_min_physical_damage) as item_min_physical_damage,
sum(add_max_physical_damage) as item_max_physical_damage
from inventory where dressed_slot != 0 and owner_id = $this->id");
$effectBonuses = self::$db->ofetch("
select
sum(mod_strength) as effect_strength,
sum(mod_dexterity) as effect_dexterity,
sum(mod_intuition) as effect_intuition,
sum(mod_endurance) as effect_endurance,
sum(mod_intelligence) as effect_intelligence,
sum(mod_wisdom) as effect_wisdom
from users_effects where owner_id = $this->id");
$obj = (object)[];
$obj->strength = max(0,$stats->strength + $itemBonuses->item_strength + $effectBonuses->effect_strength);
$obj->dexterity = max(0,$stats->dexterity + $itemBonuses->item_dexterity + $effectBonuses->effect_dexterity);
$obj->intuition = max(0,$stats->intuition + $itemBonuses->item_intuition + $effectBonuses->effect_intuition);
$obj->endurance = max(0,$stats->endurance + $itemBonuses->item_endurance + $effectBonuses->effect_endurance);
$obj->intelligence = max(0,$stats->intelligence + $itemBonuses->item_intelligence + $effectBonuses->effect_intelligence);
$obj->wisdom = max(0,$stats->wisdom + $itemBonuses->item_wisdom + $effectBonuses->effect_wisdom);
$obj->accuracy = max(0, $itemBonuses->item_accuracy);
$obj->evasion = max(0, $itemBonuses->item_evasion);
$obj->criticals = max(0, $itemBonuses->item_criticals);
$obj->min_physical_damage = max($this->minDamage, $this->minDamage + $itemBonuses->item_min_physical_damage);
$obj->max_physical_damage = max($this->maxDamage, $this->maxDamage + $itemBonuses->item_max_physical_damage);
return $obj;
} }
public function levelUp(): string public function levelUp(): string

View File

@ -21,7 +21,7 @@ function get_meshok(): object
$stat = new UserInfo(User::$current->getId()); $stat = new UserInfo(User::$current->getId());
return (object)[ return (object)[
'currentweight' => $allweight->items_weight_sum, 'currentweight' => $allweight->items_weight_sum,
'maxweight' => $stat->getStat('strength') * 4 + $allweight->items_weight_sum, 'maxweight' => $stat->getMaxWeight() + $allweight->items_weight_sum,
]; ];
} }

View File

@ -73,6 +73,7 @@ if ($req->edit) {
// Подготавливаем отображение инфы и предметов. // Подготавливаем отображение инфы и предметов.
$userInfo = new UserInfo(User::$current->getId()); $userInfo = new UserInfo(User::$current->getId());
$userStats = new UserStats(User::$current->getId()); $userStats = new UserStats(User::$current->getId());
$stat = $userStats->getFullStats();
$data = DBPDO::$db->ofetchAll('SELECT * FROM inventory WHERE owner_id = ? AND dressed_slot = 0 AND on_sale = 0', User::$current->getId()); $data = DBPDO::$db->ofetchAll('SELECT * FROM inventory WHERE owner_id = ? AND dressed_slot = 0 AND on_sale = 0', User::$current->getId());
$iteminfo = []; $iteminfo = [];
foreach ($data as $row) { foreach ($data as $row) {
@ -132,7 +133,7 @@ if ($req->goto) {
$eff = db::c()->query('SELECT 1 FROM `users_effects` WHERE `owner_id` = ?i AND (`type` = 14 OR `type` = 13)', User::$current->getId()); $eff = db::c()->query('SELECT 1 FROM `users_effects` WHERE `owner_id` = ?i AND (`type` = 14 OR `type` = 13)', User::$current->getId());
//(масса: <?= $getItemsBonuses->getItemsWeight() . '/' . User::$current->strength * 4 //(масса: <?= $getItemsBonuses->getItemsWeight() . '/' . User::$current->strength * 4
if ($d['sum_weight'] > $userStats->getStrength() * 4) { if ($d['sum_weight'] > $userStats->getMaxWeight()) {
err('У вас переполнен рюкзак, вы не можете передвигаться...'); err('У вас переполнен рюкзак, вы не можете передвигаться...');
$imove = false; $imove = false;
} }
@ -282,17 +283,17 @@ Template::header('Игра');
<!--Параметры--> <!--Параметры-->
<div> <div>
<div class="container"> <div class="container">
Сила: <?= ($userStats->getFreeStatPoints() ? $userStats->getStat('strength', 1) . '(' . strval($userStats->getFullStats()->strength) . ')' : $userStats->getFullStats()->strength) ?> Сила: <?= ($userStats->getFreeStatPoints() ? $userStats->getStat('strength', 1) . '(' . strval($stat->strength) . ')' : $stat->strength) ?>
<br> <br>
Ловкость: <?= ($userStats->getFreeStatPoints() ? $userStats->getStat('dexterity', 1) . '(' . strval($userStats->getFullStats()->dexterity) . ')' : $userStats->getFullStats()->dexterity) ?> Ловкость: <?= ($userStats->getFreeStatPoints() ? $userStats->getStat('dexterity', 1) . '(' . strval($stat->dexterity) . ')' : $stat->dexterity) ?>
<br> <br>
Интуиция: <?= ($userStats->getFreeStatPoints() ? $userStats->getStat('intuition', 1) . '(' . strval($userStats->getFullStats()->intuition) . ')' : $userStats->getFullStats()->intuition) ?> Интуиция: <?= ($userStats->getFreeStatPoints() ? $userStats->getStat('intuition', 1) . '(' . strval($stat->intuition) . ')' : $stat->intuition) ?>
<br> <br>
Выносливость: <?= ($userStats->getFreeStatPoints() ? $userStats->getStat('endurance', 1) . '(' . strval($userStats->getFullStats()->endurance) . ')' : $userStats->getFullStats()->endurance) ?> Выносливость: <?= ($userStats->getFreeStatPoints() ? $userStats->getStat('endurance', 1) . '(' . strval($stat->endurance) . ')' : $stat->endurance) ?>
<br> <br>
Интеллект: <?= ($userStats->getFreeStatPoints() ? $userStats->getStat('intelligence', 1) . '(' . strval($userStats->getFullStats()->intelligence) . ')' : $userStats->getFullStats()->intelligence) ?> Интеллект: <?= ($userStats->getFreeStatPoints() ? $userStats->getStat('intelligence', 1) . '(' . strval($stat->intelligence) . ')' : $stat->intelligence) ?>
<br> <br>
Мудрость: <?= ($userStats->getFreeStatPoints() ? $userStats->getStat('wisdom', 1) . '(' . strval($userStats->getFullStats()->wisdom) . ')' : $userStats->getFullStats()->wisdom) ?> Мудрость: <?= ($userStats->getFreeStatPoints() ? $userStats->getStat('wisdom', 1) . '(' . strval($stat->wisdom) . ')' : $stat->wisdom) ?>
<br> <br>
<?php if ($userStats->getFreeStatPoints()): ?> <?php if ($userStats->getFreeStatPoints()): ?>
<small style="color: darkgreen;">Возможных <small style="color: darkgreen;">Возможных
@ -308,11 +309,11 @@ Template::header('Игра');
<progress max="<?= $userStats->getMaxMana() ?>" <progress max="<?= $userStats->getMaxMana() ?>"
value="<?= $userStats->getMana() ?>"><?= $userStats->getMana() ?></progress> value="<?= $userStats->getMana() ?>"><?= $userStats->getMana() ?></progress>
<br> <br>
Уворот: <?= $userStats->getFullStats()->evasion ?><br> Уворот: <?= $stat->evasion ?><br>
Точность: <?= $userStats->getFullStats()->accuracy ?><br> Точность: <?= $stat->accuracy ?><br>
Шанс крита: <?= $userStats->getFullStats()->criticals ?><br> Шанс крита: <?= $stat->criticals ?><br>
Урон: <?= $userStats->getFullStats()->min_physical_damage ?> Урон: <?= $stat->min_physical_damage ?>
- <?= $userStats->getFullStats()->max_physical_damage ?> <br> - <?= $stat->max_physical_damage ?> <br>
<br> <br>
Защита от огня: ?? <br> Защита от огня: ?? <br>
Защита от воды: ?? <br> Защита от воды: ?? <br>
@ -346,7 +347,7 @@ Template::header('Игра');
<div> <!--рюкзак--> <div> <!--рюкзак-->
<table style="border: 0; padding: 2px; border-spacing: 1px; width: 100%; background-color: #a5a5a5"> <table style="border: 0; padding: 2px; border-spacing: 1px; width: 100%; background-color: #a5a5a5">
<caption>Рюкзак <caption>Рюкзак
(масса: <?= '?? /' . (int)$userStats->getStrength() * 4 ?>) (масса: <?= '?? /' . $userStats->getMaxWeight() ?>)
</caption> </caption>
<?php <?php
foreach ($iteminfo as $ii) { foreach ($iteminfo as $ii) {