diff --git a/src/Entities/Partner.php b/src/Entities/Partner.php index 844ee9d..779b175 100644 --- a/src/Entities/Partner.php +++ b/src/Entities/Partner.php @@ -3,9 +3,6 @@ namespace Game\Entities; class Partner extends Actor { - // Partner特有的基础属性配置 - public array $baseStats = []; - // Partner特有的天赋加成(与 Actor 不同) public static array $talentBonus = [ 'hp' => 20, @@ -24,118 +21,33 @@ class Partner extends Actor $this->level = $data['level'] ?? 1; $this->exp = $data['exp'] ?? 0; $this->maxExp = $data['maxExp'] ?? (int)(100 * pow(1.5, $this->level - 1)); - $this->baseStats = $data['baseStats'] ?? []; + + // 从 baseStats 提取属性(只在初始化时使用一次) + $baseStats = $data['baseStats'] ?? []; + $this->patk = $baseStats['patk'] ?? $baseStats['atk'] ?? 10; + $this->matk = $baseStats['matk'] ?? 5; + $this->pdef = $baseStats['pdef'] ?? $baseStats['def'] ?? 5; + $this->mdef = $baseStats['mdef'] ?? 3; + $this->crit = $baseStats['crit'] ?? 5; + $this->critdmg = $baseStats['critdmg'] ?? 150; + + // 装备和天赋系统 $this->equip = $data['equip'] ?? []; $this->talents = $data['talents'] ?? $this->talents; $this->talentWeights = $data['talentWeights'] ?? $this->talentWeights; // 加载法术系统数据 $this->mana = $data['mana'] ?? $this->mana; - $this->maxMana = $data['maxMana'] ?? $this->maxMana; + $this->maxMana = $data['maxMana'] ?? 100; $this->spells = $data['spells'] ?? $this->spells; $this->spellBooks = $data['spellBooks'] ?? $this->spellBooks; - // 设置当前血量为最大血量 + // 计算属性并设置生命值 $stats = $this->getStats(); + $this->maxHp = $stats['maxHp']; $this->hp = $data['hp'] ?? $stats['maxHp']; } - /** - * Partner特有的属性计算(基于baseStats和growth) - */ - public function getStats(): array - { - // Calculate base stats based on level and growth - $growth = $this->baseStats['growth'] ?? 1.0; - $levelFactor = $this->level - 1; - - // 获取天赋加成 - $talentStats = $this->getTalentStats(); - - // 向后兼容:支持旧的 atk/def 键 - $basePatk = $this->baseStats['patk'] ?? $this->baseStats['atk'] ?? 10; - $baseMatk = $this->baseStats['matk'] ?? 5; - $basePdef = $this->baseStats['pdef'] ?? $this->baseStats['def'] ?? 5; - $baseMdef = $this->baseStats['mdef'] ?? 3; - - $stats = [ - 'maxHp' => (int)(($this->baseStats['hp'] ?? 100) * (1 + $levelFactor * $growth * 0.1)) + $talentStats['maxHp'], - 'patk' => (int)($basePatk * (1 + $levelFactor * $growth * 0.1)) + $talentStats['patk'], - 'matk' => (int)($baseMatk * (1 + $levelFactor * $growth * 0.1)) + $talentStats['matk'], - 'pdef' => (int)($basePdef * (1 + $levelFactor * $growth * 0.1)) + $talentStats['pdef'], - 'mdef' => (int)($baseMdef * (1 + $levelFactor * $growth * 0.1)) + $talentStats['mdef'], - 'crit' => ($this->baseStats['crit'] ?? 5) + $talentStats['crit'], - 'critdmg' => ($this->baseStats['critdmg'] ?? 150) + $talentStats['critdmg'], - ]; - - $percentBonuses = [ - 'maxHp' => 0, 'patk' => 0, 'matk' => 0, 'pdef' => 0, 'mdef' => 0, 'crit' => 0, 'critdmg' => 0 - ]; - - // Add Equipment Stats - foreach ($this->equip as $item) { - if (empty($item)) continue; - - $enhanceLevel = $item['enhanceLevel'] ?? 0; - $enhanceMultiplier = 1 + ($enhanceLevel * 0.05); - - $stats['maxHp'] += (int)(($item['hp'] ?? 0) * $enhanceMultiplier); - $stats['patk'] += (int)(($item['patk'] ?? 0) * $enhanceMultiplier); - $stats['matk'] += (int)(($item['matk'] ?? 0) * $enhanceMultiplier); - $stats['pdef'] += (int)(($item['pdef'] ?? 0) * $enhanceMultiplier); - $stats['mdef'] += (int)(($item['mdef'] ?? 0) * $enhanceMultiplier); - $stats['crit'] += (int)(($item['crit'] ?? 0) * $enhanceMultiplier); - $stats['critdmg'] += (int)(($item['critdmg'] ?? 0) * $enhanceMultiplier); - - if (!empty($item['affixes'])) { - foreach ($item['affixes'] as $affix) { - $this->parseAffix($affix, $stats, $percentBonuses); - } - } - } - - // Apply Percent Bonuses - foreach ($stats as $key => $val) { - if (isset($percentBonuses[$key]) && $percentBonuses[$key] > 0) { - $stats[$key] = (int)($val * (1 + $percentBonuses[$key] / 100)); - } - } - - return $stats; - } - - /** - * 解析装备附魔属性 - */ - private function parseAffix(string $affix, array &$flatStats, array &$percentStats) - { - if (preg_match('/(物攻|魔攻|物防|魔防|生命值|暴击率|暴击伤害)\s+\+(\d+)(%?)/', $affix, $matches)) { - $name = $matches[1]; - $value = (int)$matches[2]; - $isPercent = $matches[3] === '%'; - - $key = match ($name) { - '物攻' => 'patk', - '魔攻' => 'matk', - '物防' => 'pdef', - '魔防' => 'mdef', - '生命值' => 'maxHp', - '暴击' => 'crit', - '暴击率' => 'crit', - '暴击伤害' => 'critdmg', - default => null - }; - - if ($key) { - if ($isPercent && !in_array($key, ['crit', 'critdmg'])) { - $percentStats[$key] += $value; - } else { - $flatStats[$key] += $value; - } - } - } - } - /** * 根据权重自动分配天赋点 * 重要: HP(生命值)总是必须至少加1点