Move Heroes and Monster to BattleState
This commit is contained in:
parent
c2fc8b0904
commit
2e5a971581
2 changed files with 72 additions and 62 deletions
|
|
@ -4,7 +4,7 @@ using System.Linq;
|
|||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffectResolver, MonsterViewpoint
|
||||
public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffectResolver
|
||||
{
|
||||
private bool STABLE_HAND_STYLE = true;
|
||||
|
||||
|
|
@ -19,10 +19,6 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
private HeroCardDatabase heroCardDatabase;
|
||||
private MonsterCardDatabase monsterCardDatabase;
|
||||
|
||||
private BattleHero[] heroes;
|
||||
|
||||
private BattleMonster[] monsters;
|
||||
|
||||
private BattleState state;
|
||||
private HandPlayability<HeroCard> heroHandPlayability;
|
||||
private HandPlayability<MonsterCard> monsterHandPlayability;
|
||||
|
|
@ -42,41 +38,23 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
this.heroCardDatabase = new HeroCardDatabase();
|
||||
this.monsterCardDatabase = new MonsterCardDatabase();
|
||||
|
||||
this.state = new BattleState();
|
||||
this.state = new BattleState(parameters);
|
||||
|
||||
this.heroEnergyUI.Init(this.state.HeroEnergy);
|
||||
this.monsterEnergyUI.Init(this.state.MonsterEnergy);
|
||||
|
||||
this.heroes = new BattleHero[parameters.HeroIds.Length];
|
||||
for (int i = 0; i < this.heroes.Length; i++) {
|
||||
HeroId id = parameters.HeroIds[i];
|
||||
|
||||
BattleHero hero = new BattleHero(id);
|
||||
hero.Init();
|
||||
this.heroes[i] = hero;
|
||||
}
|
||||
|
||||
this.monsters = new BattleMonster[parameters.MonsterIds.Length];
|
||||
for (int i = 0; i < this.monsters.Length; i++) {
|
||||
MonsterId id = parameters.MonsterIds[i];
|
||||
|
||||
BattleMonster monster = MonsterDatabase.createMonsterScript(id);
|
||||
monster.Init();
|
||||
this.monsters[i] = monster;
|
||||
}
|
||||
|
||||
this.battleSprites.Init(this.heroes, this.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.heroes[parameters.HCardOwnerIndexes[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.monsters[parameters.MCardOwnerIndexes[i]];
|
||||
mCardOwners[i] = this.state.Monsters[parameters.MCardOwnerIndexes[i]];
|
||||
}
|
||||
BattleDeck<MonsterCard> monsterDeck = new BattleDeck<MonsterCard>(
|
||||
this.monsterCardDatabase, parameters.MCardIds.Cast<int>().ToArray(), mCardOwners);
|
||||
|
|
@ -112,7 +90,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
this.state.InsightLevel.Modify(+5);
|
||||
};
|
||||
cheat.OnOneHPCode += delegate {
|
||||
foreach (BattleMonster m in this.monsters) {
|
||||
foreach (BattleMonster m in this.state.Monsters) {
|
||||
if (m.IsAlive()) {
|
||||
m.DealDamage(m.GetHP() - 1);
|
||||
}
|
||||
|
|
@ -170,7 +148,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
OnBattleStateChanged();
|
||||
this.monsterIntentions.ResumeIntentions();
|
||||
|
||||
foreach (BattleHero hero in this.heroes) {
|
||||
foreach (BattleHero hero in this.state.Heroes) {
|
||||
hero.ResetBlock();
|
||||
}
|
||||
OnBattleStateChanged();
|
||||
|
|
@ -191,13 +169,13 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
}
|
||||
|
||||
// End of hero turn
|
||||
yield return this.state.PlayArea.UseHeroDefaults(this.heroes, this.participantActivity, UseHeroDefault);
|
||||
yield return this.state.PlayArea.UseHeroDefaults(this.state.Heroes, this.participantActivity, UseHeroDefault);
|
||||
if (STABLE_HAND_STYLE) {
|
||||
this.state.HeroDeck.DiscardInExcessOf(3);
|
||||
} else {
|
||||
this.state.HeroDeck.DiscardHand();
|
||||
}
|
||||
foreach (BattleHero hero in this.heroes) {
|
||||
foreach (BattleHero hero in this.state.Heroes) {
|
||||
hero.TickStatuses();
|
||||
}
|
||||
|
||||
|
|
@ -213,7 +191,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
// Start of monster turn
|
||||
this.state.Clock.AdvanceToStep(RoundStep.StartOfMonsterTurn);
|
||||
this.state.ClearEmotionPlayed();
|
||||
foreach (BattleMonster monster in this.monsters) {
|
||||
foreach (BattleMonster monster in this.state.Monsters) {
|
||||
monster.ResetBlock();
|
||||
}
|
||||
OnBattleStateChanged();
|
||||
|
|
@ -247,7 +225,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
} else {
|
||||
this.state.MonsterDeck.DiscardHand();
|
||||
}
|
||||
foreach (BattleMonster monster in this.monsters) {
|
||||
foreach (BattleMonster monster in this.state.Monsters) {
|
||||
monster.TickStatuses();
|
||||
}
|
||||
|
||||
|
|
@ -275,7 +253,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
this.state.HeroEnergy.PayForCard(card);
|
||||
this.state.HeroDeck.RemoveCardFromHand(card);
|
||||
this.participantActivity.NotifyParticipantUsedCard(card.Owner, card);
|
||||
yield return card.Use(this, this, battlePlayerControls);
|
||||
yield return card.Use(this, this.state, this.battlePlayerControls);
|
||||
if (card.Type == CardType.Default) {
|
||||
// Already added to playArea by effect
|
||||
} else if (card.IsPermanent()) {
|
||||
|
|
@ -295,7 +273,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
yield break;
|
||||
}
|
||||
|
||||
yield return card.UseDefault(this, this, battlePlayerControls);
|
||||
yield return card.UseDefault(this, this.state, this.battlePlayerControls);
|
||||
|
||||
CheckState();
|
||||
OnBattleStateChanged();
|
||||
|
|
@ -304,7 +282,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
public IEnumerator UseMonsterCard(MonsterCard card) {
|
||||
this.state.MonsterEnergy.PayForCard(card);
|
||||
this.state.MonsterDeck.RemoveCardFromHand(card);
|
||||
yield return card.Use(this, this);
|
||||
yield return card.Use(this, this.state);
|
||||
if (card.IsPermanent()) {
|
||||
this.state.PlayArea.AddPlayedMonsterPermanent(card);
|
||||
} else if (card.IsEphemeral()) {
|
||||
|
|
@ -341,24 +319,24 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
}
|
||||
|
||||
private void CheckState() {
|
||||
foreach (BattleParticipant p in this.heroes) {
|
||||
foreach (BattleParticipant p in this.state.Heroes) {
|
||||
p.CheckState();
|
||||
}
|
||||
foreach (BattleParticipant p in this.monsters) {
|
||||
foreach (BattleParticipant p in this.state.Monsters) {
|
||||
p.CheckState();
|
||||
}
|
||||
|
||||
if (System.Array.TrueForAll(this.heroes, h => !h.IsAlive())) {
|
||||
if (System.Array.TrueForAll(this.state.Heroes, h => !h.IsAlive())) {
|
||||
BattleResult.FinishBattle(new BattleResult(false));
|
||||
} else if (System.Array.TrueForAll(this.monsters, m => !m.IsAlive())) {
|
||||
} else if (System.Array.TrueForAll(this.state.Monsters, m => !m.IsAlive())) {
|
||||
BattleResult.FinishBattle(new BattleResult(true));
|
||||
}
|
||||
}
|
||||
|
||||
private BattleParticipant[] GetTeam(TeamChoice team) {
|
||||
return (team == TeamChoice.Heroes
|
||||
? this.heroes.Cast<BattleParticipant>().ToArray()
|
||||
: this.monsters.Cast<BattleParticipant>().ToArray());
|
||||
? this.state.Heroes.Cast<BattleParticipant>().ToArray()
|
||||
: this.state.Monsters.Cast<BattleParticipant>().ToArray());
|
||||
}
|
||||
|
||||
public BattleState State {get => this.state;}
|
||||
|
|
@ -546,23 +524,16 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
}
|
||||
|
||||
private void MoveTeamToNewPositions(TeamChoice team, int[] newPositions) {
|
||||
int n = newPositions.Length;
|
||||
this.state.MoveTeamToNewPositions(team, newPositions);
|
||||
|
||||
if (team == TeamChoice.Heroes) {
|
||||
BattleHero[] newHeroes = new BattleHero[n];
|
||||
for (int i = 0; i < n; i++) {
|
||||
BattleHero hero = this.heroes[i];
|
||||
newHeroes[newPositions[i]] = hero;
|
||||
this.battleSprites.PositionHero(hero, newPositions[i]);
|
||||
for (int i = 0; i < this.state.Heroes.Length; i++) {
|
||||
this.battleSprites.PositionHero(this.state.Heroes[i], i);
|
||||
}
|
||||
this.heroes = newHeroes;
|
||||
} else {
|
||||
BattleMonster[] newMonsters = new BattleMonster[n];
|
||||
for (int i = 0; i < n; i++) {
|
||||
BattleMonster monster = this.monsters[i];
|
||||
newMonsters[newPositions[i]] = monster;
|
||||
this.battleSprites.PositionMonster(monster, newPositions[i]);
|
||||
for (int i = 0; i < this.state.Monsters.Length; i++) {
|
||||
this.battleSprites.PositionMonster(this.state.Monsters[i], i);
|
||||
}
|
||||
this.monsters = newMonsters;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -576,8 +547,4 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
public void ArmDamageTrigger(DamageTrigger damageTrigger) {
|
||||
this.damageTriggers.Add(damageTrigger);
|
||||
}
|
||||
|
||||
// MonsterViewpoint
|
||||
public BattleHero[] Heroes {get => this.heroes;}
|
||||
public BattleMonster[] Monsters {get => this.monsters;}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,9 +3,12 @@ using System.Collections;
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class BattleState
|
||||
public class BattleState: MonsterViewpoint
|
||||
{
|
||||
private bool playedEmotion;
|
||||
|
||||
private BattleHero[] heroes;
|
||||
|
||||
private BattleMonster[] monsters;
|
||||
private BattleClock clock;
|
||||
private BuffManager buffManager;
|
||||
private EnergyPool heroEnergy;
|
||||
|
|
@ -15,9 +18,11 @@ public class BattleState
|
|||
private PlayArea playArea;
|
||||
private InsightLevel insightLevel;
|
||||
|
||||
private bool playedEmotion;
|
||||
|
||||
private int STARTING_INSIGHT = 3;
|
||||
|
||||
public BattleState() {
|
||||
public BattleState(BattleParameters parameters) {
|
||||
this.clock = new BattleClock();
|
||||
this.buffManager = new BuffManager(this.clock);
|
||||
this.heroEnergy = new EnergyPool();
|
||||
|
|
@ -25,6 +30,23 @@ public class BattleState
|
|||
this.playArea = new PlayArea();
|
||||
this.insightLevel = new InsightLevel(STARTING_INSIGHT);
|
||||
|
||||
this.heroes = new BattleHero[parameters.HeroIds.Length];
|
||||
for (int i = 0; i < this.heroes.Length; i++) {
|
||||
HeroId id = parameters.HeroIds[i];
|
||||
|
||||
BattleHero hero = new BattleHero(id);
|
||||
hero.Init();
|
||||
this.heroes[i] = hero;
|
||||
}
|
||||
|
||||
this.monsters = new BattleMonster[parameters.MonsterIds.Length];
|
||||
for (int i = 0; i < this.monsters.Length; i++) {
|
||||
MonsterId id = parameters.MonsterIds[i];
|
||||
|
||||
BattleMonster monster = MonsterDatabase.createMonsterScript(id);
|
||||
monster.Init();
|
||||
this.monsters[i] = monster;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetDecks(BattleDeck<HeroCard> heroDeck, BattleDeck<MonsterCard> monsterDeck) {
|
||||
|
|
@ -57,6 +79,27 @@ public class BattleState
|
|||
this.playedEmotion = false;
|
||||
}
|
||||
|
||||
public void MoveTeamToNewPositions(TeamChoice team, int[] newPositions) {
|
||||
int n = newPositions.Length;
|
||||
if (team == TeamChoice.Heroes) {
|
||||
BattleHero[] newHeroes = new BattleHero[n];
|
||||
for (int i = 0; i < n; i++) {
|
||||
BattleHero hero = this.heroes[i];
|
||||
newHeroes[newPositions[i]] = hero;
|
||||
}
|
||||
this.heroes = newHeroes;
|
||||
} else {
|
||||
BattleMonster[] newMonsters = new BattleMonster[n];
|
||||
for (int i = 0; i < n; i++) {
|
||||
BattleMonster monster = this.monsters[i];
|
||||
newMonsters[newPositions[i]] = monster;
|
||||
}
|
||||
this.monsters = newMonsters;
|
||||
}
|
||||
}
|
||||
|
||||
public BattleHero[] Heroes {get => this.heroes;}
|
||||
public BattleMonster[] Monsters {get => this.monsters;}
|
||||
public BattleClock Clock {get => this.clock;}
|
||||
public BuffManager BuffManager {get => this.buffManager;}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue