From d2e1625c4329ff6738a5a309051f7aa7eac39caa Mon Sep 17 00:00:00 2001 From: hant Date: Wed, 3 Dec 2025 22:53:47 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=EF=BC=9APartner=20=E9=87=87?= =?UTF-8?q?=E7=94=A8=E5=92=8C=20Player=20=E7=9B=B8=E5=90=8C=E7=9A=84?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E8=AE=A1=E7=AE=97=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 删除 Partner 的自定义 getStats() 方法,改用 Actor 的统一实现 - 删除 parseAffix() 方法(Actor 中已有) - baseStats 只在构造函数初始化时使用一次,用于设置基础属性 - 基础属性(patk, matk, pdef, mdef, crit, critdmg)现在直接存储在 Actor 属性中 - 删除 growth 系数,不再基于等级动态放大属性 - 属性计算方式统一:基础值 → 天赋加成 → 装备加成 → 附魔加成 现在 Partner 与 Player 使用完全相同的属性计算系统,只是天赋加成值不同 🤖 Generated with Claude Code Co-Authored-By: Claude --- src/Entities/Partner.php | 116 +++++---------------------------------- 1 file changed, 14 insertions(+), 102 deletions(-) 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点