Ejemplo n.º 1
0
 public void ToggleMovementGrid(GameHandler.CharInfo chara, bool state)
 {
     lastDisplayed = new List <GridInfo>();
     if (state)
     {
         foreach (GridInfo g in chara.movable)
         {
             if (g.pop == 0)
             {
                 g.go.SetActive(true);
             }
             lastDisplayed.Add(g);
         }
     }
     else
     {
         foreach (GridInfo g in chara.movable)
         {
             g.go.SetActive(false);
         }
         lastDisplayed = null;
     }
 }
Ejemplo n.º 2
0
 public void ToggleAttackGrid(GameHandler.CharInfo chara, bool state)
 {
     if (state)
     {
         playerIsoPos = chara.go.GetComponent <IsoTransform>().Position;
         //var center = Grid.Find(x => x.isoPos.x == playerIsoPos.x && x.isoPos.z == playerIsoPos.z);
         var attackList = Grid.FindAll(x => CarthesianCoords(x).magnitude == 1);
         foreach (GridInfo g in attackList)
         {
             g.go.SetActive(true);
         }
         lastDisplayed = new List <GridInfo>();
         lastDisplayed = attackList;
     }
     else
     {
         foreach (GridInfo g in lastDisplayed)
         {
             g.go.SetActive((false));
         }
         lastDisplayed = null;
     }
 }
