Esempio n. 1
0
    static void NextPhase()
    {
        whichText = 0;
        ++phase;
        switch (phase)
        {
        case T_Phases.Deploy:
            UIMaster.DisplayState(GamePhase.Deploy, PlayerMaster.CurrentTurn);
            UIMaster.SetActionPanel(true);
            UIMaster.FadePhanel(0);
            break;

        case T_Phases.Cannon:
            for (int i = 0; i < PlayerMaster.CurrentPlayer.Can.Count; ++i)
            {
                PlayerMaster.CurrentPlayer.Can[i].Moved = false;
            }
            HighlightMaster.HighlightActiveCannons(PlayerMaster.CurrentPlayer);
            break;

        default:
            break;
        }

        turn_button.interactable = false;
        phaselength = TutorialUIMaster.TutorialText[(int)phase].Length;
        TutorialUIMaster.ChangeText((int)phase, whichText);
    }
Esempio n. 2
0
    public static void ClearMoveVariables()
    {
        if (target != null)
        {
            HighlightMaster.ToggleTileHighlights(false, MapMaster.CellsWithinArea(target.CurrentHex, target.MoveSpeed));
        }

        target = null;
    }
Esempio n. 3
0
    private static IEnumerator MoveToCannon()
    {
        if (!currentCannon.C.Moved)
        {
            HighlightMaster.HighlightUnitToggle(false, currentCannon.C);
        }

        yield return(TopDownCamera.LerpToPosition(currentCannon.CameraPos[0].transform.position, currentCannon.CameraPos[0].transform.rotation));

        currentCannon.CannonCam.GetComponent <Camera>().enabled = true;
        TopDownCamera.Instance.GetComponent <Camera>().enabled  = false;

        UIMaster.FadePhanel((int)UIPannels.Cannon);
        // UIMaster.TogglePanelLock(false, (int)UIPannels.Action);
        UIMaster.FadePhanel((int)UIPannels.Action);
    }
Esempio n. 4
0
    public static void EvaluateTile(HexCell h)
    {
        if (target != null && h.passable)
        {
            List <HexCell> path = HexStar.GetPath(target.CurrentHex, h, target.MoveSpeed);

            HighlightMaster.ToggleTileHighlights(false, MapMaster.CellsWithinArea(target.CurrentHex, target.MoveSpeed));

            if (path.Count > 0)
            {
                target.StartCoroutine(FollowPath(path, target));
                SoundMaster.SelectUnit();
            }

            target = null;
        }
    }
Esempio n. 5
0
    // changes the phase and "refreshes" variables as apropriate
    static IEnumerator EndofRound()
    {
        switch (gP)
        {
        case (GamePhase.Deploy):
            Debug.Log("Move from D");
            MoveMaster.PrimeMoveVariables(PlayerMaster.OtherPlayer);
            PlayerMaster.RefreshMovement();
            HighlightMaster.HighlightMovable(PlayerMaster.OtherPlayer);
            gP = GamePhase.Move;

            break;

        case (GamePhase.Cannon):
            Debug.Log("Move from C");
            PlayerMaster.RefreshMovement();
            if (PlayerMaster.CurrentTurn == 1)
            {
                MoveMaster.PrimeMoveVariables(PlayerMaster.OtherPlayer);
                HighlightMaster.HighlightMovable(PlayerMaster.OtherPlayer);
            }
            gP = GamePhase.Move;
            break;

        case (GamePhase.Move):
            Debug.Log("Cannon from M");
            HighlightMaster.HighlightActiveCannons(PlayerMaster.OtherPlayer);

            yield return(WinBySize());

            gP = GamePhase.Cannon;
            //CheckSkip();
            break;

        case (GamePhase.Attack):
            Debug.Log("Move from A");
            break;

        default:
            yield return(null);

            break;
        }
    }
Esempio n. 6
0
    public static void ExitCannon()
    {
        if (currentCannon != null)
        {
            currentCannon.StartCoroutine(LeaveCannon());
            currentCannon.Selected = false;
            currentCannon.DestroyIndicator();
            currentCannon.ReturnToDefault();

            if (!currentCannon.C.Moved)
            {
                HighlightMaster.HighlightUnitToggle(true, currentCannon.C);
            }

            currentCannon = null;

            soundM.ButtonPress();
        }
    }
