2021-01-25 18:02:58 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Battles\Magic;
|
|
|
|
|
|
2022-01-26 23:15:33 +00:00
|
|
|
|
use Battles\Database\Db;
|
2021-01-25 18:02:58 +00:00
|
|
|
|
use Battles\DressedItems;
|
|
|
|
|
use Battles\Item;
|
|
|
|
|
use Battles\User;
|
|
|
|
|
|
|
|
|
|
class Sharpen extends Magic
|
|
|
|
|
{
|
2021-08-25 01:44:36 +00:00
|
|
|
|
private int $magicDifficulty;
|
2021-01-25 18:02:58 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sharpen constructor.
|
|
|
|
|
*
|
|
|
|
|
* @param int $sharpenStrength
|
|
|
|
|
* @param int $magicDifficulty
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public function __construct(int $sharpenStrength, int $magicDifficulty)
|
|
|
|
|
{
|
|
|
|
|
$this->magicDifficulty = $magicDifficulty;
|
2021-01-28 21:05:34 +00:00
|
|
|
|
if (!$this->isUsable()) {
|
2021-01-25 18:02:58 +00:00
|
|
|
|
return $this->status;
|
|
|
|
|
}
|
2022-12-16 23:20:43 +00:00
|
|
|
|
$item = DressedItems::getDressedItemBySlot(Item::TYPE_WEAPON, $_SESSION['uid']);
|
2021-01-28 21:05:34 +00:00
|
|
|
|
// Проверяем, что в названии предмета нет цифр и плюсов.
|
2022-12-16 23:20:43 +00:00
|
|
|
|
if (preg_match('/\+\d/', $item->name)) {
|
2021-01-28 21:05:34 +00:00
|
|
|
|
return 'Этот предмет точить нельзя!';
|
|
|
|
|
}
|
2022-01-26 23:15:33 +00:00
|
|
|
|
$newMinPhysicalDamage = $item->add_min_physical_damage + $sharpenStrength;
|
|
|
|
|
$newMaxPhysicalDamage = $item->add_max_physical_damage + $sharpenStrength;
|
|
|
|
|
$newItemName = $item->name . " [+$sharpenStrength]";
|
2021-01-28 21:05:34 +00:00
|
|
|
|
|
2022-12-16 23:20:43 +00:00
|
|
|
|
Db::getInstance()->execute('UPDATE inventory SET name = ?, add_min_physical_damage = ?, add_max_physical_damage = ? WHERE item_id = ? ', [$newItemName, $newMinPhysicalDamage, $newMaxPhysicalDamage, $item->item_id]);
|
2021-01-28 21:05:34 +00:00
|
|
|
|
return "У вас получилось изготовить предмет $newItemName!";
|
2021-01-25 18:02:58 +00:00
|
|
|
|
}
|
2021-01-28 21:05:34 +00:00
|
|
|
|
|
|
|
|
|
private function isUsable(): bool
|
2021-01-25 18:02:58 +00:00
|
|
|
|
{
|
2022-01-26 23:15:33 +00:00
|
|
|
|
return $this->isNotInBattle(User::getInstance()) && $this->isSuccess(User::getInstance(), $this->magicDifficulty);
|
2021-01-25 18:02:58 +00:00
|
|
|
|
}
|
2022-12-16 23:20:43 +00:00
|
|
|
|
}
|