예제 #1
0
    public IEnumerator TurnCycle(Team team, Team team2)
    {
        while (team.AnySoldierActionsLeft())
        {
            int lastCommand = attackCommand;
            // *** PLAYER ***
            // Right click on any slot moves active unit there.
            GridSlot hitSlot = GetGridUnderMouse();
            if (hitSlot != null)
            {
                MapNode[] path = Pathfinding.FindPathAStar(team.ActiveSoldier.curPositionSlot.transform.position, hitSlot.transform.position, MapGrid.wholeMap);

                // mouse clicks
                if (hitSlot && Input.GetMouseButtonDown(1) && team.ActiveSoldier.NearEnough(path.Length))
                {
                    // shoot at enemy
                    if (hitSlot.HasEnemy())
                    {
                        attackCommand = 1;
                        uiCommandKey  = 0;
                        // Require 2 clicks to auto attack enemy
                        if (!clickedOnce)
                        {
                            clickedOnce = true;
                        }
                        else
                        {
                            clickedOnce   = false;
                            targetedEnemy = hitSlot.taken.soldierId;
                            //flags[0].MoveActiveToRaycastedPoint(hit);
                            team.ActiveSoldier.AttackSlot(hitSlot);
                            SwapSoldierIfNoTurns(team);
                        }
                    }
                    else
                    {
                        // move to slot
                        attackCommand = -1;
                        targetedEnemy = -1;
                        uiCommandKey  = -1;

                        yield return(team.ActiveSoldier.StartCoroutine(MoveToSlot(team, team2, hitSlot, path)));
                    }
                }

                // fire at nearest enemy
                if (Input.GetKeyDown(KeyCode.Alpha1))
                {
                    attackCommand = 2;
                    uiCommandKey  = 0;
                    Soldier nearestEnemy = team2.GetNearestTo(team.ActiveSoldier);
                    if (nearestEnemy)
                    {
                        targetedEnemy = nearestEnemy.soldierId;
                        if (!clickedOnce)
                        {
                            clickedOnce = true;
                        }
                        else
                        {
                            clickedOnce = false;
                            team.ActiveSoldier.AttackSlot(nearestEnemy.curPositionSlot);
                            SwapSoldierIfNoTurns(team);
                        }
                    }
                }

                // grenade throw
                if (hitSlot && Input.GetKeyDown(KeyCode.Alpha3))
                {
                    attackCommand = 3;
                    uiCommandKey  = 2;
                    if (!clickedOnce)
                    {
                        clickedOnce = true;
                    }
                    else
                    {
                        clickedOnce = false;
                        team.ActiveSoldier.AttackSlot(hitSlot, 1);
                        SwapSoldierIfNoTurns(team);
                    }
                }
                // overwatch
                if (Input.GetKeyDown(KeyCode.Alpha2))
                {
                    attackCommand = 4;
                    uiCommandKey  = 1;
                    if (!clickedOnce)
                    {
                        clickedOnce = true;
                    }
                    else
                    {
                        clickedOnce = false;
                        team.ActiveSoldier.ToOverwatch();
                        SwapSoldierIfNoTurns(team);
                    }
                }
                // reload
                if (Input.GetKeyDown(KeyCode.R))
                {
                    attackCommand = 5;
                    uiCommandKey  = 3;
                    if (!clickedOnce)
                    {
                        clickedOnce = true;
                    }
                    else
                    {
                        clickedOnce = false;
                        team.ActiveSoldier.Reload();
                        SwapSoldierIfNoTurns(team);
                    }
                }

                // FIXED: it will work to click on enemy with right click and then 1.
                // makes sure you can't do mouse+something else attack
                if (attackCommand != lastCommand && lastCommand != 0)
                {
                    clickedOnce = false;
                }

                // tabbing swaps units
                if (Input.GetKeyDown(KeyCode.Tab))
                {
                    if (targetedEnemy == -1)
                    {
                        SwapSoldier(team);
                    }
                    else
                    {
                        SwapTarget(team);
                    }
                }

                // *** ENEMIES *** deprecated
                // if enemy moves, trigger all overwatched player's soldiers

                // AI: move all enemies

                /*for (int i = 0; i < team2.units.Count; i++) {
                 *  // trigger player's overwatch
                 *  HandleOverwatchWithoutFog(team2.units[i], team);
                 * }*/
            }
            yield return(null);
        }
    }