Exemplo n.º 1
0
    //this should change later on, to optimize the selection
    IEnumerator SelectWithDelay()
    {
        yield return(new WaitForSeconds(.1f));

        MapLocal.CurrentTile = MapLocal.FindTile(StartSelectingUnit.GridPos.x, StartSelectingUnit.GridPos.y);
        ChangeOfSelection();
    }
Exemplo n.º 2
0
    IEnumerator Refresh()
    {
        while (true)
        {
            foreach (Unit U in AllEnemies)
            {
                if ((LocalMap.GetDistance(Player.GridPos, U.GridPos) <= U.unitStats.VisionRange) && U.IsAttacking == false && Player.IsAttacking == false)
                {
                    Player.IsAttacking  = true;
                    U.IsAttacking       = true;
                    LocalMap.TurnModeOn = true;
                    LocalMap.PlayerTurn = true;
                    Player.StopMoving   = true;
                    UIM.ClearPath();
                    LocalMap.CurrentTile = LocalMap.FindTile(Player.GridPos.x, Player.GridPos.y);
                    UIM.ChangeOfSelection();
                } //It stars the attack phase

                if (U.IsAttacking && Player.IsAttacking) //it waits until the player moves
                {
                    if (PassTurnBool)
                    {
                        if (U.GetComponent <AI_Handler>())
                        {
                            U.GetComponent <AI_Handler>().CurOnTurn = true;
                        }

                        PlayersTurn = false;
                        //Should not change UIM from here but whatever
                        UIM.Top_Right.CurrentIndicatorText.text = "Enemy's Turn";
                        U.unitStats.ActionPoints = U.unitStats.MaxActionPoints;

                        yield return(new WaitForSeconds(TimeForAITurn));

                        /* This just doesnt affect anything literally
                         * while(U.IsUnitInMoveAnim)
                         * {
                         *  Debug.Log("Bro");
                         * }*/

                        //Then it gives AP to the player
                        Player.unitStats.ActionPoints = Player.unitStats.MaxActionPoints;
                        PlayersTurn = true;
                        UIM.Top_Right.CurrentIndicatorText.text = "Player's Turn";

                        PassTurnBool = false;
                    }
                }
            }

            yield return(new WaitForSeconds(RefreshRate));
        }
    }
Exemplo n.º 3
0
    IEnumerator GivePlayerVision()
    {
        while (true)
        {
            //yield return new WaitUntil(() => Player.IsUnitMoving == false);

            foreach (MapTile T1 in TilesCloseToPlayer)
            {
                T1.Visible = false;
            }
            TilesCloseToPlayer.Clear();

            List <MapTile> Tiles = LocalMap.GetAreaAround(Player.GridPos, Player.unitStats.VisionRange);

            foreach (MapTile T in Tiles)
            {
                TilesCloseToPlayer.Add(T);
                T.Visible    = true;
                T.Discovered = true;

                if (T.IsBound)
                {
                    // Debug.Log("bruh");


                    Vector3Int TargetPos = LocalMap.GetOppositeTileOnBoarder(T.X, T.Y);
                    LocalMap.FindTile(TargetPos.x, TargetPos.y).Visible    = true;
                    LocalMap.FindTile(TargetPos.x, TargetPos.y).Discovered = true;
                    TilesCloseToPlayer.Add(LocalMap.FindTile(TargetPos.x, TargetPos.y));
                }



                // Debug.Log(T.GetPos);
            }
            //Clear the previous vision first
            yield return(new WaitUntil(() => Player.IsUnitMoving == true));
        }
    }
