Подсчёт бонусных очков

This commit is contained in:
Igor Barkov (iwork) 2020-07-20 15:07:49 +03:00
parent 6e73380b82
commit 0cc3454086
3 changed files with 85 additions and 34 deletions

View File

@ -9,23 +9,36 @@ class DressedItems
{
protected $DB;
protected $DBSUM;
protected $USERID;
private $dressedItem;
public $sumStrength = 0;
public $sumDexterity = 0;
public $sumIntuition = 0;
public $sumEndurance = 0;
public $sumIntelligence = 0;
public $sumWisdom = 0;
public $sumAccuracy = 0;
public $sumDodge = 0;
public $sumCriticals = 0;
/**
* DressedItems constructor.
*/
public function __construct() {}
public function __construct($user_id)
{
$this->USERID = $user_id;
}
private function getDressedItems($user_id)
private function getDressedItems()
{
try {
$this->DB = db::c()->query('SELECT * FROM inventory WHERE owner_id = ?i AND dressed_slot > 0', $user_id);
$this->DB = db::c()->query('SELECT * FROM inventory WHERE owner_id = ?i AND dressed_slot > 0', $this->USERID);
} catch (Exception $e) {
echo '<div class="debug">Не прогрузилась таблица inventory (*) для класса DressedItems.</div>';
}
}
private function getBonusesFromDressedItems($user_id)
protected function getBonusesFromDressedItems()
{
try {
$query = <<<SQL
@ -40,16 +53,16 @@ SELECT SUM(add_strength) as sum_strength,
SUM(add_criticals) as sum_criticals
FROM inventory WHERE owner_id = ?i AND dressed_slot > 0'
SQL;
$this->DBSUM = db::c()->query($query, $user_id)->fetch_assoc();
$this->DBSUM = db::c()->query($query, $this->USERID)->fetch_assoc();
} catch (Exception $e) {
echo '<div class="debug">Не прогрузилась таблица inventory (SUM) для класса DressedItems.</div>';
echo '<div class="debug">Не прогрузилась таблица inventory (SUM) для класса DressedItems:' . $e . '</div>';
}
}
public function getItemsInSlots($user_id)
public function getItemsInSlots()
{
if (!$this->DB) {
$this->getDressedItems($user_id);
$this->getDressedItems();
}
while ($row = $this->DB->fetch_assoc()) {
$dressed_item[$row['dressed_slot']] = $row;
@ -57,12 +70,50 @@ SQL;
}
}
public function getBonusesAmount($user_id)
protected function getBonuses()
{
if (!$this->DBSUM) {
$this->getBonusesFromDressedItems($user_id);
$this->getBonusesFromDressedItems();
}
return $this->DBSUM;
}
public function getStrengthBonus()
{
return $this->getBonuses()['sum_strength'];
}
public function getDexterityBonus()
{
return $this->getBonuses()['sum_dexterity'];
}
public function getIntuitionBonus()
{
return $this->getBonuses()['sum_intuition'];
}
public function getEnduranceBonus()
{
return $this->getBonuses()['sum_endurance'];
}
public function getIntelliganceBonus()
{
return $this->getBonuses()['sum_intelligence'];
}
public function getWisdomBonus()
{
return $this->getBonuses()['sum_wisdom'];
}
public function getAccuracyBonus()
{
return $this->getBonuses()['sum_accuracy'];
}
public function getDodgeBonus()
{
return $this->getBonuses()['sum_dodge'];
}
public function getCriticalsBonus()
{
return $this->getBonuses()['sum_criticals'];
}
}

View File

