battles/classes/Battles/Magic/Sharpen.php

46 lines
1.6 KiB
PHP
Raw Permalink Normal View History

<?php
namespace Battles\Magic;
use Battles\Database\Db;
use Battles\DressedItems;
use Battles\Item;
use Battles\User;
class Sharpen extends Magic
{
private int $magicDifficulty;
/**
* Sharpen constructor.
*
* @param int $sharpenStrength
* @param int $magicDifficulty
*
*/
public function __construct(int $sharpenStrength, int $magicDifficulty)
{
$this->magicDifficulty = $magicDifficulty;
if (!$this->isUsable()) {
return $this->status;
}
2022-12-16 23:20:43 +00:00
$item = DressedItems::getDressedItemBySlot(Item::TYPE_WEAPON, $_SESSION['uid']);
// Проверяем, что в названии предмета нет цифр и плюсов.
2022-12-16 23:20:43 +00:00
if (preg_match('/\+\d/', $item->name)) {
return 'Этот предмет точить нельзя!';
}
$newMinPhysicalDamage = $item->add_min_physical_damage + $sharpenStrength;
$newMaxPhysicalDamage = $item->add_max_physical_damage + $sharpenStrength;
$newItemName = $item->name . " [+$sharpenStrength]";
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]);
return "У вас получилось изготовить предмет $newItemName!";
}
private function isUsable(): bool
{
return $this->isNotInBattle(User::getInstance()) && $this->isSuccess(User::getInstance(), $this->magicDifficulty);
}
2022-12-16 23:20:43 +00:00
}