refactor(enemy): Boss 选招与战利品掉落改用 WeightedPick;删除零调用的 SelectWeightedSkill 死代码
This commit is contained in:
@@ -33,32 +33,24 @@ namespace BaseGames.Enemies
|
||||
bool isHard = dm != null &&
|
||||
(int)dm.CurrentLevel >= (int)DifficultyLevel.Hard;
|
||||
|
||||
float totalWeight = 0f;
|
||||
foreach (var entry in table.Entries)
|
||||
// 有效权重只算一遍(难度加成),再交由共享原语加权抽取;无正权重时不掉落。
|
||||
var weights = new float[table.Entries.Length];
|
||||
for (int i = 0; i < table.Entries.Length; i++)
|
||||
{
|
||||
var entry = table.Entries[i];
|
||||
float w = entry.BaseWeight;
|
||||
if (isHard && entry.ScaleWithDifficulty) w *= 1.5f;
|
||||
totalWeight += w;
|
||||
weights[i] = w;
|
||||
}
|
||||
|
||||
if (totalWeight <= 0f) return;
|
||||
int idx = WeightedPick.Index(weights);
|
||||
if (idx < 0) return;
|
||||
|
||||
float roll = Random.Range(0f, totalWeight);
|
||||
float accum = 0f;
|
||||
foreach (var entry in table.Entries)
|
||||
{
|
||||
float w = entry.BaseWeight;
|
||||
if (isHard && entry.ScaleWithDifficulty) w *= 1.5f;
|
||||
accum += w;
|
||||
if (roll <= accum)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(entry.ItemId))
|
||||
CollectibleSpawner.SpawnItem(worldPosition, entry.ItemId);
|
||||
else if (entry.LingZhuAmount > 0)
|
||||
CollectibleSpawner.SpawnLingZhu(worldPosition, entry.LingZhuAmount);
|
||||
return;
|
||||
}
|
||||
}
|
||||
var picked = table.Entries[idx];
|
||||
if (!string.IsNullOrEmpty(picked.ItemId))
|
||||
CollectibleSpawner.SpawnItem(worldPosition, picked.ItemId);
|
||||
else if (picked.LingZhuAmount > 0)
|
||||
CollectibleSpawner.SpawnLingZhu(worldPosition, picked.LingZhuAmount);
|
||||
}
|
||||
|
||||
private static void ApplyDifficultyLingZhuScale(ref int lingZhu)
|
||||
|
||||
Reference in New Issue
Block a user