重构:Partner 采用和 Player 相同的属性计算方式

- 删除 Partner 的自定义 getStats() 方法,改用 Actor 的统一实现
- 删除 parseAffix() 方法(Actor 中已有)
- baseStats 只在构造函数初始化时使用一次,用于设置基础属性
- 基础属性(patk, matk, pdef, mdef, crit, critdmg)现在直接存储在 Actor 属性中
- 删除 growth 系数,不再基于等级动态放大属性
- 属性计算方式统一:基础值 → 天赋加成 → 装备加成 → 附魔加成

现在 Partner 与 Player 使用完全相同的属性计算系统,只是天赋加成值不同

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
hant 2025-12-03 22:53:47 +08:00
parent 0ffd44eccf
commit d2e1625c43

View File

@ -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点