2021-01-25 18:02:58 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Battles\Magic;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use Battles\DressedItems;
|
|
|
|
|
use Battles\Item;
|
|
|
|
|
use Battles\User;
|
|
|
|
|
use Krugozor\Database\Mysql\Exception;
|
|
|
|
|
use db;
|
|
|
|
|
|
|
|
|
|
class Sharpen extends Magic
|
|
|
|
|
{
|
|
|
|
|
private $magicDifficulty;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sharpen constructor.
|
|
|
|
|
*
|
|
|
|
|
* @param int $sharpenStrength
|
|
|
|
|
* @param int $magicDifficulty
|
|
|
|
|
*
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function __construct(int $sharpenStrength, int $magicDifficulty)
|
|
|
|
|
{
|
|
|
|
|
$this->magicDifficulty = $magicDifficulty;
|
|
|
|
|
if ($this->isUsable()) {
|
|
|
|
|
$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]";
|
|
|
|
|
|
2021-01-25 20:02:11 +00:00
|
|
|
|
db::c()->query('UPDATE battles.inventory SET name = "?s", add_min_physical_damage = "?s", add_max_physical_damage = "?s" WHERE item_id = ?i ', $newItemName, $newMinPhysicalDamage, $newMaxPhysicalDamage, $item['item_id']);
|
2021-01-25 18:02:58 +00:00
|
|
|
|
return "У вас получилось изготовить предмет $newItemName!";
|
|
|
|
|
} else {
|
|
|
|
|
return $this->status;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private function isUsable():bool
|
|
|
|
|
{
|
|
|
|
|
$caster = new User($_SESSION['uid']);
|
|
|
|
|
return $this->isNotInBattle($caster) && $this->skillCheck($caster, $this->magicDifficulty);
|
|
|
|
|
}
|
|
|
|
|
}
|