58 lines
2.2 KiB
PHP
58 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace Location;
|
|
|
|
use Core\Db;
|
|
use DTO\KnowledgeTempleItem;
|
|
use User;
|
|
|
|
class KnowledgeTemple
|
|
{
|
|
private string $error = '';
|
|
|
|
/** Ïëàâêà ïðåäìåòà
|
|
* @param int $id id ïðåäìåòà
|
|
* @return string ñòàòóñ ñîáûòèÿ
|
|
*/
|
|
public function smeltItem(int $id): string
|
|
{
|
|
$item = new KnowledgeTempleItem(User\ItemsModel::getOwnedItemById(User::start()->info['id'], $id));
|
|
if (!$this->isSmeltable($item)) {
|
|
return $this->error;
|
|
}
|
|
User\ItemsModel::delete($id);
|
|
return 'Óäà÷íî ðàñòâîðåí ïðåäìåò "' . $item->name . '"!' . self::addReputation(1);
|
|
}
|
|
|
|
private function isSmeltable(KnowledgeTempleItem $item): bool
|
|
{
|
|
$reputation = User::start()->rep['rep1'];
|
|
if (!$item->exists()) {
|
|
$this->error = 'Ïðåäìåò íå íàéäåí.';
|
|
} elseif ($item->level < 4 && $item->id != 1035) {
|
|
$this->error = 'Ïðåäìåò äîëæåí áûòü 4-ãî è âûøå óðîâíÿ';
|
|
} elseif (
|
|
!in_array($item->type, [1, 3, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 18, 19, 20, 21, 22]) &&
|
|
$item->id != 1035
|
|
) {
|
|
$this->error = 'Õðåí âàì, à íå ðóíû! Êóäà êèäàåøü ïðåäìåò? Íå ïîäõîäèò îí! Ïðèõîäè êàê áóäåò ÷òî-òî ñòîþùåå!';
|
|
} elseif ($item->level >= 7 && $reputation < 0) {
|
|
$this->error = 'Äëÿ ðàñòâîðåíèÿ ïðåäìåòîâ 7-ãî è ñòàðøå óðîâíÿ òðåáóåòñÿ çíàê Õðàìà Çíàíèé ïåðâîãî êðóãà';
|
|
} elseif ($item->level >= 9 && $reputation < 1000) {
|
|
$this->error = 'Äëÿ ðàñòâîðåíèÿ ïðåäìåòîâ 9-ãî è ñòàðøå óðîâíÿ òðåáóåòñÿ çíàê Õðàìà Çíàíèé âòîðîãî êðóãà';
|
|
} elseif ($item->level >= 10 && $reputation < 10000) {
|
|
$this->error = 'Äëÿ ðàñòâîðåíèÿ ïðåäìåòîâ 10-ãî è ñòàðøå óðîâíÿ òðåáóåòñÿ çíàê Õðàìà Çíàíèé òðåòüåãî êðóãà';
|
|
}
|
|
return empty($this->error);
|
|
}
|
|
|
|
public static function addReputation(int $value): string
|
|
{
|
|
if ($value < 1) {
|
|
trigger_error(self::class . '::addReputation - $value can not be below zero.');
|
|
}
|
|
Db::sql('update rep set rep1 = rep1 + ? where id = ?', [$value, User::start()->info['id']]);
|
|
User::start()->rep['rep1'] += $value;
|
|
return "Ïîëó÷åíî ðåïóòàöèè: +$value åä.";
|
|
}
|
|
} |