Compare commits

...

2 Commits
master ... dev

15 changed files with 393 additions and 251 deletions

View File

@ -10,6 +10,7 @@ namespace Battles;
use Exceptions\GameException;
use Battles\Database\Db;
use Throwable;
use Battles\Models\BankModel;
class Bank
{
@ -17,15 +18,20 @@ class Bank
private int $money = 0;
private $user;
const ERROR_NO_MONEY_IN_WALLET = "Ошибка! Нет денег в кошельке!";
const ERROR_NO_BANK_ACCOUNT = "Ошибка! Счёта не существует!";
const ERROR_NO_MONEY_IN_BANK_ACCOUNT = "Ошибка! Нет денег на счету!";
const ERROR_WRONG_AMOUNT = "Ошибка! Сумма должна быть положительной!";
const LOG = [
'sendMoney' => 'Банк: Перевод средств на другой счёт.',
'receiveMoney' => 'Банк: Получение средств.',
'depositMoney' => 'Пополнение счёта.',
'withdrawMoney' => 'Снятие денег со счёта.',
private const ERROR_NO_MONEY_IN_WALLET = "Ошибка! Нет денег в кошельке!";
private const ERROR_NO_BANK_ACCOUNT = "Ошибка! Счёта не существует!";
private const ERROR_NO_MONEY_IN_BANK_ACCOUNT = "Ошибка! Нет денег на счету!";
private const ERROR_WRONG_AMOUNT = "Ошибка! Сумма должна быть положительной!";
private const MINIMUM_COMISSION_VALUE = 1;
private const OPERATION_SEND_MONEY = 'sendMoney';
private const OPERATION_DEPOSIT_MONEY = 'depositMoney';
private const OPERATION_RECEIVE_MONEY = 'receiveMoney';
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' => 'Оплата стоимости регистрации клана.',
'sellShop' => 'Продажа товара в магазине.'
];
@ -51,11 +57,7 @@ class Bank
private function bankCommission(int $amount): int
{
$bankCommission = round($amount * GameConfigs::BANK_COMISSION);
if ($bankCommission < 1) {
return 1;
} else {
return (int)$bankCommission;
}
return $bankCommission >= self::MINIMUM_COMISSION_VALUE ? (int)$bankCommission : self::MINIMUM_COMISSION_VALUE;
}
/**
@ -64,25 +66,25 @@ class Bank
* @param int $receiverId ID получателя.
* @param int $amount сумма.
* @param string $operationType тип банковской операции.
* @param int $senderId ID отправителя (ID игрока, если не указано иное).
* @param ?int $senderId ID отправителя (ID игрока, если не указано иное).
*
* @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)) {
$senderId = $this->user_id;
}
$text = self::LOG[$operationType];
if ($operationType == "sendMoney") {
if ($operationType == self::OPERATION_SEND_MONEY) {
$text .= " Комиссия: " . $this->bankCommission($amount);
} elseif ($operationType == "depositMoney") {
} elseif ($operationType == self::OPERATION_DEPOSIT_MONEY) {
$receiverId = $this->user_id;
} elseif ($operationType == "withdrawMoney") {
} elseif ($operationType == self::OPERATION_WITHDRAW_MONEY) {
$receiverId = $this->user_id;
$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;
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;
self::setBankMoney($receiverWallet->money, $receiver);
$this->bankLogs($receiver, $receiverWallet->money, "receiveMoney");
$this->bankLogs($receiver, $receiverWallet->money, self::OPERATION_RECEIVE_MONEY);
// Возвращаем изменившиеся значения
return $this->money;
}
@ -142,7 +144,7 @@ class Bank
// Отдаём сумму на счёт получателю
$this->money += $amount;
self::setBankMoney($this->money, $this->user_id);
$this->bankLogs(0, $this->money, "depositMoney");
$this->bankLogs(0, $this->money, self::OPERATION_DEPOSIT_MONEY);
// Возвращаем изменившиеся значения
return [
'walletMoney' => $this->user->money,
@ -170,7 +172,7 @@ class Bank
// Снимаем сумму с комиссией у отправителя
$this->money -= $amountWithComission;
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;
self::setWalletMoney($this->user['money'], $this->user_id);
@ -185,15 +187,16 @@ class Bank
* Установить количество денег на банковском счету.
*
* @param int $amount сумма.
* @param int $user_id ID пользователя.
* @param int $uid ID пользователя.
* @param string $operationType Тип операции. По умолчанию пусто. Если ввести, система запишет событие в банковский лог.
*
* @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 {
Db::getInstance()->execute('UPDATE bank SET money = ? WHERE user_id = ?', [$amount, $user_id]);
$bm->setMoney($amount, $uid);
if ($operationType) {
GameLogs::addBankLog(0, 0, $amount, $operationType, self::LOG[$operationType]);
}
@ -207,14 +210,14 @@ class Bank
* Установить количество денег на руках.
*
* @param int $amount сумма.
* @param int $user_id ID пользователя.
* @param int $uid ID пользователя.
*
* @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($user_id)->saveMoney();
User::getInstance($uid)->setMoney($amount);
User::getInstance($uid)->saveMoney();
}
public function getMoney(): int

View File

@ -1,9 +1,11 @@
<?php
# Date: 26.10.2020 (17:56)
namespace Battles;
class City
{
use Rooms;
public static function showStreet(int $id)
{
if ($id === 20) {
@ -17,8 +19,7 @@ class City
self::showBuilding(9, "winter_cap_tree2", 215, 500, self::$roomNames[44]) .
self::showBuilding(13, "spring_cap_statue", 222, 365, self::$roomNames[24]) .
self::showBuilding(14, "winter_cap_statue", 210, 390, "Снеговик") .
self::showBuilding(222, "cap_arr_top", 180, 650, "Торговая улица") .
'</div>';
self::showBuilding(222, "cap_arr_top", 180, 650, "Торговая улица");
} elseif ($id === 21) {
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, "Ристалище") .
@ -26,15 +27,13 @@ class City
self::showBuilding(5, "spring_cap_bank", 180, 485, self::$roomNames[29]) .
self::showBuilding(13, "spring_cap_flowershop", 220, 613, self::$roomNames[34]) .
self::showBuilding(14, "spring_cap_registratura", 170, 113, self::$roomNames[30]) .
self::showBuilding(16, "spring_cap_tower", 5, 315, self::$roomNames[31]) .
'</div>';
self::showBuilding(16, "spring_cap_tower", 5, 315, self::$roomNames[31]);
} elseif ($id === 26) {
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(4, "cap_arr_right", 259, 715, self::$roomNames[20]) .
self::showBuilding(6, "cap_gate", 170, 340, "Городские ворота") .
self::showBuilding(660, "spring_cap_vokzal", 163, 43, self::$roomNames[661]) .
'</div>';
self::showBuilding(660, "spring_cap_vokzal", 163, 43, self::$roomNames[661]);
} elseif ($id === 2601) {
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, "Руины Старого замка") .
@ -42,43 +41,42 @@ class City
self::showBuilding(10, "ava_post", 240, 300, self::$roomNames[35]) .
self::showBuilding(55, "cap_arr_left", 258, 21, self::$roomNames[2655]) .
self::showBuilding(1051, "spring_cap_lab", 130, 327, self::$roomNames[33]) .
self::showBuilding(1052, "spring_cap_lavka", 240, 425, self::$roomNames[1053]) .
'</div>';
self::showBuilding(1052, "spring_cap_lavka", 240, 425, self::$roomNames[1053]);
} elseif ($id === 2655) {
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(2055, "altr_g", 230, 340, self::$roomNames[603]) .
'</div>';
self::showBuilding(2055, "altr_g", 230, 340, self::$roomNames[603]);
} elseif ($id === 2111) {
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(14, "spring_cap_rist_solo", 210, 160, "Вход в Одиночные сражения") .
self::showBuilding(14, "spring_cap_rist_group", 243, 340, "Вход в Сражение отрядов") .
self::showBuilding(203, "spring_cap_rist_monstr", 145, 570, "Вход в Груповые сражения") .
self::showBuilding(1000, "av_zamk_rud", 80, 310, self::$roomNames[1001]) .
'</div>';
self::showBuilding(1000, "av_zamk_rud", 80, 310, self::$roomNames[1001]);
} elseif ($id === 2701) {
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(2, "cap_shar_dark", 234, 356, "Лабиринт Хаоса") .
'</div>';
self::showBuilding(2, "cap_shar_dark", 234, 356, "Лабиринт Хаоса");
} elseif ($id === 2702) {
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(10, "cap_rist_arr_left", 259, 25, self::$roomNames[20]) .
self::showBuilding(16, "auk", 120, 300, "Аукцион") .
self::showBuilding(21, "spring_cap_build2", 150, 565, "Ломбард") .
self::showBuilding(16555, "spring_cap_build3", 155, 480, "Прокатная лавка") .
'</div>';
self::showBuilding(16555, "spring_cap_build3", 155, 480, "Прокатная лавка");
}
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('
<div style="position:absolute; left:%spx; top:%spx; 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\'">
</div>',
$left, $top, $image, $description, $description, $id, $id);
return <<<HTML
<div style="position:absolute; left:{$left}px; top:{$top}px; z-index:90; cursor: pointer;">
<img src="/i/city/sub/$image.png" alt="$description" title="$description" class="building" id="$id"
onclick="window.location.href = 'city.php?got/level$id'">
</div>
HTML;
}
}

View File

@ -131,7 +131,7 @@ class Item
$mods_cost_modifier = 2 + floor($sum_mods / 50);
$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);
return $result < 1 ? 1 : $result;
return max($result, 1);
}
protected function wrap(int $number): string

View 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();
}
}

View 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);
}
}

View 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();
}
}

View File

@ -54,13 +54,13 @@ class Moderation
public static function blockUser(int $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)
{
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)

View File

@ -11,10 +11,12 @@ class Register
if (Db::getInstance()->execute('select count(*) from users where login = ? or email = ?', [$login, $email])->fetchColumn()) {
return 0;
}
Db::getInstance()->execute('insert into users (login,pass,email,borndate,ip,session_id,shadow) values (?,?,?,?,?,?,?)',
[$login, $password, $email, $birthday, $_SERVER['REMOTE_ADDR'], session_id(), '0.png']);
Db::getInstance()->execute(
'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();
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);
return $userId;
}

View File

@ -10,7 +10,7 @@ class Travel
* Соответствие ID комнаты игровому файлу.
* @var string[]
*/
public static $roomFileName = [
public static array $roomFileName = [
1 => 'main.php',
20 => 'city.php',
21 => 'city.php',
@ -98,7 +98,7 @@ class Travel
*/
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']]);
$eff = Db::getInstance()->fetchColumn('SELECT type FROM users_effects WHERE owner_id = ? AND (`type` = 10 OR `type` = 13 OR `type` = 14)', $_SESSION['uid']);
$errors = [];

View File

@ -4,7 +4,7 @@
namespace Battles;
trait UserEffects
{
public static $effectName = [
public static array $effectName = [
2 => 'Заклинание молчания',
3 => 'Заклятие форумного молчания',
4 => 'Заклятие хаоса',
@ -50,7 +50,7 @@ trait UserEffects
9994 => 'Антидот/Путы (Эликсир?)',
];
public static $effectImage = [
public static array $effectImage = [
1 => 'travma.gif',
2 => 'magic/sleep.gif',
3 => 'magic/sleepf.gif',

View File

@ -17,6 +17,7 @@ class UserStats extends User
protected $health;
protected $mana;
protected $free_stat_points;
private Models\UserStats $db;
private const STAT_MAXIMUM_AMOUNT = 40;
private const ERROR_STAT_IS_MAXIMUM = 'Ошибка: Параметр достиг своего лимита!';
private const ERROR_STAT_UNKNOWN = 'Ошибка: Неизвестный параметр!';
@ -87,6 +88,8 @@ class UserStats extends User
} else {
$query = "UPDATE users SET {$stat_name} = {$stat_name} + 1, free_stat_points = free_stat_points - 1 WHERE 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
{
$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($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;
return (new Models\UserStats($this->id))->getFull();
}
public function levelUp(): string
@ -222,6 +181,7 @@ class UserStats extends User
*/
private function saveStats()
{
//$this->db->save();
$query = 'update users set strength = ?, dexterity = ?, intuition = ?, endurance = ?,
intelligence = ?, wisdom = ?, health = ?, mana = ?, free_stat_points = ?,
level = ? where id = ?';

View File

@ -323,7 +323,7 @@ class fbattle
$this->damage[$enemy] += ($mf['he']['udar'] * $hs);
$jv = ($this->user['hp'] - $mf['he']['udar'] * $hs);
$this->exp[$enemy] += SolveExp($enemy, $this->user['id'], $mf['he']['udar'] * $hs);
$this->exp[$enemy] += self::SolveExp($enemy, $this->user['id'], $mf['he']['udar'] * $hs);
$this->add_log($this->razmen_log("krit" . $m, $this->battle[$enemy][$this->user['id']][0], $this->get_wep_type($this->enemyhar['weap']), ($mf['he']['udar'] * $hs), $enemy, $this->en_class, $this->user['id'], $this->my_class, ($this->user['hp'] - $mf['he']['udar'] * $hs), $this->user['maxhp']));
mysql_query('UPDATE users SET `hp` = `hp` - ' . ($mf['he']['udar'] * $hs) . ' WHERE `id` = ' . $this->user['id'] . '');
@ -332,7 +332,7 @@ class fbattle
$this->damage[$enemy] += ($mf['he']['udar']);
$jv = ($this->user['hp'] - $mf['he']['udar']);
$this->exp[$enemy] += SolveExp($enemy, $this->user['id'], $mf['he']['udar']);
$this->exp[$enemy] += self::SolveExp($enemy, $this->user['id'], $mf['he']['udar']);
$this->add_log($this->razmen_log("udar", $this->battle[$enemy][$this->user['id']][0], $this->get_wep_type($this->enemyhar['weap']), $mf['he']['udar'], $enemy, $this->en_class, $this->user['id'], $this->my_class, ($this->user['hp'] - $mf['he']['udar']), $this->user['maxhp']));
mysql_query('UPDATE users SET `hp` = `hp` - ' . ($mf['he']['udar']) . ' WHERE `id` = ' . $this->user['id'] . '');
@ -370,7 +370,7 @@ class fbattle
}
$this->damage[$this->user['id']] += ($mf['me']['udar'] * $hs);
$this->exp[$this->user['id']] += SolveExp($this->user['id'], $enemy, $mf['me']['udar'] * $hs);
$this->exp[$this->user['id']] += self::SolveExp($this->user['id'], $enemy, $mf['me']['udar'] * $hs);
$this->add_log($this->razmen_log("krit" . $m, $attack, $this->get_wep_type($this->user['weap']), ($mf['me']['udar'] * $hs), $this->user['id'], $this->my_class, $enemy, $this->en_class, ($this->enemyhar['hp'] - $mf['me']['udar'] * $hs), $this->enemyhar['maxhp']));
if ($enemy > _BOTSEPARATOR_) {
@ -382,7 +382,7 @@ class fbattle
// я попал куда надо
$this->damage[$this->user['id']] += ($mf['me']['udar']);
$this->exp[$this->user['id']] += SolveExp($this->user['id'], $enemy, $mf['me']['udar']);
$this->exp[$this->user['id']] += self::SolveExp($this->user['id'], $enemy, $mf['me']['udar']);
$this->add_log($this->razmen_log("udar", $attack, $this->get_wep_type($this->user['weap']), $mf['me']['udar'], $this->user['id'], $this->my_class, $enemy, $this->en_class, ($this->enemyhar['hp'] - $mf['me']['udar']), $this->enemyhar['maxhp']));
if ($enemy > _BOTSEPARATOR_) {
@ -1982,4 +1982,134 @@ class fbattle
fclose($fp); //закрытие
}
public static function SolveExp($at_id, $def_id, $damage): float
{
$mods = [
'bloodb' => 1.2,
'btl_1' => 1,
'btl_2' => 0.5,
'btl_3' => 0.05,
];
$baseexp = [
"0" => "2",
"1" => "5",
"2" => "10",
"3" => "15",
"4" => "30",
"5" => "60",
"6" => "90",
"7" => "115",
"8" => "300",
"9" => "400",
"10" => "500",
"11" => "600",
"12" => "700",
"13" => "800",
"14" => "900",
"15" => "1000",
"16" => "1100",
"17" => "1200",
"18" => "1300",
"19" => "1400",
"20" => "1500",
"21" => "1600",
];
$expmf = 0;
$bot_active = false;
$bot_def = false;
if ($at_id > _BOTSEPARATOR_) {
$at_id = Db::getInstance()->fetchColumn('select prototype from bots where bot_id = ?', $at_id);
$bot_active = true;
}
$query = 'select greatest(1, sum(price)) as allprice from users left join inventory on users.id = inventory.owner_id where id = ?';
$atAllPrice = Db::getInstance()->fetchColumn($query, $at_id);
$defAllPrice = Db::getInstance()->fetchColumn($query, $def_id);
$atInfo = new UserStats($at_id);
$defInfo = new UserStats($def_id);
$table_name = $at_id > _BOTSEPARATOR_ ? 'bots' : 'users';
$bt = Db::getInstance()->ofetch('select blood, type, t1, t2 from battle where battle_id = (select battle from ? where id = ?)', [$table_name, $at_id]);
if ($def_id > _BOTSEPARATOR_) {
$def_id = Db::getInstance()->fetchColumn('select prototype from bots where bot_id = ?', $def_id);
$bot_def = true;
}
if ($bt->blood) {
$expmf = $mods['bloodb'];
}
$filebtl = '/tmp/' . $at_id . '.btl';
if ($bt->type == 1 && file_exists($filebtl)) {
$btfl = fopen($filebtl, 'r');
$contents = fread($btfl, filesize($filebtl));
fclose($btfl);
$cnt = substr_count($contents, $def_id);
$exmod = 1;
if ($cnt <= 1) {
$exmod = $mods['btl_1'];
} elseif ($cnt == 2) {
$exmod = $mods['btl_2'];
} elseif ($cnt > 2) {
$exmod = $mods['btl_3'];
}
$expmf = $expmf * $exmod;
}
$standart = [
"0" => 1,
"1" => 1,
"2" => 15,
"3" => 111,
"4" => 265,
"5" => 526,
"6" => 882,
"7" => 919,
"8" => 919,
"9" => 919,
"10" => 919,
"11" => 919,
"12" => 919,
"13" => 919,
"14" => 919,
"15" => 919,
"16" => 919,
"17" => 919,
"18" => 919,
"19" => 919,
"20" => 919,
"21" => 919,
"22" => 919,
"23" => 919,
"24" => 919,
"25" => 919
];
$mfit = ($atAllPrice / ($standart[$atInfo->getLevel()] / 3));
if ($mfit < 0.8) {
$mfit = 0.8;
}
if ($mfit > 1.5) {
$mfit = 1.5;
}
$pls = count(explode(";", $bt->t1)) + count(explode(";", $bt->t2));
if ($pls > 2) {
$mfbot = $bot_active ? 0.3 : 1;
$mfbot2 = $bot_def ? 0.7 : 1;
} else {
$mfbot = 1;
$mfbot2 = 1;
}
if ($expmf == 0) {
$expmf = 1;
}
return round((($baseexp[$defInfo->getLevel()]) * ($defAllPrice / (($atAllPrice + $defAllPrice) / 2)) * ($damage / $defInfo->getMaxHealth()) * $expmf * $mfit * $mfbot * $mfbot2) / 3);
}
}

View File

@ -779,7 +779,7 @@ class fbattle
}
$this->damage[$enemy] += $yron;
$jv = ($hp_1['hp'] - $yron);
$this->exp[$enemy] += SolveExp($enemy, $uid, $yron);
$this->exp[$enemy] += fbattle::SolveExp($enemy, $uid, $yron);
$this->AddToLogBot($this->razmen_log("krit" . $m, $this->battle[$enemy][$uid][0], $this->GetWeaponType($this->enemyhar['weap']), $yron, $enemy, $color['he'], $uid, $color['me'], ($hp_1['hp'] - $yron), $maxhp_2['maxhp']));
mysql_query('UPDATE `bots` SET `hp` = (`hp` - ' . $yron . ') WHERE `id` = "' . $uid . '" LIMIT 1'); ### Maybe not limited
} elseif (!$this->GetBlock("me", $this->battle[$enemy][$uid][0], $defend, $enemy)) {
@ -922,7 +922,7 @@ class fbattle
$this->damage[$enemy] += $yron;
$jv = ($this->user['hp'] - $yron);
$this->exp[$enemy] += SolveExp($enemy, $this->user['id'], $yron);
$this->exp[$enemy] += fbattle::SolveExp($enemy, $this->user['id'], $yron);
$this->AddToLog($this->razmen_log("krit" . $m, $this->battle[$this->user['id']][$enemy][0], $this->GetWeaponType($this->enemyhar['weap']), $yron, $enemy, $color['me'], $this->user['id'], $color['he'], ($this->user['hp'] - $yron), $this->user['maxhp']));
mysql_query('UPDATE `users` SET `hp` = (`hp` - ' . $yron . ') WHERE `id` = "' . $this->user['id'] . '" LIMIT 1');
@ -948,7 +948,7 @@ class fbattle
$this->damage[$enemy] += $yron;
$jv = ($this->user['hp'] - $yron);
$this->exp[$enemy] += SolveExp($enemy, $this->user['id'], $yron);
$this->exp[$enemy] += fbattle::SolveExp($enemy, $this->user['id'], $yron);
$this->AddToLog($this->razmen_log("udar", $this->battle[$enemy][$this->user['id']][0], $this->GetWeaponType($this->enemyhar['weap']), $yron, $enemy, $color['me'], $this->user['id'], $color['he'], ($this->user['hp'] - $yron), $this->user['maxhp']));
mysql_query('UPDATE `users` SET `hp` = (`hp` - ' . $yron . ') WHERE `id` = "' . $this->user['id'] . '" LIMIT 1');
} else {
@ -998,7 +998,7 @@ class fbattle
}
$this->damage[$this->user['id']] += $yron;
$this->exp[$this->user['id']] += SolveExp($this->user['id'], $enemy, $yron);
$this->exp[$this->user['id']] += fbattle::SolveExp($this->user['id'], $enemy, $yron);
$this->AddToLog($this->razmen_log("krit" . $m, $attack, $this->GetWeaponType($this->user['weap']), $yron, $this->user['id'], $color['me'], $enemy, $color['he'], ($this->enemyhar['hp'] - $yron), $this->enemyhar['maxhp']));
if ($enemy > _BOTSEPARATOR_) {
@ -1030,7 +1030,7 @@ class fbattle
$yron = $hp_u['hp'];
}
$this->damage[$this->user['id']] += $yron;
$this->exp[$this->user['id']] += SolveExp($this->user['id'], $enemy, $yron);
$this->exp[$this->user['id']] += fbattle::SolveExp($this->user['id'], $enemy, $yron);
$this->AddToLog($this->razmen_log("udar", $attack, $this->GetWeaponType($this->user['weap']), $yron, $this->user['id'], $color['me'], $enemy, $color['he'], ($this->enemyhar['hp'] - $yron), $this->enemyhar['maxhp']));
if ($enemy > _BOTSEPARATOR_) {

BIN
databases/battle.logs.db Normal file

Binary file not shown.

View File

@ -7,7 +7,6 @@
use Battles\Chat;
use Battles\Database\Db;
use Battles\DressedItems;
use Battles\InventoryItem;
use Battles\Travel;
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;
}
function timeOut($ttm)
function timeOut($ttm): string
{
$out = '';
$time_still = $ttm;
@ -281,7 +284,7 @@ function addActions($time, $vars, $vls, $uid)
return $ins;
}
// использовать магию
// использовать магию (встроить в предмет?)
function usemagic($id, $target)
{
$user = Db::getInstance()->fetch('select * from users where id = ?', $_SESSION['uid']);
@ -391,134 +394,4 @@ function addchp($text, $who, $room = 0)
function err($t)
{
echo '<span class="error">' . $t . '</span>';
}
function SolveExp($at_id, $def_id, $damage): float
{
$mods = [
'bloodb' => 1.2,
'btl_1' => 1,
'btl_2' => 0.5,
'btl_3' => 0.05,
];
$baseexp = [
"0" => "2",
"1" => "5",
"2" => "10",
"3" => "15",
"4" => "30",
"5" => "60",
"6" => "90",
"7" => "115",
"8" => "300",
"9" => "400",
"10" => "500",
"11" => "600",
"12" => "700",
"13" => "800",
"14" => "900",
"15" => "1000",
"16" => "1100",
"17" => "1200",
"18" => "1300",
"19" => "1400",
"20" => "1500",
"21" => "1600",
];
$expmf = 0;
$bot_active = false;
$bot_def = false;
if ($at_id > _BOTSEPARATOR_) {
$at_id = Db::getInstance()->fetchColumn('select prototype from bots where bot_id = ?', $at_id);
$bot_active = true;
}
$query = 'select greatest(1, sum(price)) as allprice from users left join inventory on users.id = inventory.owner_id where id = ?';
$atAllPrice = Db::getInstance()->fetchColumn($query, $at_id);
$defAllPrice = Db::getInstance()->fetchColumn($query, $def_id);
$atInfo = new UserStats($at_id);
$defInfo = new UserStats($def_id);
$table_name = $at_id > _BOTSEPARATOR_ ? 'bots' : 'users';
$bt = Db::getInstance()->ofetch('select blood, type, t1, t2 from battle where battle_id = (select battle from ? where id = ?)', [$table_name, $at_id]);
if ($def_id > _BOTSEPARATOR_) {
$def_id = Db::getInstance()->fetchColumn('select prototype from bots where bot_id = ?', $def_id);
$bot_def = true;
}
if ($bt->blood) {
$expmf = $mods['bloodb'];
}
$filebtl = '/tmp/' . $at_id . '.btl';
if ($bt->type == 1 && file_exists($filebtl)) {
$btfl = fopen($filebtl, 'r');
$contents = fread($btfl, filesize($filebtl));
fclose($btfl);
$cnt = substr_count($contents, $def_id);
$exmod = 1;
if ($cnt <= 1) {
$exmod = $mods['btl_1'];
} elseif ($cnt == 2) {
$exmod = $mods['btl_2'];
} elseif ($cnt > 2) {
$exmod = $mods['btl_3'];
}
$expmf = $expmf * $exmod;
}
$standart = [
"0" => 1,
"1" => 1,
"2" => 15,
"3" => 111,
"4" => 265,
"5" => 526,
"6" => 882,
"7" => 919,
"8" => 919,
"9" => 919,
"10" => 919,
"11" => 919,
"12" => 919,
"13" => 919,
"14" => 919,
"15" => 919,
"16" => 919,
"17" => 919,
"18" => 919,
"19" => 919,
"20" => 919,
"21" => 919,
"22" => 919,
"23" => 919,
"24" => 919,
"25" => 919
];
$mfit = ($atAllPrice / ($standart[$atInfo->getLevel()] / 3));
if ($mfit < 0.8) {
$mfit = 0.8;
}
if ($mfit > 1.5) {
$mfit = 1.5;
}
$pls = count(explode(";", $bt->t1)) + count(explode(";", $bt->t2));
if ($pls > 2) {
$mfbot = $bot_active ? 0.3 : 1;
$mfbot2 = $bot_def ? 0.7 : 1;
} else {
$mfbot = 1;
$mfbot2 = 1;
}
if ($expmf == 0) {
$expmf = 1;
}
return round((($baseexp[$defInfo->getLevel()]) * ($defAllPrice / (($atAllPrice + $defAllPrice) / 2)) * ($damage / $defInfo->getMaxHealth()) * $expmf * $mfit * $mfbot * $mfbot2) / 3);
}