Пример #1
0
    public static bool AIMove(Unit u, HexCell h)
    {
        if (u != null && h.passable)
        {
            List <HexCell> path = HexStar.GetPath(u.CurrentHex, h, u.MoveSpeed);

            if (path.Count > 0)
            {
                u.StartCoroutine(FollowPath(path, u));
                SoundMaster.SelectUnit();
                return(true);
            }
        }
        return(false);
    }
Пример #2
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;
        }
    }
Пример #3
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);
        }
    }
Пример #4
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;
                        }
                    }
                }
            }
        }
    }