@ -68,8 +68,8 @@ class User
private function UserInfoDoll($isBattle = 0, $isMain = 0)
{
//https://jsfiddle.net/ngx0yvhc
$di = new DressedItems();
$dressedItems = $di->getItemsInSlots($this->id);
$di = new DressedItems($this->id);
$dressedItems = $di->getItemsInSlots();
for ($i = 1; $i <= 12; $i++) {
echo sprintf('<div class="slot-%s">', $i);

View File

@ -329,8 +329,8 @@ function countmf()
$sokr = db::c()->query('SELECT 1 FROM `users_effects` WHERE `type` = 202 AND `owner_id` = ?i', $_SESSION['uid'])->getNumRows();
$user = new User($_SESSION['uid']);
$userDressedItems = new DressedItems();
$allBonuses = $userDressedItems->getBonusesAmount($_SESSION['uid']) ?? [];
$userDressedItemsBonuses = new DressedItems();
function GetWeaponType($idwep)
{
@ -367,22 +367,17 @@ function countmf()
$mf = [];
//$user_dress = db::c()->query('SELECT SUM(`minu`), SUM(`maxu`), SUM(`mfkrit`), SUM(`mfakrit`), SUM(`mfuvorot`), SUM(`mfauvorot`), SUM(`bron1`), SUM(`bron2`), SUM(`bron3`), SUM(`bron4`) FROM `inventory` WHERE `dressed` = 1 AND `owner` = ?i', $user['id'])->fetch_row();
//FIXME Брони стало 3, а не 4.
$user_dress[6] = $bmfbron + $user->headArmor;
$user_dress[7] = $bmfbron + $user->chestArmor;
$user_dress[8] = $bmfbron + $user->legArmor;
$user_dress[9] = $bmfbron + $user->legArmor;
$user_dress[6] = $bmfbron;
$user_dress[7] = $bmfbron;
$user_dress[8] = $bmfbron;
$user_dress[9] = $bmfbron;
$mykrit = $allBonuses['sum_intuition'] * 2.95; /* + SUM(mfkrit) */
$myakrit = $allBonuses['sum_intuition'] * 2.75; /* + SUM(mfakrit) */
$myuvorot = $allBonuses['sum_dexterity'] * 5; /* + SUM(mfuvorot) */
$myauvorot = $allBonuses['sum_dexterity'] * 5; /* + SUM(mfauvorot) */
$user_dress[6] += $user['ubron1'];
$user_dress[7] += $user['ubron2'];
$user_dress[8] += $user['ubron3'];
$user_dress[9] += $user['ubron4'];
$mykrit = $user_dress[2] + ($user['inta'] * 2.95);
$myakrit = $user_dress[3] + ($user['inta'] * 2.75);
$myuvorot = $user_dress[4] + ($user['lovk'] * 5);
$myauvorot = $user_dress[5] + ($user['lovk'] * 4);
$mf['me'] = ['udar' => (floor($user['sila'] / 3) + 1 + $user_dress[0]), 'maxudar' => (floor($user['sila'] / 3) + 4 + $user_dress[1])];
@ -946,6 +941,7 @@ if (input::get('edit')) {
<?php
$showUser = new User($_SESSION['uid']);
$showUser->showUserDoll(0, 1);
$showItemsBonuses = new DressedItems();
?> <!-- Первый столбец -->
<div align="center">
<a href='main.php?edit=1&undress=all'>Снять все</a><BR>
@ -989,14 +985,18 @@ if (input::get('edit')) {
<!--Параметры-->
<div>
<div class="container">
Сила: <?= $showUser->getStrength(1) ?><br>
Ловкость: <?= $showUser->getDexterity(1) ?><br>
Интуиция: <?= $showUser->getIntuition(1) ?><br>
Выносливость: <?= $showUser->getEndurance(1) ?><br>
Интеллект: <?= $showUser->getIntelligence(1) ?><br>
Мудрость: <?= $showUser->getWisdom(1) ?><br>
Сила: <?= $showUser->getStrength(1) + $showItemsBonuses->sumStrength ?><br>
Ловкость: <?= $showUser->getDexterity(1) + $showItemsBonuses->sumDexterity ?><br>
Интуиция: <?= $showUser->getIntuition(1) + $showItemsBonuses->sumIntuition ?><br>
Выносливость: <?= $showUser->getEndurance(1) + $showItemsBonuses->sumEndurance ?><br>
Интеллект: <?= $showUser->getIntelligence(1) + $showItemsBonuses->sumIntelligence ?><br>
Мудрость: <?= $showUser->getWisdom(1) + $showItemsBonuses->sumWisdom ?><br>
<small style="color: darkgreen;">Возможных увеличений: <?= $showUser->stat_points ?></small>
<br><br>
Здоровье: <?= $showUser->getHealth() ?><br>
Уворот: ?? + <? $showItemsBonuses->sumDodge ?><br>
Точность: ?? + <? $showItemsBonuses->sumAccuracy ?><br>
Шанс крита: ?? + <? $showItemsBonuses->sumCriticals ?><br>
</div>
<?php
$mf = countmf();