Implement Whirlwind
This commit is contained in:
parent
9413ebee7e
commit
6a6f07689e
18 changed files with 330 additions and 52 deletions
|
|
@ -5,31 +5,34 @@ using UnityEngine;
|
|||
|
||||
public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffectResolver, MonsterViewpoint
|
||||
{
|
||||
public HeroId[] heroIds;
|
||||
public MonsterId[] monsterIds;
|
||||
public CardId[] cardIds;
|
||||
public MCardId[] mCardIds;
|
||||
public int[] mCardOwnerIndexes;
|
||||
|
||||
// Inspector public
|
||||
public HeroInfoUI heroUIPrefab;
|
||||
public GameObject uiCanvas;
|
||||
public BattlePlayerControls battlePlayerControls;
|
||||
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;
|
||||
private BattleDeck<HeroCard> heroDeck;
|
||||
private BattleDeck<MonsterCard> monsterDeck;
|
||||
private PlayArea playArea;
|
||||
|
||||
public BattleHero[] heroes;
|
||||
private GameObject[] heroSprites;
|
||||
private HeroInfoUI[] heroUIs;
|
||||
private BattleHero[] heroes;
|
||||
private Dictionary<BattleHero, GameObject> heroSprites;
|
||||
private Dictionary<BattleHero, HeroInfoUI> heroUIs;
|
||||
|
||||
public BattleMonster[] monsters;
|
||||
private GameObject[] monsterSprites;
|
||||
private HeroInfoUI[] monsterUIs;
|
||||
private BattleMonster[] monsters;
|
||||
private Dictionary<BattleMonster, GameObject> monsterSprites;
|
||||
private Dictionary<BattleMonster, HeroInfoUI> monsterUIs;
|
||||
|
||||
private bool heroTurn;
|
||||
private bool heroPassedTurn;
|
||||
|
|
@ -38,6 +41,62 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
private InsightLevel insightLevel;
|
||||
|
||||
void Awake() {
|
||||
this.heroIds = new HeroId[3] {
|
||||
HeroId.Brute,
|
||||
HeroId.Alchemist,
|
||||
HeroId.Shaman,
|
||||
};
|
||||
|
||||
this.cardIds = new CardId[10] {
|
||||
CardId.CrashingPunch,
|
||||
CardId.CrashingPunch,
|
||||
CardId.CrashingPunch,
|
||||
CardId.Cover,
|
||||
CardId.Cover,
|
||||
CardId.Cover,
|
||||
CardId.Thunderstorm,
|
||||
CardId.Scarring,
|
||||
CardId.Scarring,
|
||||
CardId.Meditate,
|
||||
};
|
||||
|
||||
this.monsterIds = new MonsterId[3] {
|
||||
MonsterId.Golem,
|
||||
MonsterId.Bat,
|
||||
MonsterId.Bat,
|
||||
};
|
||||
|
||||
this.mCardIds = new MCardId[10] {
|
||||
MCardId.GraniteDefense,
|
||||
MCardId.GraniteDefense,
|
||||
MCardId.GolemCharge,
|
||||
MCardId.GolemFist,
|
||||
|
||||
MCardId.VampireFangs,
|
||||
MCardId.VampireFangs,
|
||||
MCardId.Whirlwind,
|
||||
|
||||
MCardId.VampireFangs,
|
||||
MCardId.VampireFangs,
|
||||
MCardId.Whirlwind,
|
||||
};
|
||||
this.mCardOwnerIndexes = new int[10] {
|
||||
0, 0, 0, 0,
|
||||
1, 1, 1,
|
||||
2, 2, 2,
|
||||
};
|
||||
// this.mCardIds = new MCardId[5] {
|
||||
// MCardId.Whirlwind,
|
||||
// MCardId.Whirlwind,
|
||||
// MCardId.Whirlwind,
|
||||
// MCardId.Whirlwind,
|
||||
// MCardId.Whirlwind,
|
||||
// };
|
||||
// this.mCardOwnerIndexes = new int[5] {
|
||||
// 1, 1,
|
||||
// 2, 2, 2,
|
||||
// };
|
||||
|
||||
this.heroCardDatabase = new HeroCardDatabase();
|
||||
this.monsterCardDatabase = new MonsterCardDatabase();
|
||||
|
||||
|
|
@ -51,45 +110,51 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
this.insightLevel = new InsightLevel(1);
|
||||
|
||||
heroes = new BattleHero[3];
|
||||
heroSprites = new GameObject[3];
|
||||
heroUIs = new HeroInfoUI[3];
|
||||
heroSprites = new Dictionary<BattleHero, GameObject>();
|
||||
heroUIs = new Dictionary<BattleHero, HeroInfoUI>();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
HeroId id = heroIds[i];
|
||||
|
||||
heroes[i] = new BattleHero(id);
|
||||
heroes[i].Init();
|
||||
BattleHero hero = new BattleHero(id);
|
||||
hero.Init();
|
||||
heroes[i] = hero;
|
||||
|
||||
heroSprites[i] = HeroDatabase.createHeroSprite(id);
|
||||
heroSprites[i].name = "Hero" + i + "_Sprite";
|
||||
heroSprites[i].transform.position = new Vector3(-1 + -3 + 3 * i, -1.8f, 0);
|
||||
BattleParticipantSprite bps = heroSprites[i].AddComponent<BattleParticipantSprite>();
|
||||
bps.Init(battlePlayerControls, heroes[i]);
|
||||
GameObject sprite = HeroDatabase.createHeroSprite(id);
|
||||
heroSprites[hero] = sprite;
|
||||
sprite.name = "Hero" + i + "_Sprite";
|
||||
PositionSprite(TeamChoice.Heroes, sprite, i);
|
||||
BattleParticipantSprite bps = sprite.AddComponent<BattleParticipantSprite>();
|
||||
bps.Init(battlePlayerControls, hero);
|
||||
bps.OnSpriteClicked += battlePlayerControls.NotifyParticipantSpriteClicked;
|
||||
heroes[i].OnDeath += bps.NotifyDeath;
|
||||
hero.OnDeath += bps.NotifyDeath;
|
||||
|
||||
heroUIs[i] = (HeroInfoUI) Instantiate(heroUIPrefab.gameObject, uiCanvas.transform).GetComponent(typeof(HeroInfoUI));
|
||||
heroUIs[i].Init(heroSprites[i], heroes[i]);
|
||||
HeroInfoUI heroUI = (HeroInfoUI) Instantiate(heroUIPrefab.gameObject, uiCanvas.transform).GetComponent(typeof(HeroInfoUI));
|
||||
heroUI.Init(sprite, hero);
|
||||
heroUIs[hero] = heroUI;
|
||||
}
|
||||
|
||||
monsters = new BattleMonster[3];
|
||||
monsterSprites = new GameObject[3];
|
||||
monsterUIs = new HeroInfoUI[3];
|
||||
monsterSprites = new Dictionary<BattleMonster, GameObject>();
|
||||
monsterUIs = new Dictionary<BattleMonster, HeroInfoUI>();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
MonsterId id = monsterIds[i];
|
||||
|
||||
monsters[i] = MonsterDatabase.createMonsterScript(id);
|
||||
monsters[i].Init();
|
||||
BattleMonster monster = MonsterDatabase.createMonsterScript(id);
|
||||
monster.Init();
|
||||
monsters[i] = monster;
|
||||
|
||||
monsterSprites[i] = MonsterDatabase.createMonsterSprite(id);
|
||||
monsterSprites[i].name = "Monster" + i + "_Sprite";
|
||||
monsterSprites[i].transform.position = new Vector3(+1 + -3 + 3 * i, 1.2f, 0);
|
||||
BattleParticipantSprite bps = monsterSprites[i].AddComponent<BattleParticipantSprite>();
|
||||
bps.Init(battlePlayerControls, monsters[i]);
|
||||
GameObject sprite = MonsterDatabase.createMonsterSprite(id);
|
||||
monsterSprites[monster] = sprite;
|
||||
sprite.name = "Monster" + i + "_Sprite";
|
||||
PositionSprite(TeamChoice.Monsters, sprite, i);
|
||||
BattleParticipantSprite bps = sprite.AddComponent<BattleParticipantSprite>();
|
||||
bps.Init(battlePlayerControls, monster);
|
||||
bps.OnSpriteClicked += battlePlayerControls.NotifyParticipantSpriteClicked;
|
||||
monsters[i].OnDeath += bps.NotifyDeath;
|
||||
monster.OnDeath += bps.NotifyDeath;
|
||||
|
||||
monsterUIs[i] = (HeroInfoUI) Instantiate(heroUIPrefab.gameObject, uiCanvas.transform).GetComponent(typeof(HeroInfoUI));
|
||||
monsterUIs[i].Init(monsterSprites[i], monsters[i]);
|
||||
HeroInfoUI monsterUI = (HeroInfoUI) Instantiate(heroUIPrefab.gameObject, uiCanvas.transform).GetComponent(typeof(HeroInfoUI));
|
||||
monsterUI.Init(sprite, monster);
|
||||
monsterUIs[monster] = monsterUI;
|
||||
}
|
||||
|
||||
BattleParticipant[] cardOwners = new BattleParticipant[this.cardIds.Length];
|
||||
|
|
@ -121,6 +186,16 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
this.monsterDeck.OnHandPileChanged += this.battlePlayerControls.NotifyMonsterHandPileChanged;
|
||||
}
|
||||
|
||||
private void PositionSprite(TeamChoice team, GameObject sprite, int i) {
|
||||
Vector3 pos;
|
||||
if (team == TeamChoice.Heroes) {
|
||||
pos = new Vector3(-1 + -3 + 3 * i, -1.8f, 0);
|
||||
} else {
|
||||
pos = new Vector3(+1 + -3 + 3 * i, 1.2f, 0);
|
||||
}
|
||||
sprite.transform.position = pos;
|
||||
}
|
||||
|
||||
private BattleParticipant FindHeroByClass(HeroId heroId) {
|
||||
foreach (BattleHero battleHero in this.heroes) {
|
||||
if (battleHero.GetId() == heroId) return battleHero;
|
||||
|
|
@ -298,6 +373,12 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
}
|
||||
}
|
||||
|
||||
private BattleParticipant[] GetTeam(TeamChoice team) {
|
||||
return (team == TeamChoice.Heroes
|
||||
? this.heroes.Cast<BattleParticipant>().ToArray()
|
||||
: this.monsters.Cast<BattleParticipant>().ToArray());
|
||||
}
|
||||
|
||||
public EnergyPool HeroEnergy {get => this.heroEnergy;}
|
||||
public EnergyPool MonsterEnergy {get => this.monsterEnergy;}
|
||||
|
||||
|
|
@ -335,7 +416,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
public void AcquireCards(AcquireCardsEffect effect) {
|
||||
if (effect.Participant == null) return;
|
||||
|
||||
if (effect.Participant.IsHero()) {
|
||||
if (effect.Participant.Team == TeamChoice.Heroes) {
|
||||
this.AcquireCardsTyped(effect, this.heroDeck, this.heroCardDatabase);
|
||||
} else {
|
||||
this.AcquireCardsTyped(effect, this.monsterDeck, this.monsterCardDatabase);
|
||||
|
|
@ -385,6 +466,24 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
return damageDealt;
|
||||
}
|
||||
|
||||
public int DealMassDamage(MassDamageEffect effect) {
|
||||
int damageDealt = 0;
|
||||
BattleParticipant[] affectedTeam = GetTeam(effect.Team);
|
||||
foreach (BattleParticipant bp in affectedTeam) {
|
||||
damageDealt += bp.DealDamage(effect.Amount);
|
||||
foreach (DamageTrigger dt in this.damageTriggers) {
|
||||
if (dt.IsTriggeredBy(effect)) {
|
||||
EnqueueActivatedTrigger(dt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Do this after the card resolution is over to avoid reentraint effects.
|
||||
RunActivatedTriggers();
|
||||
|
||||
return damageDealt;
|
||||
}
|
||||
|
||||
public int Heal(HealEffect effect) {
|
||||
if (effect.Target == null) return 0;
|
||||
|
||||
|
|
@ -402,6 +501,61 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
effect.Target.AddStatus(effect.Status, effect.Amount);
|
||||
}
|
||||
|
||||
public void Rotate(RotateEffect effect) {
|
||||
if (effect.Positions == 0) return;
|
||||
|
||||
BattleParticipant[] currentPositions = GetTeam(effect.Team);
|
||||
|
||||
int start = int.MaxValue;
|
||||
int end = int.MinValue;
|
||||
for (int i = 0; i < currentPositions.Length; i++) {
|
||||
BattleParticipant bp = currentPositions[i];
|
||||
if (bp != null) {
|
||||
start = System.Math.Min(start, i);
|
||||
end = System.Math.Max(end, i);
|
||||
}
|
||||
}
|
||||
|
||||
int[] newPositions = new int[currentPositions.Length];
|
||||
for (int i = start; i <= end; i++) {
|
||||
if (i < start || i > end) {
|
||||
newPositions[i] = i;
|
||||
} else {
|
||||
int newI = start + TrueMod(
|
||||
i - start - effect.Positions,
|
||||
end - start + 1);
|
||||
newPositions[newI] = i;
|
||||
}
|
||||
}
|
||||
|
||||
MoveTeamToNewPositions(effect.Team, newPositions);
|
||||
}
|
||||
|
||||
private static int TrueMod(int a, int b) {
|
||||
return (a % b + b) % b;
|
||||
}
|
||||
|
||||
private 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;
|
||||
PositionSprite(team, heroSprites[hero], newPositions[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;
|
||||
PositionSprite(team, monsterSprites[monster], newPositions[i]);
|
||||
}
|
||||
this.monsters = newMonsters;
|
||||
}
|
||||
}
|
||||
|
||||
public void ArmDamageTrigger(DamageTrigger damageTrigger) {
|
||||
this.damageTriggers.Add(damageTrigger);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue