Create TurnIntentions
This commit is contained in:
parent
838c30af99
commit
94b3309bb7
9 changed files with 181 additions and 32 deletions
69
Assets/Battle/TurnIntentions.cs
Normal file
69
Assets/Battle/TurnIntentions.cs
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class TurnIntentions<BaseCardT> where BaseCardT: BaseCard
|
||||
{
|
||||
public delegate void IntentionsChangedAction();
|
||||
public event IntentionsChangedAction OnIntentionsChanged;
|
||||
|
||||
private BattleDeck<BaseCardT> mDeck;
|
||||
private EnergyPool mEnergyPool;
|
||||
private bool mActive;
|
||||
private List<BaseCardT> mCardsToUse = new List<BaseCardT>();
|
||||
|
||||
public TurnIntentions(BattleDeck<BaseCardT> deck, EnergyPool energyPool) {
|
||||
mDeck = deck;
|
||||
mEnergyPool = energyPool;
|
||||
mActive = true;
|
||||
|
||||
mDeck.OnDrawPileChanged += OnDependencyChanged;
|
||||
mEnergyPool.OnEnergyChanged += OnDependencyChanged;
|
||||
}
|
||||
|
||||
public void ResumeIntentions() {
|
||||
mActive = true;
|
||||
UpdateState();
|
||||
TriggerOnIntentionsChanged();
|
||||
}
|
||||
|
||||
public void PauseIntentions() {
|
||||
mActive = false;
|
||||
mCardsToUse.Clear();
|
||||
TriggerOnIntentionsChanged();
|
||||
}
|
||||
|
||||
private void OnDependencyChanged() {
|
||||
if (mActive) {
|
||||
UpdateState();
|
||||
TriggerOnIntentionsChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public bool WillUseCard(BaseCardT card) {
|
||||
return mCardsToUse.Contains(card);
|
||||
}
|
||||
|
||||
private void UpdateState() {
|
||||
int projectedEnergy = mEnergyPool.Energy;
|
||||
// TODO: Account for emotions
|
||||
|
||||
mCardsToUse.Clear();
|
||||
|
||||
List<BaseCardT> hand = mDeck.GetHandPile();
|
||||
for (int i = 0; i < hand.Count; i++) {
|
||||
BaseCardT card = hand[i];
|
||||
if (card.Owner.CanUseCard(card)
|
||||
&& projectedEnergy >= card.GetCost()) {
|
||||
projectedEnergy -= card.GetCost();
|
||||
mCardsToUse.Add(card);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void TriggerOnIntentionsChanged() {
|
||||
if (OnIntentionsChanged != null) {
|
||||
OnIntentionsChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue