2021-01-25 18:02:58 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Battles\Magic;
|
|
|
|
|
|
2021-01-28 21:05:34 +00:00
|
|
|
|
use Battles\Database\DBPDO;
|
2021-01-25 18:02:58 +00:00
|
|
|
|
use Battles\DressedItems;
|
|
|
|
|
use Battles\Item;
|
|
|
|
|
use Battles\User;
|
|
|
|
|
|
|
|
|
|
class Sharpen extends Magic
|
|
|
|
|
{
|
|
|
|
|
private $magicDifficulty;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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;
|
|
|
|
|
}
|
2021-01-28 21:05:34 +00:00
|
|
|
|
$item = DressedItems::getDressedItemBySlot(Item::ITEM_TYPE_WEAPON, $_SESSION['uid']);
|
|
|
|
|
// Проверяем, что в названии предмета нет цифр и плюсов.
|
|
|
|
|
if (preg_match('/[\W\S]+\+\[?[\d]]?/', $item['name'])) {
|
|
|
|
|
return 'Этот предмет точить нельзя!';
|
|
|
|
|
}
|
|
|
|
|
$newMinPhysicalDamage = $item['add_min_physical_damage'] + $sharpenStrength;
|
|
|
|
|
$newMaxPhysicalDamage = $item['add_max_physical_damage'] + $sharpenStrength;
|
|
|
|
|
$newItemName = $item['name'] . " [+$sharpenStrength]";
|
|
|
|
|
|
|
|
|
|
DBPDO::INIT()->execute('UPDATE battles.inventory SET name = ?, add_min_physical_damage = ?, add_max_physical_damage = ? WHERE item_id = ? ', [$newItemName, $newMinPhysicalDamage, $newMaxPhysicalDamage, $item['item_id']]);
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
$caster = new User($_SESSION['uid']);
|
2021-01-28 21:05:34 +00:00
|
|
|
|
return $this->isNotInBattle($caster) && $this->isSuccess($caster, $this->magicDifficulty);
|
2021-01-25 18:02:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|