Ejemplo n.º 3
0
    public void UpdateMovementGrid(GameHandler.CharInfo chara)
    {
        calcComplete = false;
        GameObject activePlayer = new GameObject();

        activePlayer = chara.go;
        playerMS     = chara.ms;
        playerJH     = chara.jh;
        Debug.Log("Started UpdateMovementGrid");
        playerIsoPos = new Vector3();
        playerIsoPos = activePlayer.GetComponent <IsoTransform>().Position;
        var gridList = new List <GridInfo>();

        gridList = Grid.FindAll(x => Mathf.Abs(x.isoPos.x - playerIsoPos.x) + Mathf.Abs(x.isoPos.z - playerIsoPos.z) <= playerMS);// && Mathf.Abs(x.isoPos.y - playerIsoPos.y + 0.5f) <= playerJH);
        if (gg.Contains(chara.go))
        {
            gridList = gridList.FindAll(x => x.pop >= 0);
        }
        else if (bg.Contains(chara.go))
        {
            gridList = gridList.FindAll(x => x.pop <= 0);
        }
        inReach = new List <GridInfo>();
        foreach (GridInfo g in gridList)
        {
            GridInfo temp = new GridInfo
            {
                go     = g.go,
                isoPos = g.isoPos,
                pop    = g.pop
            };
            inReach.Add(temp);
        }
        //origin = new GridInfo();
        origin = inReach.Find(x => x.isoPos.x == playerIsoPos.x && x.isoPos.z == playerIsoPos.z);
        //Debug.Log("Char = " + chara.go.name + " Origin: " + origin.isoPos);

        aList = new List <GridInfo>();                 //targets that met the hDif criteria
        List <GridInfo> cList = new List <GridInfo>(); //checked currents

        bList = new List <GridInfo>();                 //alternatives

        pathfinding    = new List <GridInfo> [playerMS];
        pathfinding[0] = new List <GridInfo>();
        pathfinding[0] = inReach.FindAll(x => CarthesianCoords(x).magnitude <= 1.2f && Mathf.Abs(HeightDifferenceCheck(origin, x)) <= playerJH);
        foreach (GridInfo g in pathfinding[0])
        {
            g.path = new List <int>();
            if (CarthesianCoords(g).x == 1)
            {
                g.path.Add(0);
            }
            else if (CarthesianCoords(g).x == -1)
            {
                g.path.Add(2);
            }
            else if (CarthesianCoords(g).y == 1)
            {
                g.path.Add(3);
            }
            else if (CarthesianCoords(g).y == -1)
            {
                g.path.Add(1);
            }
            g.pathDif = new List <float>()
            {
                HeightDifferenceCheck(origin, g)
            };
        }
        cList.Add(origin);
        aList.AddRange(pathfinding[0]);

        for (int p = 0; p < playerMS - 1; p++)
        {
            pathfinding[p + 1] = new List <GridInfo>();
            foreach (GridInfo g in pathfinding[p])
            {
                current = g;
                Vector2 currentPos = CarthesianCoords(current);
                //Debug.Log("Started checking for: " + currentPos);
                for (int i = -1; i <= 1; i++)
                {
                    for (int j = -1; j <= 1; j++)
                    {
                        if (i != 0 && j != 0 || i == 0 && j == 0)
                        {
                            continue;
                        }

                        target = CarthesianFind(inReach, currentPos.x + i, currentPos.y + j);

                        if (target != null)
                        {
                            if (Mathf.Abs(HeightDifferenceCheck(current, target)) <= playerJH)
                            {
                                if (!aList.Contains(target) && !cList.Contains(target))
                                {
                                    target.path = new List <int>();
                                    target.path.AddRange(current.path);
                                    if (i == 1)
                                    {
                                        target.path.Add(0);
                                    }
                                    else if (i == -1)
                                    {
                                        target.path.Add(2);
                                    }
                                    else if (j == 1)
                                    {
                                        target.path.Add(3);
                                    }
                                    else if (j == -1)
                                    {
                                        target.path.Add(1);
                                    }
                                    target.pathDif = new List <float>();
                                    target.pathDif.AddRange(current.pathDif);
                                    target.pathDif.Add(HeightDifferenceCheck(current, target));
                                    aList.Add(target);
                                }
                                else
                                {
                                    GridInfo newTarget = new GridInfo
                                    {
                                        go     = target.go,
                                        isoPos = target.isoPos
                                    };
                                    newTarget.path = new List <int>();
                                    try
                                    {
                                        newTarget.path.AddRange(current.path);
                                    }
                                    catch
                                    {
                                        //Debug.Log("Nothing to add yet.");
                                    }
                                    if (i == 1)
                                    {
                                        newTarget.path.Add(0);
                                    }
                                    else if (i == -1)
                                    {
                                        newTarget.path.Add(2);
                                    }
                                    else if (j == 1)
                                    {
                                        newTarget.path.Add(3);
                                    }
                                    else if (j == -1)
                                    {
                                        newTarget.path.Add(1);
                                    }
                                    newTarget.pathDif = new List <float>();
                                    try
                                    {
                                        newTarget.pathDif.AddRange(current.pathDif);
                                    }
                                    catch
                                    {
                                        //Debug.Log("Nothing to add yet.");
                                    }
                                    newTarget.pathDif.Add(HeightDifferenceCheck(current, newTarget));
                                    bList.Add(newTarget);
                                }

                                pathfinding[p + 1].Add(target);
                            }
                            //else Debug.Log("HeightDifferenceCheck failed for: " + (currentPos.x + i) + "/" + (currentPos.y + j));
                        }
                        //else if (target == null) Debug.Log("Target is null: " + (currentPos.x + i) + "/" + (currentPos.y + j));
                        //else if (aList.Contains(target)) Debug.Log("Target is already in aList: " + (currentPos.x + i) + "/" + (currentPos.y + j));
                        //else if (cList.Contains(target)) Debug.Log("Target is already in cList: " + (currentPos.x + i) + "/" + (currentPos.y + j));
                    }
                }
            }
        }
        chara.movable = new List <GridInfo>(aList);

        //aList = null;
        //cList = null;
        //pathfinding = null;
        //current = null;
        //target = null;
        calcComplete = true;
        //foreach (GridInfo g in aList)
        //{
        //    if(g.standable) g.go.SetActive(true);
        //}
        //gameHandler.canBeCancelled = true;
        //gameHandler.actionButton[0].interactable = true;
    }