Browse Source

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	admin/admin.php
#	classes/Battles/User.php
#	classes/Battles/UserStats.php
#	fbattle.php
#	functions.php
master
lopar 2 months ago
parent
commit
b1f578f4b0
  1. 233
      admin/NewItem.php
  2. 109
      admin/admin.php
  3. 2
      c_haos.php
  4. 2
      chat.php
  5. 49
      classes/Battles/Admin/Clan.php
  6. 49
      classes/Battles/Admin/Item.php
  7. 20
      classes/Battles/Admin/User.php
  8. 10
      classes/Battles/Chat.php
  9. 40
      classes/Battles/DressedItems.php
  10. 7
      classes/Battles/Magic/CureInjury.php
  11. 29
      classes/Battles/Magic/Magic.php
  12. 3
      config.php
  13. 6
      cronjobs/cron_bots_battle.php
  14. 9
      fbattle.php
  15. 30
      functions.php
  16. 2
      towerin.php
  17. 8
      zayavka.php

233
admin/NewItem.php

@ -1,143 +1,100 @@
<?php
# Date: 31.01.2021 (20:21)
?>
<form method=post>
<div>
<table>
<caption>Добавление вещей в магазин</caption>
<tr>
<th id="main">Основное
<tr>
<td><input name="name" placeholder="Название">
<tr>
<td><input name="image" placeholder="Картинка">
<tr>
<td><select name="shop">
<option value="0" selected disabled>Тип магазина</option>
<option value="1">Обычный</option>
<option value="2">Цветной</option>
</select>
<tr>
<td><input name=count placeholder="Количество (шт.)">
<tr>
<td><select name="item_type">
<option value="0" selected disabled>Тип предмета</option>
<option value="1">Шлем</option>
<option value="2">Броня</option>
<option value="3">Поножи</option>
<option value="4">Сапоги</option>
<option value="5">Перчатки</option>
<option value="6">Оружие</option>
<option value="7">Щит</option>
<option value="8">Пояс</option>
<option value="9">Кольцо</option>
<option value="10">Амулет</option>
<option value="20">Расходник</option>
<option value="50">Всё остальное</option>
<option value="100">Хлам</option>
</select>
<tr>
<td><input name=weight placeholder="Масса">
<tr>
<td><input name=durability placeholder="Макс. износ">
<tr>
<td><input name=price placeholder="Цена (кр.)">
<tr>
<th id="needs">Требования
<tr>
<td><input name=need_level placeholder="Уровень">
<tr>
<td><input name=need_strength placeholder="Сила">
<tr>
<td><input name=need_dexterity placeholder="Ловкость">
<tr>
<td><input name=need_intuition placeholder="Интуиция">
<tr>
<td><input name=need_endurance placeholder="Выносливость">
<tr>
<td><input name=need_intelligence placeholder="Интеллект">
<tr>
<td><input name=need_wisdom placeholder="Мудрость">
<tr>
<th id="adds">Характеристики
<tr>
<td><input name=minu placeholder="Мин.урон">
<tr>
<td><input name=maxu placeholder="Макс.урон">
<tr>
<td><input name=gsila placeholder="Сила">
<tr>
<td><input name=glovk placeholder="Ловкость">
<tr>
<td><input name=ginta placeholder="Интуиция">
<tr>
<td><input name=gintel placeholder="Интеллект">
<tr>
<td><input name=ghp placeholder="НР">
<tr>
<td><input name=mfkrit placeholder="Мф.крит">
<tr>
<td><input name=mfakrit placeholder="Мф.антикрит">
<tr>
<td><input name=mfuvorot placeholder="Мф.уворот">
<tr>
<td><input name=mfauvorot placeholder="Мф.антиуворот">
<tr>
<td><input name=gnoj placeholder="Ум.ножи">
<tr>
<td><input name=gtopor placeholder="Ум.топоры">
<tr>
<td><input name=gdubina placeholder="Ум.дубины">
<tr>
<td><input name=gmech placeholder="Ум.мечи">
<tr>
<td><input name=bron1 placeholder="Броня головы">
<tr>
<td><input name=bron2 placeholder="Броня корпуса">
<tr>
<td><input name=bron3 placeholder="Броня пояса">
<tr>
<td><input name=bron4 placeholder="Броня ног">
<tr>
<td><input name=gfire placeholder="Мастерство огня">
<tr>
<td><input name=gwater placeholder="Мастерство воды">
<tr>
<td><input name=gair placeholder="Мастерство воздуха">
<tr>
<td><input name=gearth placeholder="Мастерство земли">
<tr>
<td><input name=glight placeholder="Светлая магия">
<tr>
<td><input name=ggray placeholder="Серая магия">
<tr>
<td><input name=gdark placeholder="Темная магия">
<tr>
<td><input name=encicl placeholder="В энциклопедию">
<tr>
<td><input name=magic placeholder="Наложенно заклятие">
</table>
<INPUT TYPE="submit" value="Добавить">
</div>
</form>
require_once '../config.php';
use Battles\Admin\Item;
<?php
if (isset($_POST)) {
echo "Ждём лучших времён!";
//if($_POST['razdel'] !=7) $goden_tmp=0; else */
// $goden_tmp = $_POST['goden'];
//
// if ($_POST['shop'] == 1) if (mysql_query("INSERT INTO shop(name,duration,maxdur,cost,ecost,nlevel,nsila,nlovk,ninta,nvinos,nintel,nmudra,nnoj,ntopor,ndubina,nmech,nalign,minu,maxu,goden,gsila,glovk,ginta,gintel,ghp,mfkrit,mfakrit,mfuvorot,mfauvorot,gnoj,gtopor,gdubina,gmech,img,count,bron1,bron2,bron3,bron4,magic,type,massa,needident,nfire,nwater,nair,nearth,nlight,ngray,ndark,gfire,gwater,gair,gearth,glight,ggray,gdark,encicl,artefact,letter,isrep,razdel) VALUES ('" . $_POST['name'] . "','" . $_POST['duration'] . "','" . $_POST['maxdur'] . "','" . $_POST['cost'] . "','" . $_POST['ecost'] . "','" . $_POST['nlevel'] . "','" . $_POST['nsila'] . "','" . $_POST['nlovk'] . "','" . $_POST['ninta'] . "','" . $_POST['nvinos'] . "','" . $_POST['nintel'] . "','" . $_POST['nmudra'] . "','" . $_POST['nnoj'] . "','" . $_POST['ntopor'] . "','" . $_POST['ndubina'] . "','" . $_POST['nmech'] . "','" . $_POST['nalign'] . "','" . $_POST['minu'] . "','" . $_POST['maxu'] . "','" . $goden_tmp . "','" . $_POST['gsila'] . "','" . $_POST['glovk'] . "','" . $_POST['ginta'] . "','" . $_POST['gintel'] . "','" . $_POST['ghp'] . "','" . $_POST['mfkrit'] . "','" . $_POST['mfakrit'] . "','" . $_POST['mfuvorot'] . "','" . $_POST['mfauvorot'] . "','" . $_POST['gnoj'] . "','" . $_POST['gtopor'] . "','" . $_POST['gdubina'] . "','" . $_POST['gmech'] . "','" . $_POST['img'] . "','" . $_POST['count'] . "','" . $_POST['bron1'] . "','" . $_POST['bron2'] . "','" . $_POST['bron3'] . "','" . $_POST['bron4'] . "','" . $_POST['magic'] . "','" . $_POST['type'] . "','" . $_POST['massa'] . "','" . $_POST['needident'] . "','" . $_POST['nfire'] . "','" . $_POST['nwater'] . "','" . $_POST['nair'] . "','" . $_POST['nearth'] . "','" . $_POST['nlight'] . "','" . $_POST['ngray'] . "','" . $_POST['ndark'] . "','" . $_POST['gfire'] . "','" . $_POST['gwater'] . "','" . $_POST['gair'] . "','" . $_POST['gearth'] . "','" . $_POST['glight'] . "','" . $_POST['ggray'] . "','" . $_POST['gdark'] . "','" . $_POST['encicl'] . "','0','" . $_POST['letter'] . "','" . $_POST['isrep'] . "','" . $_POST['razdel'] . "');")) {
// echo "Предмет успешно добавлен";
// } else {
// echo "Предмет не был добавлен!-1";
// };
//
// if ($_POST['shop'] == 2) if (mysql_query("INSERT INTO fshop(name,duration,maxdur,cost,ecost,nlevel,nsila,nlovk,ninta,nvinos,nintel,nmudra,nnoj,ntopor,ndubina,nmech,nalign,minu,maxu,goden,gsila,glovk,ginta,gintel,ghp,mfkrit,mfakrit,mfuvorot,mfauvorot,gnoj,gtopor,gdubina,gmech,img,count,bron1,bron2,bron3,bron4,magic,type,massa,needident,nfire,nwater,nair,nearth,nlight,ngray,ndark,gfire,gwater,gair,gearth,glight,ggray,gdark,letter,isrep,razdel) VALUES ('" . $_POST['name'] . "','" . $_POST['duration'] . "','" . $_POST['maxdur'] . "','" . $_POST['cost'] . "','" . $_POST['ecost'] . "','" . $_POST['nlevel'] . "','" . $_POST['nsila'] . "','" . $_POST['nlovk'] . "','" . $_POST['ninta'] . "','" . $_POST['nvinos'] . "','" . $_POST['nintel'] . "','" . $_POST['nmudra'] . "','" . $_POST['nnoj'] . "','" . $_POST['ntopor'] . "','" . $_POST['ndubina'] . "','" . $_POST['nmech'] . "','" . $_POST['nalign'] . "','" . $_POST['minu'] . "','" . $_POST['maxu'] . "','" . $goden_tmp . "','" . $_POST['gsila'] . "','" . $_POST['glovk'] . "','" . $_POST['ginta'] . "','" . $_POST['gintel'] . "','" . $_POST['ghp'] . "','" . $_POST['mfkrit'] . "','" . $_POST['mfakrit'] . "','" . $_POST['mfuvorot'] . "','" . $_POST['mfauvorot'] . "','" . $_POST['gnoj'] . "','" . $_POST['gtopor'] . "','" . $_POST['gdubina'] . "','" . $_POST['gmech'] . "','" . $_POST['img'] . "','" . $_POST['count'] . "','" . $_POST['bron1'] . "','" . $_POST['bron2'] . "','" . $_POST['bron3'] . "','" . $_POST['bron4'] . "','" . $_POST['magic'] . "','" . $_POST['type'] . "','" . $_POST['massa'] . "','" . $_POST['needident'] . "','" . $_POST['nfire'] . "','" . $_POST['nwater'] . "','" . $_POST['nair'] . "','" . $_POST['nearth'] . "','" . $_POST['nlight'] . "','" . $_POST['ngray'] . "','" . $_POST['ndark'] . "','" . $_POST['gfire'] . "','" . $_POST['gwater'] . "','" . $_POST['gair'] . "','" . $_POST['gearth'] . "','" . $_POST['glight'] . "','" . $_POST['ggray'] . "','" . $_POST['gdark'] . "','" . $_POST['letter'] . "','" . $_POST['isrep'] . "','" . $_POST['razdel'] . "');")) {
// echo "Предмет успешно добавлен";
// } else {
// echo "Предмет не был добавлен!" . mysql_error();
// };
//
Item::add($_POST);
}
//End item adder
?>
<form method=post>
<div>
<table>
<caption>Добавление вещей в игру</caption>
<tr>
<th id="main">Основное
<tr>
<td><input name="name" placeholder="Название">
<tr>
<td><input name="image" placeholder="Картинка">
<tr>
<td><select name="shop">
<option value="0" selected disabled>Тип магазина</option>
<option value="1">Обычный</option>
<option value="2">Цветной</option>
</select>
<tr>
<td><input name=count placeholder="Количество (шт.)" disabled>
<tr>
<td><select name="item_type">
<option value="0" selected disabled>Тип предмета</option>
<option value="1">Шлем</option>
<option value="2">Броня</option>
<option value="3">Поножи</option>
<option value="4">Сапоги</option>
<option value="5">Перчатки</option>
<option value="6">Оружие</option>
<option value="7">Щит</option>
<option value="8">Пояс</option>
<option value="9">Кольцо</option>
<option value="10">Амулет</option>
<option value="20">Расходник</option>
<option value="50">Всё остальное</option>
<option value="100">Хлам</option>
</select>
<tr>
<td><input name=weight placeholder="Масса">
<tr>
<td><input name=durability placeholder="Макс. износ">
<tr>
<td><input name=price placeholder="Цена (кр.)" disabled>
<tr>
<th id="needs">Требования
<tr>
<td><input name=need_level placeholder="Уровень">
<tr>
<td><input name=need_strength placeholder="Сила">
<tr>
<td><input name=need_dexterity placeholder="Ловкость">
<tr>
<td><input name=need_intuition placeholder="Интуиция">
<tr>
<td><input name=need_endurance placeholder="Выносливость">
<tr>
<td><input name=need_intelligence placeholder="Интеллект">
<tr>
<td><input name=need_wisdom placeholder="Мудрость">
<tr>
<th id="adds">Характеристики
<tr>
<td><input name=minu placeholder="Мин.урон">
<tr>
<td><input name=maxu placeholder="Макс.урон">
<tr>
<td><input name=add_strength placeholder="Сила">
<tr>
<td><input name=add_dexterity placeholder="Ловкость">
<tr>
<td><input name=add_intuition placeholder="Интуиция">
<tr>
<td><input name=add_endurance placeholder="Выносливость">
<tr>
<td><input name=add_intelligence placeholder="Интеллект">
<tr>
<td><input name=add_wisdom placeholder="Мудрость">
<tr>
<td><input name=add_accuracy placeholder="Точность">
<tr>
<td><input name=add_evasion placeholder="Уворот">
<tr>
<td><input name=add_criticals placeholder="Крит">
<tr>
<td><input name=add_min_physical_damage placeholder="Мин.удар">
<tr>
<td><input name=add_min_physical_damage placeholder="Макс.удар">
</table>
<INPUT TYPE="submit" value="Добавить">
</div>
</form>

