Display power buffs
This commit is contained in:
parent
515602b670
commit
034e6beca6
8 changed files with 86 additions and 25 deletions
|
|
@ -51,7 +51,9 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
this.heroCardDatabase = new HeroCardDatabase();
|
||||
this.monsterCardDatabase = new MonsterCardDatabase();
|
||||
|
||||
this.state = new BattleState();
|
||||
this.clock = new BattleClock();
|
||||
this.buffManager = new BuffManager(this.clock);
|
||||
this.state = new BattleState(this.buffManager);
|
||||
|
||||
this.heroEnergy = new EnergyPool();
|
||||
this.heroEnergyUI.Init(this.heroEnergy);
|
||||
|
|
@ -80,7 +82,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
this.monsters[i] = monster;
|
||||
}
|
||||
|
||||
this.battleSprites.Init(this.heroes, this.monsters);
|
||||
this.battleSprites.Init(this.heroes, this.monsters, this.state);
|
||||
|
||||
BattleParticipant[] cardOwners = new BattleParticipant[parameters.HCardIds.Length];
|
||||
for (int i = 0; i < parameters.HCardIds.Length; i++) {
|
||||
|
|
@ -96,8 +98,6 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
this.monsterDeck = new BattleDeck<MonsterCard>(
|
||||
this.monsterCardDatabase, parameters.MCardIds.Cast<int>().ToArray(), mCardOwners);
|
||||
|
||||
this.clock = new BattleClock();
|
||||
this.buffManager = new BuffManager(this.clock);
|
||||
this.participantActivity = new ParticipantActivity();
|
||||
this.playArea = new PlayArea();
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ public class BattleParticipant
|
|||
public event BattleParticipantUpdateAction OnHit;
|
||||
public event BattleParticipantUpdateAction OnDeath;
|
||||
public event BattleParticipantUpdateAction OnStatusChanged;
|
||||
public event BattleParticipantUpdateAction OnBuffsChanged;
|
||||
|
||||
protected TeamChoice team;
|
||||
protected string displayName;
|
||||
|
|
@ -185,4 +186,10 @@ public class BattleParticipant
|
|||
this.OnStatusChanged(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void TriggerOnBuffsChanged() {
|
||||
if (this.OnBuffsChanged != null) {
|
||||
this.OnBuffsChanged(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ public class BattleSprites: MonoBehaviour
|
|||
private Dictionary<BattleMonster, GameObject> mMonsterSprites;
|
||||
private Dictionary<BattleMonster, HeroInfoUI> mMonsterUIs;
|
||||
|
||||
public void Init(BattleHero[] heroes, BattleMonster[] monsters) {
|
||||
public void Init(BattleHero[] heroes, BattleMonster[] monsters, BattleState battleState) {
|
||||
mHeroSprites = new Dictionary<BattleHero, GameObject>();
|
||||
mHeroUIs = new Dictionary<BattleHero, HeroInfoUI>();
|
||||
mMonsterSprites = new Dictionary<BattleMonster, GameObject>();
|
||||
|
|
@ -35,7 +35,7 @@ public class BattleSprites: MonoBehaviour
|
|||
hero.OnDeath += bps.NotifyDeath;
|
||||
|
||||
HeroInfoUI heroUI = (HeroInfoUI) Instantiate(mHeroUIPrefab.gameObject, mUiCanvas.transform).GetComponent(typeof(HeroInfoUI));
|
||||
heroUI.Init(sprite, hero);
|
||||
heroUI.Init(sprite, hero, battleState);
|
||||
mHeroUIs[hero] = heroUI;
|
||||
}
|
||||
|
||||
|
|
@ -52,7 +52,7 @@ public class BattleSprites: MonoBehaviour
|
|||
monster.OnDeath += bps.NotifyDeath;
|
||||
|
||||
HeroInfoUI monsterUI = (HeroInfoUI) Instantiate(mHeroUIPrefab.gameObject, mUiCanvas.transform).GetComponent(typeof(HeroInfoUI));
|
||||
monsterUI.Init(sprite, monster);
|
||||
monsterUI.Init(sprite, monster, battleState);
|
||||
mMonsterUIs[monster] = monsterUI;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,11 @@ public class BattleState
|
|||
private TeamChoice mTeamsTurn = TeamChoice.Monsters;
|
||||
private bool mPlayedEmotion;
|
||||
private int mRound = 0;
|
||||
private BuffManager buffManager;
|
||||
|
||||
public BattleState(BuffManager buffManager) {
|
||||
this.buffManager = buffManager;
|
||||
}
|
||||
|
||||
public bool IsTeamsTurn(TeamChoice team) {
|
||||
return team == mTeamsTurn;
|
||||
|
|
@ -38,4 +43,6 @@ public class BattleState
|
|||
mRound++;
|
||||
}
|
||||
}
|
||||
|
||||
public BuffManager BuffManager {get => this.buffManager;}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ public class BuffManager {
|
|||
List<Buff> current = GetAllBuffsFor(effect.Participant);
|
||||
current.Add(new Buff(effect.Type, effect.Amount, CalculateEnd(timeNow, effect.Duration)));
|
||||
mBuffs[effect.Participant] = current;
|
||||
effect.Participant.TriggerOnBuffsChanged();
|
||||
}
|
||||
|
||||
public int GetTotalBuffAmountOfType(BattleParticipant participant, BuffType type) {
|
||||
|
|
@ -50,8 +51,13 @@ public class BuffManager {
|
|||
}
|
||||
|
||||
private void NotifyBattleTime(BattleTime timeNow) {
|
||||
foreach (List<Buff> buffs in mBuffs.Values) {
|
||||
buffs.RemoveAll(buff => timeNow.Int >= buff.End.Int);
|
||||
foreach (KeyValuePair<BattleParticipant, List<Buff>> p in mBuffs) {
|
||||
BattleParticipant participant = p.Key;
|
||||
List<Buff> buffs = p.Value;
|
||||
int buffsRemoved = buffs.RemoveAll(buff => timeNow.Int >= buff.End.Int);
|
||||
if (buffsRemoved > 0) {
|
||||
participant.TriggerOnBuffsChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ public class HeroInfoUI : MonoBehaviour
|
|||
{
|
||||
protected GameObject target;
|
||||
protected BattleParticipant battleParticipant;
|
||||
protected BattleState battleState;
|
||||
|
||||
public Text nameText;
|
||||
public Image healthBarBgImage;
|
||||
public Image healthBarFgImage;
|
||||
|
|
@ -24,11 +26,13 @@ public class HeroInfoUI : MonoBehaviour
|
|||
private static Color MED_HP_COLOR = new Color(0.8f, 0.8f, 0f);
|
||||
private static Color LOW_HP_COLOR = new Color(0.8f, 0f, 0f);
|
||||
|
||||
public void Init(GameObject sprite, BattleParticipant battleParticipant) {
|
||||
public void Init(
|
||||
GameObject sprite, BattleParticipant battleParticipant, BattleState battleState) {
|
||||
this.target = sprite;
|
||||
this.battleParticipant = battleParticipant;
|
||||
this.battleState = battleState;
|
||||
|
||||
this.statusUI.Init(battleParticipant);
|
||||
this.statusUI.Init(battleParticipant, battleState);
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
|
|
|
|||
|
|
@ -11,16 +11,24 @@ public class StatusIconUI : MonoBehaviour
|
|||
|
||||
private BattleStatus status;
|
||||
|
||||
public void Init(BattleStatus status) {
|
||||
this.status = status;
|
||||
public void InitStatus(BattleStatus status) {
|
||||
Sprite sprite = Resources.Load<Sprite>(GetStatusResourcePath(status));
|
||||
this.statusImage.sprite = sprite;
|
||||
}
|
||||
|
||||
public void InitBuff(BuffType buffType) {
|
||||
Sprite sprite = Resources.Load<Sprite>(GetBuffResourcePath(buffType));
|
||||
this.statusImage.sprite = sprite;
|
||||
}
|
||||
|
||||
private static string GetStatusResourcePath(BattleStatus status) {
|
||||
return "BattleIcons/StatusIcon" + status;
|
||||
}
|
||||
|
||||
private static string GetBuffResourcePath(BuffType buffType) {
|
||||
return "BattleIcons/BuffIcon" + buffType;
|
||||
}
|
||||
|
||||
public void SetAmount(int amount, int index) {
|
||||
this.turnsText.text = "" + amount;
|
||||
this.transform.localPosition = new Vector2(-index * 22, 0);
|
||||
|
|
|
|||
|
|
@ -10,14 +10,20 @@ public class StatusUI : MonoBehaviour
|
|||
public StatusIconUI iconPrefab;
|
||||
|
||||
private BattleParticipant battleParticipant;
|
||||
private BattleState battleState;
|
||||
|
||||
private Dictionary<BattleStatus, StatusIconUI> icons;
|
||||
private Dictionary<BattleStatus, StatusIconUI> statusIcons;
|
||||
|
||||
public void Init(BattleParticipant battleParticipant) {
|
||||
private Dictionary<BuffType, StatusIconUI> buffIcons;
|
||||
|
||||
public void Init(BattleParticipant battleParticipant, BattleState battleState) {
|
||||
this.battleParticipant = battleParticipant;
|
||||
this.battleState = battleState;
|
||||
|
||||
this.icons = new Dictionary<BattleStatus, StatusIconUI>();
|
||||
this.battleParticipant.OnStatusChanged += this.NotifyBattleStatusChanged;
|
||||
this.statusIcons = new Dictionary<BattleStatus, StatusIconUI>();
|
||||
this.buffIcons = new Dictionary<BuffType, StatusIconUI>();
|
||||
this.battleParticipant.OnStatusChanged += this.NotifyBattleStatusOrBuffsChanged;
|
||||
this.battleParticipant.OnBuffsChanged += this.NotifyBattleStatusOrBuffsChanged;
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
|
|
@ -25,10 +31,10 @@ public class StatusUI : MonoBehaviour
|
|||
UpdateAppearance();
|
||||
}
|
||||
|
||||
public void NotifyBattleStatusChanged(BattleParticipant updatedParticipant) {
|
||||
public void NotifyBattleStatusOrBuffsChanged(BattleParticipant updatedParticipant) {
|
||||
if (updatedParticipant != this.battleParticipant) {
|
||||
throw new System.InvalidOperationException(
|
||||
"NotifyBattleStatusChanged was notified about a different participant.");
|
||||
"NotifyBattleStatusOrBuffsChanged was notified about a different participant.");
|
||||
}
|
||||
UpdateAppearance();
|
||||
}
|
||||
|
|
@ -41,21 +47,44 @@ public class StatusUI : MonoBehaviour
|
|||
}
|
||||
|
||||
StatusIconUI iconUI = null;
|
||||
this.icons.TryGetValue(status, out iconUI);
|
||||
this.statusIcons.TryGetValue(status, out iconUI);
|
||||
if (this.battleParticipant.HasStatus(status)) {
|
||||
if (iconUI == null) {
|
||||
iconUI = Instantiate(this.iconPrefab.gameObject, this.transform).GetComponent<StatusIconUI>();
|
||||
iconUI.Init(status);
|
||||
this.icons[status] = iconUI;
|
||||
iconUI.InitStatus(status);
|
||||
this.statusIcons[status] = iconUI;
|
||||
}
|
||||
iconUI.SetAmount(this.battleParticipant.GetStatusAmount(status), index);
|
||||
index++;
|
||||
iconUI.SetAmount(this.battleParticipant.GetStatusAmount(status), index++);
|
||||
} else {
|
||||
if (iconUI != null) {
|
||||
Destroy(iconUI.gameObject);
|
||||
this.icons.Remove(status);
|
||||
this.statusIcons.Remove(status);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Dictionary<BuffType, StatusIconUI> previousBuffIcons = new Dictionary<BuffType, StatusIconUI>(this.buffIcons);
|
||||
List<Buff> currentBuffs = this.battleState.BuffManager.GetAllBuffsFor(this.battleParticipant);
|
||||
|
||||
foreach (Buff buff in currentBuffs) {
|
||||
StatusIconUI iconUI = null;
|
||||
previousBuffIcons.TryGetValue(buff.Type, out iconUI);
|
||||
if (iconUI == null) {
|
||||
iconUI = Instantiate(this.iconPrefab.gameObject, this.transform).GetComponent<StatusIconUI>();
|
||||
iconUI.InitBuff(buff.Type);
|
||||
this.buffIcons[buff.Type] = iconUI;
|
||||
} else {
|
||||
previousBuffIcons.Remove(buff.Type);
|
||||
}
|
||||
iconUI.SetAmount(buff.Amount, index++);
|
||||
}
|
||||
|
||||
// If a buff is left in previousBuffIcons, it has been removed.
|
||||
foreach (KeyValuePair<BuffType, StatusIconUI> p in previousBuffIcons) {
|
||||
BuffType buffType = p.Key;
|
||||
StatusIconUI iconUI = p.Value;
|
||||
Destroy(iconUI.gameObject);
|
||||
this.buffIcons.Remove(buffType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue