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 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<BattleHero, GameObject>();
heroUIs = new Dictionary<BattleHero, HeroInfoUI>();
for (int i = 0; i < 3; i++) {
this.heroes = new BattleHero[heroIds.Length];
this.heroSprites = new Dictionary<BattleHero, GameObject>();
this.heroUIs = new Dictionary<BattleHero, HeroInfoUI>();
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<BattleParticipantSprite>();
@ -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<BattleMonster, GameObject>();
monsterUIs = new Dictionary<BattleMonster, HeroInfoUI>();
this.monsters = new BattleMonster[monsterIds.Length];
this.monsterSprites = new Dictionary<BattleMonster, GameObject>();
this.monsterUIs = new Dictionary<BattleMonster, HeroInfoUI>();
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<BattleParticipantSprite>();
@ -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<HeroCard>(
this.heroCardDatabase, this.cardIds.Cast<int>().ToArray(), cardOwners);
this.heroCardDatabase, cardIds.Cast<int>().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<MonsterCard>(
this.monsterCardDatabase, this.mCardIds.Cast<int>().ToArray(), mCardOwners);
this.monsterCardDatabase, mCardIds.Cast<int>().ToArray(), mCardOwners);
this.playArea = new PlayArea();