109
admin/admin.php

@ -4,10 +4,11 @@
* Author: Igor Barkov <lopar.4ever@gmail.com>
* Project name: Battles-Game
*/
require_once '../functions.php';
require_once '../config.php';
use Battles\Database\Db;
use Battles\GameConfigs;
use Battles\Admin\Clan;
use Battles\Admin\User as AUser;
use Battles\Chat;
use Battles\Moderation;
use Battles\Template;
use Battles\User;
@ -29,72 +30,25 @@ if (isset($_POST['syschatmsg'])) {
}
//clans to reg
$unregisteredClans = new class {
public function getList()
{
$row = Db::getInstance()->ofetchAll('SELECT * FROM clans WHERE status = 0');
$i = 0;
while ($i < count($row)) {
$id = $row[$i]->owner_id;
$login = User::getInstance($row[$i]->owner_id)->getLogin();
$fullName = $row[$i]->full_name;
$shortName = $row[$i]->short_name;
$info = nl2br($row[$i]->info);
$i++;
echo <<<UNREGCLANLIST
<div>
<fieldset style="display: inline;">
<legend>$fullName [$shortName]</legend>
Глава клана: <span class="abils">$login</span><br>
Описание:<div class="abils">$info</div>
<BR>
<button onclick="location.href='?regclan=$id'">Зарегистрировать</button>
<button onclick="location.href='?remclan=$id'">Отказать</button>
</fieldset>
</div>
UNREGCLANLIST;
}
unset($i);
}
public function allowRegister($id)
{
Db::getInstance()->execute('UPDATE clans SET status = 1 WHERE status = 0 AND owner_id = ?', $id);
}
public function disallowRegister($id)
{
Db::getInstance()->execute('DELETE FROM clans WHERE status = 0 AND owner_id = ?', $id);
User::getInstance()->money()->modifyBank(GameConfigs::CLAN['clan_register_cost']);
}
};
$unregisteredClans->getList();
Clan::getUnapprovedList();
if (isset($_GET['regclan'])) {
$unregisteredClans->allowRegister($_GET['regclan']);
Clan::allowRegister($_GET['regclan']);
header('Location:/admin/admin.php');
exit;
}
if (isset($_GET['remclan'])) {
$unregisteredClans->disallowRegister($_GET['remclan']);
Clan::disallowRegister($_GET['remclan']);
header('Location:/admin/admin.php');
exit;
}
# Телеграф.
if (!empty($_POST['receiver']) && !empty($_POST['tgmsg'])) {
$receiver = Db::getInstance()->ofetch('SELECT id FROM users WHERE login= ?', $_POST['receiver']);
telegraph($receiver->id, $_POST['tgmsg']);
Chat::sendTelegraf($_POST['tgmsg'], User::getInstance($_POST['receiver'])->getId());
echo "Успешно.";
}
# Показывает невидимок.
$row = Db::getInstance()->ofetchAll('SELECT id,login FROM users LEFT JOIN users_effects ue on users.id = ue.owner_id WHERE type = 1022 ORDER BY `id` DESC');
foreach ($row as $r) {
$invisList .= '<b>[id] = ' .$r->id. ', ' .$r->login. '</b><br>';
}
User::getInstance()->
Template::header('ᐰdminка');
?>
<link rel=stylesheet href="/css/admin.css">
@ -123,27 +77,50 @@ Template::header('ᐰdminка');
<button disabled><img src="../i/magic/check.gif" alt="check"> Проверка</button>
<form method='post'>
<legend>Добавить в «дело» игрока заметку о нарушении правил, прокрутке и пр.</legend>
<input name='ldnick' placeholder='Логин'> <input name='ldtext' size='50' placeholder='Сообщение'>
<input type='submit' value='Добавить'><br>
<fieldset>
<legend>Добавить в «дело» игрока заметку о нарушении правил, прокрутке и пр.</legend>
<label>
<input name='ldnick' placeholder='Логин'>
</label>
<label>
<input name='ldtext' size='50' placeholder='Сообщение'>
</label>
<input type='submit' value='Добавить'><br>
</fieldset>
</form>
<form method='post'>
<fieldset>
<legend>Отправить системное сообщение в чат</legend>
<input name='syschatmsg' size='74' placeholder='Введите сообщение'>
<input type='submit' value='Отправить'>
<label>
<input name='syschatmsg' size='74' placeholder='Введите сообщение'>
</label>
<input type='submit' value='Отправить'>
</fieldset>
</form>
<form method='post'>
<fieldset>
<legend>Телеграф</legend>
<input name='receiver' placeholder='Логин'>
<input name='tgmsg' size='50' placeholder='Сообщение'>
<input type='submit' value='Отправить'>
<label>
<input name='receiver' placeholder='Логин'>
</label>
<label>
<input name='tgmsg' size='50' placeholder='Сообщение'>
</label>
<input type='submit' value='Отправить'>
</fieldset>
</form>
<form method='post'>
<fieldset>
<legend>Поменять статус</legend>
<input name='login' placeholder='Логин'>
<input name='status' placeholder='Статус'>
<input type='submit' value='Изменить статус'>
<label>
<input name='login' placeholder='Логин'>
</label>
<label>
<input name='status' placeholder='Статус'>
</label>
<input type='submit' value='Изменить статус'>
</fieldset>
</form>
<span class="legend">Невидимки</span><br>
<div class="abils" style="width: fit-content;"><?= $invisList ?></div>
<div class="abils" style="width: fit-content; font-weight: bold;"><?= AUser::getInvisiblesList() ?></div>

