Будь проклят тот день, когда я решил ввести неймспейсы...

This commit is contained in:
lopar
2020-10-28 22:21:08 +02:00
parent f1b9ce6a45
commit d38d62c5b5
159 changed files with 339 additions and 304 deletions
+58
View File
@@ -0,0 +1,58 @@
<?php
# Date: 16.09.2020 (08:23)
// Магия лечения травм
namespace Battles\Magic;
use Battles\UserEffects;
use Battles\User;
class CureInjury extends magic
{
private $target;
use UserEffects;
/**
* Магия лечения травм. Если у персонажа несколько травм, лечится самая тяжёлая.
* @param $target - кого лечим.
* @param $injuryType - тип травмы, которую лечим. 11 лёгкая, 12 средняя, 13 тяжёлая, 14 неизлечимая.
* @throws \Krugozor\Database\Mysql\Exception
*/
public function __construct($target, $injuryType)
{
$this->target = $target;
if ($target && $this->isUsable()) {
$injury = \db::c()->query('SELECT effect_id, type, name FROM users_effects WHERE type IN (11,12,13,14) AND owner_id = ?i ORDER BY type DESC LIMIT 1', $target)->fetch_object();
$targetName = $this->target->login;
if (in_array($injury->effect_id, [11, 12, 13, 14]) && $injuryType >= $injury->type) {
\db::c()->query('DELETE FROM users_effects WHERE effect_id = ?i', $injury->effect_id);
if (empty($injury->name) || $injury->name == 'Неизвестный эффект') {
$injuryName = self::$effectName[$injury->type];
} else {
$injuryName = $injury->name;
}
return "Вы вылечили повреждение ${injuryName} персонажу ${targetName}.";
} elseif ($injury->effect_id && $injuryType == 15) {
\db::c()->query('DELETE FROM users_effects WHERE type IN (11,12,13,14) AND owner_id = ?i', $target);
return "Вы вылечили все повреждения персонажу ${targetName}.";
} else {
return false;
}
} else {
return $this->status;
}
}
/**
* Проверки на успех.
* @return bool
*/
private function isUsable()
{
$caster = new User($_SESSION['uid']);
if ($this->target == $_SESSION['uid']) {
$this->target = $caster;
} else {
$this->target = new User($this->target);
}
return ($this->isVisible($caster, $this->target) && $this->isNotDead($caster) && $this->enoughMana($caster) && $this->isNotInBattle($caster));
}
}
+47
View File
@@ -0,0 +1,47 @@
<?php
# Date: 16.09.2020 (08:45)
namespace Battles\Magic;
class Magic
{
protected $status;
protected function isVisible($caster, $target)
{
if ($caster->battle != $target->battle || $caster->room != $target->room) {
$this->status = 'Вы не видите цель!';
return false;
} else {
return true;
}
}
protected function isNotDead($caster)
{
if ($caster->health < 1) {
$this->status = 'Вы мертвы!';
return false;
} else {
return true;
}
}
protected function enoughMana($caster)
{
if ($caster->mana < 1) {
$this->status = 'Недостаточно пыли!';
return false;
} else {
return true;
}
}
protected function isNotInBattle($caster)
{
if ($caster->battle) {
$this->status = 'Невозможно применить в поединке!';
return false;
} else {
return true;
}
}
}
+41
View File
@@ -0,0 +1,41 @@
<?php
namespace Battles\Magic;
use db;
class attack
{
private $target_user;
private $caster;
private function __construct($target_user_id)
{
if (!$this->caster) {
$this->caster = db::c()->query('SELECT * FROM `users` WHERE `id` = ?i', $_SESSION['uid']);
}
if (!$this->target_user) {
$this->target_user = db::c()->query('SELECT * FROM `users` WHERE `id` = ?i', $target_user_id);
}
if ($this->checks() == 1) {
return 'Done!';
}
}
private function checks()
{
if ($this->caster['battle']) {
return 'Не в бою...';
}
else {
return 1;
}
}
public static function id($playerId)
{
return new self($playerId);
}
}