示例#1
0
 /// <summary>
 /// Handles all the logic for the human player input stages
 /// </summary>
 public override void Think()
 {
     if (endTurnRequested)
     {
         endTurnRequested = false;
         NextDecision     = new Decision()
         {
             Type = DecisionType.EndTurn
         };
     }
     if (mouseClicked)
     {
         mouseClicked = false;
         var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         if (Physics.Raycast(ray, out RaycastHit hit))
         {
             if (hit.collider.CompareTag("Unit"))
             {
                 var unit = hit.collider.gameObject.GetComponentInParent <Unit>();
                 if (unit.Faction == FactionManager.FactionIndex)
                 {
                     if (unit == SelectedUnit)
                     {
                         deselectUnit();
                     }
                     else
                     {
                         deselectUnit();
                         SelectedUnit = unit;
                         MatchManager.ActivateUIForUnit(SelectedUnit);
                         SelectedUnit.gameObject.AddComponent <SelectedUnit>();
                     }
                 }
                 else
                 {
                     if (SelectedUnit != null)
                     {
                         NextDecision = CreateAttackDecision(SelectedUnit, unit);
                     }
                 }
             }
             else if (hit.collider.CompareTag("Map") && SelectedUnit)
             {
                 var cell = MatchManager.MapManager.GetCell(hit.point);
                 if (MapManager.IsFree(cell))
                 {
                     NextDecision = CreateMoveDecision(SelectedUnit, cell);
                 }
             }
         }
         else
         {
             deselectUnit();
         }
     }
 }
 /// <summary>
 /// Checks for a random enemy in range if the unit was in another position
 /// </summary>
 /// <param name="unit">The unit from where to look from</param>
 /// <param name="fromX">The X coordinate of the supposed position</param>
 /// <param name="fromY">The Y coordinate of the supposed position</param>
 /// <returns>A random unit in range or null if there are no units in range</returns>
 protected Unit enemyInRange(Unit unit, int fromX, int fromY)
 {
     foreach (var enemyUnit in MatchManager.EnemyUnits(unit))
     {
         if (Utils.MahnattanDistance(fromX, fromY, enemyUnit.CellPosition.x, enemyUnit.CellPosition.y) <= unit.AttackRange)
         {
             return(enemyUnit);
         }
     }
     return(null);
 }
示例#3
0
 /// <summary>
 /// Deselects an unit, removing the <see cref="SelectedUnit"/> component and turning it back to its default state
 /// </summary>
 private void deselectUnit()
 {
     if (SelectedUnit != null)
     {
         var selectedUnitComponent = SelectedUnit.GetComponent <SelectedUnit>();
         selectedUnitComponent.Deselect();
         Destroy(selectedUnitComponent);
         MatchManager.DeactivateUIForUnit(SelectedUnit);
         SelectedUnit = null;
     }
 }
 public override void Initialize(MatchManager matchController, FactionManager factionManager)
 {
     base.Initialize(matchController, factionManager);
     FactionManager.Units.OrderBy(u => u.AttackPower).Reverse();
 }
示例#5
0
 public virtual void Initialize(MatchManager matchController, FactionManager factionManager)
 {
     MatchManager   = matchController;
     FactionManager = factionManager;
 }