2
c_haos.php

@ -67,7 +67,7 @@ if ($_POST['pay']) {
if ($_POST['adm_start_raid'] && $user['id'] == 1256) {
mysql_query("DELETE FROM `cit_haos_status`;");
mysql_query("DELETE FROM `cit_haos_var`;");
Chat::addSYSMessage('Начинается прием заявок в рейд на Цитадель Хаоса! Начало рейда через 15 минут.');
Chat::sendSys('Начинается прием заявок в рейд на Цитадель Хаоса! Начало рейда через 15 минут.');
$ch_time = time();
mysql_query("UPDATE variables SET value='{$ch_time}' where var='cit_haos_time';");
}

2
chat.php

@ -12,7 +12,7 @@ use Battles\Template;
require_once "config.php";
$chat = new Chat(Db::getInstance());
if (!empty($_POST['msg'])) {
$chat->addMessage($_POST['msg']);
$chat->sendMessage($_POST['msg']);
}
Template::header('chat');

49
classes/Battles/Admin/Clan.php

@ -0,0 +1,49 @@
<?php
namespace Battles\Admin;
use Battles\Bank;
use Battles\Database\Db;
use Battles\GameConfigs;
use Battles\User;
class Clan
{
public static function getUnapprovedList(): string
{
$list = '';
$rows = Db::getInstance()->ofetchAll('select * from clans where status = 0');
foreach ($rows as $row) {
$id = $row->owner_id;
$login = User::getInstance($id)->getLogin();
$full = $row->full_name;
$short = $row->short_name;
$info = nl2br($row->info);
$list .= <<<UNREGCLANLIST
<div>
<fieldset style="display: inline;">
<legend>$full [$short]</legend>
Глава клана: <span class="abils">$login</span><br>
Описание:<div class="abils">$info</div>
<BR>
<button onclick="location.href='?regclan=$id'">Зарегистрировать</button>
<button onclick="location.href='?remclan=$id'">Отказать</button>
</fieldset>
</div>
UNREGCLANLIST;
}
return $list;
}
public static function allowRegister($id)
{
Db::getInstance()->execute('UPDATE clans SET status = 1 WHERE status = 0 AND owner_id = ?', $id);
}
public static function disallowRegister($id)
{
$bank = new Bank($id);
Db::getInstance()->execute('DELETE FROM clans WHERE status = 0 AND owner_id = ?', $id);
$bank::setBankMoney($bank->getMoney() + GameConfigs::CLAN['clan_register_cost'], $id);
}
}

49
classes/Battles/Admin/Item.php

@ -0,0 +1,49 @@
<?php
namespace Battles\Admin;
use Battles\Database\Db;
class Item
{
public static function add(array $params): void
{
$query = 'insert into items (
name, item_type, durability,
need_strength, need_dexterity, need_intuition, need_endurance, need_intelligence, need_wisdom,
add_strength, add_dexterity, add_intuition, add_endurance, add_intelligence, add_wisdom,
add_accuracy, add_evasion, add_criticals, add_min_physical_damage, add_max_physical_damage,
image, weight)
values (
:name, :item_type, :durability,
:need_strength, :need_dexterity, :need_intuition, :need_endurance, :need_intelligence, :need_wisdom,
:add_strength, :add_dexterity, :add_intuition, :add_endurance, :add_intelligence, :add_wisdom,
:add_accuracy, :add_evasion, :add_criticals, :add_min_physical_damage, :add_max_physical_damage,
:image, :weight)';
$values = [
'name' => $params['name'] ?? uniqid(),
'item_type' => $params['item_type'],
'durability' => $params['durability'] ?? 1,
'need_strength' => $params['need_strength'] ?? 0,
'need_dexterity' => $params['need_dexterity'] ?? 0,
'need_intuition' => $params['need_intuition'] ?? 0,
'need_endurance' => $params['need_endurance'] ?? 0,
'need_intelligence' => $params['need_intelligence'] ?? 0,
'need_wisdom' => $params['need_wisdom'] ?? 0,
'add_strength' => $params['add_strength'] ?? 0,
'add_dexterity' => $params['add_dexterity'] ?? 0,
'add_intuition' => $params['add_intuition'] ?? 0,
'add_endurance' => $params['add_endurance'] ?? 0,
'add_intelligence' => $params['add_intelligence'] ?? 0,
'add_wisdom' => $params['add_wisdom'] ?? 0,
'add_accuracy' => $params['add_accuracy'] ?? 0,
'add_evasion' => $params['add_evasion'] ?? 0,
'add_criticals' => $params['add_criticals'] ?? 0,
'add_min_physical_damage' => $params['add_min_physical_damage'] ?? 0,
'add_max_physical_damage' => $params['add_max_physical_damage'] ?? 0,
'image' => $params['image'] ?? 'noitem.png',
'weight' => $params['weight'] ?? 1,
];
Db::getInstance()->execute($query, $values);
}
}

