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 Dictionary<BattleMonster, HeroInfoUI> monsterUIs;
|
||||||
|
|
||||||
private BattleState state;
|
private BattleState state;
|
||||||
private bool heroPassedTurn;
|
|
||||||
private EnergyPool heroEnergy;
|
private EnergyPool heroEnergy;
|
||||||
private EnergyPool monsterEnergy;
|
private EnergyPool monsterEnergy;
|
||||||
private InsightLevel insightLevel;
|
private InsightLevel insightLevel;
|
||||||
|
|
@ -207,8 +206,6 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
||||||
this.battlePlayerControls.Init(
|
this.battlePlayerControls.Init(
|
||||||
this.heroDeck, this.monsterDeck, this.playArea, this.insightLevel,
|
this.heroDeck, this.monsterDeck, this.playArea, this.insightLevel,
|
||||||
this.heroHandPlayability, this.uiCanvas.transform.localScale.x);
|
this.heroHandPlayability, this.uiCanvas.transform.localScale.x);
|
||||||
this.battlePlayerControls.OnCardUsed += this.NotifyHeroCardUsed;
|
|
||||||
this.battlePlayerControls.OnTurnPassed += this.NotifyHeroTurnPassed;
|
|
||||||
this.insightLevel.OnChanged += this.battlePlayerControls.NotifyInsightLevelChanged;
|
this.insightLevel.OnChanged += this.battlePlayerControls.NotifyInsightLevelChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -272,10 +269,19 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
||||||
OnBattleStateChanged();
|
OnBattleStateChanged();
|
||||||
|
|
||||||
// Heroes act until they pass
|
// Heroes act until they pass
|
||||||
while (!this.heroPassedTurn) {
|
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;
|
yield return null;
|
||||||
}
|
}
|
||||||
this.heroPassedTurn = false;
|
}
|
||||||
|
|
||||||
// End of hero turn
|
// End of hero turn
|
||||||
this.heroDeck.DiscardHand();
|
this.heroDeck.DiscardHand();
|
||||||
|
|
@ -317,14 +323,11 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
||||||
OnBattleStateChanged();
|
OnBattleStateChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void NotifyHeroCardUsed(HeroCard card) {
|
public IEnumerator UseHeroCard(HeroCard card) {
|
||||||
if (!CanUseHeroCard(card)) {
|
if (!CanUseHeroCard(card)) {
|
||||||
throw new System.InvalidOperationException("Cannot use card " + card.GetDisplayName());
|
throw new System.InvalidOperationException("Cannot use card " + card.GetDisplayName());
|
||||||
}
|
}
|
||||||
StartCoroutine(UseHeroCard(card));
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEnumerator UseHeroCard(HeroCard card) {
|
|
||||||
this.heroEnergy.PayForCard(card);
|
this.heroEnergy.PayForCard(card);
|
||||||
this.heroDeck.RemoveCardFromHand(card);
|
this.heroDeck.RemoveCardFromHand(card);
|
||||||
yield return card.Use(this, this, battlePlayerControls);
|
yield return card.Use(this, this, battlePlayerControls);
|
||||||
|
|
@ -356,12 +359,6 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
||||||
CheckState();
|
CheckState();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void NotifyHeroTurnPassed() {
|
|
||||||
if (this.state.HeroTurn) {
|
|
||||||
this.heroPassedTurn = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool CanUseHeroCard(HeroCard card) {
|
public bool CanUseHeroCard(HeroCard card) {
|
||||||
return this.heroHandPlayability.IsPlayable(card);
|
return this.heroHandPlayability.IsPlayable(card);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,6 @@ public class BattlePlayerControls : MonoBehaviour
|
||||||
public GameObject uiCanvas;
|
public GameObject uiCanvas;
|
||||||
public GameObject cardPrefab;
|
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<HeroCard> heroDeck;
|
||||||
private BattleDeck<MonsterCard> monsterDeck;
|
private BattleDeck<MonsterCard> monsterDeck;
|
||||||
private PlayArea playArea;
|
private PlayArea playArea;
|
||||||
|
|
@ -26,6 +21,7 @@ public class BattlePlayerControls : MonoBehaviour
|
||||||
private HandControls<HeroCard> heroHandControls;
|
private HandControls<HeroCard> heroHandControls;
|
||||||
private HandControls<MonsterCard> monsterHandControls;
|
private HandControls<MonsterCard> monsterHandControls;
|
||||||
private Dictionary<BaseCard, GameObject> cardsInPlayUIs;
|
private Dictionary<BaseCard, GameObject> cardsInPlayUIs;
|
||||||
|
public PlayerAction playerAction;
|
||||||
|
|
||||||
public void Init(
|
public void Init(
|
||||||
BattleDeck<HeroCard> heroDeck, BattleDeck<MonsterCard> monsterDeck, PlayArea playArea,
|
BattleDeck<HeroCard> heroDeck, BattleDeck<MonsterCard> monsterDeck, PlayArea playArea,
|
||||||
|
|
@ -65,7 +61,7 @@ public class BattlePlayerControls : MonoBehaviour
|
||||||
private void OnHeroCardClicked(HeroCard card) {
|
private void OnHeroCardClicked(HeroCard card) {
|
||||||
if (this.singleTargeting == null) {
|
if (this.singleTargeting == null) {
|
||||||
if (this.battleController.CanUseHeroCard(card)) {
|
if (this.battleController.CanUseHeroCard(card)) {
|
||||||
OnCardUsed(card);
|
this.playerAction = new PlayerAction(card);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -89,7 +85,7 @@ public class BattlePlayerControls : MonoBehaviour
|
||||||
|
|
||||||
public void PassTurnButtonClicked() {
|
public void PassTurnButtonClicked() {
|
||||||
if (this.singleTargeting == null) {
|
if (this.singleTargeting == null) {
|
||||||
OnTurnPassed();
|
this.playerAction = new PlayerAction(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -150,4 +146,10 @@ public class BattlePlayerControls : MonoBehaviour
|
||||||
public void NotifyInsightLevelChanged() {
|
public void NotifyInsightLevelChanged() {
|
||||||
this.monsterHandControls.InsightLevel = this.insightLevel.Level;
|
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:
|
||||||
3
TODO.txt
3
TODO.txt
|
|
@ -1,7 +1,8 @@
|
||||||
- Animate rearrange hand after card is used
|
- Animate rearrange hand after card is used
|
||||||
- Make hero cards be used in sequence Coroutines, not in parallel
|
|
||||||
- Do not Highlight unusable cards
|
- Do not Highlight unusable cards
|
||||||
- Show which cards enemies will use
|
- Show which cards enemies will use
|
||||||
- Show on who enemies will use the cards
|
- Show on who enemies will use the cards
|
||||||
- Extend BattleState to be more than hero turn true/false
|
- 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