private void NextUntsTurn() { if (_aiTurnStack.Count == 0) { EndAITurn(); return; } if (_currentAIUnit != null) { _currentAIUnit.UnSelected(); } _currentAIUnit = _aiTurnStack.Pop(); _currentAIUnit.Selected(); _currentAIUnit.onUnitFinishTurn += OnUnitFinishTurn; _currentAIUnit.NewTurn(); }
private void BuildTurnStack() // distance based stack, basic AI for now { List <AIUnit> allAliveAIUnits = GetAllAliveAIUnits(); for (int i = 0; i < allAliveAIUnits.Count; i++) { AIUnit aiUnit = allAliveAIUnits[i]; aiUnit.closetPlayerUnitsData = _playerUnitsCtrl.GetClosetPlayerUnitsData(aiUnit); } allAliveAIUnits = allAliveAIUnits.OrderByDescending(x => x.closetPlayerUnitsData[0].distanceFromUnit).ToList(); _aiTurnStack = new Stack <AIUnit>(); for (int i = 0; i < allAliveAIUnits.Count; i++) { _aiTurnStack.Push(allAliveAIUnits[i]); } }
public List <AIUnit> GetAIUnitsCloseby(PlayerUnit playerUnit) { List <AIUnit> closeByAIUnits = new List <AIUnit>(); List <AIUnit> allAliveAIUnits = GetAllAliveAIUnits(); for (int i = 0; i < allAliveAIUnits.Count; i++) { AIUnit unit = allAliveAIUnits[i]; bool close = levelGrid.IsTwoPositionsCloseByOnGrid(playerUnit.transform.position, unit.transform.position); if (close) { closeByAIUnits.Add(unit); } } return(closeByAIUnits); }
IEnumerator InitializeUnitsCR() { for (int i = 0; i < _maxUnits; i++) { GameAbstractFactory gameAbtractFactory = GameFactoryProducer.GetFactory("AIUnitsFactory"); AIUnit newUnit = gameAbtractFactory.GetAIUnit(); newUnit.alive = true; newUnit.gameObject.transform.position = spawnPoints[i].position; newUnit.gameObject.transform.eulerAngles = new Vector3(0, 225, 0); newUnit.gameObject.SetActive(true); newUnit.onUnitLostLifeEvent += OnUnitLostLifeEvent; newUnit.levelGrid = levelGrid; _aiUnits[i] = newUnit; levelGrid.CloseCellAthisPosition(spawnPoints[i].position); // setting the cells as blocked yield return(new WaitForSeconds(.1f)); } _currentAIUnit = _aiUnits[0]; aliveAIUnitsSO.Value = _maxUnits; }
public List <DistanceData> GetClosetPlayerUnitsData(AIUnit aiUnit) // retunrs ordered list { List <DistanceData> closetUnitsData = new List <DistanceData>(); List <PlayerUnit> allAlivePlayerUnits = GetAllAlivePlayerUnits(); for (int i = 0; i < allAlivePlayerUnits.Count; i++) { PlayerUnit unit = allAlivePlayerUnits[i]; float distance = Vector3.Distance(aiUnit.transform.position, unit.transform.position); DistanceData distanceData = new DistanceData(); distanceData.unit = unit; distanceData.distanceFromUnit = distance; closetUnitsData.Add(distanceData); } closetUnitsData = closetUnitsData.OrderBy(x => x.distanceFromUnit).ToList(); return(closetUnitsData); }
private void CheckForAttackIfPossible() { List <AIUnit> closeAIUnits = _aiUnitsCtrl.GetAIUnitsCloseby(_currentUnit); if (closeAIUnits.Count > 0) { AIUnit attackUnit = closeAIUnits[0]; _currentUnit.attackTarget = attackUnit; if (onPlayerUnitAttackPossibleEvent != null && _currentUnit.CanDoAnotherAttack()) { onPlayerUnitAttackPossibleEvent.Invoke(); } } else { if (onPlayerUnitAttackNotPossibleEvent != null) { onPlayerUnitAttackNotPossibleEvent.Invoke(); } } }
public abstract void RecycleAIUnit(AIUnit aiUnit);
public void Enter() { _currentAIUnit = null; Invoke("NewTurn", 2.0f); // little delay for showing enemy turn UI }
private void OnUnitFinishTurn(AIUnit unit) { unit.onUnitFinishTurn -= OnUnitFinishTurn; NextUntsTurn(); }
public override void RecycleAIUnit(AIUnit aiUnit) { PoolManager.Instance.PutObjectBacktoPool(aiUnit.gameObject); }
public override void RecycleAIUnit(AIUnit aiUnit) { }