Remove assumption of 3 heroes and 3 monsters

This commit is contained in:
henriquenakashima 2020-09-24 00:30:46 -04:00
parent 6a6f07689e
commit 33a28cf58e

View file

@ -12,13 +12,6 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
public EnergyUI heroEnergyUI; public EnergyUI heroEnergyUI;
public EnergyUI monsterEnergyUI; public EnergyUI monsterEnergyUI;
// Input
private HeroId[] heroIds;
private MonsterId[] monsterIds;
private CardId[] cardIds;
private MCardId[] mCardIds;
private int[] mCardOwnerIndexes;
// Private // Private
private HeroCardDatabase heroCardDatabase; private HeroCardDatabase heroCardDatabase;
private MonsterCardDatabase monsterCardDatabase; private MonsterCardDatabase monsterCardDatabase;
@ -41,13 +34,13 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
private InsightLevel insightLevel; private InsightLevel insightLevel;
void Awake() { void Awake() {
this.heroIds = new HeroId[3] { HeroId[] heroIds = new HeroId[3] {
HeroId.Brute, HeroId.Brute,
HeroId.Alchemist, HeroId.Alchemist,
HeroId.Shaman, HeroId.Shaman,
}; };
this.cardIds = new CardId[10] { CardId[] cardIds = new CardId[10] {
CardId.CrashingPunch, CardId.CrashingPunch,
CardId.CrashingPunch, CardId.CrashingPunch,
CardId.CrashingPunch, CardId.CrashingPunch,
@ -60,13 +53,13 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
CardId.Meditate, CardId.Meditate,
}; };
this.monsterIds = new MonsterId[3] { MonsterId[] monsterIds = new MonsterId[3] {
MonsterId.Golem, MonsterId.Golem,
MonsterId.Bat, MonsterId.Bat,
MonsterId.Bat, MonsterId.Bat,
}; };
this.mCardIds = new MCardId[10] { MCardId[] mCardIds = new MCardId[10] {
MCardId.GraniteDefense, MCardId.GraniteDefense,
MCardId.GraniteDefense, MCardId.GraniteDefense,
MCardId.GolemCharge, MCardId.GolemCharge,
@ -80,19 +73,19 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
MCardId.VampireFangs, MCardId.VampireFangs,
MCardId.Whirlwind, MCardId.Whirlwind,
}; };
this.mCardOwnerIndexes = new int[10] { int[] mCardOwnerIndexes = new int[10] {
0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2,
}; };
// this.mCardIds = new MCardId[5] { // MCardId[] mCardIds = new MCardId[5] {
// MCardId.Whirlwind, // MCardId.Whirlwind,
// MCardId.Whirlwind, // MCardId.Whirlwind,
// MCardId.Whirlwind, // MCardId.Whirlwind,
// MCardId.Whirlwind, // MCardId.Whirlwind,
// MCardId.Whirlwind, // MCardId.Whirlwind,
// }; // };
// this.mCardOwnerIndexes = new int[5] { // int[] mCardOwnerIndexes = new int[5] {
// 1, 1, // 1, 1,
// 2, 2, 2, // 2, 2, 2,
// }; // };
@ -109,18 +102,18 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
this.insightLevel = new InsightLevel(1); this.insightLevel = new InsightLevel(1);
heroes = new BattleHero[3]; this.heroes = new BattleHero[heroIds.Length];
heroSprites = new Dictionary<BattleHero, GameObject>(); this.heroSprites = new Dictionary<BattleHero, GameObject>();
heroUIs = new Dictionary<BattleHero, HeroInfoUI>(); this.heroUIs = new Dictionary<BattleHero, HeroInfoUI>();
for (int i = 0; i < 3; i++) { for (int i = 0; i < this.heroes.Length; i++) {
HeroId id = heroIds[i]; HeroId id = heroIds[i];
BattleHero hero = new BattleHero(id); BattleHero hero = new BattleHero(id);
hero.Init(); hero.Init();
heroes[i] = hero; this.heroes[i] = hero;
GameObject sprite = HeroDatabase.createHeroSprite(id); GameObject sprite = HeroDatabase.createHeroSprite(id);
heroSprites[hero] = sprite; this.heroSprites[hero] = sprite;
sprite.name = "Hero" + i + "_Sprite"; sprite.name = "Hero" + i + "_Sprite";
PositionSprite(TeamChoice.Heroes, sprite, i); PositionSprite(TeamChoice.Heroes, sprite, i);
BattleParticipantSprite bps = sprite.AddComponent<BattleParticipantSprite>(); BattleParticipantSprite bps = sprite.AddComponent<BattleParticipantSprite>();
@ -128,23 +121,23 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
bps.OnSpriteClicked += battlePlayerControls.NotifyParticipantSpriteClicked; bps.OnSpriteClicked += battlePlayerControls.NotifyParticipantSpriteClicked;
hero.OnDeath += bps.NotifyDeath; 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); heroUI.Init(sprite, hero);
heroUIs[hero] = heroUI; this.heroUIs[hero] = heroUI;
} }
monsters = new BattleMonster[3]; this.monsters = new BattleMonster[monsterIds.Length];
monsterSprites = new Dictionary<BattleMonster, GameObject>(); this.monsterSprites = new Dictionary<BattleMonster, GameObject>();
monsterUIs = new Dictionary<BattleMonster, HeroInfoUI>(); this.monsterUIs = new Dictionary<BattleMonster, HeroInfoUI>();
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
MonsterId id = monsterIds[i]; MonsterId id = monsterIds[i];
BattleMonster monster = MonsterDatabase.createMonsterScript(id); BattleMonster monster = MonsterDatabase.createMonsterScript(id);
monster.Init(); monster.Init();
monsters[i] = monster; this.monsters[i] = monster;
GameObject sprite = MonsterDatabase.createMonsterSprite(id); GameObject sprite = MonsterDatabase.createMonsterSprite(id);
monsterSprites[monster] = sprite; this.monsterSprites[monster] = sprite;
sprite.name = "Monster" + i + "_Sprite"; sprite.name = "Monster" + i + "_Sprite";
PositionSprite(TeamChoice.Monsters, sprite, i); PositionSprite(TeamChoice.Monsters, sprite, i);
BattleParticipantSprite bps = sprite.AddComponent<BattleParticipantSprite>(); BattleParticipantSprite bps = sprite.AddComponent<BattleParticipantSprite>();
@ -152,28 +145,28 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
bps.OnSpriteClicked += battlePlayerControls.NotifyParticipantSpriteClicked; bps.OnSpriteClicked += battlePlayerControls.NotifyParticipantSpriteClicked;
monster.OnDeath += bps.NotifyDeath; 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); monsterUI.Init(sprite, monster);
monsterUIs[monster] = monsterUI; this.monsterUIs[monster] = monsterUI;
} }
BattleParticipant[] cardOwners = new BattleParticipant[this.cardIds.Length]; BattleParticipant[] cardOwners = new BattleParticipant[cardIds.Length];
for (int i = 0; i < this.cardIds.Length; i++) { for (int i = 0; i < cardIds.Length; i++) {
cardOwners[i] = FindHeroByClass(HeroCardDatabase.GetHeroIdOfCard(this.cardIds[i])); cardOwners[i] = FindHeroByClass(HeroCardDatabase.GetHeroIdOfCard(cardIds[i]));
} }
this.heroDeck = new BattleDeck<HeroCard>( this.heroDeck = new BattleDeck<HeroCard>(
this.heroCardDatabase, this.cardIds.Cast<int>().ToArray(), cardOwners); this.heroCardDatabase, cardIds.Cast<int>().ToArray(), cardOwners);
BattleParticipant[] mCardOwners = new BattleParticipant[this.mCardIds.Length]; BattleParticipant[] mCardOwners = new BattleParticipant[mCardIds.Length];
if (this.mCardIds.Length != this.mCardOwnerIndexes.Length) { if (mCardIds.Length != mCardOwnerIndexes.Length) {
throw new System.ArgumentException( throw new System.ArgumentException(
"mCardIds and mCardOwnerIndexes need to have the same length"); "mCardIds and mCardOwnerIndexes need to have the same length");
} }
for (int i = 0; i < this.mCardIds.Length; i++) { for (int i = 0; i < mCardIds.Length; i++) {
mCardOwners[i] = this.monsters[this.mCardOwnerIndexes[i]]; mCardOwners[i] = this.monsters[mCardOwnerIndexes[i]];
} }
this.monsterDeck = new BattleDeck<MonsterCard>( this.monsterDeck = new BattleDeck<MonsterCard>(
this.monsterCardDatabase, this.mCardIds.Cast<int>().ToArray(), mCardOwners); this.monsterCardDatabase, mCardIds.Cast<int>().ToArray(), mCardOwners);
this.playArea = new PlayArea(); this.playArea = new PlayArea();