Implement OilOfSharpness
This commit is contained in:
parent
2190070fee
commit
31cb8fe4c0
45 changed files with 604 additions and 21 deletions
64
Assets/Battle/BuffManager.cs
Normal file
64
Assets/Battle/BuffManager.cs
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
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();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue