Show cards in PlayArea
This commit is contained in:
parent
d67a7372c9
commit
8b33f3ff5a
6 changed files with 70 additions and 16 deletions
|
|
@ -74,12 +74,12 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
||||||
}
|
}
|
||||||
this.heroDeck = new HeroDeck(this.cardIds, cardOwners);
|
this.heroDeck = new HeroDeck(this.cardIds, cardOwners);
|
||||||
|
|
||||||
this.battlePlayerControls.Init(this.heroDeck);
|
this.playArea = new PlayArea();
|
||||||
|
|
||||||
|
this.battlePlayerControls.Init(this.heroDeck, this.playArea);
|
||||||
this.battlePlayerControls.OnCardUsed += this.NotifyCardUsed;
|
this.battlePlayerControls.OnCardUsed += this.NotifyCardUsed;
|
||||||
this.battlePlayerControls.OnTurnPassed += this.NotifyTurnPassed;
|
this.battlePlayerControls.OnTurnPassed += this.NotifyTurnPassed;
|
||||||
this.heroDeck.OnHandPileChanged += this.battlePlayerControls.NotifyHandPileChanged;
|
this.heroDeck.OnHandPileChanged += this.battlePlayerControls.NotifyHandPileChanged;
|
||||||
|
|
||||||
this.playArea = new PlayArea();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private BattleParticipant FindHeroByClass(HeroId heroId) {
|
private BattleParticipant FindHeroByClass(HeroId heroId) {
|
||||||
|
|
@ -139,7 +139,6 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
||||||
}
|
}
|
||||||
|
|
||||||
public void NotifyCardUsed(BaseCard card) {
|
public void NotifyCardUsed(BaseCard card) {
|
||||||
Debug.Log("NotifyCardUsed " + card);
|
|
||||||
if (!CanUseCard(card)) {
|
if (!CanUseCard(card)) {
|
||||||
throw new System.InvalidOperationException("Cannot use card " + card.GetDisplayName());
|
throw new System.InvalidOperationException("Cannot use card " + card.GetDisplayName());
|
||||||
}
|
}
|
||||||
|
|
@ -159,7 +158,6 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
||||||
|
|
||||||
public void NotifyTurnPassed() {
|
public void NotifyTurnPassed() {
|
||||||
if (this.heroTurn) {
|
if (this.heroTurn) {
|
||||||
Debug.Log("NotifyTurnPassed");
|
|
||||||
StartEnemyTurn();
|
StartEnemyTurn();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,15 +16,21 @@ public class BattlePlayerControls : MonoBehaviour
|
||||||
|
|
||||||
private HeroDeck heroDeck;
|
private HeroDeck heroDeck;
|
||||||
private List<GameObject> cardsInHandUIs;
|
private List<GameObject> cardsInHandUIs;
|
||||||
|
private PlayArea playArea;
|
||||||
|
private Dictionary<BaseCard, GameObject> cardsInPlayUIs;
|
||||||
|
|
||||||
public void Init(HeroDeck heroDeck) {
|
public void Init(HeroDeck heroDeck, PlayArea playArea) {
|
||||||
this.heroDeck = heroDeck;
|
this.heroDeck = heroDeck;
|
||||||
|
this.playArea = playArea;
|
||||||
|
|
||||||
|
this.cardsInPlayUIs = new Dictionary<BaseCard, GameObject>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start is called before the first frame update
|
// Start is called before the first frame update
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
|
NotifyPlayAreaChanged();
|
||||||
|
this.playArea.OnPlayAreaChanged += NotifyPlayAreaChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
|
|
@ -45,19 +51,23 @@ public class BattlePlayerControls : MonoBehaviour
|
||||||
BaseCard card = hand[i];
|
BaseCard card = hand[i];
|
||||||
GameObject cardUI = Instantiate(this.cardPrefab, this.uiCanvas.transform);
|
GameObject cardUI = Instantiate(this.cardPrefab, this.uiCanvas.transform);
|
||||||
this.cardsInHandUIs.Add(cardUI);
|
this.cardsInHandUIs.Add(cardUI);
|
||||||
cardUI.transform.position = CalculateCardPosition(i, hand.Count);
|
cardUI.transform.position = CalculateHandCardPosition(i, hand.Count);
|
||||||
cardUI.GetComponent<CardUI>().Init(card);
|
cardUI.GetComponent<CardUI>().Init(card);
|
||||||
int cardIndex = i;
|
int cardIndex = i;
|
||||||
cardUI.GetComponent<Button>().onClick.AddListener(delegate {OnCardClicked(card);});
|
cardUI.GetComponent<Button>().onClick.AddListener(delegate {OnCardClicked(card);});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Vector3 CalculateCardPosition(int index, int count) {
|
private const int CARD_WIDTH = 122;
|
||||||
const int CARD_SIZE = 120;
|
private const int CARD_HEIGHT = 155;
|
||||||
|
|
||||||
|
private Vector3 CalculateHandCardPosition(int index, int count) {
|
||||||
const int SPACING = 8;
|
const int SPACING = 8;
|
||||||
const int DELTA = CARD_SIZE + SPACING;
|
const int DELTA = CARD_WIDTH + SPACING;
|
||||||
|
|
||||||
return new Vector3(Screen.width * 0.5f - DELTA / 2 * (count - 1) + DELTA * index, 160, 0);
|
return new Vector3(Screen.width * 0.5f - DELTA / 2 * (count - 1) + DELTA * index,
|
||||||
|
160,
|
||||||
|
0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnCardClicked(BaseCard card) {
|
private void OnCardClicked(BaseCard card) {
|
||||||
|
|
@ -95,4 +105,54 @@ public class BattlePlayerControls : MonoBehaviour
|
||||||
public void NotifyHandPileChanged() {
|
public void NotifyHandPileChanged() {
|
||||||
SetHand(this.heroDeck.GetHandPile());
|
SetHand(this.heroDeck.GetHandPile());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void NotifyPlayAreaChanged() {
|
||||||
|
DestroyCardsThatLeftPlayArea();
|
||||||
|
CreateCardsThatEnteredPlayArea();
|
||||||
|
RepositionCardsInPlayArea();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DestroyCardsThatLeftPlayArea() {
|
||||||
|
List<BaseCard> cardsToRemove = new List<BaseCard>();
|
||||||
|
foreach (KeyValuePair<BaseCard, GameObject> pair in this.cardsInPlayUIs) {
|
||||||
|
if (!this.playArea.GetHeroPermanents().Contains(pair.Key)) {
|
||||||
|
Destroy(pair.Value);
|
||||||
|
cardsToRemove.Add(pair.Key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (BaseCard cardToRemove in cardsToRemove) {
|
||||||
|
this.cardsInPlayUIs.Remove(cardToRemove);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CreateCardsThatEnteredPlayArea() {
|
||||||
|
foreach (BaseCard card in this.playArea.GetHeroPermanents()) {
|
||||||
|
if (!this.cardsInPlayUIs.ContainsKey(card)) {
|
||||||
|
GameObject cardUI = Instantiate(this.cardPrefab, this.uiCanvas.transform);
|
||||||
|
// Leave position to be set by RepositionCardsInPlayArea();
|
||||||
|
cardUI.GetComponent<CardUI>().Init(card);
|
||||||
|
this.cardsInPlayUIs.Add(card, cardUI);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RepositionCardsInPlayArea() {
|
||||||
|
List<BaseCard> permanentList = this.playArea.GetHeroPermanents();
|
||||||
|
for (int i = 0; i < permanentList.Count; i++) {
|
||||||
|
BaseCard card = permanentList[i];
|
||||||
|
GameObject cardUI = this.cardsInPlayUIs[card];
|
||||||
|
cardUI.transform.position = CalculatePlayAreaCardPosition(i, permanentList.Count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Vector3 CalculatePlayAreaCardPosition(int index, int count) {
|
||||||
|
const int SPACING = 8;
|
||||||
|
const int DELTA = CARD_HEIGHT + SPACING;
|
||||||
|
const int PADDING = 8;
|
||||||
|
|
||||||
|
return new Vector3(PADDING + CARD_WIDTH / 2,
|
||||||
|
Screen.height - PADDING - DELTA * index - CARD_HEIGHT / 2,
|
||||||
|
0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@ public class CardCover : BaseCard
|
||||||
SingleTargeting singleTargeting = new SingleTargeting(new OtherHeroTargetPolicy(this.owner));
|
SingleTargeting singleTargeting = new SingleTargeting(new OtherHeroTargetPolicy(this.owner));
|
||||||
yield return playerControls.StartCoroutine(playerControls.ChooseTarget(singleTargeting));
|
yield return playerControls.StartCoroutine(playerControls.ChooseTarget(singleTargeting));
|
||||||
BattleParticipant target = singleTargeting.GetTarget();
|
BattleParticipant target = singleTargeting.GetTarget();
|
||||||
Debug.Log("Covering " + target);
|
|
||||||
target.AddBlock(3);
|
target.AddBlock(3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@ public class CardCrashingPunch : BaseCard
|
||||||
SingleTargeting singleTargeting = new SingleTargeting(new AnyTargetPolicy());
|
SingleTargeting singleTargeting = new SingleTargeting(new AnyTargetPolicy());
|
||||||
yield return playerControls.StartCoroutine(playerControls.ChooseTarget(singleTargeting));
|
yield return playerControls.StartCoroutine(playerControls.ChooseTarget(singleTargeting));
|
||||||
BattleParticipant target = singleTargeting.GetTarget();
|
BattleParticipant target = singleTargeting.GetTarget();
|
||||||
Debug.Log("Punching " + target);
|
|
||||||
target.DealDamage(3);
|
target.DealDamage(3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@ public class CardLightningStrike : BaseCard
|
||||||
SingleTargeting singleTargeting = new SingleTargeting(new AnyTargetPolicy());
|
SingleTargeting singleTargeting = new SingleTargeting(new AnyTargetPolicy());
|
||||||
yield return playerControls.StartCoroutine(playerControls.ChooseTarget(singleTargeting));
|
yield return playerControls.StartCoroutine(playerControls.ChooseTarget(singleTargeting));
|
||||||
BattleParticipant target = singleTargeting.GetTarget();
|
BattleParticipant target = singleTargeting.GetTarget();
|
||||||
Debug.Log("Striking " + target + " with lightning.");
|
|
||||||
target.DealDamage(3);
|
target.DealDamage(3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ public class CardThunderstorm : BaseCard
|
||||||
}
|
}
|
||||||
|
|
||||||
public override IEnumerator Use(IBattleEffectApplier effectApplier, BattlePlayerControls playerControls) {
|
public override IEnumerator Use(IBattleEffectApplier effectApplier, BattlePlayerControls playerControls) {
|
||||||
Debug.Log("A storm is brewing.");
|
|
||||||
effectApplier.Apply(new IncreaseMaxEnergyEffect(1));
|
effectApplier.Apply(new IncreaseMaxEnergyEffect(1));
|
||||||
effectApplier.Apply(new AcquireCardsEffect(new CardId[] {CardId.LightningStrike, CardId.LightningStrike}, BattleZone.DrawPile, this.owner));
|
effectApplier.Apply(new AcquireCardsEffect(new CardId[] {CardId.LightningStrike, CardId.LightningStrike}, BattleZone.DrawPile, this.owner));
|
||||||
yield break;
|
yield break;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue