/// <summary> /// Returns the closest BattleEntity in front of a specified one. /// <para>For players this would return whoever is in front if the entity specified is in the back. /// For enemies this would return the closest enemy in front of the specified one.</para> /// </summary> /// <param name="battleEntity">The BattleEntity to find the entity in front of.</param> /// <returns>The closest BattleEntity in front of the specified one. null if no BattleEntity is in front of the specified one.</returns> public BattleEntity GetEntityInFrontOf(BattleEntity battleEntity) { //Players if (battleEntity.EntityType == EntityTypes.Player) { //If this player is in the back, return the player in the front if (battleEntity == BackPlayer) { return(FrontPlayer); } } //Enemies else if (battleEntity.EntityType == EntityTypes.Enemy) { //Check for an enemy with a lower BattleIndex than this one BattleEnemy enemy = (BattleEnemy)battleEntity; int inFrontEnemy = FindOccupiedEnemyIndex(enemy.BattleIndex - 1, true); //We found the enemy in front of this one; return it if (inFrontEnemy >= 0) { return(Enemies[inFrontEnemy]); } } //There is no BattleEntity in front of this one, so return null return(null); }
/// <summary> /// Gets the BattleEntities behind a particular BattleEntity. /// </summary> /// <param name="entity">The BattleEntity to find entities behind</param> /// <returns>An array of BattleEntities behind the given one. If none are behind, an empty array.</returns> public BattleEntity[] GetEntitiesBehind(BattleEntity entity) { List <BattleEntity> behindEntities = new List <BattleEntity>(); //If it's a Player, check if the entity is in the front or the back if (entity.EntityType == EntityTypes.Player) { //If the entity is in the front, return the Back player if (entity == FrontPlayer) { behindEntities.Add(BackPlayer); } } else { BattleEnemy battleEnemy = entity as BattleEnemy; //Get this enemy's BattleIndex int enemyIndex = battleEnemy.BattleIndex; //Look for all enemies with a BattleIndex greater than this one, which indicates it's behind for (int i = 0; i < Enemies.Count; i++) { BattleEnemy enemy = Enemies[i]; if (enemy != null && enemy.BattleIndex > enemyIndex) { behindEntities.Add(enemy); } } } return(behindEntities.ToArray()); }
protected override void SequenceEndBranch() { switch (SequenceStep) { case 0: User.AnimManager.PlayAnimation(AnimationGlobals.RunningName); CurSequenceAction = new MoveToSeqAction(User, User.BattlePosition, WalkDuration); break; case 1: User.AnimManager.PlayAnimation(User.GetIdleAnim()); //Remove the item when finished //For Players, remove the item from the inventory if (User.EntityType == Enumerations.EntityTypes.Player) { Inventory.Instance.RemoveItem(itemAction.ItemUsed); } //It has to be an Enemy, so remove its held item else { BattleEnemy enemy = (BattleEnemy)User; enemy.SetHeldCollectible(null); } EndSequence(); break; default: PrintInvalidSequence(); break; } }
/// <summary> /// Tells whether one BattleEntity is in front of another. /// </summary> /// <param name="behindEntity">The BattleEntity that is supposedly behind <paramref name="frontEntity"/>.</param> /// <param name="frontEntity">The BattleEntity that is supposedly in front of <paramref name="behindEntity"/>.</param> /// <returns></returns> public bool IsEntityInFrontOf(BattleEntity behindEntity, BattleEntity frontEntity) { //If the entities aren't the same type of BattleEntity or if they're the same BattleEntity, then ignore if (behindEntity.EntityType != frontEntity.EntityType || behindEntity == frontEntity) { return(false); } //For players, check if the front entity is the front player if (behindEntity.EntityType == EntityTypes.Player) { if (frontEntity == FrontPlayer) { return(true); } } else { //For enemies, compare the front entity's BattleIndex with the one behind //If the front entity's BattleIndex is lower, then it's in front BattleEnemy behindEnemy = (BattleEnemy)behindEntity; BattleEnemy frontEnemy = (BattleEnemy)frontEntity; return(frontEnemy.BattleIndex < behindEnemy.BattleIndex); } //For all other cases, return false return(false); }
/// <summary> /// Gets the BattleEntities adjacent to a particular BattleEntity. /// <para>This considers all foreground entities (Ex. Adjacent to Mario would be his Partner and the first Enemy)</para> /// </summary> /// <param name="entity">The BattleEntity to find entities adjacent to</param> /// <param name="getDead">Gets any adjacent entities even if they're dead</param> /// <returns>An array of adjacent BattleEntities. If none are adjacent, an empty array.</returns> public BattleEntity[] GetAdjacentEntities(BattleEntity entity) { List <BattleEntity> adjacentEntities = new List <BattleEntity>(); //If the entity is an enemy, it can either be two Enemies or the front Player and another Enemy if (entity.EntityType == EntityTypes.Enemy) { BattleEnemy enemy = entity as BattleEnemy; int enemyIndex = enemy.BattleIndex; int prevEnemyIndex = FindOccupiedEnemyIndex(enemyIndex - 1, true); int nextEnemyIndex = FindOccupiedEnemyIndex(enemyIndex + 1); //Check if there's an Enemy before this one if (prevEnemyIndex >= 0) { adjacentEntities.Add(Enemies[prevEnemyIndex]); } //There's no Enemy, so target the Front Player else { adjacentEntities.Add(FrontPlayer); } //Check if there's an Enemy after this one if (nextEnemyIndex >= 0) { adjacentEntities.Add(Enemies[nextEnemyIndex]); } } //If it's a Player, it will be either Mario/Partner and the first enemy else if (entity.EntityType == EntityTypes.Player) { //The previous entity for Players is always Mario or his Partner, unless the latter has 0 HP //The back Player has no one else adjacent to him/her aside from the Front player if (entity == BackPlayer) { adjacentEntities.Add(FrontPlayer); } else if (entity == FrontPlayer) { //NOTE: The dead check is being removed for consistency with other methods //if (BackPlayer.IsDead == false) //{ adjacentEntities.Add(BackPlayer); //} //Add the next enemy int nextEnemy = FindOccupiedEnemyIndex(0); if (nextEnemy >= 0) { adjacentEntities.Add(Enemies[nextEnemy]); } } } return(adjacentEntities.ToArray()); }
/// <summary> /// Adds enemies to battle /// </summary> /// <param name="enemies">A list containing the enemies to add to battle</param> public void AddEnemies(List <BattleEnemy> enemies) { //Look through all enemies and add one to the specified position for (int i = 0; i < enemies.Count; i++) { if (EnemySpotsAvailable == false) { Debug.LogError($"Cannot add enemy {enemies[i].Name} because there are no available spots left in battle! Exiting loop!"); break; } int index = FindAvailableEnemyIndex(0); BattleEnemy enemy = enemies[i]; //Set reference and position, then increment the number alive Enemies[index] = enemy; Vector2 battlepos = EnemyStartPos + new Vector2(PositionXDiff * index, 0); if (enemy.HeightState == HeightStates.Airborne) { battlepos.Y -= AirborneY; } else if (enemy.HeightState == HeightStates.Ceiling) { battlepos.Y -= CeilingY; } enemy.Position = battlepos; enemy.SetBattlePosition(battlepos); enemy.SetBattleIndex(index); //Start battle for the enemy enemy.OnBattleStart(); IncrementEnemiesAlive(); //Call the enemy added event EnemyAddedEvent?.Invoke(enemy); } }
/// <summary> /// Sorts enemies by battle indices, with lower indices appearing first /// </summary> private int SortEnemiesByBattleIndex(BattleEnemy enemy1, BattleEnemy enemy2) { if (enemy1 == null) { return(1); } else if (enemy2 == null) { return(-1); } //Compare battle indices if (enemy1.BattleIndex < enemy2.BattleIndex) { return(-1); } else if (enemy1.BattleIndex > enemy2.BattleIndex) { return(1); } return(0); }
public GulpitAI(BattleEnemy gulpit) : base(gulpit) { }
protected EnemyAIBehavior(BattleEnemy enemy) { Enemy = enemy; }
public GoombaAI(BattleEnemy enemy) : base(enemy) { }
protected override void OnEnd() { base.OnEnd(); //Remove the item over the BattleEntity's head if (RevivalItemShown != null) { RevivedEntity.BManager.battleUIManager.RemoveUIElement(RevivalItemShown); RevivalItemShown = null; } //Revive the BattleEntity only if it's currently in battle if (RevivedEntity.IsInBattle == true) { //Get revival data from the item IRevivalItem revivalData = RevivalItem as IRevivalItem; if (revivalData != null) { //If the revival item heals 0 or fewer HP, log a warning if (revivalData.RevivalHPRestored <= 0) { Debug.LogWarning($"{RevivalItem.Name} heals 0 or fewer HP, so {RevivedEntity.Name} won't actually be revived!"); } //Heal HP RevivedEntity.HealHP(revivalData.RevivalHPRestored); //Play the idle animation RevivedEntity.AnimManager.PlayAnimation(RevivedEntity.GetIdleAnim()); //Remove the item //For players, remove it from the inventory if (RevivedEntity.EntityType == Enumerations.EntityTypes.Player) { Inventory.Instance.RemoveItem(RevivalItem); } //It has to be an enemy, so remove its held item else { BattleEnemy revivedEnemy = (BattleEnemy)RevivedEntity; revivedEnemy.SetHeldCollectible(null); } } else { Debug.LogError($"{RevivalItem.Name} does not implement {nameof(IRevivalItem)}, so {RevivedEntity.Name} can't be revived!"); } //Failsafe; handle a dead BattleEntity in the event the RevivalItem doesn't actually revive or heal if (RevivedEntity.IsDead == true) { RevivedEntity.BManager.HandleEntityDeath(RevivedEntity); } } else { Debug.LogWarning($"{RevivedEntity.Name} isn't in battle and thus won't be revived!"); } //Clear references RevivedEntity = null; RevivalItem = null; }
public ShyGuyAI(BattleEnemy enemy) : base(enemy) { }
public DefaultEnemyAI(BattleEnemy enemy) : base(enemy) { }
private void RemoveShowHPProperty(BattleEnemy enemy) { enemy.SubtractShowHPProperty(); }
private void AddShowHPProperty(BattleEnemy enemy) { enemy.AddShowHPProperty(); }
private void OnEnemyAdded(BattleEnemy enemy) { //Tell the enemy to show its HP. Note that we have an integer in case they have been tattled AddShowHPProperty(enemy); }