Beispiel #1
0
 public IEnumerator PathInBackground(HexCell dest, HexCell start)
 {
     path.Clear();
     isPath = false;
     path   = Pathfinder.CalculatePath(dest, start);
     isPath = true;
     yield return(1);
 }
Beispiel #2
0
    public void SelectPoint(Transform point)
    {
        if (point == firstPathfinderPoint)
        {
            return;
        }

        if (path.Length > 0)
        {
            ResetAllPoints();
            UpdateHull();

            firstPathfinderPoint  = null;
            secondPathfinderPoint = null;

            path = new Edge[0];
            pathLine.SetPositions(new Vector3[0]);
        }

        if (firstPathfinderPoint == null)
        {
            firstPathfinderPoint = point;
            firstPathfinderPoint.GetComponent <Image>().color = Color.blue;
        }
        else
        {
            secondPathfinderPoint = point;
            secondPathfinderPoint.GetComponent <Image>().color = Color.blue;
            path = pathfinder.CalculatePath(graph, graph.FindNode(firstPathfinderPoint), graph.FindNode(secondPathfinderPoint));

            pathLine.positionCount = path.Length + 1;

            pathLine.SetPosition(0, secondPathfinderPoint.position);

            //Desenha as linhas do segundo ponto selecionado até o primeiro seguindo os pontos já calculados
            for (int i = 0; i < path.Length - 1; i++)
            {
                float distanceNodeA = Mathf.Pow(firstPathfinderPoint.position.x - path[i].nodeA.transform.position.x, 2) + Mathf.Pow(firstPathfinderPoint.position.y - path[i].nodeA.transform.position.y, 2);
                float distanceNodeB = Mathf.Pow(firstPathfinderPoint.position.x - path[i].nodeB.transform.position.x, 2) + Mathf.Pow(firstPathfinderPoint.position.y - path[i].nodeB.transform.position.y, 2);

                if (distanceNodeA < distanceNodeB)
                {
                    pathLine.SetPosition(i + 1, path[i].nodeA.transform.position);
                }
                else
                {
                    pathLine.SetPosition(i + 1, path[i].nodeB.transform.position);
                }
            }
            pathLine.SetPosition(path.Length, firstPathfinderPoint.position);
        }
    }
Beispiel #3
0
        public void Handle(Session Session, String data)
        {
            string All  = "";
            string All2 = "";

            string[] negativ1 = data.Split('|');
            //D|T|0|#warmap:boxhitpoints|2000
            Form1.Client.ExecuteQuery("UPDATE characters SET currentx = '" + negativ1[3] + "', currenty = '" + negativ1[4].Replace("W", "") + "' WHERE userid = '" + Session.UserID + "'");
            DataTable Table = Form1.Client.ReadDataTable("SELECT * FROM collectables");

            foreach (DataRow DRow in Table.Rows)
            {
                if (negativ1[3] == DRow["x"] + "" && negativ1[4].Replace("W", "") == DRow["y"] + "")
                {
                    SFDataPacket Packet24      = new SFDataPacket(new string[] { "O", "I", DRow["id"] + "" });
                    byte[]       InitDisplay24 = Encoding.Default.GetBytes(Encoders.DecryptMsg(Packet24.create_message(), false) + "\0");
                    Session.Sock.NoDelay = true;
                    Session.Sock.Send(InitDisplay24);

                    SFDataPacket Packet        = new SFDataPacket(new string[] { "D", "T", "0", "#warmap:box" + DRow["box"], DRow["reward"] + "" });
                    byte[]       InitDisplay23 = Encoding.Default.GetBytes(Encoders.DecryptMsg(Packet.create_message(), false) + "\0");
                    Session.Sock.NoDelay = true;
                    Session.Sock.Send(InitDisplay23);
                }
            }
            All2 = Pathfinder.CalculatePath(negativ1);
            SFDataPacket Packet16 = new SFDataPacket(new string[] { "S", Session.UserID + "", All.Replace("W", ""), "1" });

            byte[] InitDisplay16 = Encoding.Default.GetBytes(Encoders.DecryptMsg(Packet16.create_message(), false) + "\0");
            Session.Sock.NoDelay = true;
            Session.Sock.Send(InitDisplay16);
            SFDataPacket Packet17 = new SFDataPacket(new string[] { "M", Session.UserID + "", All2.Replace("W", "") });

            byte[] InitDisplay17 = Encoding.Default.GetBytes(Encoders.DecryptMsg(Packet17.create_message(), false) + "\0");
            Session.Sock.NoDelay = true;
            Session.Sock.Send(InitDisplay17);
            SFDataPacket Packet20 = new SFDataPacket(new string[] { "ping" });

            byte[] InitDisplay20 = Encoding.Default.GetBytes(Encoders.DecryptMsg(Packet20.create_message(), false) + "\0");
            Session.Sock.NoDelay = true;
            Session.Sock.Send(InitDisplay20);
            //O|I|1000251412
            //O|M|1000203203
            //M|41780102|334,-174#335,-174#336,-174#337,-174#338,-174#339,-174#340,-174#341,-174#342,-174#343,-174#344,-174#345,-174#346,-174#347,-174#348,-174#349,-174#350,-174#350,-175#351,-175#351,-176
        }