20
classes/Battles/Admin/User.php

@ -0,0 +1,20 @@
<?php
namespace Battles\Admin;
use Battles\Database\Db;
class User
{
private const INVISIBILITY_EFFECT = 1022;
public static function getInvisiblesList(): string
{
$list = '';
$row = Db::getInstance()->ofetchAll('select id, login from users left join users_effects ue on users.id = ue.owner_id where type = ' . self::INVISIBILITY_EFFECT);
foreach ($row as $item) {
$list .= '[id] = ' . $item->id . ', ' . $item->login . '<br>';
}
return $list;
}
}

10
classes/Battles/Chat.php

@ -62,14 +62,18 @@ class Chat
return $wrappedMessage;
}
public function addMessage(string $msg)
public function sendMessage(string $msg)
{
$this->db->execute('insert into chat (user_id, msg) values (?,?)', [User::getInstance()->getId(), $msg]);
}
public static function addSYSMessage( string $msg, ?int $receiver_id = null)
public static function sendSys(string $msg, ?int $receiver_id = null)
{
Db::getInstance()->execute('insert into chat (user_id, msg, receiver_id, type) values (?,?,?,?)', [User::getInstance()->getId(), $msg, $receiver_id, 'sys']);
Db::getInstance()->execute('insert into chat (user_id, msg, receiver_id, type) values (-1,?,?,?)', [$msg, $receiver_id, 'sys']);
}
public static function sendTelegraf(string $msg, int $receiver_id)
{
Db::getInstance()->execute('insert into chat (user_id, msg, receiver_id, type) values (-1,?,?,?)', [$msg, $receiver_id, 'sms']);
}
}

