Fix flow to/from battle, add cheat code to win

This commit is contained in:
henriquenakashima 2020-09-28 23:41:27 -04:00
parent 0b295af56b
commit 959458ad74
7 changed files with 58 additions and 16 deletions

View file

@ -43,7 +43,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
BattleParameters parameters = BattleSetup.RetrieveParameters(); BattleParameters parameters = BattleSetup.RetrieveParameters();
if (parameters == null) { if (parameters == null) {
Debug.Log("Using default battle"); Debug.Log("Using default battle");
parameters = DebugBattle.CreateParameters(); parameters = CheatBattle.CreateParameters();
} }
this.heroCardDatabase = new HeroCardDatabase(); this.heroCardDatabase = new HeroCardDatabase();
@ -150,6 +150,10 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
void Start() void Start()
{ {
StartCoroutine(RunBattleRounds()); StartCoroutine(RunBattleRounds());
new GameObject("CheatBattle").AddComponent<CheatBattle>().OnWinCode += delegate {
BattleResult.FinishBattle(new BattleResult(true));
};
} }
// Update is called once per frame // Update is called once per frame

View file

@ -2,7 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
public class DebugBattle public class CheatBattle: MonoBehaviour
{ {
public static BattleParameters CreateParameters() { public static BattleParameters CreateParameters() {
HeroId[] heroIds = new HeroId[3] { HeroId[] heroIds = new HeroId[3] {
@ -66,4 +66,22 @@ public class DebugBattle
parameters.SetMonsters(monsterIds, mCardIds, mCardOwnerIndexes); parameters.SetMonsters(monsterIds, mCardIds, mCardOwnerIndexes);
return parameters; return parameters;
} }
public delegate void CheatAction();
public event CheatAction OnWinCode;
private string lastCommands = "";
void Update() {
this.lastCommands += Input.inputString;
if (this.lastCommands.Length > 10) {
this.lastCommands = this.lastCommands.Substring(this.lastCommands.Length - 10);
}
if (this.lastCommands.EndsWith("win")) {
this.OnWinCode();
}
}
} }

View file

@ -12,7 +12,7 @@ public class Scene_Chapter1_Cave: StoryScene
yield return new WaitForSeconds(1f); yield return new WaitForSeconds(1f);
BattleParameters battleParameters = BuildBattleGolemBats(); BattleParameters battleParameters = BuildBattleGolemBats();
BattleSetup.StartBattle(battleParameters); this.StartBattleThenNextSceneId(battleParameters, SceneId.Chapter1_Cave);
} }
private BattleParameters BuildBattleGolemBats() { private BattleParameters BuildBattleGolemBats() {

View file

@ -6,26 +6,26 @@ public class Scene_Prologue_First: StoryScene {
public override IEnumerator Play(StoryDisplay storyDisplay) { public override IEnumerator Play(StoryDisplay storyDisplay) {
storyDisplay.SetBackground("BGNightSky"); storyDisplay.SetBackground("BGNightSky");
yield return new WaitForSeconds(1f); //yield return new WaitForSeconds(1f);
yield return storyDisplay.DisplayText("Are you going out again?", DialogPosition.Left); yield return storyDisplay.DisplayText("Are you going out again?", DialogPosition.Left);
yield return new WaitForSeconds(1f); //yield return new WaitForSeconds(1f);
yield return storyDisplay.DisplayText("Yes.", DialogPosition.Right); yield return storyDisplay.DisplayText("Yes.", DialogPosition.Right);
yield return new WaitForSeconds(1f); //yield return new WaitForSeconds(1f);
yield return storyDisplay.DisplayText( yield return storyDisplay.DisplayText(
"Do you not get bored of doing the same things over and over? Seeing the same people, dealing with the same problems?", "Do you not get bored of doing the same things over and over? Seeing the same people, dealing with the same problems?",
DialogPosition.Left); DialogPosition.Left);
yield return new WaitForSeconds(1f); //yield return new WaitForSeconds(1f);
yield return storyDisplay.DisplayText( yield return storyDisplay.DisplayText(
"Sometimes I feel like I'm imprisoned in my own life. Like I'm stuck in it, passing the time, until it ends.", "Sometimes I feel like I'm imprisoned in my own life. Like I'm stuck in it, passing the time, until it ends.",
DialogPosition.Left); DialogPosition.Left);
yield return storyDisplay.DisplayText( yield return storyDisplay.DisplayText(
"Life is finite, after all. There is only so much you can do in it.", "Life is finite, after all. There is only so much you can do in it.",
DialogPosition.Left); DialogPosition.Left);
yield return new WaitForSeconds(2f); //yield return new WaitForSeconds(2f);
yield return storyDisplay.DisplayText( yield return storyDisplay.DisplayText(
"Finite in time, yes. But infinite in possibilities...", "Finite in time, yes. But infinite in possibilities...",
DialogPosition.Right); DialogPosition.Right);
yield return new WaitForSeconds(2f); //yield return new WaitForSeconds(2f);
this.SetNextSceneId(SceneId.Chapter1_Cave); this.SetNextSceneId(SceneId.Chapter1_Cave);
} }

View file

@ -6,22 +6,30 @@ public class StoryController : MonoBehaviour
{ {
public StoryDisplay storyDisplay; public StoryDisplay storyDisplay;
private SceneId nextSceneId; // TODO: Read which scene should be loaded.
private static SceneId sNextSceneId = SceneId.Prologue_First;
void Start() { void Start() {
// TODO: Read which scene should be loaded.
this.nextSceneId = SceneId.Prologue_First;
StartCoroutine(this.PlayScenes()); StartCoroutine(this.PlayScenes());
} }
private IEnumerator PlayScenes() { private IEnumerator PlayScenes() {
while (true) { while (true) {
SceneId id = this.nextSceneId; // Debug.Log("SceneId id = " + sNextSceneId);
this.nextSceneId = SceneId.None; SceneId id = sNextSceneId;
// Debug.Log("sNextSceneId = " + SceneId.None);
sNextSceneId = SceneId.None;
// Debug.Log("StoryScene scene = Load()");
StoryScene scene = StorySceneDatabase.Load(id); StoryScene scene = StorySceneDatabase.Load(id);
// Debug.Log("yield return scene.Play()");
yield return scene.Play(this.storyDisplay); yield return scene.Play(this.storyDisplay);
this.nextSceneId = scene.GetNextSceneId(); // Debug.Log("sNextSceneId = scene.GetNextSceneId() [" + scene.GetNextSceneId() + "]");
sNextSceneId = scene.GetNextSceneId();
// Debug.Log("if scene.IsBattleNext() [" + scene.IsBattleNext() + "]");
if (scene.IsBattleNext()) {
// Debug.Log("yield break");
yield break;
}
} }
} }
} }

View file

@ -4,12 +4,24 @@ using UnityEngine;
public abstract class StoryScene public abstract class StoryScene
{ {
private bool battleIsNext;
private SceneId nextSceneId = SceneId.None; private SceneId nextSceneId = SceneId.None;
public abstract IEnumerator Play(StoryDisplay storyDisplay); public abstract IEnumerator Play(StoryDisplay storyDisplay);
protected void SetNextSceneId(SceneId id) { protected void SetNextSceneId(SceneId id) {
this.nextSceneId = id; this.nextSceneId = id;
this.battleIsNext = false;
}
public void StartBattleThenNextSceneId(BattleParameters battleParameters, SceneId id) {
this.nextSceneId = id;
this.battleIsNext = true;
BattleSetup.StartBattle(battleParameters);
}
public bool IsBattleNext() {
return this.battleIsNext;
} }
public SceneId GetNextSceneId() { public SceneId GetNextSceneId() {