Beispiel #4
0
    /* Calculates path from selected spaceship to hovered cell */
    private IEnumerator <int> GetPathToDraw()
    {
        GameObject selectedObject;

        if ((selectedObject = EventManager.selectionManager.SelectedObject) != null)
        {
            if (selectedObject.tag == "Unit")
            {
                var spaceship = selectedObject.GetComponent <Spaceship>();
                if (MouseHooverCoordinates != spaceship.Coordinates && !spaceship.Flying && FromCoordinates(MouseHooverCoordinates) != null && FromCoordinates(MouseHooverCoordinates).IsEmpty())
                {
                    PathToDraw = Pathfinder.CalculatePath(this.FromCoordinates(spaceship.Coordinates), this.FromCoordinates(MouseHooverCoordinates));
                }
            }
        }

        yield return(1);
    }
Beispiel #5
0
    /*
     * TODO: Probably this function will be called from some round update
     */
    public IEnumerator MoveTo(HexCoordinates dest)
    {
        if (CanMakeAction())
        {
            gameController.LockInput();
            TurnEnginesOn();
            //while (Coordinates != dest && actionPoints > 0)
            //{
            //    Debug.Log("moving " + actionPoints);
            //    actionPoints--;
            //    if (dest.Z > Coordinates.Z && dest.X >= Coordinates.X)
            //        Move(EDirection.TopRight);
            //    else if (dest.Z > Coordinates.Z && dest.X < Coordinates.X)
            //        Move(EDirection.TopLeft);
            //    else if (dest.Z < Coordinates.Z && dest.X > Coordinates.X)
            //        Move(EDirection.BottomRight);
            //    else if (dest.Z < Coordinates.Z && dest.X <= Coordinates.X)
            //        Move(EDirection.BottomLeft);
            //    else if (dest.X > Coordinates.X)
            //        Move(EDirection.Right);
            //    else if (dest.X < Coordinates.X)
            //        Move(EDirection.Left);
            //    yield return new WaitForSeconds(1.05f);

            //}

            path = Pathfinder.CalculatePath(grid.FromCoordinates(Coordinates), grid.FromCoordinates(dest));
            while (Coordinates != dest && actionPoints > 0)
            {
                Move(path.First());
                path.RemoveAt(0);
                actionPoints--;
                yield return(new WaitForSeconds(1.05f));
            }
            Flying = false;
            TurnEnginesOff();
            Debug.Log("Flying done, ActionPoints: " + actionPoints);
            gameController.UnlockInput();
        }
    }
    private void GeneratePath()
    {
        Pathfinder pathfinder = new Pathfinder(castleMap, startingRoom, endingRoom, blankRoomGrids);

        path = pathfinder.CalculatePath();
    }