Esempio n. 1
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));
        }
    }
Esempio n. 2
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();
        }
    }