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->free_stat_points = $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 $stat_name - имя стата. Может принимать значения 'strength', 'dexterity', 'intuition', * 'endurance', 'intelligence', 'wisdom'. * @param int $isMainWindow - переключатель "главного окна". Если включить, дополнительно будет показывать ссылку * на повышение стата на 1, при условии наличия свободных очков статов. * * @return string * @throws GameException */ public function getStat(string $stat_name, int $isMainWindow = 0): string { if (!in_array($stat_name, self::STAT_NAMES_ARRAY)) { throw new GameException(self::ERROR_STAT_UNKNOWN); } $stat = strval($this->$stat_name); if ($this->free_stat_points && $isMainWindow && $this->$stat_name < self::STAT_MAXIMUM_AMOUNT) { $rand = strval(mt_rand()); $stat .= " [+]"; } return $stat; } /** * Повышает один из выбранных статов на 1, но не выше self::STAT_MAXIMUM_AMOUNT при условии наличия свободных очков * статов. * * @param string $stat_name - имя стата. Может принимать значения 'strength', 'dexterity', 'intuition', * 'endurance', 'intelligence', 'wisdom'. * * @throws GameException */ public function addOnePointToStat(string $stat_name) { if (!in_array($stat_name, self::STAT_NAMES_ARRAY)) { throw new GameException(self::ERROR_STAT_UNKNOWN); } if ($this->free_stat_points <= 0 || $this->$stat_name >= self::STAT_MAXIMUM_AMOUNT) { throw new GameException(self::ERROR_STAT_IS_MAXIMUM); } else { Stats::addOne($stat_name, $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->free_stat_points; } /** * @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->strength = max(0, $stats->strength + $itemBonuses->item_strength + $effectBonuses->effect_strength); //$obj->dexterity = max(0, $stats->dexterity + $itemBonuses->item_dexterity + $effectBonuses->effect_dexterity); //$obj->intuition = max(0, $stats->intuition + $itemBonuses->item_intuition + $effectBonuses->effect_intuition); //$obj->endurance = max(0, $stats->endurance + $itemBonuses->item_endurance + $effectBonuses->effect_endurance); //$obj->intelligence = max(0, $stats->intelligence + $itemBonuses->item_intelligence + $effectBonuses->effect_intelligence); //$obj->wisdom = max(0, $stats->wisdom + $itemBonuses->item_wisdom + $effectBonuses->effect_wisdom); $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->free_stat_points += 2; $this->save(); Chat::addSYSMessage('Внимание, вы получили ' . $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->free_stat_points, $this->level, $this->id //where ]); } }