コード例 #1
0
    public void MoveUnit()
    {
        AttackUnit = null;
        if (path.Count == 0)
        {
            return;
        }
        List <HexCell> move = new List <HexCell>();

        move.Add(path[0]);
        int cellNumber = 1;

        while (movementLeft > 0 && path.Count > 1)
        {
            if (path.Count > cellNumber)
            {
                int movementCost = HexUnit.GetMoveCost(path[cellNumber - 1], path[cellNumber], path[cellNumber - 1].GetNeighborDirection(path[cellNumber]), true);
                if (movementCost == -1 || movementCost > movementLeft)
                {
                    break;
                }
                else
                {
                    move.Add(path[cellNumber]);
                    movementLeft -= movementCost;
                    cellNumber++;
                }
            }
            else
            {
                break;
            }
        }

        if (move.Count > 1)
        {
            AttackUnit = null;
            AttackCity = null;
            City city = move[move.Count - 1].City;
            if (city && hexUnit.HexUnitType == HexUnit.UnitType.COMBAT && GetCityState() != city.GetCityState())
            {
                AttackCity = city;
                CombatSystem.CityFight(this, city);
                SetMovementLeft(0);
            }
            else
            {
                HexUnit unitToFight = move[move.Count - 1].GetFightableUnit(HexUnit);
                if (unitToFight)
                {
                    AttackUnit = unitToFight;
                    CombatSystem.UnitFight(this, unitToFight.GetComponent <Unit>());
                    SetMovementLeft(0);
                }
            }

            path.RemoveRange(0, move.Count - 1);
            HexUnit.Travel(move);
        }
    }
コード例 #2
0
ファイル: HexGameUI.cs プロジェクト: JCly-rikiu/HexMap
 void DoMove()
 {
     if (grid.HasPath)
     {
         selectedUnit.Travel(grid.GetPath());
         grid.ClearPath();
     }
 }
コード例 #3
0
 private void DoMove()
 {
     if (hexGrid.HasPath)
     {
         selectedUnit.Travel(hexGrid.GetPath());
         hexGrid.ClearPath();
     }
 }
コード例 #4
0
ファイル: GameUI.cs プロジェクト: liuzhognxiu/HexMapEditor
 void DoMove()
 {
     if (grid.HasPath)
     {
         // selectedUnit.Location = currentCell;
         selectedUnit.Travel(grid.GetPath());
         grid.ClearPath();
     }
 }
コード例 #5
0
    /*    public bool WaterMoving
     *  {
     *      get
     *      {
     *          return waterMoving;
     *      }
     *
     *      set
     *      {
     *          waterMoving = value;
     *      }
     *  }
     *  //  IEnumerator ElevationChange()
     *  //{
     *
     *  //}
     *
     *  void CreateWaterTravelUnit()
     *  {
     *      HexProjectile waterProjectile = GameManager.instance.projectile;
     *      waterProjectile.projectileMovement = 100;
     *      HexCell cell = TargetedWaterCells[0];
     *      int test = 0;
     *
     *      if (cell && !cell.Unit)
     *      {
     *          grid.AddProjectile(Instantiate(waterProjectile), cell, Random.Range(0f, 360f));
     *
     *          WaterMoving = true;
     *
     *          for (int i = 1; i < TargetedWaterCells.Length; i++)
     *          {
     *
     *              grid.FindPath(TargetedWaterCells[test], TargetedWaterCells[test+1], waterProjectile.projectileMovement);
     *              cell.Projectile.Travel(grid.GetPath());
     *              test++;
     *          }
     *
     *          grid.FindPath(TargetedWaterCells[0], TargetedWaterCells[1], waterProjectile.projectileMovement);
     *          List <HexCell> firstPath = grid.GetPath();
     *
     *          grid.FindPath(TargetedWaterCells[1], TargetedWaterCells[2], waterProjectile.projectileMovement);
     *          List<HexCell> secondPath = grid.GetPath();
     *          cell.Projectile.Travel(firstPath);
     *          TargetedWaterCells[1].Projectile.Travel(secondPath);
     *
     *
     *      }
     *
     *  }
     */

    void DoMove()
    {
        if (grid.HasPath && grid.PathIsReachable)
        {
            activeUnit.Travel(grid.GetPath());
            grid.ClearPath();
            grid.SearchInRange(activeUnit.Location, activeUnit.movement, 1);
        }
    }
コード例 #6
0
 void DoMove()
 {
     if (HexGrid.HasValidPath)
     {
         m_selectedUnit.Travel();
         ClearPaths();
         m_selectedUnit = null;
     }
 }
コード例 #7
0
 void DoMove()
 {
     if (grid.HasPath)
     {
         selectedUnit.Travel(grid.GetPath());
         grid.ClearPath();
         selectedUnit.currentDestinationCell = currentCell;//задаем конечную точку
     }
 }
コード例 #8
0
 private void DoMove()
 {
     if (hexGrid.HasPath)
     {
         //selectedUnit.Location = currentCell;
         selectedUnit.Travel(hexGrid.GetPath());
         hexGrid.ClearPath();
     }
     selectedUnit = null;
 }
コード例 #9
0
 void DoMove()
 {
     if (grid.HasPath)
     {
         List <HexCell> path = grid.GetPath();
         SendPath(path);
         myUnit.Travel(path, true);
         grid.ClearPath();
     }
 }
コード例 #10
0
    void DoMove(int[] p)
    {
        List <HexCell> path = new List <HexCell>();

        for (int i = 0; i < p.Length; i++)
        {
            path.Add(grid.GetCell(p[i]));
        }

        otherUnit.Travel(path);
    }
コード例 #11
0
ファイル: BattleUI.cs プロジェクト: LordAbver/hexagon
 void DoMove()
 {
     if (grid.HasPath)
     {
         _selectedUnit.Travel(grid.GetPath());
         grid.ClearPath();
         grid.SelectCell(_currentCell);
         grid.ClearMoves(_selectedUnit);
         grid.ClearAttacks(_selectedUnit);
         EnableOption("Move", false);
     }
 }
コード例 #12
0
    void DoMove()
    {
        if (grid.HasPath)
        {
            selectedUnit.Travel(grid.GetPath());
            grid.ClearPath();

            // Add
            currentCell  = null;
            selectedUnit = null;
        }
    }
コード例 #13
0
 // TODO исправить поиск пути каждый ход для каждого юнита, либо сделать это заранее во время хода(чтобы не тратить время на обсчет ходов)
 private void DoUnitActions(HexGrid grid, HexUnit unit)
 {
     if (unit.currentDestinationCell && unit.currentDestinationCell != unit.Location)
     {
         grid.FindPath(unit.Location, unit.currentDestinationCell, unit, false);
         if (grid.HasPath)
         {
             unit.Travel(grid.GetPath());
             grid.ClearPath();
         }
     }
     else
     {
         unit.currentDestinationCell = null;
     }
 }
コード例 #14
0
 void DoMove()
 {
     if (grid.HasPath /*&& grid.IsReachable(currentCell)*/)
     {
         selectedUnit.Travel(grid.GetPath());
         gameManager.RemovePointsAction(currentCell.Distance);
         grid.ClearPath();
         if (resourcePointIndices.Contains(currentCell.SpecialIndex))
         {
             ShowScoutUI();
         }
         else
         {
             HideScoutUI();
         }
     }
 }