40
classes/Battles/DressedItems.php

@ -13,18 +13,20 @@ use stdClass;
class DressedItems
{
private $USERID;
private $dressedItem;
private static $db;
private int $USERID;
private stdClass $dressedItem;
private static Db $db;
private object $dressed;
/**
* DressedItems constructor.
* @param int $user_id ID игрока.
* @param int $user_id ID игрока.
*/
public function __construct(int $user_id)
{
self::$db = Db::getInstance();
$this->USERID = $user_id;
$this->dressed = self::$db->ofetchAll('select * from inventory where dressed_slot > 0 and owner_id = ?', $this->USERID);
}
public static function getDressedItemBySlot($itemSlot, $ownerId)
@ -34,9 +36,8 @@ class DressedItems
public function getItemsInSlots(): stdClass
{
$items = self::$db->ofetchALL('SELECT * FROM inventory WHERE owner_id = ? AND dressed_slot > 0', $this->USERID);
$this->dressedItem = new stdClass();
foreach ($items as $item) {
foreach ($this->dressed as $item) {
$i = $item->dressed_slot;
$this->dressedItem->$i = $item;
}
@ -55,8 +56,35 @@ class DressedItems
Inventory::undressOne($slot_id, $this->USERID);
}
}
public static function undressAllItems($user_id)
{
return self::$db->execute('UPDATE inventory SET dressed_slot = 0 WHERE dressed_slot BETWEEN 1 AND 12 AND owner_id = ?', $user_id);
}
public function checkRequirements()
{
$stats = (new UserStats($this->USERID))->getFullStats();
$q = 'select count(*) from inventory where
dressed_slot > 0 and
need_strength > ? and
need_dexterity > ? and
need_intuition > ? and
need_endurance > ? and
need_intelligence > ? and
need_wisdom > ? and
owner_id = ?';
$args = [
$stats->strength,
$stats->dexterity,
$stats->intuition,
$stats->endurance,
$stats->intelligence,
$stats->wisdom,
$this->USERID
];
if (self::$db->fetchColumn($q, $args) > 0) {
self::undressAllItems($this->USERID);
}
}
}