Esempio n. 7
0
    public static void BuildCombatAreas()
    {
        if (instance.combatPoints.Count == 0)
        {
            return;
        }

        while (instance.combatPoints.Count != 0)
        {
            Unit origin = instance.combatPoints[0].Unit;
            instance.combatPoints.RemoveAt(0);

            List <Unit> combatArea = BuildCombatArea(origin);
            instance.combatAreas.Add(combatArea);
            foreach (Unit u in combatArea)
            {
                HighlightMaster.HighlightUnitToggle(true, u);
            }
        }
        instance.combatCount = instance.combatAreas.Count;
    }
Esempio n. 8
0
    private static void MoveToTile(HexCell h, ref Unit u)
    {
        HighlightMaster.ToggleTileHighlights(false, MapMaster.CellsWithinArea(u.CurrentHex, u.MoveSpeed));

        MapMaster.Map[u.CurrentHex.R, u.CurrentHex.Q].Passable = true;
        MapMaster.Map[u.CurrentHex.R, u.CurrentHex.Q].Unit     = null;

        u.gameObject.transform.position = h.SpawnVector;

        MapMaster.Map[h.R, h.Q].Unit     = u;
        MapMaster.Map[h.R, h.Q].Passable = false;
        u.Moved = true;

        u.CurrentHex = MapMaster.Map[h.R, h.Q];

        HighlightMaster.HighlightUnitToggle(false, u);

        AttackMaster.BuildCombatPoints(u.CurrentHex);

        u = null;

        UnitsToMove--;
    }
Esempio n. 9
0
    public static void SetTarget(Unit u)
    {
        if (!u.Moved && u.Player == PlayerMaster.CurrentTurn)
        {
            if (target != null)
            {
                HighlightMaster.ToggleTileHighlights(false, MapMaster.CellsWithinArea(target.CurrentHex, target.MoveSpeed));
                if (target.UName != "Cannon" && !target.Equals(u))
                {
                    target.GetComponentInChildren <Animator>().Play("GoToIdle");
                }
            }

            target = u;
            instance.timePressed = 0;
            SoundMaster.SelectUnit();

            if (u.UName != "Cannon")
            {
                u.GetComponentInChildren <Animator>().Play("AtenHut");
            }

            foreach (HexCell h in MapMaster.CellsWithinArea(u.CurrentHex, u.MoveSpeed))
            {
                if (HexStar.GetPath(u.CurrentHex, h, u.MoveSpeed).Count > 0)
                {
                    HighlightMaster.HighlightTile(h);
                }
            }

            if (instance.uQue.Count != 0)
            {
                instance.uQue.Clear();
            }
            //playthatfunkysound(h.Unit.UName);
        }
    }
