public static bool CheckIfLastAttacker() { if (TurnManager.Instance.CurrentPhase == TurnPhases.Attack) { foreach (UnitScript ally in Player.Players[TurnManager.Instance.PlayerHavingTurn].PlayerUnits) { if (ally.hasAttacked == false && ally.CheckIfIsInCombat()) { return(false); } } PopupTextController.AddPopupText("No more units can attack!", PopupTypes.Info); return(true); } if (TurnManager.Instance.CurrentPhase == TurnPhases.Shooting) { foreach (UnitScript ally in Player.Players[TurnManager.Instance.PlayerHavingTurn].PlayerUnits) { if (ally.GetComponent <ShootingScript>() != null && ally.GetComponent <ShootingScript>().CanShoot) { return(false); } } PopupTextController.AddPopupText("No more units can shoot!", PopupTypes.Info); return(true); } return(false); }
/// <summary> /// Selects a random unit that still has actions this phase /// </summary> public void SelectRandomUnit() { if (type != PlayerType.Local) { return; } List <Unit> PossibleUnits = new List <Unit>(); foreach (Unit unit in playerUnits) { if (unit.CanAttackOrMoveNow()) { PossibleUnits.Add(unit); } } if (PossibleUnits.Count > 0) { SelectUnit(PossibleUnits[UnityEngine.Random.Range(0, PossibleUnits.Count)]); } else { PopupTextController.AddPopupText("No more units ot act!", PopupTypes.Info); } }
public bool CanAttackDestructible(DestructibleScript target, bool showText) { if (CheckIfIsInCombat() && Input.GetMouseButtonDown(0) && showText) { PopupTextController.AddPopupText("Cannot destroy objects while in combat!", PopupTypes.Info); } return(StandsNextToDestructible(target) && hasAttacked == false && CheckIfIsInCombat() == false && TurnManager.Instance.CurrentPhase == TurnPhases.Attack); }
public void DoAI() { //First, find who can we move! AND if nobody, then we pass turn Queue <UnitScript> unitsToMove = GetPossibleUnits(); if (unitsToMove != null && unitsToMove.Count > 0) { UnitScript currentUnit = unitsToMove.Dequeue(); if (IsInInfiniteLoop(currentUnit)) { PopupTextController.AddPopupText("Bug appeared! Tell Dogo about it!", PopupTypes.Info); Log.SpawnLog("An AI - bug happenned. Please tell Dogo about it."); GameStateManager.NextPhase(); return; } LastThreeSelectedUnits.Add(currentUnit); if (LastThreeSelectedUnits.Count > 3) { LastThreeSelectedUnits.RemoveAt(0); } MouseManager.Instance.SelectAUnit(currentUnit, true); ///////////////////// ABILITIES HERE////////////////////////////// // Here we should check if we want to use an active ability! if (CheckIfGoodToUseAbility(currentUnit)) { CombatController.Instance.MakeAIWait(3f); return; } //Debug.Log("Starting evaluating"); AI_Controller.Instance.EvaluateTiles(this, currentUnit, GetPossibleMoves(currentUnit, true)); //Debug.Log("Finished evaluating"); if (AI_Controller.tilesAreEvaluated) { var kvp = GetTheMove(currentUnit, EvaluatedTiles); if (this is AI_Base_Attack) { CameraController.Instance.SetCamToU(currentUnit); } else if (this is AI_Base_Movement && (kvp.Key != null)) { CameraController.Instance.SetCamToU(currentUnit, currentUnit.transform.position != kvp.Key.transform.position); } PerformTheAction(currentUnit, kvp); } } if (this is AI_Attack) { CombatController.Instance.MakeAIWait(3f); } else { CombatController.Instance.MakeAIWait(1f); } }
public virtual void Attack(IDamageable target) { BattlescapeGraphics.ColouringTool.UncolourAllTiles(); targetObject = target; if (sourceUnit.GetMyOwner().HasAttacksOrMovesLeft() == false) { PopupTextController.AddPopupText("No more units can attack!", PopupTypes.Info); } }
public void RegenerateDefenceOutOfCombat() { if (CurrentDefence < Defence && DefenceReduction > 0) { CurrentDefence++; DefenceReduction--; PopupTextController.AddPopupText("Regenerate!", PopupTypes.Stats); Log.SpawnLog(name + " regenerates 1 point of defence."); } }
public void CheckIfAnyMoreUnitsToMove() { foreach (UnitScript ally in Player.Players[TurnManager.Instance.PlayerHavingTurn].PlayerUnits) { if (CanUnitMoveAtAll(ally.GetComponent <UnitMovement>())) { return; } } PopupTextController.AddPopupText("No more units to move!", PopupTypes.Info); }
public void PoisonEffect() { GetComponentInChildren <AnimController>().AnimateWound(); PopupTextController.AddPopupText("Poison!!", PopupTypes.Info); Log.SpawnLog("Poison affects " + name + "!"); if (PoisonCounter >= 4) { CurrentHP--; Log.SpawnLog(name + " gets 1 point of damage from poison!"); } CurrentDefence--; PoisonCounter--; }
public void SetNewTurn(bool isRealGame) { if (NewTurnEvent != null) { NewTurnEvent(); } text1.isOff = false; text2.isOff = false; SwitchPlayerHavingTurn(); CurrentPhase = TurnPhases.Movement; if (GameStateManager.Instance.IsCurrentPlayerAI()) { Debug.Log("New AI turn."); } if (isRealGame) { turnSource.Play(); TurnCount++; if (TurnCount > 16) { PopupTextController.AddPopupText("Time is up!", PopupTypes.Stats); } else if (TurnCount == 16) { PopupTextController.AddPopupText("Final Turn!", PopupTypes.Damage); Log.SpawnLog("The last turn of the game has begun!"); Log.SpawnLog("Movement phase begins."); } else if (TurnCount >= 11) { PopupTextController.AddPopupText("Remaining turns: " + (16 - TurnCount).ToString() + "!", PopupTypes.Damage); Log.SpawnLog("New turn. Remaining turns: " + (16 - TurnCount).ToString() + "."); Log.SpawnLog("Movement phase begins."); } else if (TurnCount > 1) { PopupTextController.AddPopupText("New Turn!", PopupTypes.Info); Log.SpawnLog("New turn."); Log.SpawnLog("Movement phase begins."); } else { PopupTextController.AddPopupText("Press Escape to see Victory Conditions!", PopupTypes.Info); Log.SpawnLog("Prepare for the Battle! Press Escape to see Victory Conditions!"); Log.SpawnLog("Movement phase begins."); } } StartCoroutine(SetColour()); }
public override void ModifyAttack(IDamageable target, int damageToTarget) { List <IDamageable> alreadyDamaged = new List <IDamageable>(); foreach (Tile tile in target.currentPosition.closeNeighbours) { if (tile.GetMyDamagableObject() != null && alreadyDamaged.Contains(tile.GetMyDamagableObject()) == false) { PopupTextController.AddPopupText("-" + splashDamage, PopupTypes.Damage); Unit owner = buffGroup.owner as Unit; tile.GetMyDamagableObject().TakeDamage(owner, splashDamage); alreadyDamaged.Add(tile.GetMyDamagableObject()); } } }
void CheckForInput() { if (GameStateManager.Instance.IsCurrentPlayerLocal() == false) { return; } if (Helper.IsOverNonHealthBarUI()) { return; } if (GameStateManager.Instance.GameState == GameStates.AttackState && Input.GetMouseButtonDown(0) && MouseManager.Instance.SelectedUnit != null && MouseManager.Instance.MouseoveredUnit != null && MouseManager.Instance.SelectedUnit.EnemyList.Contains(MouseManager.Instance.MouseoveredUnit) && !MouseManager.Instance.SelectedUnit.hasAttacked && MouseManager.Instance.SelectedUnit.CanAttack) { SendCommandToAttack(MouseManager.Instance.SelectedUnit, MouseManager.Instance.MouseoveredUnit, false, !MouseManager.Instance.SelectedUnit.isStoppingRetaliation && MouseManager.Instance.MouseoveredUnit.DoesRetaliate); MouseManager.Instance.SelectedUnit.hasAttacked = true; } if (GameStateManager.Instance.GameState == GameStates.AttackState && Input.GetMouseButtonDown(0) && MouseManager.Instance.SelectedUnit != null && MouseManager.Instance.MouseoveredUnit != null && MouseManager.Instance.SelectedUnit.EnemyList.Contains(MouseManager.Instance.MouseoveredUnit.GetComponent <UnitScript>()) && !MouseManager.Instance.SelectedUnit.hasAttacked && MouseManager.Instance.SelectedUnit.CanAttack == false) { PopupTextController.AddPopupText("This unit cannot attack!", PopupTypes.Info); } //THIS below is just for testing and allows to shoot with Z key. XD. Its just for quick testing if a shot works ;) REAL shooting exists inside ShootingScript currently apparently /*if (MouseManager.Instance.SelectedUnit != null && MouseManager.Instance.SelectedUnit.GetComponent<ShootingScript>() != null && Input.GetKeyDown(KeyCode.Z) && MouseManager.Instance.MouseoveredUnit != null && Application.isEditor) * { * Shoot(MouseManager.Instance.SelectedUnit, MouseManager.Instance.MouseoveredUnit, false); * }*/ if (GameStateManager.Instance.GameState == GameStates.AttackState && Input.GetMouseButtonDown(0) && MouseManager.Instance.SelectedUnit != null && MouseManager.Instance.mouseoveredDestructible != null && MouseManager.Instance.SelectedUnit.CanAttackDestructible(MouseManager.Instance.mouseoveredDestructible.GetComponent <DestructibleScript>(), true)) { if (GameStateManager.Instance.MatchType == MatchTypes.Online) { photonView.RPC ( "RPCMeleeAttackObstacle", PhotonTargets.All, Mathf.RoundToInt(MouseManager.Instance.SelectedUnit.transform.position.x), Mathf.RoundToInt(MouseManager.Instance.SelectedUnit.transform.position.z), Mathf.RoundToInt(MouseManager.Instance.mouseoveredDestructible.transform.position.x), Mathf.RoundToInt(MouseManager.Instance.mouseoveredDestructible.transform.position.z) ); } else { MeleeAttackObstacle(MouseManager.Instance.SelectedUnit, MouseManager.Instance.mouseoveredDestructible.GetComponent <DestructibleScript>()); } } }
void SetNextPhase(bool didAI) { if ((GameStateManager.Instance.IsCurrentPlayerAI() == true && didAI == false) || (GameStateManager.Instance.IsCurrentPlayerAI() == false && didAI == true) || CurrentPhase == TurnPhases.Enemy || GameStateManager.Instance.GameState == GameStates.AnimatingState) { return; } if (CurrentPhase == TurnPhases.Movement) { TileColouringTool.UncolourAllTiles(); PopupTextController.AddPopupText("Next Phase!", PopupTypes.Info); Log.SpawnLog("Shooting phase begins."); PathCreator.Instance.ClearPath(); ShootingPhase(); } else if (CurrentPhase == TurnPhases.Shooting) { PopupTextController.AddPopupText("Next Phase!", PopupTypes.Info); Log.SpawnLog("Attack phase begins."); AttackPhase(); } }
IEnumerator CheckForBackstabsInCoroutine() { IsTimeForBackstabs = true; quittingUnit = MouseManager.Instance.SelectedUnit; List <UnitScript> enemies = quittingUnit.EnemyList; for (int i = 0; i < enemies.Count; i++) { UnitScript enemy = enemies[i]; int roll = UnityEngine.Random.Range(0, 100); if (quittingUnit.QuitCombatPercent < roll) { CombatController.Instance.SendCommandToAttack(enemy, quittingUnit, false, false); yield return(new WaitForSeconds(2f)); if (quittingUnit.CurrentHP <= 0) { break; } } else { PopupTextController.AddPopupText("Miss!", PopupTypes.Info); if (GameStateManager.Instance.MatchType == MatchTypes.Online) { Log.NetworkSpawnLog(quittingUnit.name + " escaped from combat succesfully!"); } else { Log.SpawnLog(quittingUnit.name + " escaped from combat succesfully!"); } } if (quittingUnit == null) { yield return(null); } } IsTimeForBackstabs = false; CommandFinishQuitCombat(quittingUnit.CurrentHP <= 0); }
void SelectNextAvailableUnit() { List <UnitScript> AllUnits = new List <UnitScript>(VictoryLossChecker.GetMyUnitList()); List <UnitScript> PossibleUnits = new List <UnitScript>(); foreach (UnitScript unit in AllUnits) { if (GameStateManager.Instance.CanUnitActInThisPhase(unit)) { PossibleUnits.Add(unit); } } if (PossibleUnits.Count > 0) { SelectAUnit(PossibleUnits[Random.Range(0, PossibleUnits.Count)], true); } else { PopupTextController.AddPopupText("No more units ot act!", PopupTypes.Info); } }
public static bool IsInLineOfSight(Vector3 start, Vector3 target, bool showNoPopup) { Vector3 startPos = start /*+Vector3.up * 0.01f*/; Vector3 endPos = target /*+Vector3.up * 0.01f*/; Vector3 direction = endPos - startPos; foreach (RaycastHit hit in Physics.RaycastAll(startPos, direction, Vector3.Distance(startPos, endPos) + 0.01f)) { if (hit.collider.transform.gameObject.tag == "Tile") { if (hit.collider.transform.gameObject.GetComponent <Tile>().isShootable == false) { if (Input.GetMouseButtonDown(0) && showNoPopup == false) { PopupTextController.AddPopupText("Can not shoot through this obstacle!", PopupTypes.Info); } return(false); } } } return(true); }
//in the future most likely more functions might want to do things OnAttack - abilities and so on //public event Action<Unit, Unit, int> AttackEvent; //if damage is 0, it's a miss, if it's somehow TOTALLY blocked it could be negative maybe or just not send this. public void HitTarget(IDamageable target, Damage damage) { foreach (AbstractAttackModifier modifier in modifiers) { modifier.ModifyDamage(damage); } foreach (AbstractAttackModifier modifier in modifiers) { modifier.ModifyAttack(target, damage); } PlayerInput.instance.isInputBlocked = false; if (damage == 0) { StatisticChangeBuff defenceDebuff = Instantiate(Resources.Load("Buffs/MechanicsBuffs/Combat Wound") as GameObject).GetComponent <StatisticChangeBuff>(); defenceDebuff.ApplyOnTarget(target); LogConsole.instance.SpawnLog(this.info.unitName + " attacks " + target.GetMyName() + ", but misses completely!"); LogConsole.instance.SpawnLog(target.GetMyName() + " loses 1 point of Defence temporarily."); PopupTextController.AddPopupText("-1 Defence", PopupTypes.Stats); } else if (damage > 0) { LogConsole.instance.SpawnLog(this.info.unitName + " deals " + damage + " damage to " + target.GetMyName() + "!"); PopupTextController.AddPopupText("-" + damage, PopupTypes.Damage); target.TakeDamage(this, damage); foreach (AbstractBuff buff in target.buffs.FindAllBuffsOfType("Combat Wound")) { buff.RemoveFromTargetInstantly(); } } if (target is Unit) { var targetUnit = target as Unit; if (targetUnit.CanRetaliate(this) && owner.type != PlayerType.Network) { Networking.instance.SendCommandToGiveChoiceOfRetaliation(targetUnit, this); } } }
public bool DealDamage(UnitScript attacker, UnitScript target, int damage, bool isPoisoned, bool Retaliatable, int hits) { if (CheckIfDamageBlocked(attacker, target)) { PopupTextController.AddPopupText("Blocked!", PopupTypes.Damage); Log.SpawnLog(attacker.name + " attacks " + target.name + " but the attack gets blocked!"); } if (hits >= 2) { Log.SpawnLog(attacker.name + " attacks " + target.name + "! " + damage + " point(s) of damage is dealt."); PopupTextController.AddParalelPopupText("-" + damage.ToString(), PopupTypes.Damage); } if (hits <= 1) { Log.SpawnLog(attacker.name + " attacks " + target.name + ", but only reduces their Defence by 1!"); // PopupTextController.AddParalelPopupText("Hit!", PopupTypes.Info); PopupTextController.AddParalelPopupText("-1 Defence", PopupTypes.Stats); } /*if (hits == 0) * { * Log.SpawnLog(attacker.name + " attacks " + target.name + ", but misses completely."); * PopupTextController.AddPopupText("Miss!", PopupTypes.Info); * }*/ bool isShot = attacker.isRanged && (GameStateManager.Instance.GameState != GameStates.RetaliationState && GameStateManager.Instance.GameState != GameStates.AttackState) == false; bool didDie = target.DealDamage(damage, hits > 0, isPoisoned, isShot); if (target.CanCurrentlyRetaliate && target.CurrentHP > 0 && Retaliatable && Player.IsPlayerLocal(target.PlayerID)) { GameStateManager.Instance.StartRetaliationChoice(); } return(didDie); }
public void ToggleHighlight() { bool thereIsAUnitWhoCanMove = false; if (toggle == false) { foreach (Tile tile in Map.Board) { if (tile.isBeingColoredByNormalHighlighter) { tile.isBeingColoredByNormalHighlighter = false; tile.GetComponent <Renderer>().material.color = Color.white; } } } else { if (TurnManager.Instance.CurrentPhase == TurnPhases.Movement && (GameStateManager.Instance.GameState == GameStates.IdleState || GameStateManager.Instance.GameState == GameStates.MoveState)) { foreach (Tile tile in Map.Board) { if (tile.myUnit != null && tile.myUnit.PlayerID == TurnManager.Instance.PlayerToMove && MovementQuestions.Instance.CanUnitMoveAtAll(tile.myUnit.GetComponent <UnitMovement>()) == true) { tile.GetComponent <Renderer>().material.color = Color.green; tile.isBeingColoredByNormalHighlighter = true; thereIsAUnitWhoCanMove = true; } } if (thereIsAUnitWhoCanMove == false && isPressingControl == false && TurnManager.Instance.TurnCount > 0) { PopupTextController.AddPopupText("No more units can move!", PopupTypes.Info); } } if (TurnManager.Instance.CurrentPhase == TurnPhases.Shooting && (GameStateManager.Instance.GameState == GameStates.IdleState || GameStateManager.Instance.GameState == GameStates.ShootingState)) { foreach (Tile tile in Map.Board) { if (tile.myUnit != null && tile.myUnit.PlayerID == TurnManager.Instance.PlayerToMove && tile.myUnit.isRanged && tile.myUnit.GetComponent <ShootingScript>().CanShoot == true) { tile.GetComponent <Renderer>().material.color = Color.green; tile.isBeingColoredByNormalHighlighter = true; thereIsAUnitWhoCanMove = true; } } if (thereIsAUnitWhoCanMove == false && isPressingControl == false && TurnManager.Instance.TurnCount > 0) { PopupTextController.AddPopupText("No more units can shoot!", PopupTypes.Info); } } else if (TurnManager.Instance.CurrentPhase == TurnPhases.Attack && (GameStateManager.Instance.GameState == GameStates.IdleState || GameStateManager.Instance.GameState == GameStates.AttackState)) { foreach (Tile tile in Map.Board) { if (tile.myUnit != null && tile.myUnit.PlayerID == TurnManager.Instance.PlayerToMove && tile.myUnit.hasAttacked != true && tile.myUnit.CanAttack && tile.myUnit.CheckIfIsInCombat() == true) { tile.GetComponent <Renderer>().material.color = Color.green; tile.isBeingColoredByNormalHighlighter = true; thereIsAUnitWhoCanMove = true; } } if (thereIsAUnitWhoCanMove == false && isPressingControl == false && TurnManager.Instance.TurnCount > 0) { PopupTextController.AddPopupText("No more units can attack!", PopupTypes.Info); } } isPressingControl = true; } }
void SendLogs() { PopupTextController.AddPopupText("No more arrows!", PopupTypes.Info); Log.SpawnLog("Hunter has no more arrows!"); }
public void GetPoisoned(int value) { PoisonCounter += value; PopupTextController.AddPopupText("Poison!!", PopupTypes.Info); Log.SpawnLog(name + " gets poisoned!"); }