private void Awake() { Instance = this; arenaGeneratorScript = GetComponent <ArenaGeneratorScript>(); unitGeneratorScript = GetComponent <UnitGeneratorScript>(); turnOrderController = GetComponent <TurnOrderController>(); }
void Awake() { _tileMap = GameManager.Instance.GetTileMap(); _image = GetComponent <Image> (); _turnOrderController = GameManager.Instance.GetTurnOrderController(); //TODO: Need better solutiuon here. Never reference game objects by name. _combatController = GameObject.Find("CombatController").GetComponent <CombatController> (); name = string.Format("{0} - {1}", name, GetInstanceID()); gameObject.name = string.Format("{0} - {1}", gameObject.name, GetInstanceID()); }
/// <summary> /// Clears the action targets. /// </summary> public void ClearActionTargets() { foreach (Unit unit in IntendedActionTargets) { if (!unit.TileHighlighter.IsPersistent) { unit.ShowDamagedColor(false); } } IntendedActionTargets.Clear(); TurnOrderController.UntargetUnitImages(); }
/// <summary> /// Gets the nearest enemy. /// </summary> /// <returns>The nearest enemy.</returns> protected Unit GetNearestEnemy() { TurnOrderController turnOrderController = GameManager.Instance.GetTurnOrderController(); float currentDistance = Mathf.Infinity; Unit nearestEnemy = null; foreach (Unit unit in turnOrderController.GetAllUnits()) { if (!_self.IsFriendlyUnit(unit)) { float distance = Vector3.Distance(unit.Tile, _self.Tile); if (distance < currentDistance) { currentDistance = distance; nearestEnemy = unit; } } } //Debug.Log (string.Format("Nearest Enemy - {0}: {1}", nearestEnemy, currentDistance)); return(nearestEnemy); }
/// <summary> /// Init this instance. /// </summary> private IEnumerator Init() { yield return(null); // Clear all highlighted turn order images controller.TurnOrderController.DeHighlightUnitImage(); // If there is no highlighted unit, it means no actual unit performed an actual action the past turn if (controller.HighlightedUnit != null) { if (controller.HighlightedUnit.IsPlayerControlled) { controller.ConfirmationSource.PlayOneShot(controller.ConfirmationSource.clip); } _tileMap = controller.TileMap; TurnOrderController turnOrderController = controller.TurnOrderController; // Clear out radial button container list controller.RadialButtonContainers.Clear(); // Clear existing action targets and reset them controller.ClearActionTargets(); // Destroy Radial Menu on unit that just finished turn if they have it Unit finishedUnit = turnOrderController.GetNextUp(); if (finishedUnit.IsPlayerControlled) { RadialMenuController radialMenuController = finishedUnit.GetCanvas().GetComponentInChildren <RadialMenuController> (true); if (radialMenuController != null) { Destroy(radialMenuController.gameObject); } } } // If all objectives are complete, end combat if (_tileMap.AreAllEnemiesDefeated()) { controller.MusicController.TransitionMusic(true); controller.TurnOrderController.DeHighlightUnitImage(); controller.ChangeState <DisplayPostCombatStatsState> (); } else { // If there is no highlighted unit, it means no actual unit performed an actual action the past turn if (controller.HighlightedUnit != null) { Unit unit = controller.HighlightedUnit; unit.DeactivateCombatMenu(); unit.TileHighlighter.RemoveHighlightedTiles(); // Determine where the unit will be placed in the turn order int orderIndex = -1; if (!unit.HasExecutedDeferredAbility) { Action action = unit.Action; if (action != null && action.Ability != null && action.Ability.Turns > 0) { orderIndex = action.Ability.Turns; } } else { unit.HasExecutedDeferredAbility = false; } controller.TurnOrderController.FinishTurn(unit, orderIndex); controller.HighlightedUnit.Unselect(); controller.HighlightedUnit = null; } controller.ChangeState <InitTurnState> (); } }
private void Start() { arenaPath = GetComponent <ArenaPathScript>(); unitLayer = 1 << LayerMask.NameToLayer("Unit"); turnController = MainScript.Instance.GetTurnOrderController; }
private IEnumerator Init() { _tileMap = controller.TileMap; controller.ShowCursorAndTileSelector(false); controller.SelectionIndicator.ClearIndicators(); controller.MissionObjectivesPanel.SetActive(false); // Setup turn order TurnOrderController turnOrderController = controller.TurnOrderController; Unit unit = controller.TurnOrderController.GetNextUp(); StartCoroutine(controller.CameraController.MoveToPosition(unit.transform.position)); controller.HighlightCharacter(unit); // Determine if music needs to be transitioned higher/lower MusicController musicController = controller.MusicController; if (IsEnemyNearby(turnOrderController.GetAllUnits())) { musicController.TransitionMusic(false); } else { musicController.TransitionMusic(true); } // Incremental Effects List <Effect> effects = unit.GetEffects(); if (effects != null && effects.Count > 0) { // Lower music so you can hear ability SFX yield return(StartCoroutine(controller.MusicController.LowerCombatMusic())); int index = 0; do { Effect effect = effects [index]; // Only run this logic with over time effects if (effect.GetEffectType() == EffectType.OVER_TIME) { bool showedEffectPopupText = false; effect.ApplyIncrementalEffect(unit); List <GameObject> vfxGameObjects = ApplyVFXToTargets(effect.GetVFXPath(), new List <Unit>() { unit }); if (effect.GetDisplayString() != "") { showedEffectPopupText = true; PopupTextController.CreatePopupText(effect.GetIncrementalDisplayString(), unit.transform.position, effect.GetColor()); } // If unit is killed after application of effect, handle death unit.UpdateHealthbar(); // If pop up text was shown, wait x seconds so it doesn't stack with other potential ones if (showedEffectPopupText) { yield return(new WaitForSeconds(2.0f)); } if (unit.IsDead()) { HandleDeath(unit); } DestroyVFX(vfxGameObjects); } index++; } while (index < effects.Count && unit != null); // Bring music back up to normal volume yield return(StartCoroutine(controller.MusicController.RaiseCombatMusic())); } // Decrement Effect Turns if (unit != null) { unit.DecrementEffectTurns(); } yield return(null); // If unit is not available at this point, switch state to next unit in the turn order if (unit == null) { controller.ChangeState <TurnOverState> (); } else { if (unit.IsPlayerControlled) { controller.ChangeState <PlayerTurnState> (); } else { controller.ChangeState <CPUTurnState> (); } } }