125 lines
4.2 KiB
C#
125 lines
4.2 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class BattleState: MonsterViewpoint
|
|
{
|
|
public delegate void Procedure();
|
|
public event Procedure OnHeroPositionsSet;
|
|
public event Procedure OnMonsterPositionsSet;
|
|
|
|
private BattleHero[] heroes;
|
|
|
|
private BattleMonster[] monsters;
|
|
private BattleClock clock;
|
|
private BuffManager buffManager;
|
|
private EnergyPool heroEnergy;
|
|
private EnergyPool monsterEnergy;
|
|
private BattleDeck<HeroCard> heroDeck;
|
|
private BattleDeck<MonsterCard> monsterDeck;
|
|
private PlayArea playArea;
|
|
private InsightLevel insightLevel;
|
|
|
|
private bool playedEmotion;
|
|
|
|
private int STARTING_INSIGHT = 3;
|
|
|
|
public BattleState(BattleParameters parameters) {
|
|
this.clock = new BattleClock();
|
|
this.buffManager = new BuffManager(this.clock);
|
|
this.heroEnergy = new EnergyPool();
|
|
this.monsterEnergy = new EnergyPool();
|
|
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) {
|
|
this.heroDeck = heroDeck;
|
|
this.monsterDeck = monsterDeck;
|
|
}
|
|
|
|
public bool IsTeamsTurnToPlay(TeamChoice team) {
|
|
if (team == TeamChoice.Heroes) {
|
|
return this.clock.Now.RoundStep == RoundStep.StartOfHeroTurn;
|
|
} else {
|
|
return this.clock.Now.RoundStep == RoundStep.StartOfMonsterTurn;
|
|
}
|
|
}
|
|
|
|
public bool CanPlayEmotion(TeamChoice team) {
|
|
return !playedEmotion && IsTeamsTurnToPlay(team);
|
|
}
|
|
|
|
public void NotifyPlayedEmotion(TeamChoice team) {
|
|
if (!CanPlayEmotion(team)) {
|
|
throw new System.InvalidOperationException("BattleState received NotifyPlayedEmotion but "
|
|
+ "cannot play emotion");
|
|
}
|
|
|
|
playedEmotion = true;
|
|
}
|
|
|
|
public void ClearEmotionPlayed() {
|
|
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;
|
|
TriggerOnHeroPositionsSet();
|
|
} 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;
|
|
TriggerOnMonsterPositionsSet();
|
|
}
|
|
}
|
|
|
|
private void TriggerOnHeroPositionsSet() {
|
|
if (OnHeroPositionsSet != null) OnHeroPositionsSet();
|
|
}
|
|
|
|
private void TriggerOnMonsterPositionsSet() {
|
|
if (OnMonsterPositionsSet != null) OnMonsterPositionsSet();
|
|
}
|
|
|
|
public BattleHero[] Heroes {get => this.heroes;}
|
|
public BattleMonster[] Monsters {get => this.monsters;}
|
|
public BattleClock Clock {get => this.clock;}
|
|
public BuffManager BuffManager {get => this.buffManager;}
|
|
|
|
public EnergyPool HeroEnergy {get => this.heroEnergy;}
|
|
public EnergyPool MonsterEnergy {get => this.monsterEnergy;}
|
|
public BattleDeck<HeroCard> HeroDeck {get => this.heroDeck;}
|
|
public BattleDeck<MonsterCard> MonsterDeck {get => this.monsterDeck;}
|
|
public PlayArea PlayArea {get => this.playArea;}
|
|
public InsightLevel InsightLevel {get => this.insightLevel;}
|
|
}
|