// Use this for initialization
        void Start()
        {
            //Actual constructor code. This should still be here after the demo :p
            playerCharacter  = 0;
            battlefield      = new Battlefield();
            currentCharacter = -1;
            battleStage      = BattleLoopStage.Initial;
            halfTurnsElapsed = 0;

            turnPlayerText.enabled       = false;
            turnChangeBackground.enabled = false;
            victoryImage.enabled         = false;
            defeatImage.enabled          = false;

            getLevel();
            deserializeMap();
            deserializeLevel();

            //TODO replace this with predicate based execution
            CameraController.inputEnabled = false;
            mainCamera.enabled            = false;
            cutsceneCamera.enabled        = true;
            if (level.cutsceneIDs.Length != 0)
            {
                cutscene.startCutscene(level.cutsceneIDs[0]);
            }
        }
Beispiel #2
0
 public ExecutionInfo(Battlefield battlefield, GameObjective objective, int halfTurnsElapsed, BattleLoopStage battleStage, bool afterVictoryImage)
 {
     this.battlefield       = battlefield;
     this.objective         = objective;
     this.halfTurnsElapsed  = halfTurnsElapsed;
     this.battleStage       = battleStage;
     this.afterVictoryImage = afterVictoryImage;
 }
Beispiel #3
0
        public static BattleLoopStage NextPhase(this BattleLoopStage stage)
        {
            //We don't go back into pick mid-battle
            if (stage == BattleLoopStage.EndTurn)
            {
                return(BattleLoopStage.BattleLoopStart);
            }

            return((BattleLoopStage)(((int)(stage) + 1)));
        }
        // Use this for initialization
        void Start()
        {
            //Just for testing because we don't have any way to set the campaign yet:
            Character[]  characters     = new[] { new Character("Alice", true), new Character("The evil lord zxqv", false) };
            List <Coord> alicePickTiles = new List <Coord> {
                new Coord(0, 0), new Coord(0, 1), new Coord(1, 0)
            };
            List <Coord> evilGuyPickTiles = new List <Coord> {
                new Coord(3, 7), new Coord(7, 4)
            };
            Dictionary <Character, List <Coord> > validPickTiles = new Dictionary <Character, List <Coord> >();

            validPickTiles[characters[0]] = alicePickTiles;
            validPickTiles[characters[1]] = evilGuyPickTiles;
            Level    level        = new Level("DemoMap", characters, null, validPickTiles);
            Campaign testCampaign = new Campaign("test", 0, new[] { level });

            Persistance.campaign = testCampaign;

            //This will be encoded in the campaign. Somewhere.
            CutsceneCharacter blair   = CutsceneCharacter.blair;
            CutsceneCharacter juniper = CutsceneCharacter.juniper;
            CutsceneScript    script  = new CutsceneScript(new List <CutsceneScriptLine> {
                new CutsceneScriptLine(CutsceneAction.SetBackground, background: CutsceneBackground.Academy),
                new CutsceneScriptLine(CutsceneAction.SetCharacter, character: blair, side: CutsceneSide.Left),
                new CutsceneScriptLine(CutsceneAction.SayDialogue, character: blair, dialogue: "My name is Blair!"),
                new CutsceneScriptLine(CutsceneAction.SetCharacter, character: juniper, side: CutsceneSide.Right),
                new CutsceneScriptLine(CutsceneAction.SayDialogue, character: juniper, dialogue: "and I'm Juniper."),
                new CutsceneScriptLine(CutsceneAction.SayDialogue, character: blair, dialogue: "There's a third major character, Bruno. He would've been here, but he got tied up with paperwork"),
                new CutsceneScriptLine(CutsceneAction.SayDialogue, character: juniper, dialogue: "Which is to say we ran out of budget"),
                new CutsceneScriptLine(CutsceneAction.SayDialogue, character: juniper, dialogue: "Anyways, I hope you enjoy this slick as h*ck demo"),
                new CutsceneScriptLine(CutsceneAction.TransitionOut, side: CutsceneSide.Right),
                new CutsceneScriptLine(CutsceneAction.TransitionOut, side: CutsceneSide.Left)
            });

            cutscene.setup(script);

            //Actual constructor code. This should still be here after the demo :p
            playerCharacter  = 0;
            battlefield      = new Battlefield();
            currentCharacter = -1;
            battleStage      = BattleLoopStage.Initial;

            turnPlayerText.enabled       = false;
            turnChangeBackground.enabled = false;
            victoryImage.enabled         = false;
            defeatImage.enabled          = false;
            getLevel();
            deserializeMap();
        }
