From 33a28cf58e3fbc2482238d79e05706099c14f8ca Mon Sep 17 00:00:00 2001 From: henriquenakashima Date: Thu, 24 Sep 2020 00:30:46 -0400 Subject: [PATCH] Remove assumption of 3 heroes and 3 monsters --- Assets/Battle/BattleController.cs | 69 ++++++++++++++----------------- 1 file changed, 31 insertions(+), 38 deletions(-) diff --git a/Assets/Battle/BattleController.cs b/Assets/Battle/BattleController.cs index 418e39e..bfe108c 100644 --- a/Assets/Battle/BattleController.cs +++ b/Assets/Battle/BattleController.cs @@ -12,13 +12,6 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe public EnergyUI heroEnergyUI; public EnergyUI monsterEnergyUI; - // Input - private HeroId[] heroIds; - private MonsterId[] monsterIds; - private CardId[] cardIds; - private MCardId[] mCardIds; - private int[] mCardOwnerIndexes; - // Private private HeroCardDatabase heroCardDatabase; private MonsterCardDatabase monsterCardDatabase; @@ -41,13 +34,13 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe private InsightLevel insightLevel; void Awake() { - this.heroIds = new HeroId[3] { + HeroId[] heroIds = new HeroId[3] { HeroId.Brute, HeroId.Alchemist, HeroId.Shaman, }; - this.cardIds = new CardId[10] { + CardId[] cardIds = new CardId[10] { CardId.CrashingPunch, CardId.CrashingPunch, CardId.CrashingPunch, @@ -60,13 +53,13 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe CardId.Meditate, }; - this.monsterIds = new MonsterId[3] { + MonsterId[] monsterIds = new MonsterId[3] { MonsterId.Golem, MonsterId.Bat, MonsterId.Bat, }; - this.mCardIds = new MCardId[10] { + MCardId[] mCardIds = new MCardId[10] { MCardId.GraniteDefense, MCardId.GraniteDefense, MCardId.GolemCharge, @@ -80,19 +73,19 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe MCardId.VampireFangs, MCardId.Whirlwind, }; - this.mCardOwnerIndexes = new int[10] { + int[] mCardOwnerIndexes = new int[10] { 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, }; - // this.mCardIds = new MCardId[5] { + // MCardId[] mCardIds = new MCardId[5] { // MCardId.Whirlwind, // MCardId.Whirlwind, // MCardId.Whirlwind, // MCardId.Whirlwind, // MCardId.Whirlwind, // }; - // this.mCardOwnerIndexes = new int[5] { + // int[] mCardOwnerIndexes = new int[5] { // 1, 1, // 2, 2, 2, // }; @@ -109,18 +102,18 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe this.insightLevel = new InsightLevel(1); - heroes = new BattleHero[3]; - heroSprites = new Dictionary(); - heroUIs = new Dictionary(); - for (int i = 0; i < 3; i++) { + this.heroes = new BattleHero[heroIds.Length]; + this.heroSprites = new Dictionary(); + this.heroUIs = new Dictionary(); + for (int i = 0; i < this.heroes.Length; i++) { HeroId id = heroIds[i]; BattleHero hero = new BattleHero(id); hero.Init(); - heroes[i] = hero; + this.heroes[i] = hero; GameObject sprite = HeroDatabase.createHeroSprite(id); - heroSprites[hero] = sprite; + this.heroSprites[hero] = sprite; sprite.name = "Hero" + i + "_Sprite"; PositionSprite(TeamChoice.Heroes, sprite, i); BattleParticipantSprite bps = sprite.AddComponent(); @@ -128,23 +121,23 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe bps.OnSpriteClicked += battlePlayerControls.NotifyParticipantSpriteClicked; hero.OnDeath += bps.NotifyDeath; - HeroInfoUI heroUI = (HeroInfoUI) Instantiate(heroUIPrefab.gameObject, uiCanvas.transform).GetComponent(typeof(HeroInfoUI)); + HeroInfoUI heroUI = (HeroInfoUI) Instantiate(this.heroUIPrefab.gameObject, this.uiCanvas.transform).GetComponent(typeof(HeroInfoUI)); heroUI.Init(sprite, hero); - heroUIs[hero] = heroUI; + this.heroUIs[hero] = heroUI; } - monsters = new BattleMonster[3]; - monsterSprites = new Dictionary(); - monsterUIs = new Dictionary(); + this.monsters = new BattleMonster[monsterIds.Length]; + this.monsterSprites = new Dictionary(); + this.monsterUIs = new Dictionary(); for (int i = 0; i < 3; i++) { MonsterId id = monsterIds[i]; BattleMonster monster = MonsterDatabase.createMonsterScript(id); monster.Init(); - monsters[i] = monster; + this.monsters[i] = monster; GameObject sprite = MonsterDatabase.createMonsterSprite(id); - monsterSprites[monster] = sprite; + this.monsterSprites[monster] = sprite; sprite.name = "Monster" + i + "_Sprite"; PositionSprite(TeamChoice.Monsters, sprite, i); BattleParticipantSprite bps = sprite.AddComponent(); @@ -152,28 +145,28 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe bps.OnSpriteClicked += battlePlayerControls.NotifyParticipantSpriteClicked; monster.OnDeath += bps.NotifyDeath; - HeroInfoUI monsterUI = (HeroInfoUI) Instantiate(heroUIPrefab.gameObject, uiCanvas.transform).GetComponent(typeof(HeroInfoUI)); + HeroInfoUI monsterUI = (HeroInfoUI) Instantiate(this.heroUIPrefab.gameObject, this.uiCanvas.transform).GetComponent(typeof(HeroInfoUI)); monsterUI.Init(sprite, monster); - monsterUIs[monster] = monsterUI; + this.monsterUIs[monster] = monsterUI; } - BattleParticipant[] cardOwners = new BattleParticipant[this.cardIds.Length]; - for (int i = 0; i < this.cardIds.Length; i++) { - cardOwners[i] = FindHeroByClass(HeroCardDatabase.GetHeroIdOfCard(this.cardIds[i])); + BattleParticipant[] cardOwners = new BattleParticipant[cardIds.Length]; + for (int i = 0; i < cardIds.Length; i++) { + cardOwners[i] = FindHeroByClass(HeroCardDatabase.GetHeroIdOfCard(cardIds[i])); } this.heroDeck = new BattleDeck( - this.heroCardDatabase, this.cardIds.Cast().ToArray(), cardOwners); + this.heroCardDatabase, cardIds.Cast().ToArray(), cardOwners); - BattleParticipant[] mCardOwners = new BattleParticipant[this.mCardIds.Length]; - if (this.mCardIds.Length != this.mCardOwnerIndexes.Length) { + BattleParticipant[] mCardOwners = new BattleParticipant[mCardIds.Length]; + if (mCardIds.Length != mCardOwnerIndexes.Length) { throw new System.ArgumentException( "mCardIds and mCardOwnerIndexes need to have the same length"); } - for (int i = 0; i < this.mCardIds.Length; i++) { - mCardOwners[i] = this.monsters[this.mCardOwnerIndexes[i]]; + for (int i = 0; i < mCardIds.Length; i++) { + mCardOwners[i] = this.monsters[mCardOwnerIndexes[i]]; } this.monsterDeck = new BattleDeck( - this.monsterCardDatabase, this.mCardIds.Cast().ToArray(), mCardOwners); + this.monsterCardDatabase, mCardIds.Cast().ToArray(), mCardOwners); this.playArea = new PlayArea();