64 lines
No EOL
1.9 KiB
C#
64 lines
No EOL
1.9 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
public class Buff {
|
|
private BuffType mType;
|
|
private int mAmount;
|
|
private BattleTime mEnd;
|
|
|
|
public Buff(BuffType type, int amount, BattleTime end) {
|
|
mType = type;
|
|
mAmount = amount;
|
|
mEnd = end;
|
|
}
|
|
|
|
public BuffType Type {get => mType;}
|
|
public int Amount {get => mAmount;}
|
|
public BattleTime End {get => mEnd;}
|
|
}
|
|
|
|
public class BuffManager {
|
|
|
|
private Dictionary<BattleParticipant, List<Buff>> mBuffs = new Dictionary<BattleParticipant, List<Buff>>();
|
|
|
|
public BuffManager(BattleClock clock) {
|
|
clock.OnTimeChanged += NotifyBattleTime;
|
|
}
|
|
|
|
public void AddBuff(BuffParticipantEffect effect, BattleTime timeNow) {
|
|
List<Buff> current = GetAllBuffsFor(effect.Participant);
|
|
current.Add(new Buff(effect.Type, effect.Amount, CalculateEnd(timeNow, effect.Duration)));
|
|
mBuffs[effect.Participant] = current;
|
|
}
|
|
|
|
public int GetTotalBuffAmountOfType(BattleParticipant participant, BuffType type) {
|
|
int total = 0;
|
|
foreach (Buff buff in GetAllBuffsFor(participant)) {
|
|
if (buff.Type == type) {
|
|
total += buff.Amount;
|
|
}
|
|
}
|
|
return total;
|
|
}
|
|
|
|
public List<Buff> GetAllBuffsFor(BattleParticipant participant) {
|
|
if (mBuffs.ContainsKey(participant)) {
|
|
return mBuffs[participant];
|
|
} else {
|
|
return new List<Buff>();
|
|
}
|
|
}
|
|
|
|
private void NotifyBattleTime(BattleTime timeNow) {
|
|
foreach (List<Buff> buffs in mBuffs.Values) {
|
|
buffs.RemoveAll(buff => timeNow.Int >= buff.End.Int);
|
|
}
|
|
}
|
|
|
|
private static BattleTime CalculateEnd(BattleTime timeNow, BuffDuration duration) {
|
|
if (duration == BuffDuration.UntilEndOfNextHeroTurn) {
|
|
return new BattleTime(timeNow.RoundNumber + 1, RoundStep.EndOfHeroTurn);
|
|
}
|
|
throw new System.Exception();
|
|
}
|
|
} |