From 959458ad7493a41b08acb791dc0e9bd055b85b6a Mon Sep 17 00:00:00 2001 From: henriquenakashima Date: Mon, 28 Sep 2020 23:41:27 -0400 Subject: [PATCH] Fix flow to/from battle, add cheat code to win --- Assets/Battle/BattleController.cs | 6 ++++- .../Battle/{DebugBattle.cs => CheatBattle.cs} | 20 ++++++++++++++++- ...ebugBattle.cs.meta => CheatBattle.cs.meta} | 0 Assets/Story/Scenes/Scene_Chapter1_Cave.cs | 2 +- Assets/Story/Scenes/Scene_Prologue_First.cs | 12 +++++----- Assets/Story/StoryController.cs | 22 +++++++++++++------ Assets/Story/StoryScene.cs | 12 ++++++++++ 7 files changed, 58 insertions(+), 16 deletions(-) rename Assets/Battle/{DebugBattle.cs => CheatBattle.cs} (79%) rename Assets/Battle/{DebugBattle.cs.meta => CheatBattle.cs.meta} (100%) diff --git a/Assets/Battle/BattleController.cs b/Assets/Battle/BattleController.cs index 6160991..9ce5f56 100644 --- a/Assets/Battle/BattleController.cs +++ b/Assets/Battle/BattleController.cs @@ -43,7 +43,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe BattleParameters parameters = BattleSetup.RetrieveParameters(); if (parameters == null) { Debug.Log("Using default battle"); - parameters = DebugBattle.CreateParameters(); + parameters = CheatBattle.CreateParameters(); } this.heroCardDatabase = new HeroCardDatabase(); @@ -150,6 +150,10 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe void Start() { StartCoroutine(RunBattleRounds()); + + new GameObject("CheatBattle").AddComponent().OnWinCode += delegate { + BattleResult.FinishBattle(new BattleResult(true)); + }; } // Update is called once per frame diff --git a/Assets/Battle/DebugBattle.cs b/Assets/Battle/CheatBattle.cs similarity index 79% rename from Assets/Battle/DebugBattle.cs rename to Assets/Battle/CheatBattle.cs index 1d4ec70..639e1ee 100644 --- a/Assets/Battle/DebugBattle.cs +++ b/Assets/Battle/CheatBattle.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using UnityEngine; -public class DebugBattle +public class CheatBattle: MonoBehaviour { public static BattleParameters CreateParameters() { HeroId[] heroIds = new HeroId[3] { @@ -66,4 +66,22 @@ public class DebugBattle parameters.SetMonsters(monsterIds, mCardIds, mCardOwnerIndexes); 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(); + } + } } diff --git a/Assets/Battle/DebugBattle.cs.meta b/Assets/Battle/CheatBattle.cs.meta similarity index 100% rename from Assets/Battle/DebugBattle.cs.meta rename to Assets/Battle/CheatBattle.cs.meta diff --git a/Assets/Story/Scenes/Scene_Chapter1_Cave.cs b/Assets/Story/Scenes/Scene_Chapter1_Cave.cs index 0cb073a..3ecda64 100644 --- a/Assets/Story/Scenes/Scene_Chapter1_Cave.cs +++ b/Assets/Story/Scenes/Scene_Chapter1_Cave.cs @@ -12,7 +12,7 @@ public class Scene_Chapter1_Cave: StoryScene yield return new WaitForSeconds(1f); BattleParameters battleParameters = BuildBattleGolemBats(); - BattleSetup.StartBattle(battleParameters); + this.StartBattleThenNextSceneId(battleParameters, SceneId.Chapter1_Cave); } private BattleParameters BuildBattleGolemBats() { diff --git a/Assets/Story/Scenes/Scene_Prologue_First.cs b/Assets/Story/Scenes/Scene_Prologue_First.cs index 30eb162..1267f94 100644 --- a/Assets/Story/Scenes/Scene_Prologue_First.cs +++ b/Assets/Story/Scenes/Scene_Prologue_First.cs @@ -6,26 +6,26 @@ public class Scene_Prologue_First: StoryScene { public override IEnumerator Play(StoryDisplay storyDisplay) { 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 new WaitForSeconds(1f); + //yield return new WaitForSeconds(1f); yield return storyDisplay.DisplayText("Yes.", DialogPosition.Right); - yield return new WaitForSeconds(1f); + //yield return new WaitForSeconds(1f); 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?", DialogPosition.Left); - yield return new WaitForSeconds(1f); + //yield return new WaitForSeconds(1f); 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.", DialogPosition.Left); yield return storyDisplay.DisplayText( "Life is finite, after all. There is only so much you can do in it.", DialogPosition.Left); - yield return new WaitForSeconds(2f); + //yield return new WaitForSeconds(2f); yield return storyDisplay.DisplayText( "Finite in time, yes. But infinite in possibilities...", DialogPosition.Right); - yield return new WaitForSeconds(2f); + //yield return new WaitForSeconds(2f); this.SetNextSceneId(SceneId.Chapter1_Cave); } diff --git a/Assets/Story/StoryController.cs b/Assets/Story/StoryController.cs index 735ffe5..d72e1a1 100644 --- a/Assets/Story/StoryController.cs +++ b/Assets/Story/StoryController.cs @@ -6,22 +6,30 @@ public class StoryController : MonoBehaviour { public StoryDisplay storyDisplay; - private SceneId nextSceneId; + // TODO: Read which scene should be loaded. + private static SceneId sNextSceneId = SceneId.Prologue_First; void Start() { - // TODO: Read which scene should be loaded. - this.nextSceneId = SceneId.Prologue_First; - StartCoroutine(this.PlayScenes()); } private IEnumerator PlayScenes() { while (true) { - SceneId id = this.nextSceneId; - this.nextSceneId = SceneId.None; + // Debug.Log("SceneId id = " + sNextSceneId); + SceneId id = sNextSceneId; + // Debug.Log("sNextSceneId = " + SceneId.None); + sNextSceneId = SceneId.None; + // Debug.Log("StoryScene scene = Load()"); StoryScene scene = StorySceneDatabase.Load(id); + // Debug.Log("yield return scene.Play()"); 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; + } } } } diff --git a/Assets/Story/StoryScene.cs b/Assets/Story/StoryScene.cs index 91cf285..2747c9a 100644 --- a/Assets/Story/StoryScene.cs +++ b/Assets/Story/StoryScene.cs @@ -4,12 +4,24 @@ using UnityEngine; public abstract class StoryScene { + private bool battleIsNext; private SceneId nextSceneId = SceneId.None; public abstract IEnumerator Play(StoryDisplay storyDisplay); protected void SetNextSceneId(SceneId 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() {