[wip] code smell, psr-12, mvc, other, forgot by 1 year.
This commit is contained in:
parent
775a56c4c8
commit
2bb6bef614
@ -10,6 +10,7 @@ namespace Battles;
|
|||||||
use Exceptions\GameException;
|
use Exceptions\GameException;
|
||||||
use Battles\Database\Db;
|
use Battles\Database\Db;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
use Battles\Models\BankModel;
|
||||||
|
|
||||||
class Bank
|
class Bank
|
||||||
{
|
{
|
||||||
@ -17,15 +18,20 @@ class Bank
|
|||||||
private int $money = 0;
|
private int $money = 0;
|
||||||
private $user;
|
private $user;
|
||||||
|
|
||||||
const ERROR_NO_MONEY_IN_WALLET = "Ошибка! Нет денег в кошельке!";
|
private const ERROR_NO_MONEY_IN_WALLET = "Ошибка! Нет денег в кошельке!";
|
||||||
const ERROR_NO_BANK_ACCOUNT = "Ошибка! Счёта не существует!";
|
private const ERROR_NO_BANK_ACCOUNT = "Ошибка! Счёта не существует!";
|
||||||
const ERROR_NO_MONEY_IN_BANK_ACCOUNT = "Ошибка! Нет денег на счету!";
|
private const ERROR_NO_MONEY_IN_BANK_ACCOUNT = "Ошибка! Нет денег на счету!";
|
||||||
const ERROR_WRONG_AMOUNT = "Ошибка! Сумма должна быть положительной!";
|
private const ERROR_WRONG_AMOUNT = "Ошибка! Сумма должна быть положительной!";
|
||||||
const LOG = [
|
private const MINIMUM_COMISSION_VALUE = 1;
|
||||||
'sendMoney' => 'Банк: Перевод средств на другой счёт.',
|
private const OPERATION_SEND_MONEY = 'sendMoney';
|
||||||
'receiveMoney' => 'Банк: Получение средств.',
|
private const OPERATION_DEPOSIT_MONEY = 'depositMoney';
|
||||||
'depositMoney' => 'Пополнение счёта.',
|
private const OPERATION_RECEIVE_MONEY = 'receiveMoney';
|
||||||
'withdrawMoney' => 'Снятие денег со счёта.',
|
private const OPERATION_WITHDRAW_MONEY = 'withdrawMoney';
|
||||||
|
private const LOG = [
|
||||||
|
self::OPERATION_SEND_MONEY => 'Банк: Перевод средств на другой счёт.',
|
||||||
|
self::OPERATION_RECEIVE_MONEY => 'Банк: Получение средств.',
|
||||||
|
self::OPERATION_DEPOSIT_MONEY => 'Пополнение счёта.',
|
||||||
|
self::OPERATION_WITHDRAW_MONEY => 'Снятие денег со счёта.',
|
||||||
'clanRegister' => 'Оплата стоимости регистрации клана.',
|
'clanRegister' => 'Оплата стоимости регистрации клана.',
|
||||||
'sellShop' => 'Продажа товара в магазине.'
|
'sellShop' => 'Продажа товара в магазине.'
|
||||||
];
|
];
|
||||||
@ -51,11 +57,7 @@ class Bank
|
|||||||
private function bankCommission(int $amount): int
|
private function bankCommission(int $amount): int
|
||||||
{
|
{
|
||||||
$bankCommission = round($amount * GameConfigs::BANK_COMISSION);
|
$bankCommission = round($amount * GameConfigs::BANK_COMISSION);
|
||||||
if ($bankCommission < 1) {
|
return $bankCommission >= self::MINIMUM_COMISSION_VALUE ? (int)$bankCommission : self::MINIMUM_COMISSION_VALUE;
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
return (int)$bankCommission;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -64,25 +66,25 @@ class Bank
|
|||||||
* @param int $receiverId ID получателя.
|
* @param int $receiverId ID получателя.
|
||||||
* @param int $amount сумма.
|
* @param int $amount сумма.
|
||||||
* @param string $operationType тип банковской операции.
|
* @param string $operationType тип банковской операции.
|
||||||
* @param int $senderId ID отправителя (ID игрока, если не указано иное).
|
* @param ?int $senderId ID отправителя (ID игрока, если не указано иное).
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function bankLogs(int $receiverId, int $amount, string $operationType, int $senderId = null): void
|
private function bankLogs(int $receiverId, int $amount, string $operationType, ?int $senderId = null): void
|
||||||
{
|
{
|
||||||
if (is_null($senderId)) {
|
if (is_null($senderId)) {
|
||||||
$senderId = $this->user_id;
|
$senderId = $this->user_id;
|
||||||
}
|
}
|
||||||
$text = self::LOG[$operationType];
|
$text = self::LOG[$operationType];
|
||||||
if ($operationType == "sendMoney") {
|
if ($operationType == self::OPERATION_SEND_MONEY) {
|
||||||
$text .= " Комиссия: " . $this->bankCommission($amount);
|
$text .= " Комиссия: " . $this->bankCommission($amount);
|
||||||
} elseif ($operationType == "depositMoney") {
|
} elseif ($operationType == self::OPERATION_DEPOSIT_MONEY) {
|
||||||
$receiverId = $this->user_id;
|
$receiverId = $this->user_id;
|
||||||
} elseif ($operationType == "withdrawMoney") {
|
} elseif ($operationType == self::OPERATION_WITHDRAW_MONEY) {
|
||||||
$receiverId = $this->user_id;
|
$receiverId = $this->user_id;
|
||||||
$text .= " Комиссия: " . $this->bankCommission($amount);
|
$text .= " Комиссия: " . $this->bankCommission($amount);
|
||||||
}
|
}
|
||||||
GameLogs::addBankLog($senderId,$receiverId,$amount,$operationType,$text);
|
GameLogs::addBankLog($senderId, $receiverId, $amount, $operationType, $text);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -110,11 +112,11 @@ class Bank
|
|||||||
// Снимаем сумму с комиссией у отправителя
|
// Снимаем сумму с комиссией у отправителя
|
||||||
$this->money -= $amountWithComission;
|
$this->money -= $amountWithComission;
|
||||||
self::setBankMoney($this->money, $this->user_id);
|
self::setBankMoney($this->money, $this->user_id);
|
||||||
$this->bankLogs($receiver, $this->money, "sendMoney");
|
$this->bankLogs($receiver, $this->money, self::OPERATION_SEND_MONEY);
|
||||||
// Отдаём сумму на счёт получателю
|
// Отдаём сумму на счёт получателю
|
||||||
$receiverWallet->money += $amount;
|
$receiverWallet->money += $amount;
|
||||||
self::setBankMoney($receiverWallet->money, $receiver);
|
self::setBankMoney($receiverWallet->money, $receiver);
|
||||||
$this->bankLogs($receiver, $receiverWallet->money, "receiveMoney");
|
$this->bankLogs($receiver, $receiverWallet->money, self::OPERATION_RECEIVE_MONEY);
|
||||||
// Возвращаем изменившиеся значения
|
// Возвращаем изменившиеся значения
|
||||||
return $this->money;
|
return $this->money;
|
||||||
}
|
}
|
||||||
@ -142,7 +144,7 @@ class Bank
|
|||||||
// Отдаём сумму на счёт получателю
|
// Отдаём сумму на счёт получателю
|
||||||
$this->money += $amount;
|
$this->money += $amount;
|
||||||
self::setBankMoney($this->money, $this->user_id);
|
self::setBankMoney($this->money, $this->user_id);
|
||||||
$this->bankLogs(0, $this->money, "depositMoney");
|
$this->bankLogs(0, $this->money, self::OPERATION_DEPOSIT_MONEY);
|
||||||
// Возвращаем изменившиеся значения
|
// Возвращаем изменившиеся значения
|
||||||
return [
|
return [
|
||||||
'walletMoney' => $this->user->money,
|
'walletMoney' => $this->user->money,
|
||||||
@ -170,7 +172,7 @@ class Bank
|
|||||||
// Снимаем сумму с комиссией у отправителя
|
// Снимаем сумму с комиссией у отправителя
|
||||||
$this->money -= $amountWithComission;
|
$this->money -= $amountWithComission;
|
||||||
self::setBankMoney($this->money, $this->user_id);
|
self::setBankMoney($this->money, $this->user_id);
|
||||||
$this->bankLogs(0, $this->money, "withdrawMoney");
|
$this->bankLogs(0, $this->money, self::OPERATION_WITHDRAW_MONEY);
|
||||||
// Отдаём сумму в кошелёк получателя
|
// Отдаём сумму в кошелёк получателя
|
||||||
$this->user['money'] += $amount;
|
$this->user['money'] += $amount;
|
||||||
self::setWalletMoney($this->user['money'], $this->user_id);
|
self::setWalletMoney($this->user['money'], $this->user_id);
|
||||||
@ -185,15 +187,16 @@ class Bank
|
|||||||
* Установить количество денег на банковском счету.
|
* Установить количество денег на банковском счету.
|
||||||
*
|
*
|
||||||
* @param int $amount сумма.
|
* @param int $amount сумма.
|
||||||
* @param int $user_id ID пользователя.
|
* @param int $uid ID пользователя.
|
||||||
* @param string $operationType Тип операции. По умолчанию пусто. Если ввести, система запишет событие в банковский лог.
|
* @param string $operationType Тип операции. По умолчанию пусто. Если ввести, система запишет событие в банковский лог.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function setBankMoney(int $amount, int $user_id, string $operationType = ''): void
|
public static function setBankMoney(int $amount, int $uid, string $operationType = ''): void
|
||||||
{
|
{
|
||||||
|
$bm = new BankModel();
|
||||||
try {
|
try {
|
||||||
Db::getInstance()->execute('UPDATE bank SET money = ? WHERE user_id = ?', [$amount, $user_id]);
|
$bm->setMoney($amount, $uid);
|
||||||
if ($operationType) {
|
if ($operationType) {
|
||||||
GameLogs::addBankLog(0, 0, $amount, $operationType, self::LOG[$operationType]);
|
GameLogs::addBankLog(0, 0, $amount, $operationType, self::LOG[$operationType]);
|
||||||
}
|
}
|
||||||
@ -207,14 +210,14 @@ class Bank
|
|||||||
* Установить количество денег на руках.
|
* Установить количество денег на руках.
|
||||||
*
|
*
|
||||||
* @param int $amount сумма.
|
* @param int $amount сумма.
|
||||||
* @param int $user_id ID пользователя.
|
* @param int $uid ID пользователя.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function setWalletMoney(int $amount, int $user_id): void
|
public static function setWalletMoney(int $amount, int $uid): void
|
||||||
{
|
{
|
||||||
User::getInstance($user_id)->setMoney($amount);
|
User::getInstance($uid)->setMoney($amount);
|
||||||
User::getInstance($user_id)->saveMoney();
|
User::getInstance($uid)->saveMoney();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMoney(): int
|
public function getMoney(): int
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
# Date: 26.10.2020 (17:56)
|
# Date: 26.10.2020 (17:56)
|
||||||
namespace Battles;
|
namespace Battles;
|
||||||
|
|
||||||
class City
|
class City
|
||||||
{
|
{
|
||||||
use Rooms;
|
use Rooms;
|
||||||
|
|
||||||
public static function showStreet(int $id)
|
public static function showStreet(int $id)
|
||||||
{
|
{
|
||||||
if ($id === 20) {
|
if ($id === 20) {
|
||||||
@ -17,8 +19,7 @@ class City
|
|||||||
self::showBuilding(9, "winter_cap_tree2", 215, 500, self::$roomNames[44]) .
|
self::showBuilding(9, "winter_cap_tree2", 215, 500, self::$roomNames[44]) .
|
||||||
self::showBuilding(13, "spring_cap_statue", 222, 365, self::$roomNames[24]) .
|
self::showBuilding(13, "spring_cap_statue", 222, 365, self::$roomNames[24]) .
|
||||||
self::showBuilding(14, "winter_cap_statue", 210, 390, "Снеговик") .
|
self::showBuilding(14, "winter_cap_statue", 210, 390, "Снеговик") .
|
||||||
self::showBuilding(222, "cap_arr_top", 180, 650, "Торговая улица") .
|
self::showBuilding(222, "cap_arr_top", 180, 650, "Торговая улица");
|
||||||
'</div>';
|
|
||||||
} elseif ($id === 21) {
|
} elseif ($id === 21) {
|
||||||
echo '<div style="position:relative; display: inline-block;" id="ione"><img alt="background" src="/i/city/spring_cap_strash_day.jpg">' .
|
echo '<div style="position:relative; display: inline-block;" id="ione"><img alt="background" src="/i/city/spring_cap_strash_day.jpg">' .
|
||||||
self::showBuilding(3, "cap_arr_right", 255, 708, "Ристалище") .
|
self::showBuilding(3, "cap_arr_right", 255, 708, "Ристалище") .
|
||||||
@ -26,15 +27,13 @@ class City
|
|||||||
self::showBuilding(5, "spring_cap_bank", 180, 485, self::$roomNames[29]) .
|
self::showBuilding(5, "spring_cap_bank", 180, 485, self::$roomNames[29]) .
|
||||||
self::showBuilding(13, "spring_cap_flowershop", 220, 613, self::$roomNames[34]) .
|
self::showBuilding(13, "spring_cap_flowershop", 220, 613, self::$roomNames[34]) .
|
||||||
self::showBuilding(14, "spring_cap_registratura", 170, 113, self::$roomNames[30]) .
|
self::showBuilding(14, "spring_cap_registratura", 170, 113, self::$roomNames[30]) .
|
||||||
self::showBuilding(16, "spring_cap_tower", 5, 315, self::$roomNames[31]) .
|
self::showBuilding(16, "spring_cap_tower", 5, 315, self::$roomNames[31]);
|
||||||
'</div>';
|
|
||||||
} elseif ($id === 26) {
|
} elseif ($id === 26) {
|
||||||
echo '<div style="position:relative; display: inline-block;" id="ione"><img alt="background" src="/i/city/spring_cap_park_day.jpg">' .
|
echo '<div style="position:relative; display: inline-block;" id="ione"><img alt="background" src="/i/city/spring_cap_park_day.jpg">' .
|
||||||
self::showBuilding(3, "cap_arr_left", 259, 27, self::$roomNames[2601]) .
|
self::showBuilding(3, "cap_arr_left", 259, 27, self::$roomNames[2601]) .
|
||||||
self::showBuilding(4, "cap_arr_right", 259, 715, self::$roomNames[20]) .
|
self::showBuilding(4, "cap_arr_right", 259, 715, self::$roomNames[20]) .
|
||||||
self::showBuilding(6, "cap_gate", 170, 340, "Городские ворота") .
|
self::showBuilding(6, "cap_gate", 170, 340, "Городские ворота") .
|
||||||
self::showBuilding(660, "spring_cap_vokzal", 163, 43, self::$roomNames[661]) .
|
self::showBuilding(660, "spring_cap_vokzal", 163, 43, self::$roomNames[661]);
|
||||||
'</div>';
|
|
||||||
} elseif ($id === 2601) {
|
} elseif ($id === 2601) {
|
||||||
echo '<div style="position:relative; display: inline-block;" id="ione"><img alt="background" src="/i/city/sub/cap_zamk_day.jpg">' .
|
echo '<div style="position:relative; display: inline-block;" id="ione"><img alt="background" src="/i/city/sub/cap_zamk_day.jpg">' .
|
||||||
self::showBuilding(1, "spring_cap_ruins", 166, 48, "Руины Старого замка") .
|
self::showBuilding(1, "spring_cap_ruins", 166, 48, "Руины Старого замка") .
|
||||||
@ -42,43 +41,42 @@ class City
|
|||||||
self::showBuilding(10, "ava_post", 240, 300, self::$roomNames[35]) .
|
self::showBuilding(10, "ava_post", 240, 300, self::$roomNames[35]) .
|
||||||
self::showBuilding(55, "cap_arr_left", 258, 21, self::$roomNames[2655]) .
|
self::showBuilding(55, "cap_arr_left", 258, 21, self::$roomNames[2655]) .
|
||||||
self::showBuilding(1051, "spring_cap_lab", 130, 327, self::$roomNames[33]) .
|
self::showBuilding(1051, "spring_cap_lab", 130, 327, self::$roomNames[33]) .
|
||||||
self::showBuilding(1052, "spring_cap_lavka", 240, 425, self::$roomNames[1053]) .
|
self::showBuilding(1052, "spring_cap_lavka", 240, 425, self::$roomNames[1053]);
|
||||||
'</div>';
|
|
||||||
} elseif ($id === 2655) {
|
} elseif ($id === 2655) {
|
||||||
echo '<div style="position:relative; display: inline-block;" id="ione"><img alt="background" src="/i/city/ar_e_d.jpg">' .
|
echo '<div style="position:relative; display: inline-block;" id="ione"><img alt="background" src="/i/city/ar_e_d.jpg">' .
|
||||||
self::showBuilding(10, "arr_right_png2", 260, 710, self::$roomNames[2601]) .
|
self::showBuilding(10, "arr_right_png2", 260, 710, self::$roomNames[2601]) .
|
||||||
self::showBuilding(2055, "altr_g", 230, 340, self::$roomNames[603]) .
|
self::showBuilding(2055, "altr_g", 230, 340, self::$roomNames[603]);
|
||||||
'</div>';
|
|
||||||
} elseif ($id === 2111) {
|
} elseif ($id === 2111) {
|
||||||
echo '<div style="position:relative; display: inline-block;" id="ione"><img alt="background" src="/i/city/av_rist_day.jpg">' .
|
echo '<div style="position:relative; display: inline-block;" id="ione"><img alt="background" src="/i/city/av_rist_day.jpg">' .
|
||||||
self::showBuilding(1, "cap_arr_left", 240, 30, self::$roomNames[21]) .
|
self::showBuilding(1, "cap_arr_left", 240, 30, self::$roomNames[21]) .
|
||||||
self::showBuilding(14, "spring_cap_rist_solo", 210, 160, "Вход в Одиночные сражения") .
|
self::showBuilding(14, "spring_cap_rist_solo", 210, 160, "Вход в Одиночные сражения") .
|
||||||
self::showBuilding(14, "spring_cap_rist_group", 243, 340, "Вход в Сражение отрядов") .
|
self::showBuilding(14, "spring_cap_rist_group", 243, 340, "Вход в Сражение отрядов") .
|
||||||
self::showBuilding(203, "spring_cap_rist_monstr", 145, 570, "Вход в Груповые сражения") .
|
self::showBuilding(203, "spring_cap_rist_monstr", 145, 570, "Вход в Груповые сражения") .
|
||||||
self::showBuilding(1000, "av_zamk_rud", 80, 310, self::$roomNames[1001]) .
|
self::showBuilding(1000, "av_zamk_rud", 80, 310, self::$roomNames[1001]);
|
||||||
'</div>';
|
|
||||||
} elseif ($id === 2701) {
|
} elseif ($id === 2701) {
|
||||||
echo '<div style="position:relative; display: inline-block;" id="ione"><img alt="background" src="/i/city/av_arena_bg1_day2.jpg">' .
|
echo '<div style="position:relative; display: inline-block;" id="ione"><img alt="background" src="/i/city/av_arena_bg1_day2.jpg">' .
|
||||||
self::showBuilding(1, "cap_3strelka", 260, 30, "Берег Залива") .
|
self::showBuilding(1, "cap_3strelka", 260, 30, "Берег Залива") .
|
||||||
self::showBuilding(2, "cap_shar_dark", 234, 356, "Лабиринт Хаоса") .
|
self::showBuilding(2, "cap_shar_dark", 234, 356, "Лабиринт Хаоса");
|
||||||
'</div>';
|
|
||||||
} elseif ($id === 2702) {
|
} elseif ($id === 2702) {
|
||||||
echo '<div style="position:relative; display: inline-block;" id="ione"><img alt="background" src="/i/city/spring_cap_torg_day.jpg">' .
|
echo '<div style="position:relative; display: inline-block;" id="ione"><img alt="background" src="/i/city/spring_cap_torg_day.jpg">' .
|
||||||
self::showBuilding(6, "spring_cap_build1", 175, 70, "Академия") .
|
self::showBuilding(6, "spring_cap_build1", 175, 70, "Академия") .
|
||||||
self::showBuilding(10, "cap_rist_arr_left", 259, 25, self::$roomNames[20]) .
|
self::showBuilding(10, "cap_rist_arr_left", 259, 25, self::$roomNames[20]) .
|
||||||
self::showBuilding(16, "auk", 120, 300, "Аукцион") .
|
self::showBuilding(16, "auk", 120, 300, "Аукцион") .
|
||||||
self::showBuilding(21, "spring_cap_build2", 150, 565, "Ломбард") .
|
self::showBuilding(21, "spring_cap_build2", 150, 565, "Ломбард") .
|
||||||
self::showBuilding(16555, "spring_cap_build3", 155, 480, "Прокатная лавка") .
|
self::showBuilding(16555, "spring_cap_build3", 155, 480, "Прокатная лавка");
|
||||||
'</div>';
|
}
|
||||||
|
if (in_array($id, [20, 21, 26, 2601, 2655, 2111, 2701, 2702])) {
|
||||||
|
echo '</div>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function showBuilding(int $id, string $image, int $top, int $left, string $description)
|
private static function showBuilding(int $id, string $image, int $top, int $left, string $description): string
|
||||||
{
|
{
|
||||||
return sprintf('
|
return <<<HTML
|
||||||
<div style="position:absolute; left:%spx; top:%spx; z-index:90; cursor: pointer;">
|
<div style="position:absolute; left:{$left}px; top:{$top}px; z-index:90; cursor: pointer;">
|
||||||
<img src="/i/city/sub/%s.png" alt="%s" title="%s" class="building" id="%s" onclick="window.location.href = \'city.php?got/level%s\'">
|
<img src="/i/city/sub/$image.png" alt="$description" title="$description" class="building" id="$id"
|
||||||
</div>',
|
onclick="window.location.href = 'city.php?got/level$id'">
|
||||||
$left, $top, $image, $description, $description, $id, $id);
|
</div>
|
||||||
|
HTML;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -131,7 +131,7 @@ class Item
|
|||||||
$mods_cost_modifier = 2 + floor($sum_mods / 50);
|
$mods_cost_modifier = 2 + floor($sum_mods / 50);
|
||||||
$damage_cost_modifier = 1 + floor($sum_damage / 100);
|
$damage_cost_modifier = 1 + floor($sum_damage / 100);
|
||||||
$result = intval($sum_stats * $stats_cost_modifier + $sum_mods * $mods_cost_modifier + $sum_damage * $damage_cost_modifier);
|
$result = intval($sum_stats * $stats_cost_modifier + $sum_mods * $mods_cost_modifier + $sum_damage * $damage_cost_modifier);
|
||||||
return $result < 1 ? 1 : $result;
|
return max($result, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function wrap(int $number): string
|
protected function wrap(int $number): string
|
||||||
|
22
classes/Battles/Models/BankModel.php
Normal file
22
classes/Battles/Models/BankModel.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Battles\Models;
|
||||||
|
|
||||||
|
class BankModel extends Model
|
||||||
|
{
|
||||||
|
protected static string $tableName = 'bank';
|
||||||
|
protected static string $primaryKey = 'id';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $money
|
||||||
|
* @param int $uid
|
||||||
|
*/
|
||||||
|
public function setMoney(int $money, int $uid): void
|
||||||
|
{
|
||||||
|
$this->columns = [
|
||||||
|
self::$primaryKey => $uid,
|
||||||
|
'money' => $money,
|
||||||
|
];
|
||||||
|
$this->updateByPrimaryKey();
|
||||||
|
}
|
||||||
|
}
|
50
classes/Battles/Models/Model.php
Normal file
50
classes/Battles/Models/Model.php
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Battles\Models;
|
||||||
|
|
||||||
|
use Battles\Database\Db;
|
||||||
|
|
||||||
|
class Model
|
||||||
|
{
|
||||||
|
protected static string $tableName = '';
|
||||||
|
protected static string $primaryKey = '';
|
||||||
|
protected array $columns = [];
|
||||||
|
|
||||||
|
protected function getColumnValue($column)
|
||||||
|
{
|
||||||
|
return $this->columns[$column];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function setColumnValue($column, $value)
|
||||||
|
{
|
||||||
|
$this->columns[$column] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Полная перезапись. Отсутствующие параметры превратятся в default|null.
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function save()
|
||||||
|
{
|
||||||
|
$q = 'replace into ' . self::$tableName . ' (' . implode(', ', array_keys($this->columns)) . ') values(';
|
||||||
|
$keys = [];
|
||||||
|
foreach ($this->columns as $key => $value) {
|
||||||
|
$keys[':' . $key] = $value;
|
||||||
|
}
|
||||||
|
$q .= implode(', ', array_keys($keys)) . ')';
|
||||||
|
Db::getInstance()->execute($q, $keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function updateByPrimaryKey()
|
||||||
|
{
|
||||||
|
$q = 'update ' . self::$tableName . ' set ';
|
||||||
|
$keys = [];
|
||||||
|
foreach ($this->columns as $key => $value) {
|
||||||
|
$keys[':' . $key] = $value;
|
||||||
|
$q .= $key . ' = :' . $key . ', ';
|
||||||
|
}
|
||||||
|
$q = rtrim($q, ',');
|
||||||
|
$q .= 'where ' . self::$primaryKey . ' = :' . self::$primaryKey;
|
||||||
|
Db::getInstance()->execute($q, $keys);
|
||||||
|
}
|
||||||
|
}
|
104
classes/Battles/Models/UserStats.php
Normal file
104
classes/Battles/Models/UserStats.php
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Battles\Models;
|
||||||
|
|
||||||
|
use Battles\Database\Db;
|
||||||
|
|
||||||
|
class UserStats extends Model
|
||||||
|
{
|
||||||
|
protected int $strength;
|
||||||
|
protected int $dexterity;
|
||||||
|
protected int $intuition;
|
||||||
|
protected int $endurance;
|
||||||
|
protected int $intelligence;
|
||||||
|
protected int $wisdom;
|
||||||
|
protected int $health;
|
||||||
|
protected int $mana;
|
||||||
|
protected int $free_stat_points;
|
||||||
|
private int $id;
|
||||||
|
private const KULAK_MIN_DAMAGE = 1;
|
||||||
|
private const KULAK_MAX_DAMAGE = 2;
|
||||||
|
|
||||||
|
protected static string $tableName = 'users';
|
||||||
|
protected static string $primaryKey = 'id';
|
||||||
|
|
||||||
|
public function __construct($uid)
|
||||||
|
{
|
||||||
|
$this->id = $uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getFull(): object
|
||||||
|
{
|
||||||
|
$stats = Db::getInstance()->ofetch("
|
||||||
|
select
|
||||||
|
strength,
|
||||||
|
dexterity,
|
||||||
|
intuition,
|
||||||
|
endurance,
|
||||||
|
intelligence,
|
||||||
|
wisdom
|
||||||
|
from users where id = $this->id");
|
||||||
|
$itemBonuses = Db::getInstance()->ofetch("
|
||||||
|
select
|
||||||
|
sum(add_strength) as item_strength,
|
||||||
|
sum(add_dexterity) as item_dexterity,
|
||||||
|
sum(add_intuition) as item_intuition,
|
||||||
|
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 = Db::getInstance()->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(self::KULAK_MIN_DAMAGE, self::KULAK_MIN_DAMAGE + $itemBonuses->item_min_physical_damage);
|
||||||
|
$obj->max_physical_damage = max(self::KULAK_MAX_DAMAGE, self::KULAK_MAX_DAMAGE + $itemBonuses->item_max_physical_damage);
|
||||||
|
return $obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addPoint(string $stat)
|
||||||
|
{
|
||||||
|
$query = "update users set $stat = $stat + 1, free_stat_points = free_stat_points - 1 where " . self::$primaryKey . " = ?";
|
||||||
|
Db::getInstance()->execute($query, $this->id);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save()
|
||||||
|
{
|
||||||
|
$this->columns = [
|
||||||
|
self::$primaryKey => $this->id,
|
||||||
|
'strength' => $this->strength,
|
||||||
|
'dexterity' => $this->dexterity,
|
||||||
|
'intuition' => $this->intuition,
|
||||||
|
'endurance' => $this->endurance,
|
||||||
|
'intelligence' => $this->intelligence,
|
||||||
|
'wisdom' => $this->wisdom,
|
||||||
|
'health' => $this->health,
|
||||||
|
'mana' => $this->mana,
|
||||||
|
'free_stat_points' => $this->free_stat_points,
|
||||||
|
'level' => $this->level,
|
||||||
|
];
|
||||||
|
$this->updateByPrimaryKey();
|
||||||
|
}
|
||||||
|
}
|
@ -54,13 +54,13 @@ class Moderation
|
|||||||
public static function blockUser(int $target)
|
public static function blockUser(int $target)
|
||||||
{
|
{
|
||||||
self::addEffectStatusToUserLog($target, "Блокировка");
|
self::addEffectStatusToUserLog($target, "Блокировка");
|
||||||
Db::getInstance()->execute('UPDATE battles.users SET block = 1 WHERE id = ?', $target);
|
Db::getInstance()->execute('UPDATE users SET block = 1 WHERE id = ?', $target);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function unBlockUser(int $target)
|
public static function unBlockUser(int $target)
|
||||||
{
|
{
|
||||||
self::addEffectStatusToUserLog($target, "Блокировка" . self::STATUS_OFF);
|
self::addEffectStatusToUserLog($target, "Блокировка" . self::STATUS_OFF);
|
||||||
Db::getInstance()->execute('UPDATE battles.users SET block = 0 WHERE block = 1 AND id = ?', $target);
|
Db::getInstance()->execute('UPDATE users SET block = 0 WHERE block = 1 AND id = ?', $target);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function addToUserLog(int $target, string $message, int $senderId)
|
public static function addToUserLog(int $target, string $message, int $senderId)
|
||||||
|
@ -11,10 +11,12 @@ class Register
|
|||||||
if (Db::getInstance()->execute('select count(*) from users where login = ? or email = ?', [$login, $email])->fetchColumn()) {
|
if (Db::getInstance()->execute('select count(*) from users where login = ? or email = ?', [$login, $email])->fetchColumn()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Db::getInstance()->execute('insert into users (login,pass,email,borndate,ip,session_id,shadow) values (?,?,?,?,?,?,?)',
|
Db::getInstance()->execute(
|
||||||
[$login, $password, $email, $birthday, $_SERVER['REMOTE_ADDR'], session_id(), '0.png']);
|
'insert into users (login,pass,email,borndate,ip,session_id,shadow) values (?,?,?,?,?,?,?)',
|
||||||
|
[$login, $password, $email, $birthday, $_SERVER['REMOTE_ADDR'], session_id(), '0.png']
|
||||||
|
);
|
||||||
$userId = Db::getInstance()->lastInsertId();
|
$userId = Db::getInstance()->lastInsertId();
|
||||||
Db::getInstance()->execute('insert into online (user_id, login_time, room, real_time) values (?,?,1,?)', [$userId, time(), time()]);
|
Db::getInstance()->execute('insert into online (user_id, login_time, room, real_time) values (?,unix_timestamp(),1,unix_timestamp())', $userId);
|
||||||
Db::getInstance()->execute('insert into bank (user_id) values ?', $userId);
|
Db::getInstance()->execute('insert into bank (user_id) values ?', $userId);
|
||||||
return $userId;
|
return $userId;
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ class Travel
|
|||||||
* Соответствие ID комнаты игровому файлу.
|
* Соответствие ID комнаты игровому файлу.
|
||||||
* @var string[]
|
* @var string[]
|
||||||
*/
|
*/
|
||||||
public static $roomFileName = [
|
public static array $roomFileName = [
|
||||||
1 => 'main.php',
|
1 => 'main.php',
|
||||||
20 => 'city.php',
|
20 => 'city.php',
|
||||||
21 => 'city.php',
|
21 => 'city.php',
|
||||||
@ -98,7 +98,7 @@ class Travel
|
|||||||
*/
|
*/
|
||||||
public static function toRoom(int $roomId, int $roomIdCurrent): void
|
public static function toRoom(int $roomId, int $roomIdCurrent): void
|
||||||
{
|
{
|
||||||
UserStats::getInstance()->
|
//UserStats::getInstance()->
|
||||||
$itemsWeightOverflow = Db::getInstance()->fetchColumn('SELECT SUM(weight) - (select strength * 4 from users where id = ?) AS weight_overflow FROM inventory WHERE owner_id = ? AND on_sale = 0', [$_SESSION['uid'], $_SESSION['uid']]);
|
$itemsWeightOverflow = Db::getInstance()->fetchColumn('SELECT SUM(weight) - (select strength * 4 from users where id = ?) AS weight_overflow FROM inventory WHERE owner_id = ? AND on_sale = 0', [$_SESSION['uid'], $_SESSION['uid']]);
|
||||||
$eff = Db::getInstance()->fetchColumn('SELECT type FROM users_effects WHERE owner_id = ? AND (`type` = 10 OR `type` = 13 OR `type` = 14)', $_SESSION['uid']);
|
$eff = Db::getInstance()->fetchColumn('SELECT type FROM users_effects WHERE owner_id = ? AND (`type` = 10 OR `type` = 13 OR `type` = 14)', $_SESSION['uid']);
|
||||||
$errors = [];
|
$errors = [];
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
namespace Battles;
|
namespace Battles;
|
||||||
trait UserEffects
|
trait UserEffects
|
||||||
{
|
{
|
||||||
public static $effectName = [
|
public static array $effectName = [
|
||||||
2 => 'Заклинание молчания',
|
2 => 'Заклинание молчания',
|
||||||
3 => 'Заклятие форумного молчания',
|
3 => 'Заклятие форумного молчания',
|
||||||
4 => 'Заклятие хаоса',
|
4 => 'Заклятие хаоса',
|
||||||
@ -50,7 +50,7 @@ trait UserEffects
|
|||||||
9994 => 'Антидот/Путы (Эликсир?)',
|
9994 => 'Антидот/Путы (Эликсир?)',
|
||||||
];
|
];
|
||||||
|
|
||||||
public static $effectImage = [
|
public static array $effectImage = [
|
||||||
1 => 'travma.gif',
|
1 => 'travma.gif',
|
||||||
2 => 'magic/sleep.gif',
|
2 => 'magic/sleep.gif',
|
||||||
3 => 'magic/sleepf.gif',
|
3 => 'magic/sleepf.gif',
|
||||||
|
@ -17,6 +17,7 @@ class UserStats extends User
|
|||||||
protected $health;
|
protected $health;
|
||||||
protected $mana;
|
protected $mana;
|
||||||
protected $free_stat_points;
|
protected $free_stat_points;
|
||||||
|
private Models\UserStats $db;
|
||||||
private const STAT_MAXIMUM_AMOUNT = 40;
|
private const STAT_MAXIMUM_AMOUNT = 40;
|
||||||
private const ERROR_STAT_IS_MAXIMUM = 'Ошибка: Параметр достиг своего лимита!';
|
private const ERROR_STAT_IS_MAXIMUM = 'Ошибка: Параметр достиг своего лимита!';
|
||||||
private const ERROR_STAT_UNKNOWN = 'Ошибка: Неизвестный параметр!';
|
private const ERROR_STAT_UNKNOWN = 'Ошибка: Неизвестный параметр!';
|
||||||
@ -87,6 +88,8 @@ class UserStats extends User
|
|||||||
} else {
|
} else {
|
||||||
$query = "UPDATE users SET {$stat_name} = {$stat_name} + 1, free_stat_points = free_stat_points - 1 WHERE id = ?";
|
$query = "UPDATE users SET {$stat_name} = {$stat_name} + 1, free_stat_points = free_stat_points - 1 WHERE id = ?";
|
||||||
Db::getInstance()->execute($query, $this->id);
|
Db::getInstance()->execute($query, $this->id);
|
||||||
|
//$this->db = new \Battles\Models\UserStats(23);
|
||||||
|
$this->db->addPoint($stat_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,51 +164,7 @@ class UserStats extends User
|
|||||||
|
|
||||||
public function getFullStats(): object
|
public function getFullStats(): object
|
||||||
{
|
{
|
||||||
$stats = Db::getInstance()->ofetch("
|
return (new Models\UserStats($this->id))->getFull();
|
||||||
select
|
|
||||||
strength,
|
|
||||||
dexterity,
|
|
||||||
intuition,
|
|
||||||
endurance,
|
|
||||||
intelligence,
|
|
||||||
wisdom
|
|
||||||
from users where id = $this->id");
|
|
||||||
$itemBonuses = Db::getInstance()->ofetch("
|
|
||||||
select
|
|
||||||
sum(add_strength) as item_strength,
|
|
||||||
sum(add_dexterity) as item_dexterity,
|
|
||||||
sum(add_intuition) as item_intuition,
|
|
||||||
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 = Db::getInstance()->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
|
||||||
@ -222,6 +181,7 @@ class UserStats extends User
|
|||||||
*/
|
*/
|
||||||
private function saveStats()
|
private function saveStats()
|
||||||
{
|
{
|
||||||
|
//$this->db->save();
|
||||||
$query = 'update users set strength = ?, dexterity = ?, intuition = ?, endurance = ?,
|
$query = 'update users set strength = ?, dexterity = ?, intuition = ?, endurance = ?,
|
||||||
intelligence = ?, wisdom = ?, health = ?, mana = ?, free_stat_points = ?,
|
intelligence = ?, wisdom = ?, health = ?, mana = ?, free_stat_points = ?,
|
||||||
level = ? where id = ?';
|
level = ? where id = ?';
|
||||||
|
BIN
databases/battle.logs.db
Normal file
BIN
databases/battle.logs.db
Normal file
Binary file not shown.
@ -7,7 +7,6 @@
|
|||||||
|
|
||||||
use Battles\Chat;
|
use Battles\Chat;
|
||||||
use Battles\Database\Db;
|
use Battles\Database\Db;
|
||||||
use Battles\DressedItems;
|
|
||||||
use Battles\InventoryItem;
|
use Battles\InventoryItem;
|
||||||
use Battles\Travel;
|
use Battles\Travel;
|
||||||
use Battles\User;
|
use Battles\User;
|
||||||
@ -25,7 +24,11 @@ if (User::getInstance()->getBlock()) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Проверки на соответствие скрипта и комнаты, которые были натыканы по всем файлам.
|
//Проверки на соответствие скрипта и комнаты, которые были натыканы по всем файлам.
|
||||||
Travel::roomRedirects(User::getInstance()->getRoom(), User::getInstance()->getBattle(), User::getInstance()->getInTower());
|
Travel::roomRedirects(
|
||||||
|
User::getInstance()->getRoom(),
|
||||||
|
User::getInstance()->getBattle(),
|
||||||
|
User::getInstance()->getInTower()
|
||||||
|
);
|
||||||
|
|
||||||
///*
|
///*
|
||||||
// * Проверки на соответствие скрипта и комнаты, которые были натыканы по всем файлам.
|
// * Проверки на соответствие скрипта и комнаты, которые были натыканы по всем файлам.
|
||||||
@ -220,7 +223,7 @@ function showhrefmagic(array $dress): string
|
|||||||
return $r;
|
return $r;
|
||||||
}
|
}
|
||||||
|
|
||||||
function timeOut($ttm)
|
function timeOut($ttm): string
|
||||||
{
|
{
|
||||||
$out = '';
|
$out = '';
|
||||||
$time_still = $ttm;
|
$time_still = $ttm;
|
||||||
@ -281,7 +284,7 @@ function addActions($time, $vars, $vls, $uid)
|
|||||||
return $ins;
|
return $ins;
|
||||||
}
|
}
|
||||||
|
|
||||||
// использовать магию
|
// использовать магию (встроить в предмет?)
|
||||||
function usemagic($id, $target)
|
function usemagic($id, $target)
|
||||||
{
|
{
|
||||||
$user = Db::getInstance()->fetch('select * from users where id = ?', $_SESSION['uid']);
|
$user = Db::getInstance()->fetch('select * from users where id = ?', $_SESSION['uid']);
|
||||||
|
Loading…
Reference in New Issue
Block a user