Exemplo n.º 4
0
    //GameObject Temp;
    // I should clean this fixed update later
    void Update()   //it has to be update in order to register
    {
        GetInput();
        CameraMovement();
        CameraZoom();
        //select
        if (LMBdown && !UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject()) //this prevents me from actually clicking on a UI element
        {
            MapTile Temp = GetMapTileOnMousePos();

            if (Temp != null)
            {
                MapGRef.CurrentTile = Temp;
                UIM.ChangeOfSelection();
            }
            else
            {
                //Making the selection the opposite one
                Vector3Int TempV      = MapGRef.GetOppositeTileOnBoarder(Temp.X, Temp.Y);
                Vector2Int TargetPos  = new Vector2Int(TempV.x, TempV.y);
                MapTile    TargetTile = MapGRef.FindTile(TargetPos.x, TargetPos.y);

                if (TargetTile != null)
                {
                    MapGRef.CurrentTile = TargetTile;
                    UIM.ChangeOfSelection();
                }
            }


            /*
             * if (InMoveMode)// this is for the ON turn thing only
             * {
             *  if (AllCurrentPaths.ContainsKey(MapGRef.CurrentTile))
             *      StartCoroutine(CurUnit.MoveUnitTo(cellPos.x, cellPos.y));
             *
             *  InMoveMode = false;
             * }*/


            //   ShowAllDebugUI();
        }
        //movement
        if (!(MapGRef.TurnModeOn || CurUnit == null || !RMBdown || UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject()))
        {
            Vector3 pz = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            pz.z = 0;
            Vector3Int cellPos = grid.WorldToCell(pz);


            if (MapGRef.FindTile(cellPos.x, cellPos.y) != null && MapGRef.FindTile(cellPos.x, cellPos.y).Walkable)
            {
                StartCoroutine(CurUnit.MoveUnitTo(cellPos.x, cellPos.y));

                MapGRef.CurrentTile = MapGRef.FindTile(cellPos.x, cellPos.y);
                UIM.ChangeOfSelection();
                //  UIM.ClearPath();
            }
            else
            {
                Vector3Int TempV      = MapGRef.GetOppositeTileOnBoarder(cellPos.x, cellPos.y);
                Vector2Int TargetPos  = new Vector2Int(TempV.x, TempV.y);
                MapTile    TargetTile = MapGRef.FindTile(TargetPos.x, TargetPos.y);

                if (TargetTile != null)
                {
                    StartCoroutine(CurUnit.MoveUnitTo(TargetPos.x, TargetPos.y));

                    MapGRef.CurrentTile = TargetTile;
                    UIM.ChangeOfSelection();
                }
            }
        }

/*
 *      //This is just for the area thing (I gotta migrate all this to the UI_Manager)
 *      if (InMoveMode)
 *      {
 *          Vector3 pz = Camera.main.ScreenToWorldPoint(Input.mousePosition);
 *          pz.z = 0;
 *          Vector3Int cellPos = grid.WorldToCell(pz);
 *          //  Vector3 cellPosFloat = cellPos + new Vector3(0.5f, 0.5f, 0);
 *
 *          MapTile NewCurHoveredTile = MapGRef.FindTile(cellPos.x, cellPos.y);
 *
 *          //So once this happens it is the old one
 *          if (NewCurHoveredTile != CurHoveredTile && AllCurrentPaths.ContainsKey(NewCurHoveredTile))
 *          {
 *              // MapGRef.ThirdLayer.ClearAllTiles();
 *              //This makes it so it everything is cleared
 *              List<MapTile> CurHovPath = AllCurrentPaths[NewCurHoveredTile];
 *              if (CurHovPath != null && CurHovPath != OldCurPath)
 *              {
 *                  //This refreshes the old path to the orginal
 *                  if (OldCurPath != null)
 *                      foreach (MapTile M in OldCurPath)
 *                      {
 *                          if (M != null)
 *                              MapGRef.ThirdLayer.SetTile(new Vector3Int(M.X, M.Y, 0), MapGRef.particles_tiles.Area[5]);
 *                      }
 *
 *                  for (int x = 0; x < CurHovPath.Count; x++)
 *                  {
 *                      if (CurHovPath[x] != null)
 *                      {
 *                          if (x != CurHovPath.Count - 1)
 *                          {
 *
 *                              MapGRef.ThirdLayer.SetTile(new Vector3Int(CurHovPath[x].X, CurHovPath[x].Y, 0), MapGRef.particles_tiles.Area[6]);
 *                          } else
 *                          {
 *                              MapGRef.ThirdLayer.SetTile(new Vector3Int(CurHovPath[x].X, CurHovPath[x].Y, 0), MapGRef.particles_tiles.Area[7]);
 *                          }
 *
 *                      }
 *
 *                  }
 *
 *                  OldCurPath = CurHovPath;
 *
 *              } else
 *
 *
 *
 *                  //  MapGRef.ThirdLayer.SetTile(new Vector3Int(NewCurHoveredTile.X, NewCurHoveredTile.Y, 0), MapGRef.particles_tiles.Area[6]);
 *                  CurHoveredTile = NewCurHoveredTile;
 *          }
 *
 *
 *      }*/

        //DragScreen();

        if (Escp)
        {
            UIM.ShowEscapeMenu();
        }
    }
Exemplo n.º 5
0
    public IEnumerator MoveUnitTo(int TargetX, int TargetY) //this one will be the one thats called in general and will allow to stop
    {
        if (IsUnitMoving)
        {
            StopMoving = true;

            while (IsUnitMoving) //this can cause an infinite loops but whatever
            {
                // Debug.Log("Waiting");
                yield return(null);
            }
        }


        List <MapTile> Path = new List <MapTile>();


        if (MapLocal.FindTile(TargetX, TargetY).Walkable)
        {
            Path = MapLocal.Pathfinding(GridPos, new Vector2Int(TargetX, TargetY));

            if (Path != null)
            {
                IsUnitMoving = true;
                if (IsThisMainP)
                {
                    UI_MLocal.ShowPath(Path); //Show the UI
                }
                //Start the walk thing
                for (int x = 0; x < Path.Count; x++)
                {
                    //In here I start the movement for the next tile
                    //Yielding until its completed
                    yield return(StartCoroutine(MoveNextTile(Path[x].X, Path[x].Y)));

                    if (StopMoving)
                    {
                        StopMoving = false;
                        break;
                    }

                    if (IsThisMainP)
                    {
                        UI_MLocal.ClearSpecPath(x);
                    }
                }

                IsUnitMoving = false;
            }
            else
            {
                Debug.Log("Path is null");
                //This is a way to fix it for the AI
                if (this.GetComponent <AI_Handler>()) //this is kinda cheap
                {
                    this.GetComponent <AI_Handler>().UpdateMovementNow = true;
                }
            }
        }



        /*
         * List<MapTile> MyPath = new List<MapTile>();
         * Vector2Int DebugPos = new Vector2Int(TargetX, TargetY);
         * if (MapLocal.FindTile(TargetX,TargetY).Walkable == true)
         * {
         *  // if (!IsUnitMoving)
         *  // {
         *  MyPath = MapLocal.Pathfinding(GridPos, new Vector2Int(DebugPos.x, DebugPos.y));
         *      //  StartCoroutine(PathMoveAnim(MyPath));
         *      if (MyPath != null)
         *      {
         *          StartCoroutine(MoveToTileAnim(MyPath));
         *      }
         *      else
         *      {
         *          Debug.Log("Path couldnt be found");
         *      }
         * // }
         *
         * } else
         * {
         *  Debug.Log("Target Tile isnt walkable");
         * }
         *
         *
         *
         *
         * //This should be in another function to be more organized tho
         *
         * //  PlaceTarget(DebugPos.x, DebugPos.y); Add this somewhere else
         */
    }