refactor(enemy): Boss 选招与战利品掉落改用 WeightedPick;删除零调用的 SelectWeightedSkill 死代码
This commit is contained in:
@@ -127,37 +127,6 @@ namespace BaseGames.Boss
|
||||
/// <summary>Inspector 中注册的全部技能 SO(只读)。</summary>
|
||||
public BossSkillSO[] Skills => _skills;
|
||||
|
||||
/// <summary>
|
||||
/// 从候选技能列表中按 weight 加权随机选择一个技能。
|
||||
/// 权重为 0 的技能不参与选择;所有候选权重均为 0 时返回 null。
|
||||
/// </summary>
|
||||
public BossSkillSO SelectWeightedSkill(System.Collections.Generic.IList<BossSkillSO> candidates)
|
||||
{
|
||||
if (candidates == null || candidates.Count == 0) return null;
|
||||
|
||||
float totalWeight = 0f;
|
||||
for (int i = 0; i < candidates.Count; i++)
|
||||
{
|
||||
var s = candidates[i];
|
||||
if (s != null && s.weight > 0f) totalWeight += s.weight;
|
||||
}
|
||||
if (totalWeight <= 0f) return null;
|
||||
|
||||
float roll = UnityEngine.Random.value * totalWeight;
|
||||
float acc = 0f;
|
||||
for (int i = 0; i < candidates.Count; i++)
|
||||
{
|
||||
var s = candidates[i];
|
||||
if (s == null || s.weight <= 0f) continue;
|
||||
acc += s.weight;
|
||||
if (roll <= acc) return s;
|
||||
}
|
||||
// 浮点精度兜底:返回最后一个有效候选
|
||||
for (int i = candidates.Count - 1; i >= 0; i--)
|
||||
if (candidates[i]?.weight > 0f) return candidates[i];
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行一个 Boss 技能。若当前正在执行或技能冷却未就绪则返回。
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user