Esempio n. 10
0
    static IEnumerator Fight() //Handles and manages the FightScene
    {
        gP = GamePhase.Attack;

        while (AttackMaster.CombatCount != 0)
        {
            float rotation;
            if (PlayerMaster.CurrentTurn == 0)
            {
                rotation = 180;
            }
            else
            {
                rotation = 0;
            }

            instance.StartCoroutine(TopDownCamera.LerpToPosition(AttackMaster.CenterOfCombat(), Quaternion.Euler(90, rotation, 0)));
            yield return(new WaitForSeconds(2.0f));               //Wait to give the player a chance to see stuff

            instance.StartCoroutine(UIMaster.MoveCurtains(true)); //lower curtains
            yield return(null);                                   //Wait at least one frame so that UIMaster.MovingCurtians can change value

            while (UIMaster.MovingCurtains)
            {
                yield return(null);
            }

            List <Unit> currentCombat = AttackMaster.CurrentCombatArea;
            List <Unit> toKill        = AttackMaster.FightResults();
            FightSceneMaster.SetUpFight(currentCombat, toKill);    //Prepare the fightscene

            yield return(new WaitForSeconds(1.0f));                //Pause for dramatic effect

            instance.StartCoroutine(UIMaster.MoveCurtains(false)); //Raise Curtains
            yield return(null);

            while (UIMaster.MovingCurtains)
            {
                yield return(null);
            }

            SoundMaster.AttackCharge();
            instance.StartCoroutine(FightSceneMaster.ToBattle()); //Begins FightScene
            yield return(null);                                   //Wait at least one frame so that FightSceneMaster.Fighting can change value

            while (FightSceneMaster.Fighting)
            {
                yield return(null);
            }

            //SoundMaster.AttackResolution();
            instance.StartCoroutine(UIMaster.MoveCurtains(true)); //Lower curtains again
            yield return(null);                                   //Wait at least one frame so that UIMaster.MovingCurtians can change value

            while (UIMaster.MovingCurtains)
            {
                yield return(null);
            }

            FightSceneMaster.CleanUp();                            //Resets FightScene

            yield return(new WaitForSeconds(0.25f));               //Pause

            instance.StartCoroutine(UIMaster.MoveCurtains(false)); //Raise curtains
            yield return(new WaitForFixedUpdate());                //Wait at least one frame so that UIMaster.MovingCurtians can change value

            while (UIMaster.MovingCurtains)
            {
                yield return(null);
            }

            yield return(new WaitForSeconds(1.0f));

            foreach (Unit u in toKill)
            {
                PlayerMaster.KillUnit(u);           //Kills dead units
            }
            yield return(new WaitForSeconds(1.0f)); //Pause to see aftermath
        }

        //return to player's position after the fight
        instance.StartCoroutine(TopDownCamera.LerpToPosition(PlayerMaster.CurrentPlayer.CameraPosistion, PlayerMaster.CurrentPlayer.CameraRotation));

        DeactivateCannonByMove(PlayerMaster.OtherPlayer);

        if (PlayerMaster.CurrentTurn == 0)
        {
            HighlightMaster.HighlightMovable(PlayerMaster.OtherPlayer);
        }

        UIMaster.DisplayScore();

        // WinByMove();

        UIMaster.SetActionPanel(true); //Turns action pannel back on
        UIMaster.FadePhanel((int)UIPannels.Action);

        CannonMaster.CheckCannonCapture();

        gP = GamePhase.Move;
        yield return(ChangeTurn());

        acceptInput = true;
    }
Esempio n. 11
0
    //Alters aspects of the game state (such as highlights or unit numbers) based on phase and other information
    private static IEnumerator AlterState()
    {
        switch (gP)
        {
        case (GamePhase.Deploy):

            if (DeployMaster.instance.uoList.Count != 0)
            {
                yield return(DeployMaster.DeployUnitsCoroutine());

                yield return(new WaitForSeconds(1.5f));
            }
            UIMaster.UpdateDeployAmount();
            break;

        case (GamePhase.Cannon):
            // CheckSkip();

            /*      if (PlayerMaster.CurrentTurn == 0)
             *    {
             *        CheckSkip();
             *    } */

            CannonMaster.ExitCannon();
            HighlightMaster.UnhighlightCannons(PlayerMaster.CurrentPlayer);
            DeactivateCannonByCannon(PlayerMaster.OtherPlayer);

            if (PlayerMaster.CurrentTurn == 0)
            {
                //DeactivateCannonByMove(PlayerMaster.OtherPlayer);
                HighlightMaster.HighlightActiveCannons(PlayerMaster.OtherPlayer);
            }
            break;

        case (GamePhase.Move):

            if (MoveMaster.UnitsToMove != 0)
            {
                HighlightMaster.UnhighlightMovable(PlayerMaster.CurrentPlayer);
                MoveMaster.ClearMoveVariables();
            }
            AttackMaster.BuildCombatAreas();

            ActivateCannonByMove(PlayerMaster.CurrentPlayer);
            DeactivateCannonByMove(PlayerMaster.CurrentPlayer);

            if (AttackMaster.CombatCount == 0)
            {
                CannonMaster.CheckCannonCapture();
                yield return(WinByMove());

                if (PlayerMaster.CurrentTurn == 0)
                {
                    MoveMaster.PrimeMoveVariables(PlayerMaster.OtherPlayer);
                    HighlightMaster.HighlightMovable(PlayerMaster.OtherPlayer);
                }
            }

            else if (AttackMaster.CombatCount != 0)
            {
                //  AttackMaster.BuildCombatAreas();
                //gP = GamePhase.Attack;

                UIMaster.SetActionPanel(false);     //Deactivates off action panel
                UIMaster.FadePhanel((int)UIPannels.Action);
                acceptInput = false;

                instance.StartCoroutine(Fight());
                //yield return Fight();
            }
            break;

        case (GamePhase.Attack):
            break;

        default:
            yield return(null);

            break;
        }
    }
