using System; using UnityEngine; namespace DoomBreakers { public class PlayerStateMachine : StateMachine { protected bool _inputDodgedLeft; protected int _quickAttackIncrement; protected Vector3 _velocity; protected bool SafeToSetIdle() //Still require these checks to have player behave as desired. { //We don't want to set to idle each frame if already Idle AND is Jumping AND is Falling ect. if (_state.GetType() != typeof(PlayerIdle) && _state.GetType() != typeof(PlayerClimb) && _state.GetType() != typeof(PlayerFall) && _state.GetType() != typeof(PlayerJump) && _state.GetType() != typeof(PlayerDodge) && _state.GetType() != typeof(PlayerQuickAttack) && _state.GetType() != typeof(PlayerUpwardAttack) && _state.GetType() != typeof(PlayerDownwardAttack) && _state.GetType() != typeof(PlayerKnockAttack) && _state.GetType() != typeof(PlayerHoldAttack) && _state.GetType() != typeof(PlayerReleaseAttack) && _state.GetType() != typeof(PlayerDefend) && _state.GetType() != typeof(PlayerGainedEquipment) && _state.GetType() != typeof(PlayerBrokenEquipment) && _state.GetType() != typeof(PlayerHitByQuickAttack) && _state.GetType() != typeof(PlayerHitByPowerAttack) && _state.GetType() != typeof(PlayerHitByKnockAttack) && _state.GetType() != typeof(PlayerHitDefending) && _state.GetType() != typeof(PlayerExhausted) && _state.GetType() != typeof(PlayerDying) && _state.GetType() != typeof(PlayerDead)) return true; return false; } protected bool SafeToSetMove() { if (_state.GetType() != typeof(PlayerMove) && _state.GetType() != typeof(PlayerSprint) && _state.GetType() != typeof(PlayerFall) && _state.GetType() != typeof(PlayerJump) && _state.GetType() != typeof(PlayerDodge) && _state.GetType() != typeof(PlayerQuickAttack) && _state.GetType() != typeof(PlayerUpwardAttack) && _state.GetType() != typeof(PlayerDownwardAttack) && _state.GetType() != typeof(PlayerKnockAttack) && _state.GetType() != typeof(PlayerHoldAttack) && _state.GetType() != typeof(PlayerReleaseAttack) && _state.GetType() != typeof(PlayerDefend) && _state.GetType() != typeof(PlayerGainedEquipment) && _state.GetType() != typeof(PlayerBrokenEquipment) && _state.GetType() != typeof(PlayerHitByQuickAttack) && _state.GetType() != typeof(PlayerHitByPowerAttack) && _state.GetType() != typeof(PlayerHitByKnockAttack) && _state.GetType() != typeof(PlayerHitDefending) && _state.GetType() != typeof(PlayerExhausted) && _state.GetType() != typeof(PlayerDying) && _state.GetType() != typeof(PlayerDead)) return true; return false; } protected bool SafeToSetSprint() { if ( _state.GetType() != typeof(PlayerSprint) && _state.GetType() != typeof(PlayerFall) && _state.GetType() != typeof(PlayerJump) && _state.GetType() != typeof(PlayerDodge) && _state.GetType() != typeof(PlayerQuickAttack) && _state.GetType() != typeof(PlayerUpwardAttack) && _state.GetType() != typeof(PlayerDownwardAttack) && _state.GetType() != typeof(PlayerKnockAttack) && _state.GetType() != typeof(PlayerHoldAttack) && _state.GetType() != typeof(PlayerReleaseAttack) && _state.GetType() != typeof(PlayerDefend) && _state.GetType() != typeof(PlayerGainedEquipment) && _state.GetType() != typeof(PlayerBrokenEquipment) && _state.GetType() != typeof(PlayerHitByQuickAttack) && _state.GetType() != typeof(PlayerHitByPowerAttack) && _state.GetType() != typeof(PlayerHitByKnockAttack) && _state.GetType() != typeof(PlayerHitDefending) && _state.GetType() != typeof(PlayerExhausted) && _state.GetType() != typeof(PlayerDying) && _state.GetType() != typeof(PlayerDead)) return true; return false; } protected bool SafeToSetJump() { if (_state.GetType() != typeof(PlayerJump) && _state.GetType() != typeof(PlayerGainedEquipment) && _state.GetType() != typeof(PlayerExhausted)) return true; return false; } protected bool SafeToSetClimb() { if (_state.GetType() != typeof(PlayerJump) && _state.GetType() != typeof(PlayerGainedEquipment) && _state.GetType() != typeof(PlayerExhausted) && _state.GetType() != typeof(PlayerDefend) && _state.GetType() != typeof(PlayerDying) && _state.GetType() != typeof(PlayerDead)) return true; return false; } protected bool SafeToSetHoldAttack() { if (_state.GetType() != typeof(PlayerJump) && _state.GetType() != typeof(PlayerClimb) && _state.GetType() != typeof(PlayerReleaseAttack) && _state.GetType() != typeof(PlayerGainedEquipment) && _state.GetType() != typeof(PlayerBrokenEquipment) && _state.GetType() != typeof(PlayerFall) && _state.GetType() != typeof(PlayerExhausted)) return true; return false; } protected bool SafeToProcessCollisions() { if (IsDying()) return false; if (_state.GetType() == typeof(PlayerExhausted)) return false; return true; } protected bool ProcessArrowAttack(int playerFaceDir, ref Transform t) { if (!IsDefendingSelf()) { SetState(PlayerStatePool._instance.GetPlayerHitByQuickAttackObjState(this, _velocity));// new PlayerHitByQuickAttack(this, _velocity)); return true; } else { ObjectPooler._instance.InstantiateForPlayer(PrefabID.Prefab_DustHitFX, t, 0, playerFaceDir); AudioEventManager.PlayPlayerSFX(PlayerSFXID.PlayerDefenseHitSFX); SetState(PlayerStatePool._instance.GetPlayerHitDefendingObjState(this, _velocity));//new PlayerHitDefending(this, _velocity)); return false; } //return false; } protected bool ProcessFireballAttack(int playerFaceDir, ref Transform t) { if (!IsDefendingSelf()) { SetState(PlayerStatePool._instance.GetPlayerHitByQuickAttackObjState(this, _velocity));// new PlayerHitByQuickAttack(this, _velocity)); return true; } else { ObjectPooler._instance.InstantiateForPlayer(PrefabID.Prefab_FireHitFX, t, 0, playerFaceDir); AudioEventManager.PlayPlayerSFX(PlayerSFXID.PlayerDefenseHitSFX); SetState(PlayerStatePool._instance.GetPlayerHitDefendingObjState(this, _velocity));//new PlayerHitDefending(this, _velocity)); return false; } //return false; } protected bool ProcessQuickAttackFromEnemy(ref BasicEnemyBaseState attackingBanditState, int banditFaceDir, int playerFaceDir, ref Transform t) { if (attackingBanditState.GetType() == typeof(BanditQuickAttack) || attackingBanditState.GetType() == typeof(SkeletonQuickAttack) || attackingBanditState.GetType() == typeof(GoblinQuickAttack)) { if (!IsDefendingSelf()) { SetState(PlayerStatePool._instance.GetPlayerHitByQuickAttackObjState(this, _velocity));//new PlayerHitByQuickAttack(this, _velocity)); return true; } else//if (IsDefendingSelf()) { if (IsDefendingCorrectDirection(banditFaceDir, playerFaceDir)) { ObjectPooler._instance.InstantiateForPlayer(PrefabID.Prefab_DustHitFX, t, 0, playerFaceDir); AudioEventManager.PlayPlayerSFX(PlayerSFXID.PlayerDefenseHitSFX); SetState(PlayerStatePool._instance.GetPlayerHitDefendingObjState(this, _velocity));//new PlayerHitDefending(this, _velocity)); return false; } else { SetState(PlayerStatePool._instance.GetPlayerHitByQuickAttackObjState(this, _velocity));// new PlayerHitByQuickAttack(this, _velocity)); return true; } } } return false; } protected bool ProcessPowerAttackFromEnemy(ref BasicEnemyBaseState attackingBanditState, int banditFaceDir, int playerFaceDir, ref Transform t) { if (_state.GetType() == typeof(PlayerHitByPowerAttack)) //Only process once. return false; if (attackingBanditState.GetType() == typeof(BanditReleaseAttack) || attackingBanditState.GetType() == typeof(SkeletonReleaseAttack) || attackingBanditState.GetType() == typeof(GoblinReleaseAttack)) { if (!IsDefendingSelf()) { SetState(PlayerStatePool._instance.GetPlayerHitByPowerAttackObjState(this, _velocity, null));// new PlayerHitByPowerAttack(this, _velocity, null)); return true; } else//if (IsDefendingSelf()) { if (IsDefendingCorrectDirection(banditFaceDir, playerFaceDir)) { ObjectPooler._instance.InstantiateForPlayer(PrefabID.Prefab_DustHitFX, t, 0, playerFaceDir); AudioEventManager.PlayPlayerSFX(PlayerSFXID.PlayerDefenseHitSFX); SetState(PlayerStatePool._instance.GetPlayerHitDefendingObjState(this, _velocity));// new PlayerHitDefending(this, _velocity)); return false; } else { SetState(PlayerStatePool._instance.GetPlayerHitByPowerAttackObjState(this, _velocity, null));// new PlayerHitByPowerAttack(this, _velocity, null)); return true; } } } return false; } protected bool ProcessGroundSlamFromEnemy(ref BasicEnemyBaseState attackingEnemyTankState, int enemyTankFaceDir, int playerFaceDir, ref Transform t) { if (_state.GetType() == typeof(PlayerHitByKnockAttack)) //Only process once. return false; if (attackingEnemyTankState.GetType() == typeof(TrollGroundPoundAttack) || attackingEnemyTankState.GetType() == typeof(TrollQuickSlamAttack) || attackingEnemyTankState.GetType() == typeof(TrollPunchAttack) || attackingEnemyTankState.GetType() == typeof(TrollFall)) { AudioEventManager.PlayPlayerSFX(PlayerSFXID.PlayerKnockAttackSFX); SetState(PlayerStatePool._instance.GetPlayerHitByKnockAttackObjState(this, _velocity, null)); return true; } return false; } protected bool IsDefendingCorrectDirection(int enemyFaceDir, int playerFaceDir) { //Detrmine which way the player is facing whilst defending & the enemy bandit is attacking. //Why? Player doesn't successfully defend against enemy attack defending the wrong face direction. //Enemy would only ever be attacking if directly in front of player. //So if player face direction is 1 (right) then enemy would have to be -1 (left) //case sceneria true for successful defence. if (playerFaceDir == 1 && enemyFaceDir == -1 || playerFaceDir == -1 && enemyFaceDir == 1) return true; return false; } protected bool IsDefendingSelf() { if (_state.GetType() == typeof(PlayerDefend)) return true; if (_state.GetType() == typeof(PlayerHitDefending)) return true; return false; } protected bool IsClimbing() { if (_state.GetType() == typeof(PlayerClimb)) return true; return false; } protected bool IsIgnoreDamage() { if (_state.GetType() == typeof(PlayerDodge)) return true; if (_state.GetType() == typeof(PlayerDodged)) return true; if (_state.GetType() == typeof(PlayerGainedEquipment)) return true; if (_state.GetType() == typeof(PlayerBrokenEquipment)) return true; if (_state.GetType() == typeof(PlayerExhausted)) return true; if (_state.GetType() == typeof(PlayerDying)) return true; if (_state.GetType() == typeof(PlayerDead)) return true; if (_state.GetType() == typeof(PlayerRevive)) return true; return false; } protected bool SafeToSetDying() { if (_state.GetType() != typeof(PlayerDying)) return true; return false; } protected bool IsDying() { if (_state.GetType() == typeof(PlayerDying)) return true; if (_state.GetType() == typeof(PlayerDead)) return true; if (_state.GetType() == typeof(PlayerRevive)) return true; return false; } } }