Create StatusUI
This commit is contained in:
parent
dd9b360bfc
commit
03ca23d484
11 changed files with 484 additions and 17 deletions
|
|
@ -5,8 +5,9 @@ using UnityEngine;
|
|||
|
||||
public class BattleParticipant
|
||||
{
|
||||
public delegate void DeathAction(BattleParticipant participant);
|
||||
public event DeathAction OnDeath;
|
||||
public delegate void BattleParticipantUpdateAction(BattleParticipant participant);
|
||||
public event BattleParticipantUpdateAction OnDeath;
|
||||
public event BattleParticipantUpdateAction OnStatusChanged;
|
||||
|
||||
protected bool isHero;
|
||||
protected string displayName;
|
||||
|
|
@ -55,6 +56,7 @@ public class BattleParticipant
|
|||
public void CheckState() {
|
||||
if (this.hp <= 0) {
|
||||
this.dead = true;
|
||||
WipeStatus();
|
||||
TriggerOnDeath();
|
||||
}
|
||||
}
|
||||
|
|
@ -99,20 +101,35 @@ public class BattleParticipant
|
|||
}
|
||||
|
||||
public int AddStatus(BattleStatus status, int amount) {
|
||||
if (amount <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int currentAmount;
|
||||
this.statuses.TryGetValue(status, out currentAmount);
|
||||
this.statuses[status] = currentAmount + amount;
|
||||
TriggerOnStatusChanged();
|
||||
return amount;
|
||||
}
|
||||
|
||||
public void TickStatuses() {
|
||||
Dictionary<BattleStatus, int> newStatuses = new Dictionary<BattleStatus, int>();
|
||||
foreach (KeyValuePair<BattleStatus, int> pair in this.statuses) {
|
||||
if (pair.Value >= 1) {
|
||||
newStatuses[pair.Key] = pair.Value - 1;
|
||||
if (this.statuses.Count > 0) {
|
||||
Dictionary<BattleStatus, int> newStatuses = new Dictionary<BattleStatus, int>();
|
||||
foreach (KeyValuePair<BattleStatus, int> pair in this.statuses) {
|
||||
if (pair.Value > 1) {
|
||||
newStatuses[pair.Key] = pair.Value - 1;
|
||||
}
|
||||
}
|
||||
this.statuses = newStatuses;
|
||||
TriggerOnStatusChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public void WipeStatus() {
|
||||
if (this.statuses.Count > 0) {
|
||||
this.statuses = new Dictionary<BattleStatus, int>();
|
||||
TriggerOnStatusChanged();
|
||||
}
|
||||
this.statuses = newStatuses;
|
||||
}
|
||||
|
||||
public bool CanUseCard(BaseCard card) {
|
||||
|
|
@ -122,4 +139,18 @@ public class BattleParticipant
|
|||
public bool HasStatus(BattleStatus status) {
|
||||
return this.statuses.ContainsKey(status);
|
||||
}
|
||||
|
||||
public int GetStatusAmount(BattleStatus status) {
|
||||
if (!this.statuses.ContainsKey(status)) {
|
||||
return 0;
|
||||
} else {
|
||||
return this.statuses[status];
|
||||
}
|
||||
}
|
||||
|
||||
private void TriggerOnStatusChanged() {
|
||||
if (this.OnStatusChanged != null) {
|
||||
this.OnStatusChanged(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue