Remove hero/monster CardDatabase from BattleController

This commit is contained in:
henriquenakashima 2020-10-13 23:13:53 -04:00
parent db92332783
commit 04d00ebede
2 changed files with 20 additions and 26 deletions

View file

@ -16,9 +16,6 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
public BattleSprites battleSprites; public BattleSprites battleSprites;
// Private // Private
private HeroCardDatabase heroCardDatabase;
private MonsterCardDatabase monsterCardDatabase;
private BattleState state; private BattleState state;
private HandPlayability<HeroCard> heroHandPlayability; private HandPlayability<HeroCard> heroHandPlayability;
private HandPlayability<MonsterCard> monsterHandPlayability; private HandPlayability<MonsterCard> monsterHandPlayability;
@ -35,9 +32,6 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
parameters = CheatBattle.CreateParameters(); parameters = CheatBattle.CreateParameters();
} }
this.heroCardDatabase = new HeroCardDatabase();
this.monsterCardDatabase = new MonsterCardDatabase();
this.state = new BattleState(parameters); this.state = new BattleState(parameters);
this.heroEnergyUI.Init(this.state.HeroEnergy); this.heroEnergyUI.Init(this.state.HeroEnergy);
@ -45,20 +39,6 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
this.battleSprites.Init(this.state.Heroes, this.state.Monsters, this.state); this.battleSprites.Init(this.state.Heroes, this.state.Monsters, this.state);
BattleParticipant[] cardOwners = new BattleParticipant[parameters.HCardIds.Length];
for (int i = 0; i < parameters.HCardIds.Length; i++) {
cardOwners[i] = this.state.Heroes[parameters.HCardOwnerIndexes[i]];
}
BattleDeck<HeroCard> heroDeck = new BattleDeck<HeroCard>(
this.heroCardDatabase, parameters.HCardIds.Cast<int>().ToArray(), cardOwners);
BattleParticipant[] mCardOwners = new BattleParticipant[parameters.MCardIds.Length];
for (int i = 0; i < parameters.MCardIds.Length; i++) {
mCardOwners[i] = this.state.Monsters[parameters.MCardOwnerIndexes[i]];
}
BattleDeck<MonsterCard> monsterDeck = new BattleDeck<MonsterCard>(
this.monsterCardDatabase, parameters.MCardIds.Cast<int>().ToArray(), mCardOwners);
this.state.SetDecks(heroDeck, monsterDeck);
this.participantActivity = new ParticipantActivity(); this.participantActivity = new ParticipantActivity();
this.heroHandPlayability = new HandPlayability<HeroCard>( this.heroHandPlayability = new HandPlayability<HeroCard>(
@ -397,9 +377,9 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
if (effect.Participant == null) return; if (effect.Participant == null) return;
if (effect.Participant.Team == TeamChoice.Heroes) { if (effect.Participant.Team == TeamChoice.Heroes) {
this.AcquireCardsTyped(effect, this.state.HeroDeck, this.heroCardDatabase); this.AcquireCardsTyped(effect, this.state.HeroDeck, new HeroCardDatabase());
} else { } else {
this.AcquireCardsTyped(effect, this.state.MonsterDeck, this.monsterCardDatabase); this.AcquireCardsTyped(effect, this.state.MonsterDeck, new MonsterCardDatabase());
} }
} }

View file

@ -1,6 +1,7 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using UnityEngine; using UnityEngine;
public class BattleState: MonsterViewpoint public class BattleState: MonsterViewpoint
@ -35,6 +36,10 @@ public class BattleState: MonsterViewpoint
this.playArea = new PlayArea(); this.playArea = new PlayArea();
this.insightLevel = new InsightLevel(STARTING_INSIGHT); this.insightLevel = new InsightLevel(STARTING_INSIGHT);
InitHeroesAndMonsters(parameters);
}
private void InitHeroesAndMonsters(BattleParameters parameters) {
this.heroes = new BattleHero[parameters.HeroIds.Length]; this.heroes = new BattleHero[parameters.HeroIds.Length];
for (int i = 0; i < this.heroes.Length; i++) { for (int i = 0; i < this.heroes.Length; i++) {
HeroId id = parameters.HeroIds[i]; HeroId id = parameters.HeroIds[i];
@ -52,11 +57,20 @@ public class BattleState: MonsterViewpoint
monster.Init(); monster.Init();
this.monsters[i] = monster; this.monsters[i] = monster;
} }
}
public void SetDecks(BattleDeck<HeroCard> heroDeck, BattleDeck<MonsterCard> monsterDeck) { BattleParticipant[] cardOwners = new BattleParticipant[parameters.HCardIds.Length];
this.heroDeck = heroDeck; for (int i = 0; i < parameters.HCardIds.Length; i++) {
this.monsterDeck = monsterDeck; cardOwners[i] = this.heroes[parameters.HCardOwnerIndexes[i]];
}
this.heroDeck = new BattleDeck<HeroCard>(
new HeroCardDatabase(), parameters.HCardIds.Cast<int>().ToArray(), cardOwners);
BattleParticipant[] mCardOwners = new BattleParticipant[parameters.MCardIds.Length];
for (int i = 0; i < parameters.MCardIds.Length; i++) {
mCardOwners[i] = this.monsters[parameters.MCardOwnerIndexes[i]];
}
this.monsterDeck = new BattleDeck<MonsterCard>(
new MonsterCardDatabase(), parameters.MCardIds.Cast<int>().ToArray(), mCardOwners);
} }
public bool IsTeamsTurnToPlay(TeamChoice team) { public bool IsTeamsTurnToPlay(TeamChoice team) {