Esempio n. 12
0
    public static void DecideMove()
    {
        if (target != null)
        {
            if (Input.GetKey(KeyCode.Mouse0))
            {
                instance.BuildMarker();
            }
            else if (Input.GetKeyUp(KeyCode.Mouse0) && instance.radiusMarker != null)
            {
                instance.timePressed = 0;

                foreach (HexCell h in MapMaster.CellsWithinArea(target.CurrentHex, instance.uSize))
                {
                    Unit u = h.Unit;
                    if (u != null)
                    {
                        if (!u.Moved && u.Player == PlayerMaster.CurrentTurn)
                        {
                            instance.uQue.Add(u);
                        }
                    }
                }

                GameObject.Destroy(instance.radiusMarker);
                instance.radiusMarker = null;
                instance.uSize        = 0;
                // target = null;
            }
        }

        if (Input.GetKeyDown(KeyCode.Mouse0) /*&& Events.GetComponent<Pause>().paused == false*/)
        {
            Ray        ray;
            RaycastHit hit;
            ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out hit))
            {
                Unit    u = hit.transform.gameObject.GetComponent <Unit>();
                HexCell h = hit.transform.gameObject.GetComponent <HexCell>();
                //Debug.Log(u == null ? "" : u.UName);

                if (u != null)
                {
                    SetTarget(u);
                }
                else if (h != null)
                {
                    if (instance.uQue.Count == 0)
                    {
                        EvaluateTile(h);
                    }
                    else
                    {
                        if (target != null)
                        {
                            HighlightMaster.ToggleTileHighlights(false, MapMaster.CellsWithinArea(target.CurrentHex, target.MoveSpeed));

                            Vector3 directionVector = HexCell.TravelDirection(target.CurrentHex.Cube, h.Cube);
                            Vector2 endpoint;
                            HexCell goal;

                            List <HexCell> newPath;

                            List <KeyValuePair <Unit, List <HexCell> > > paths = new List <KeyValuePair <Unit, List <HexCell> > >();

                            foreach (Unit un in instance.uQue)
                            {
                                un.CurrentHex.passable = true;
                            }
                            foreach (Unit un in instance.uQue)
                            {
                                endpoint = HexCell.NewLocationInOffset(un.CurrentHex.Cube, directionVector);
                                if (!MapMaster.IsCellOnMap((int)endpoint.y, (int)endpoint.x))
                                {
                                    continue;
                                }
                                goal    = MapMaster.Map[(int)endpoint.y, (int)endpoint.x];
                                newPath = HexStar.GetPath(un.CurrentHex, goal, un.MoveSpeed);
                                if (newPath.Count > 0)
                                {
                                    paths.Add(new KeyValuePair <Unit, List <HexCell> >(un, newPath));
                                }
                                else
                                {
                                    un.CurrentHex.passable = false;
                                }
                            }

                            EvaluateTileGroup(paths);
                            instance.uQue.Clear();
                            if (!target.Moved && target.UName == "Infantry")
                            {
                                target.GetComponentInChildren <Animator>().Play("GoToIdle");
                            }
                            target = null;
                        }
                    }
                }
            }
        }
    }
