id = $data->id; $this->strength = $data->strength; $this->dexterity = $data->dexterity; $this->intuition = $data->intuition; $this->endurance = $data->endurance; $this->intelligence = $data->intelligence; $this->wisdom = $data->wisdom; $this->health = $data->health; $this->mana = $data->mana; $this->freeStatPoints = $data->free_stat_points; $this->level = $data->level; parent::__construct($user); $this->maxHealth = round(($this->endurance * 3) + ($this->endurance / 2) * ($this->level - 1) + ($this->endurance / 5) * (($this->level - 1) * ($this->level - 2) / 2)); $this->maxMana = round(($this->wisdom * 3) + ($this->wisdom / 2) * ($this->level - 1) + ($this->wisdom / 5) * (($this->level - 1) * ($this->level - 2) / 2)); } /** * Отдаёт информацию о базовом(!) стате. * * @param string $statName - имя стата. Может принимать значения 'strength', 'dexterity', 'intuition', * 'endurance', 'intelligence', 'wisdom'. * @param int $isMainWindow - переключатель "главного окна". Если включить, дополнительно будет показывать ссылку * на повышение стата на 1, при условии наличия свободных очков статов. * * @return string * @throws GameException */ public function getStat(string $statName, int $isMainWindow = 0): string { if (!in_array($statName, self::STAT_NAMES_ARRAY)) { throw new GameException(self::ERROR_STAT_UNKNOWN); } $stat = strval($this->$statName); if ($this->freeStatPoints && $isMainWindow && $this->$statName < self::STAT_MAXIMUM_AMOUNT) { $rand = strval(mt_rand()); $stat .= " [+]"; } return $stat; } /** * Повышает один из выбранных статов на 1, но не выше self::STAT_MAXIMUM_AMOUNT при условии наличия свободных очков * статов. * * @param string $statName - имя стата. Может принимать значения 'strength', 'dexterity', 'intuition', * 'endurance', 'intelligence', 'wisdom'. * * @throws GameException */ public function addOnePointToStat(string $statName) { if (!in_array($statName, self::STAT_NAMES_ARRAY)) { throw new GameException(self::ERROR_STAT_UNKNOWN); } if ($this->freeStatPoints <= 0 || $this->$statName >= self::STAT_MAXIMUM_AMOUNT) { throw new GameException(self::ERROR_STAT_IS_MAXIMUM); } else { Stats::addOne($statName, $this->id); } } public function getMaxWeight(): int { return max($this->strength * 5, 50); } /** * @return mixed */ public function getHealth() { return $this->health; } /** * @return mixed */ public function getMana() { return $this->mana; } /** * @return mixed */ public function getFreeStatPoints() { return $this->freeStatPoints; } /** * @return float */ public function getMaxHealth(): float { return $this->maxHealth; } /** * @return float */ public function getMaxMana(): float { return $this->maxMana; } public function getFullStats(): object { $stats = Stats::getAll($this->id); $itemBonuses = Inventory::getBonuses($this->id); $effectBonuses = Effects::getStatMods($this->id); $obj = (object)[]; foreach (self::STAT_NAMES_ARRAY as $stat) { $obj->$stat = max(0, $stats->$stat + $itemBonuses->{'item_' . $stat} + $effectBonuses->{'effect_' . $stat}); } $obj->accuracy = max(0, $itemBonuses->item_accuracy); $obj->evasion = max(0, $itemBonuses->item_evasion); $obj->criticals = max(0, $itemBonuses->item_criticals); $obj->min_physical_damage = max($this->minDamage, $this->minDamage + $itemBonuses->item_min_physical_damage); $obj->max_physical_damage = max($this->maxDamage, $this->maxDamage + $itemBonuses->item_max_physical_damage); return $obj; } public function levelUp(): string { $this->level += 1; $this->freeStatPoints += 2; $this->save(); Chat::sendSys('Внимание, вы получили ' . $this->level . 'уровень. Доступны очки распределения параметров.'); return 'Персонаж перешёл на ' . $this->level . 'уровень.'; } /** Сохраняет в базу актуальные статы, здоровье, ману, свободные очки статов и уровень. * */ private function save() { Stats::save([ $this->strength, //set $this->dexterity, $this->intuition, $this->endurance, $this->intelligence, $this->wisdom, $this->health, $this->mana, $this->freeStatPoints, $this->level, $this->id //where ]); } }