Create PlayerAction and use hero cards in parallel
This commit is contained in:
parent
d48780d629
commit
a2ced7a003
5 changed files with 61 additions and 25 deletions
|
|
@ -30,7 +30,6 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
private Dictionary<BattleMonster, HeroInfoUI> monsterUIs;
|
||||
|
||||
private BattleState state;
|
||||
private bool heroPassedTurn;
|
||||
private EnergyPool heroEnergy;
|
||||
private EnergyPool monsterEnergy;
|
||||
private InsightLevel insightLevel;
|
||||
|
|
@ -207,8 +206,6 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
this.battlePlayerControls.Init(
|
||||
this.heroDeck, this.monsterDeck, this.playArea, this.insightLevel,
|
||||
this.heroHandPlayability, this.uiCanvas.transform.localScale.x);
|
||||
this.battlePlayerControls.OnCardUsed += this.NotifyHeroCardUsed;
|
||||
this.battlePlayerControls.OnTurnPassed += this.NotifyHeroTurnPassed;
|
||||
this.insightLevel.OnChanged += this.battlePlayerControls.NotifyInsightLevelChanged;
|
||||
}
|
||||
|
||||
|
|
@ -272,10 +269,19 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
OnBattleStateChanged();
|
||||
|
||||
// Heroes act until they pass
|
||||
while (!this.heroPassedTurn) {
|
||||
yield return null;
|
||||
while (true) {
|
||||
PlayerAction playerAction = this.battlePlayerControls.RetrievePlayerAction();
|
||||
if (playerAction != null) {
|
||||
if (playerAction.IsTurnPassed()) {
|
||||
break;
|
||||
} else {
|
||||
HeroCard card = playerAction.GetCardUsed();
|
||||
yield return UseHeroCard(card);
|
||||
}
|
||||
} else {
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
this.heroPassedTurn = false;
|
||||
|
||||
// End of hero turn
|
||||
this.heroDeck.DiscardHand();
|
||||
|
|
@ -317,14 +323,11 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
OnBattleStateChanged();
|
||||
}
|
||||
|
||||
public void NotifyHeroCardUsed(HeroCard card) {
|
||||
public IEnumerator UseHeroCard(HeroCard card) {
|
||||
if (!CanUseHeroCard(card)) {
|
||||
throw new System.InvalidOperationException("Cannot use card " + card.GetDisplayName());
|
||||
}
|
||||
StartCoroutine(UseHeroCard(card));
|
||||
}
|
||||
|
||||
public IEnumerator UseHeroCard(HeroCard card) {
|
||||
this.heroEnergy.PayForCard(card);
|
||||
this.heroDeck.RemoveCardFromHand(card);
|
||||
yield return card.Use(this, this, battlePlayerControls);
|
||||
|
|
@ -356,12 +359,6 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
CheckState();
|
||||
}
|
||||
|
||||
public void NotifyHeroTurnPassed() {
|
||||
if (this.state.HeroTurn) {
|
||||
this.heroPassedTurn = true;
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanUseHeroCard(HeroCard card) {
|
||||
return this.heroHandPlayability.IsPlayable(card);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,11 +12,6 @@ public class BattlePlayerControls : MonoBehaviour
|
|||
public GameObject uiCanvas;
|
||||
public GameObject cardPrefab;
|
||||
|
||||
public delegate void CardUsedAction(HeroCard card);
|
||||
public event CardUsedAction OnCardUsed;
|
||||
public delegate void TurnPassedAction();
|
||||
public event TurnPassedAction OnTurnPassed;
|
||||
|
||||
private BattleDeck<HeroCard> heroDeck;
|
||||
private BattleDeck<MonsterCard> monsterDeck;
|
||||
private PlayArea playArea;
|
||||
|
|
@ -26,6 +21,7 @@ public class BattlePlayerControls : MonoBehaviour
|
|||
private HandControls<HeroCard> heroHandControls;
|
||||
private HandControls<MonsterCard> monsterHandControls;
|
||||
private Dictionary<BaseCard, GameObject> cardsInPlayUIs;
|
||||
public PlayerAction playerAction;
|
||||
|
||||
public void Init(
|
||||
BattleDeck<HeroCard> heroDeck, BattleDeck<MonsterCard> monsterDeck, PlayArea playArea,
|
||||
|
|
@ -65,7 +61,7 @@ public class BattlePlayerControls : MonoBehaviour
|
|||
private void OnHeroCardClicked(HeroCard card) {
|
||||
if (this.singleTargeting == null) {
|
||||
if (this.battleController.CanUseHeroCard(card)) {
|
||||
OnCardUsed(card);
|
||||
this.playerAction = new PlayerAction(card);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -89,7 +85,7 @@ public class BattlePlayerControls : MonoBehaviour
|
|||
|
||||
public void PassTurnButtonClicked() {
|
||||
if (this.singleTargeting == null) {
|
||||
OnTurnPassed();
|
||||
this.playerAction = new PlayerAction(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -150,4 +146,10 @@ public class BattlePlayerControls : MonoBehaviour
|
|||
public void NotifyInsightLevelChanged() {
|
||||
this.monsterHandControls.InsightLevel = this.insightLevel.Level;
|
||||
}
|
||||
|
||||
public PlayerAction RetrievePlayerAction() {
|
||||
PlayerAction result = this.playerAction;
|
||||
this.playerAction = null;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
25
Assets/Battle/PlayerAction.cs
Normal file
25
Assets/Battle/PlayerAction.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerAction
|
||||
{
|
||||
private bool turnPassed;
|
||||
private HeroCard cardUsed;
|
||||
|
||||
public PlayerAction(HeroCard cardUsed) {
|
||||
if (cardUsed != null) {
|
||||
this.cardUsed = cardUsed;
|
||||
} else {
|
||||
this.turnPassed = true;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsTurnPassed() {
|
||||
return this.turnPassed;
|
||||
}
|
||||
|
||||
public HeroCard GetCardUsed() {
|
||||
return this.cardUsed;
|
||||
}
|
||||
}
|
||||
11
Assets/Battle/PlayerAction.cs.meta
Normal file
11
Assets/Battle/PlayerAction.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1dd3bc250a935b84da415b58385a6010
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
5
TODO.txt
5
TODO.txt
|
|
@ -1,7 +1,8 @@
|
|||
- Animate rearrange hand after card is used
|
||||
- Make hero cards be used in sequence Coroutines, not in parallel
|
||||
- Do not Highlight unusable cards
|
||||
- Show which cards enemies will use
|
||||
- Show on who enemies will use the cards
|
||||
- Extend BattleState to be more than hero turn true/false
|
||||
- Create BattleParameters
|
||||
- Create BattleParameters
|
||||
- Highlight which card is targeting
|
||||
- Allow cancelling targeting
|
||||
Loading…
Add table
Add a link
Reference in a new issue