Esempio n. 13
0
    private static IEnumerator FollowPath(List <HexCell> path, Unit u)
    {
        u.Moved = true;
        u.CurrentHex.Passable         = true;
        u.CurrentHex.unit             = null;
        path[path.Count - 1].passable = false;

        Animator a        = null;
        bool     infOrCav = u.UName == "Cannon" ? false : true;

        if (infOrCav)
        {
            a = u.gameObject.GetComponentInChildren <Animator>();
        }

        yield return(new WaitForFixedUpdate());

        ++movingUnits;

        UIMaster.SetActionPanel(false);
        //  path[path.Count - 1].Unit = u;

        if (infOrCav)
        {
            a.Play("MoveStart");
        }

        Rigidbody r = u.gameObject.GetComponent <Rigidbody>();

        if (r != null)
        {
            r.detectCollisions = false;
            r.useGravity       = false;
        }

        yield return(new WaitForSeconds(0.25f));

        SoundMaster.StartUnitMove();

        while (path.Count > 0)
        {
            yield return(new WaitForEndOfFrame());

            yield return(LearpToTile(u, path[0]));

            path.RemoveAt(0);
        }

        SoundMaster.StopUnitMove();

        yield return(new WaitForFixedUpdate());

        --movingUnits;

        if (!(movingUnits > 0))
        {
            UIMaster.SetActionPanel(true);
        }

        if (r != null)
        {
            r.detectCollisions = true;
            r.useGravity       = true;
        }

        if (infOrCav)
        {
            a.Play("MoveEnd");
        }

        u.CurrentHex.Unit    = u;
        u.transform.rotation = u.URotation();
        HighlightMaster.HighlightUnitToggle(false, u);
        AttackMaster.BuildCombatPoints(u.CurrentHex);
    }
Esempio n. 14
0
    public static List <Unit> FightResults()
    {
        List <Unit> toKill = new List <Unit>();
        int         p1     = 0;
        int         p2     = 0;

        if (instance.combatAreas.Count != 0)
        {
            foreach (Unit u in instance.combatAreas[0])
            {
                if (u.Player == 0)
                {
                    p1++;
                }
                else
                {
                    p2++;
                }
                HighlightMaster.HighlightUnitToggle(true, u);
            }
        }

        if (p1 == p2)
        {
            foreach (Unit u in instance.combatAreas[0])
            {
                if (u != null)
                {
                    toKill.Add(u);
                }
            }
        }
        else
        {
            if (p1 > p2)
            {
                p1 = p2;
            }

            else
            {
                p2 = p1;
            }

            foreach (Unit u in instance.combatAreas[0])
            {
                if (u != null)
                {
                    if (u.Player == 0 && p1 != 0)
                    {
                        toKill.Add(u);
                        p1--;
                    }

                    else if (u.Player == 1 && p2 != 0)
                    {
                        toKill.Add(u);
                        p2--;
                    }
                }
            }
        }

        foreach (Unit u in instance.combatAreas[0])
        {
            if (u != null)
            {
                HighlightMaster.HighlightUnitToggle(false, u);
            }
        }

        instance.combatAreas.Remove(instance.combatAreas[0]);
        instance.combatCount--;
        return(toKill);
    }
Esempio n. 15
0
    public static void ResolveFight()
    {
        int p1 = 0;
        int p2 = 0;

        if (instance.combatAreas.Count != 0)
        {
            foreach (Unit u in instance.combatAreas[0])
            {
                if (u.Player == 0)
                {
                    p1++;
                }
                else
                {
                    p2++;
                }
                HighlightMaster.HighlightUnitToggle(true, u);
            }
        }

        if (p1 == p2)
        {
            foreach (Unit u in instance.combatAreas[0])
            {
                if (u != null)
                {
                    PlayerMaster.KillUnit(u);
                }
            }
        }
        else
        {
            if (p1 > p2)
            {
                p1 = p2;
            }

            else
            {
                p2 = p1;
            }

            foreach (Unit u in instance.combatAreas[0])
            {
                if (u != null)
                {
                    if (u.Player == 0 && p1 != 0)
                    {
                        PlayerMaster.KillUnit(u);
                        p1--;
                    }

                    else if (u.Player == 1 && p2 != 0)
                    {
                        PlayerMaster.KillUnit(u);
                        p2--;
                    }
                }
            }
        }

        foreach (Unit u in instance.combatAreas[0])
        {
            if (u != null)
            {
                HighlightMaster.HighlightUnitToggle(false, u);
            }
        }

        instance.combatAreas.Remove(instance.combatAreas[0]);
        instance.combatCount--;
    }