7
classes/Battles/Magic/CureInjury.php

@ -46,7 +46,12 @@ class CureInjury extends Magic
{
$this->target = $this->target == $_SESSION['uid'] ? User::getInstance() : User::getInstance($this->target);
$this->login = $this->target->getLogin();
return ($this->isVisible(User::getInstance(), $this->target) && $this->isNotDead(User::getInstance()) && $this->enoughMana(User::getInstance()) && $this->isNotInBattle(User::getInstance()));
return (
$this->isVisible(User::getInstance(), $this->target) &&
$this->isNotDead(User::getInstance()) &&
$this->enoughMana(User::getInstance()) &&
$this->isNotInBattle(User::getInstance())
);
}
public static function cast($target, $type): self

29
classes/Battles/Magic/Magic.php

@ -1,11 +1,26 @@
<?php
# Date: 16.09.2020 (08:45)
namespace Battles\Magic;
use Battles\Database\Db;
class Magic
{
protected $status;
protected string $status;
private Db $db;
private object $magic;
public function __construct(Db $db, int $id)
{
$this->magic = $db->ofetch('select * from magic where id = ?', $id);
}
public function getMagic(): object
{
return $this->magic;
}
protected function isVisible($caster, $target):bool
protected function isVisible($caster, $target): bool
{
if ($caster->battle != $target->battle || $caster->room != $target->room) {
$this->status = 'Вы не видите цель!';
@ -15,7 +30,7 @@ class Magic
}
}
protected function isNotDead($caster):bool
protected function isNotDead($caster): bool
{
if ($caster->health < 1) {
$this->status = 'Вы мертвы!';
@ -25,7 +40,7 @@ class Magic
}
}
protected function enoughMana($caster):bool
protected function enoughMana($caster): bool
{
if ($caster->mana < 1) {
$this->status = 'Недостаточно пыли!';
@ -35,7 +50,7 @@ class Magic
}
}
protected function isNotInBattle($caster):bool
protected function isNotInBattle($caster): bool
{
if ($caster->battle) {
$this->status = 'Невозможно применить в поединке!';
@ -52,12 +67,12 @@ class Magic
*
* @return bool
*/
protected function isSuccess($caster, int $difficulty = 40):bool
protected function isSuccess($caster, int $difficulty = 40): bool
{
# 40 - потолок стата.
if ($difficulty > 40) {
$difficulty = 40;
}
return mt_rand(1,$difficulty) < $caster->intelligence;
return mt_rand(1, $difficulty) < $caster->intelligence;
}
}

3
config.php

@ -6,9 +6,6 @@
* Project name: Battles-Game
*/
use Battles\Database\Db;
use Battles\User;
include_once 'classes/Database/db.php';
include_once 'classes/Database/Mysql.php';
include_once 'classes/Database/Statement.php';

6
cronjobs/cron_bots_battle.php

@ -552,10 +552,10 @@ class fbattle
}
if ($arr_battle['win'] == 1) {
Chat::addSYSMessage('Внимание! Тьма одержала победу благодаря великим воинам: <b>' . $uss . '</b>');
Chat::sendSys('Внимание! Тьма одержала победу благодаря великим воинам: <b>' . $uss . '</b>');
$this->AddToLog('<span class=date>' . date("H:i") . '</span> ' . 'Бой закончен, победа за <B>Силами Тьмы</B><BR>');
} else {
Chat::addSYSMessage('Внимание! Свет одержал победу благодаря великим воинам: <b>' . $uss . '</b>');
Chat::sendSys('Внимание! Свет одержал победу благодаря великим воинам: <b>' . $uss . '</b>');
$this->AddToLog('<span class=date>' . date("H:i") . '</span> ' . 'Бой закончен, победа за <B>Силами Света</B><BR>');
}
mysql_query('UPDATE `variables` SET `value` = "' . $arr_battle['win'] . '" WHERE `var` = "arena_win" LIMIT 1');
@ -586,7 +586,7 @@ class fbattle
}
} else {
if ($this->battle_data['aren_of'] == 1) {
Chat::addSYSMessage('Внимание! Бой на Арене Ангелов завершился ничьей, на этой недели силы тьмы и света равны.');
Chat::sendSys('Внимание! Бой на Арене Ангелов завершился ничьей, на этой недели силы тьмы и света равны.');
mysql_query('UPDATE `variables` SET `value` = 3 WHERE `var` = "arena_win" LIMIT 1');
mysql_query('UPDATE `battle` SET `aren_of` = 0 WHERE `id` = "' . $arr_battle['id'] . '" AND `aren_of` = 1 LIMIT 1');
}

9
fbattle.php

@ -1,4 +1,9 @@
<?php
use Battles\DressedItems;
use Battles\Template;
use Battles\User;
if (isset($_POST['end'])) {
header("Location: main.php");
exit;
@ -15,7 +20,7 @@ if (isset($user['id'])) {
include('./classes/battle_new.class.php');
$fbattle = new fbattle($user['battle']);
\Battles\Template::header('fbattle');
Template::header('fbattle');
?>
<script type="text/javascript" src="js/sl2.js"></script>
<script type="text/javascript" src="js/ch.js"></script>
@ -287,7 +292,7 @@ $fbattle = new fbattle($user['battle']);
if (($user['hp'] > 0) && $fbattle->battle) {
echo '<center><FONT COLOR=red><b>Ожидаем хода противника...</b></FONT><BR><INPUT TYPE=submit value="Обновить" name=' . (($user['battle'] > 0) ? "battle" : "end") . '><BR></CENTER>';
} elseif ($user['hp'] <= 0 && $fbattle->battle) {
\Battles\InventoryItem::autoDrop();
(new DressedItems(User::getInstance()->getId()))->checkRequirements();
echo '<center><FONT COLOR=red><b>Ожидаем, пока бой закончат другие игроки...</b></FONT><BR><INPUT TYPE=submit value="Обновить" name=' . (($user['battle'] > 0) ? "battle" : "end") . '><BR></CENTER>';
}
break;

30
functions.php

@ -24,7 +24,12 @@ if (User::getInstance()->getBlock()) {
//Проверки на соответствие скрипта и комнаты, которые были натыканы по всем файлам.
Travel::roomRedirects(User::getInstance()->getRoom(), User::getInstance()->getBattle());
if (!empty($_GET['goto']) && !empty($_GET['tStamp']) && !empty($_GET['vcode']) && $_GET['vcode'] == md5(sha1($_GET['goto'] . $_GET['tStamp']))) {
if (
!empty($_GET['goto']) &&
!empty($_GET['tStamp']) &&
!empty($_GET['vcode']) &&
$_GET['vcode'] == md5(sha1($_GET['goto'] . $_GET['tStamp']))
) {
$query = 'update users u, online o set u.room = ?, o.room = ? where user_id = id and user_id = ?';
Db::getInstance()->execute($query, [$_GET['goto'], $_GET['goto'], User::getInstance()->getId()]);
User::getInstance()->setRoom(intval($_GET['goto']));
@ -164,7 +169,7 @@ function addActions($time, $vars, $vls, $uid)
}
/* ВАЖНО! (#44)
* addch() и addchp() заменяются на Chat::class->addSYSMessage($message, [optional]$receiver);
* addch() и addchp() заменяются на Chat::class->sendSys($message, [optional]$receiver);
* Для addchp() используется второй опциональный ключ.
* Это 150+ вхождений в куче файлов, где надо менять структуру вызова функции из-за их несовместимости.
* Возможно, приоритетом стоит сделать унификацию свитков нападения, которых самих около 20 и которые
@ -173,30 +178,13 @@ function addActions($time, $vars, $vls, $uid)
function addch($text, $room = 0)
{
if ($room == 0) {
$room = User::getInstance()->getRoom();
}
if ($fp = @fopen("tmp/chat.txt", "a")) { //открытие
flock($fp, LOCK_EX); //БЛОКИРОВКА ФАЙЛА
fwrite($fp, ":[" . time() . "]:[!sys!!]:[" . ($text) . "]:[" . $room . "]\r\n"); //работа с файлом
fflush($fp); //ОЧИЩЕНИЕ ФАЙЛОВОГО БУФЕРА И ЗАПИСЬ В ФАЙЛ
flock($fp, LOCK_UN); //СНЯТИЕ БЛОКИРОВКИ
fclose($fp); //закрытие
}
Chat::sendSys($text);
}
function addchp($text, $who, $room = 0)
{
if ($room == 0) {
$room = User::getInstance()->getRoom();
}
$fp = fopen("tmp/chat.txt", "a"); //открытие
flock($fp, LOCK_EX); //БЛОКИРОВКА ФАЙЛА
fwrite($fp, ":[" . time() . "]:[{$who}]:[" . ($text) . "]:[" . $room . "]\r\n"); //работа с файлом
fflush($fp); //ОЧИЩЕНИЕ ФАЙЛОВОГО БУФЕРА И ЗАПИСЬ В ФАЙЛ
flock($fp, LOCK_UN); //СНЯТИЕ БЛОКИРОВКИ
fclose($fp); //закрытие
Chat::sendSys($text, $who);
}
function err($t)

2
towerin.php

@ -289,7 +289,7 @@ if (($kol_pl + $ls) < 2 && ($tur_data['start_time'] + 60) <= time()) {
mysql_query('UPDATE `deztow_turnir` SET `winner` = \'' . $user['id'] . '\', `winnerlog` = \'' . Nick::id($user['id'])->full(1) . '\', `endtime` = \'' . time() . '\', `active` = FALSE, `log` = CONCAT(`log`,\'' . "<span class=date>" . date("d.m.y H:i") . "</span> Турнир завершен. Победитель : " . Nick::id($user['id'])->full(1) . " Приз : <b>" . $tur['coin'] . "</b> кр. <br />" . '\') WHERE `active` = TRUE LIMIT 1');
addchp('<font color=red>Внимание!</font> Поздравляем! Вы победитель турнира Башни смерти! Получаете <b>' . $tur['coin'] . '</b> кр.', '{[]}' . $user['login'] . '{[]}');
Chat::addSYSMessage('Внимание! Битва в Башне Смерти завершена. Победитель:' . $user['login'] . ' [' . $user['level'] . ']');
Chat::sendSys('Внимание! Битва в Башне Смерти завершена. Победитель:' . $user['login'] . ' [' . $user['level'] . ']');
if ($tur['art'] == 1) {
$bs_art = 0;
} else {

8
zayavka.php

@ -207,7 +207,7 @@ class Zayavka
return $this->errorMessage;
} else {
if ($type == 3) {
Chat::addSYSMessage("Внимание! Подана заявка на хаотический поединок ({$t1min} - {$t1max}), который начнется через {$start} минут.");
Chat::sendSys("Внимание! Подана заявка на хаотический поединок ({$t1min} - {$t1max}), который начнется через {$start} минут.");
}
$start = time() + $start * 60;
@ -662,19 +662,19 @@ Template::header('zayavka');
}
if (!empty($_POST['back2'])) {
$z = $zay->getlist(2, null, $user->getZayavka());
Chat::addSYSMessage('Внимание!' . Nick::id($user->getId())->short() . ' отозвал заявку.');
Chat::sendSys('Внимание!' . Nick::id($user->getId())->short() . ' отозвал заявку.');
echo $zay->delteam($user->getId(), $user->getZayavka(), 2);
}
if (!empty($_POST['cansel'])) {
$z = $zay->getlist(2, null, $user->getZayavka());
echo $zay->delteam($z[$user->getZayavka()]['team2'][0], $user->getZayavka(), 2);
Chat::addSYSMessage('Внимание!' . Nick::id($user->getId())->short() . ' отказался от поединка.');
Chat::sendSys('Внимание!' . Nick::id($user->getId())->short() . ' отказался от поединка.');
}
if (!empty($_POST['confirm2']) && empty($user->getZayavka())) {
$z = $zay->getlist(2, null, $_REQUEST['gocombat']);
$toper = db::c()->query('SELECT `klan` FROM `users` WHERE `id` = ?i', $z[$_REQUEST['gocombat']]['team1'][0])->fetch_assoc();
if ($user->getClan() != $toper['klan'] || !$user->getClan()) {
Chat::addSYSMessage('Внимание!' . Nick::id($user->getId())->short() . ' принял заявку, нужно принять вызов или отказать.');
Chat::sendSys('Внимание!' . Nick::id($user->getId())->short() . ' принял заявку, нужно принять вызов или отказать.');
}
echo $zay->addteam(2, 2);
echo "</b></font><BR>Ожидаем подтверждения боя. <input type=submit name=back2 value='Отозвать заявку'>";

Loading…
Cancel
Save