136 lines
4.9 KiB
C#
136 lines
4.9 KiB
C#
|
using System.Collections.Generic;
|
|||
|
|
|||
|
namespace Game
|
|||
|
{
|
|||
|
public class FactionBuffManager
|
|||
|
{
|
|||
|
private Dictionary<string, Buff> activeBuffs; // 激活的buff列表
|
|||
|
|
|||
|
public FactionBuffManager()
|
|||
|
{
|
|||
|
activeBuffs = new Dictionary<string, Buff>();
|
|||
|
}
|
|||
|
|
|||
|
// 处理职业或种族buff的激活
|
|||
|
public void CheckBuffs(List<Character> characters)
|
|||
|
{
|
|||
|
Dictionary<string, int> countByFaction = new Dictionary<string, int>();
|
|||
|
|
|||
|
// 统计每个职业/种族的数量
|
|||
|
foreach (var character in characters)
|
|||
|
{
|
|||
|
foreach (var faction in character.Config.Professions) // 职业/种族
|
|||
|
{
|
|||
|
if (!countByFaction.ContainsKey(faction))
|
|||
|
{
|
|||
|
countByFaction[faction] = 0;
|
|||
|
}
|
|||
|
|
|||
|
countByFaction[faction]++;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// 遍历每个职业/种族,查看是否满足Buff的条件
|
|||
|
foreach (var entry in countByFaction)
|
|||
|
{
|
|||
|
string factionName = entry.Key;
|
|||
|
int count = entry.Value;
|
|||
|
|
|||
|
// 如果满足Buff条件,就激活Buff
|
|||
|
Buff factionBuff = GetBuffByFaction(factionName, count);
|
|||
|
if (factionBuff != null)
|
|||
|
{
|
|||
|
if (!activeBuffs.ContainsKey(factionName))
|
|||
|
{
|
|||
|
activeBuffs.Add(factionName, factionBuff);
|
|||
|
ApplyBuffToCharacters(factionBuff, characters);
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
// 如果该buff不再满足条件,则去除
|
|||
|
if (activeBuffs.ContainsKey(factionName))
|
|||
|
{
|
|||
|
activeBuffs.Remove(factionName);
|
|||
|
RemoveBuffFromCharacters(factionName, characters);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// 根据职业/种族数量获取对应的Buff
|
|||
|
private Buff GetBuffByFaction(string factionName, int count)
|
|||
|
{
|
|||
|
// 你可以根据预设的条件(例如战士类英雄数量达到3个,给全体战士加护甲等)来决定返回哪个Buff
|
|||
|
if (factionName == "战士" && count >= 3)
|
|||
|
{
|
|||
|
return new Buff("战士Buff", "战士增加30%护甲", new List<BuffEffect>
|
|||
|
{
|
|||
|
new BuffEffect(BuffEffectType.Armor, 0.3f, true)
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
private void ApplyBuffToCharacters(Buff buff, List<Character> characters)
|
|||
|
{
|
|||
|
foreach (var character in characters)
|
|||
|
{
|
|||
|
// 遍历角色的Factions,如果该角色属于该buff的职业/种族,应用buff
|
|||
|
if (character.Config.Professions.Name.Contains(buff.Name))
|
|||
|
{
|
|||
|
foreach (var effect in buff.Effects)
|
|||
|
{
|
|||
|
ApplyEffectToCharacter(effect, character);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void RemoveBuffFromCharacters(string factionName, List<Character> characters)
|
|||
|
{
|
|||
|
// 遍历角色并移除buff的效果
|
|||
|
foreach (var character in characters)
|
|||
|
{
|
|||
|
if (character.Config.Professions.Name.Contains(factionName))
|
|||
|
{
|
|||
|
foreach (var effect in activeBuffs[factionName].Effects)
|
|||
|
{
|
|||
|
RemoveEffectFromCharacter(effect, character);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void ApplyEffectToCharacter(BuffEffect effect, Character character)
|
|||
|
{
|
|||
|
switch (effect.EffectType)
|
|||
|
{
|
|||
|
case BuffEffectType.AttackDamage:
|
|||
|
character.OtherAttackDamage +=
|
|||
|
effect.IsPercentage ? character.OtherAttackDamage * effect.Value : effect.Value;
|
|||
|
break;
|
|||
|
case BuffEffectType.Armor:
|
|||
|
character.OtherArmor += effect.IsPercentage ? character.OtherArmor * effect.Value : effect.Value;
|
|||
|
break;
|
|||
|
// 其他效果的处理逻辑...
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void RemoveEffectFromCharacter(BuffEffect effect, Character character)
|
|||
|
{
|
|||
|
switch (effect.EffectType)
|
|||
|
{
|
|||
|
case BuffEffectType.AttackDamage:
|
|||
|
character.OtherAttackDamage -=
|
|||
|
effect.IsPercentage ? character.OtherAttackDamage * effect.Value : effect.Value;
|
|||
|
break;
|
|||
|
case BuffEffectType.Armor:
|
|||
|
character.OtherArmor -= effect.IsPercentage ? character.OtherArmor * effect.Value : effect.Value;
|
|||
|
break;
|
|||
|
// 其他效果的移除逻辑...
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|