Beispiel #5
0
        void Start()
        {
            playerCharacter  = 0;
            battlefield      = new Battlefield();
            currentCharacter = -1;
            battleStage      = BattleLoopStage.Initial;
            halfTurnsElapsed = 0;

            turnPlayerText.enabled       = false;
            turnChangeBackground.enabled = false;
            victoryImage.enabled         = false;
            defeatImage.enabled          = false;

            useNormalCamera();

            getLevel();
            deserializeMap();
            deserializeLevel();

            mainCamera.GetComponent <CameraController>().updateMaxPos(battlefield.map.GetLength(0), battlefield.map.GetLength(1));
        }
 private void setBattleLoopStage(BattleLoopStage stage)
 {
     battleStage        = stage;
     battleStageChanged = true;
 }
 //Convenience
 private void advanceBattleStage()
 {
     battleStage        = battleStage.NextPhase();
     battleStageChanged = true;
 }
        // Update is called once per frame
        async void Update()
        {
            switch (battleStage)
            {
            case BattleLoopStage.Initial:
                if (!cutscene.inProgress)
                {
                    advanceBattleStage();
                }
                break;

            case BattleLoopStage.Pick:
                //TODO This is temp just for testing until pick phase gets built.
                addUnit(UnitType.Knight, level.characters[0], 0, 0);
                addUnit(UnitType.Knight, level.characters[0], 1, 0);
                addUnit(UnitType.Knight, level.characters[0], 0, 1);
                addUnit(UnitType.Knight, level.characters[1], 3, 7);
                addUnit(UnitType.Knight, level.characters[1], 4, 7);
                foreach (Unit unit in battlefield.charactersUnits[level.characters[1]])
                {
                    Renderer rend = unit.gameObject.GetComponent <Renderer>();
                    rend.material.shader = Shader.Find("_Color");
                    rend.material.SetColor("_Color", Color.green);
                    rend.material.shader = Shader.Find("Specular");
                    rend.material.SetColor("_SpecColor", Color.green);
                }

                advanceBattleStage();
                break;

            case BattleLoopStage.BattleLoopStart:
                advanceBattleStage();
                break;

            case BattleLoopStage.TurnChange:
                //There's probably a less fragile way of doing this. It's just to make sure this call only happens once per turn loop.
                if (!turnPlayerText.enabled)
                {
                    currentCharacter             = (currentCharacter + 1) % level.characters.Length;
                    turnPlayerText.text          = level.characters[currentCharacter].name + "'s turn";
                    turnPlayerText.enabled       = true;
                    turnChangeBackground.enabled = true;
                    Util.setTimeout(advanceBattleStage, 1000);
                }
                break;

            case BattleLoopStage.TurnChangeEnd:
                turnPlayerText.enabled       = false;
                turnChangeBackground.enabled = false;
                advanceBattleStage();
                break;

            case BattleLoopStage.UnitSelection:
                //Player input. LMB
                if (Input.GetButtonDown("Select"))
                {
                    RaycastHit hit;
                    Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                    if (Physics.Raycast(ray, out hit, 1000.0f))
                    {
                        Vector3Int       tileCoords   = Util.WorldToGrid(hit.transform.position);
                        IBattlefieldItem selectedItem = battlefield.battlefieldItemAt(tileCoords.x, tileCoords.y, tileCoords.z);
                        if (selectedItem is Tile)
                        {
                            //Selected a tile, show info abt that tile
                            //TODO: Show info about tile if a tile is clicked
                            Tile selectedTile = selectedItem as Tile;
                            highlightSingleObject(selectedTile.gameObject);
                        }
                        else if (selectedItem is Unit)
                        {
                            Unit selectedUnit = selectedItem as Unit;

                            if (selectedUnit.getCharacter(battlefield) == level.characters[currentCharacter] && !selectedUnit.hasMovedThisTurn)
                            {
                                //Selected friendly unit. show move options.
                                highlightSingleObject(selectedUnit.gameObject, 1);
                                this.highlightedFriendlyUnit = selectedUnit;

                                moveOptions = selectedUnit.getValidMoves(tileCoords.x, tileCoords.y, battlefield);
                                foreach (Coord moveOption in moveOptions)
                                {
                                    highlightMultipleObjects(battlefield.map[moveOption.x, moveOption.y].Peek().gameObject);
                                }

                                this.highlightedEnemyUnits = selectedUnit.getTargets(tileCoords.x, tileCoords.y, battlefield, level.characters[currentCharacter]);
                                foreach (Unit targetableUnit in highlightedEnemyUnits)
                                {
                                    highlightMultipleObjects(targetableUnit.gameObject, 2);
                                }

                                advanceBattleStage();
                            }
                            else
                            {
                                //Selected enemy unit. Show unit and its move options.
                                //TODO: highlight enemy's valid move tiles.
                            }
                        }
                        else if (selectedItem == null)
                        {
                            //Clicked on empty space! Nbd, don't do anything.
                            Debug.Log("Clicked on empty space");
                        }
                        else
                        {
                            Debug.LogWarning("Item of unrecognized type clicked on.");
                        }
                    }
                }


                //If player has selected a move:
                //TODO play the animation
                break;

            case BattleLoopStage.ActionSelection:
                if (Input.GetButtonDown("Select"))
                {
                    RaycastHit hit;
                    Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                    if (Physics.Raycast(ray, out hit, 1000.0f))
                    {
                        Vector3Int       tileCoords   = Util.WorldToGrid(hit.transform.position);
                        IBattlefieldItem selectedItem = battlefield.battlefieldItemAt(tileCoords.x, tileCoords.y, tileCoords.z);
                        if (selectedItem is Tile)
                        {
                            //We selected a tile! lets move to it
                            if (moveOptions.Any(move => (move.x == tileCoords.x && move.y == tileCoords.y)))
                            {
                                moveUnit(highlightedFriendlyUnit, tileCoords);
                                deselectMoveOptions();

                                highlightedFriendlyUnit.hasMovedThisTurn = true;

                                if (battlefield.charactersUnits[level.characters[currentCharacter]].All(unit => unit.hasMovedThisTurn))
                                {
                                    advanceBattleStage();
                                }
                                else
                                {
                                    this.battleStage = BattleLoopStage.UnitSelection;
                                }
                            }
                        }
                        else if (selectedItem == null)
                        {
                            //Clicked on empty space, deselect
                            deselectMoveOptions();
                            battleStage = BattleLoopStage.UnitSelection;
                        }
                        else if (selectedItem is Unit)
                        {
                            Unit selectedUnit = selectedItem as Unit;

                            if (highlightedFriendlyUnit == selectedUnit)
                            {
                                //clicked on the same unit, deselect
                                deselectMoveOptions();
                                battleStage = BattleLoopStage.UnitSelection;
                            }
                            else if (selectedUnit.getCharacter(battlefield) == level.characters[currentCharacter])
                            {
                                //Clicked on a friendly unit. Deselect the current one.
                                deselectMoveOptions();
                                battleStage = BattleLoopStage.UnitSelection;
                            }
                            else
                            {
                                //Clicked on a hostile unit! fight!
                                if (highlightedEnemyUnits.Contains(selectedUnit))
                                {
                                    bool defenderDefeated = highlightedFriendlyUnit.doBattleWith(
                                        selectedUnit,
                                        battlefield.map[tileCoords.x, tileCoords.y].Peek(),
                                        battlefield);

                                    await Task.Delay(TimeSpan.FromMilliseconds(250));

                                    if (defenderDefeated)
                                    {
                                        highlightedEnemyUnits.RemoveAll(units => units == null);
                                    }
                                    else
                                    {
                                        //Counterattack
                                        Coord unitCoords = battlefield.getUnitCoords(highlightedFriendlyUnit);
                                        selectedUnit.doBattleWith(
                                            highlightedFriendlyUnit,
                                            battlefield.map[unitCoords.x, unitCoords.y].Peek(),
                                            battlefield);
                                    }
                                    checkWinAndLose();

                                    highlightedFriendlyUnit.hasMovedThisTurn = true;
                                    await Task.Delay(TimeSpan.FromMilliseconds(250));

                                    deselectMoveOptions();

                                    //If all of our units have moved advance. Otherwise, go back to unit selection.
                                    if (battlefield.charactersUnits[level.characters[currentCharacter]].All(unit => unit.hasMovedThisTurn))
                                    {
                                        advanceBattleStage();
                                    }
                                    else
                                    {
                                        this.battleStage = BattleLoopStage.UnitSelection;
                                    }
                                }
                            }
                        }
                        else
                        {
                            Debug.LogWarning("Item of unrecognized type clicked on.");
                        }
                    }
                }

                break;

            case BattleLoopStage.EndTurn:
                foreach (Unit unit in battlefield.charactersUnits[level.characters[currentCharacter]])
                {
                    unit.hasMovedThisTurn = false;
                }

                checkWinAndLose();
                advanceBattleStage();
                break;
            }
        }
 //Convenience
 private void advanceBattleStage()
 {
     battleStage = battleStage.NextPhase();
 }