Exemplo n.º 1
0
    /// <summary>
    /// 初始化状态机时,构造一个状态机
    /// </summary>
    void ConstructFSM()
    {
        FSM = new FSMSystem();

        AttackState attackState = new AttackState(gameObject);

        attackState.AddTransition(Transition.LostEnemy, StateID.Wander);

        MoveToState moveToState = new MoveToState(gameObject, MoveTarget);

        moveToState.AddTransition(Transition.ReadyToAttack, StateID.Attack);
        moveToState.AddTransition(Transition.LostEnemy, StateID.Wander);

        WanderState wanderState = new WanderState(gameObject, wanderPoints);

        wanderState.AddTransition(Transition.SawEnemy, StateID.MoveTo);
        wanderState.AddTransition(Transition.SawItem, StateID.MoveTo);



        FSM.AddState(attackState);
        FSM.AddState(wanderState);
        FSM.AddState(moveToState);



        FSM.start(StateID.Wander);
    }
Exemplo n.º 2
0
    void Awake()
    {
        Fsm = new StateMachine <Enemy>(this);
        State <Enemy> state;

        switch (this.startState)
        {
        case StartState.Wander:
            state = new WanderState(this, Fsm, 30.0f);
            break;

        case StartState.ReachGoal:
            state = new ReachGoalState(this, Fsm, target);
            break;

        case StartState.Flock:
            state = new FlockState(this, Fsm, target, group);
            break;

        case StartState.Flee:
            state = new FleeState(this, Fsm, target);
            break;

        case StartState.FleeMultiple:
            state = new FleeMultipleState(this, Fsm, group);
            break;

        default:
            state = new WanderState(this, Fsm, 30.0f);
            break;
        }
        Fsm.InitialState(state);
    }
 private void Awake()
 {
     chaseState  = new ChaseState(this);
     alertState  = new AlertState(this);
     patrolState = new PatrolState(this);
     wanderState = new WanderState(this);
 }
Exemplo n.º 4
0
 public void StopWander()
 {
     //destination = null;
     Debug.Log("" + transform.name);
     //navMeshAgent.isStopped = true;
     curState = WanderState.Stop;
 }
Exemplo n.º 5
0
 public StateMachine(Enemy t_enemy)
 {
     m_wanderState  = new WanderState(t_enemy, this);
     m_combatState  = new CombatState(t_enemy, this);
     m_deadState    = new DeadState(t_enemy);
     m_currentState = m_wanderState;
 }
Exemplo n.º 6
0
 protected override void OnEnable()
 {
     npc         = this.GetComponent <NPC_BaseClass>();
     wanderState = this;
     followState = this.GetComponent <FollowState>();
     avoidState  = this.GetComponent <AvoidState>();
     ChillABit();
 }
Exemplo n.º 7
0
	void Awake () {
		wanderState = new WanderState (wanderTimeMin, wanderTimeMax, wanderSpeed, wanderRadius);
		idleState = new IdleState (idleTime);
		chaseState = new ChaseState (chaseTime, chaseSpeed);
		attackState = new AttackState ();
		deadState = new DeadState ();
		leaveAltarState = new LeaveAltarState ();
	}
Exemplo n.º 8
0
 protected override void Awake()
 {
     base.Awake();
     Target         = FindObjectOfType <Player>().transform;
     m_StateMachine = GetComponent <StateMachine>();
     m_WanderState  = new WanderState(gameObject, WanderSpeed, StartChasingDistance, ChangeToChaseState);
     m_ChaseState   = new ChaseState(gameObject, Target, StartAttackDistance, QuitChasingDistance, ChangeToWanderState, ChangeToAttackState);
     m_AttackeState = new AttackState(gameObject, Target, ChangeToChaseState, QuitAttackDistance, AttackDistance);
 }
Exemplo n.º 9
0
    //This is where we take our break
    public void TakeABreak()
    {
        timer -= Time.deltaTime;

        if (timer <= 0f)
        {
            curState = WanderState.CheckPos;
        }
    }
Exemplo n.º 10
0
    private WanderState()
    {
        if (_instance != null)
        {
            return;
        }

        _instance = this;
    }
Exemplo n.º 11
0
 private void Awake()
 {
     enemy            = GetComponent <Enemy>();
     anim             = GetComponent <Animator>();
     idleState        = new IdleState(this);
     wanderState      = new WanderState(this);
     rangeAttackState = new RangeAttackState(this);
     dieState         = new DieState(this);
     isWaiting        = false;
 }
Exemplo n.º 12
0
        void Awake()
        {
            _npcManager   = GetComponent <NPCManager>();
            _flockManager = Indestructibles.FlockManagerInstance;

            Wander   = new WanderState(_npcManager, avoidObstacles, avoidNpCs);
            Chase    = new ChaseState(_npcManager, avoidObstacles);
            Idle     = new IdleState();
            Flocking = new FlockingState();

            CurrentState = Wander;
        }
Exemplo n.º 13
0
    // Use this for initialization
    void Start()
    {
        // Self references
        this.dangerHitbox  = this.transform.FindChild("Danger Zone").gameObject;
        this.targetingCone = this.transform.FindChild("Line of Sight").gameObject;
        _bodyBounds        = CreateBodyBounds();
        Fsm = new StateMachine <Enemy>(this);
        State <Enemy> state;

        switch (this.startState)
        {
        case StartState.Wander:
            state = new WanderState(this, Fsm, 30.0f);
            break;

        case StartState.ReachGoal:
            state = new ReachGoalState(this, Fsm, target);
            break;

        case StartState.Flock:
            state = new FlockState(this, Fsm, target, group);
            break;

        case StartState.Flee:
            state = new FleeState(this, Fsm, target);
            break;

        case StartState.FleeMultiple:
            state = new FleeMultipleState(this, Fsm, group);
            break;

        case StartState.FollowPath:
            Debug.Log("Setting state");
            state = new FollowPathState(this, Fsm, PathFinding.spawnGameObjectsAtPathPoints(PathFinding.generatePath(gameObject, target)));
            Debug.Log("Done setting state");
            break;

        case StartState.SeekTargetWithPath:
            state = new SeekTargetWithPathState(this, Fsm, target);
            break;

        case StartState.Patrol:
            state = new PatrolState(this, Fsm, patrolPath, patrolPauseTime);
            break;

        default:
            state = new WanderState(this, Fsm, 30.0f);
            break;
        }
        Fsm.InitialState(state);

        SetDangerous(false);
    }
Exemplo n.º 14
0
    private void Awake()
    {
        sleepState  = new SleepState(this);
        outState    = new OutState(this);
        useState    = new UseState(this);
        wanderState = new WanderState(this);

        timesRefused = 1;
        navMeshAgent = GetComponent <NavMeshAgent>();
        time         = clock.GetComponent <DigitalGameTimeClock>().currentTime;

        prefKeys = new float[activities.Length];
        SortPreferences();
    }
Exemplo n.º 15
0
    private void MakeFSM()
    {
        WanderState wander = new WanderState();

        wander.AddTransition(Transition.SawPlayer, StateID.Flee);

        FleeState flee = new FleeState();

        flee.AddTransition(Transition.NoPlayer, StateID.Wander);

        fsm = new FSMSystem();

        fsm.AddState(wander);
        fsm.AddState(flee);
    }
Exemplo n.º 16
0
    private void MakeFSM()
    {
        WanderState wander = new WanderState();

        wander.AddTransition(Transition.SawPlayer, StateID.Fighting);

        FightingState fight = new FightingState();

        fight.AddTransition(Transition.LostPlayer, StateID.Wander);

        fsm = new FSMSystem();

        fsm.AddState(wander);
        fsm.AddState(fight);
    }
Exemplo n.º 17
0
    //See if I should take a break
    public void ShouldITakeABreak()
    {
        float value = Random.Range(0f, 1f);

        if (value > 0.75f)
        {
            randomTime = Random.Range(1f, 3f);
            timer      = randomTime;
            curState   = WanderState.TakeABreak;
        }
        else
        {
            curState = WanderState.CheckPos;
        }
    }
Exemplo n.º 18
0
    public void CheckPos()
    {
        tempTarDes        = RandomNavMeshPos(transform.position, 25f, -1);
        targetDestination = tempTarDes;
        //This should fix the Infinite bug
        Vector3 infVec3 = new Vector3(99999, 99999, 99999);

        if (targetDestination.x > infVec3.x)
        {
            curState = WanderState.CheckPos;
        }
        else
        {
            curState = WanderState.PickNewDestination;
        }
    }
    private void makeFSM()
    {
        fsm = new FSMSystem();

        WanderState wanderState = new WanderState(gameObject, Vector3.forward * speed,
                                                  NpcType.PlayerBot, detectRange, guntipPosition);

        wanderState.AddTransition(Transition.Wander_Attack, StateID.EnemyAttackStateID);

        attackState = new AttackState(guntipPosition, Vector3.forward * speed,
                                      Resources.Load("Prefabs/shot_prefab") as GameObject, id);
        attackState.Target = GameManager.Instance.Player;
        attackState.AddTransition(Transition.Attack_Wander, StateID.EnemyWanderStateID);

        fsm.AddState(wanderState);
        fsm.AddState(attackState);
    }
Exemplo n.º 20
0
 //Start our Wander
 public void StartWandering()
 {
     if (!navMeshAgent.pathPending)
     {
         if (navMeshAgent.remainingDistance <= navMeshAgent.stoppingDistance)
         {
             if (!navMeshAgent.hasPath || navMeshAgent.velocity.sqrMagnitude == 0f)
             {
                 curState = WanderState.ShouldITakeABreak;
             }
         }
     }
     else
     {
         navMeshAgent.destination = targetDestination;
     }
 }
    private void Awake()
    {
        wanderState = new WanderState (this); // huntStart = new HuntState (this); May replace with this
        idleState = new IdleState (this); // huntStart = new HuntState (this); May replace with this
        forageState = new ForageState (this);
        flightState = new FlightState (this);
        pursuitState = new PursuitState (this);
        exitState = new ExitState (this);
        enterState = new EnterState (this);
        navMeshAgent = GetComponent<NavMeshAgent>();

        navMeshAgent.enabled = true;
        // navMeshObstacle.enabled = false;

        navMeshRadius = navMeshAgent.radius;

        navMeshAgent.avoidancePriority = Random.Range(0, 100);  // Randomly set the avoidance priority
    }
Exemplo n.º 22
0
    // Use this for initialization
    void Start()
    {
        _bodyBounds = CreateBodyBounds();
        Fsm         = new StateMachine <Enemy>(this);
        State <Enemy> state;

        switch (this.startState)
        {
        case StartState.Wander:
            state = new WanderState(this, Fsm, 30.0f);
            break;

        case StartState.ReachGoal:
            state = new ReachGoalState(this, Fsm, target);
            break;

        case StartState.Flock:
            state = new FlockState(this, Fsm, target, group);
            break;

        case StartState.Flee:
            state = new FleeState(this, Fsm, target);
            break;

        case StartState.FleeMultiple:
            state = new FleeMultipleState(this, Fsm, group);
            break;

        case StartState.FollowPath:
            Debug.Log("Setting state");
            state = new FollowPathState(this, Fsm, PathFinding.spawnGameObjectsAtPathPoints(PathFinding.generatePath(gameObject, target)));
            Debug.Log("Done setting state");
            break;

        case StartState.SeekTargetWithPath:
            state = new SeekTargetWithPathState(this, Fsm, target);
            break;

        default:
            state = new WanderState(this, Fsm, 30.0f);
            break;
        }
        Fsm.InitialState(state);
    }
Exemplo n.º 23
0
    public void GetOurNewDestination()
    {
        path = new NavMeshPath();
        navMeshAgent.CalculatePath(targetDestination, path);

        Debug.Log(navMeshAgent.CalculatePath(targetDestination, path));

        if (path.status == NavMeshPathStatus.PathPartial || path.status == NavMeshPathStatus.PathInvalid)
        {
            curState = WanderState.CheckPos;
        }
        else
        {
            navMeshAgent.SetPath(path);

            //	GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
            //	cube.transform.position = targetDestination;

//				cube.GetComponent<MeshRenderer>().material.color = color;
            curState = WanderState.Wander;
        }

        Debug.Log(navMeshAgent.CalculatePath(targetDestination, path));
    }
Exemplo n.º 24
0
    public override void Init()
    {
        base.Init();
        wanderState     = new WanderState(this);
        hideState       = new HideState(this);
        retreatState    = new Retreat(this, enemyObj.health.maxHealth);
        refillAmmoState = new RefifllAmmo(this);
        stunnedState    = new StunnedState(this);

        hideState.AddTransition(() =>
        {
            if (hideState.doneHiding)
            {
                Diagnostic.Instance.AddLog(enemyObj.gameObject, "Ok, done hiding");
                return(true);
            }
            return(false);
        }, wanderState);

        //Will look for healthpack if health is not at max
        wanderState.AddTransition(() =>
        {
            if (enemyObj.health.GetHealth() < enemyObj.health.maxHealth)
            {
                var packs = GameManager.Instance.GetAvailableHealthPacks();
                if (packs.Count > 0)
                {
                    if (stateMachine.GetCurrentState() != retreatState)
                    {
                        retreatState.allPacks = packs.ToArray();

                        Diagnostic.Instance.AddLog(enemyObj.gameObject, "Low health, got nothing to do, going to get some");
                        return(true);
                    }
                }
            }
            return(false);
        }, retreatState);

        //Will look for healthpack if health is not at max
        wanderState.AddTransition(() =>
        {
            if (enemyObj.rifle.Ammo < enemyObj.rifle.MaxAmmo)
            {
                var packs = GameManager.Instance.GetAvailableAmmoPacks();
                if (packs.Count > 0)
                {
                    if (stateMachine.GetCurrentState() != refillAmmoState)
                    {
                        refillAmmoState.allPacks = packs.ToArray();

                        Diagnostic.Instance.AddLog(enemyObj.gameObject, "Low ammo, got nothing to do, going to get some");
                        return(true);
                    }
                }
            }
            return(false);
        }, refillAmmoState);

        retreatState.AddTransition(() =>
        {
            var packs = GameManager.Instance.GetAvailableHealthPacks();
            //If the health was restored, or no packs available  go back wandering
            if (enemyObj.health.GetHealth() >= enemyObj.health.maxHealth ||
                enemyObj.health.GetHealth() < enemyObj.health.maxHealth && packs.Count == 0)
            {
                Diagnostic.Instance.AddLog(enemyObj.gameObject, "Feeling better, going to stroll around...");
                return(true);
            }

            return(false);
        }, wanderState);

        refillAmmoState.AddTransition(() =>
        {
            var packs = GameManager.Instance.GetAvailableAmmoPacks();
            //If the health was restored, or no packs available  go back wandering
            if (enemyObj.rifle.Ammo >= enemyObj.rifle.MaxAmmo ||
                enemyObj.rifle.Ammo < enemyObj.rifle.MaxAmmo && packs.Count == 0)
            {
                Diagnostic.Instance.AddLog(enemyObj.gameObject, "Feeling better, going to stroll around...");
                return(true);
            }

            return(false);
        }, wanderState);

        stunnedState.AddTransition(() =>
        {
            if (!stunnedState.isStunned)
            {
                return(true);
            }

            return(false);
        },
                                   hideState);

        stateMachine.SetState(wanderState);
    }
Exemplo n.º 25
0
 private WanderState NewWander()
 {
     wander = new WanderState(transform, moveAmnt, WanderCallBack);
     return(wander);
 }
Exemplo n.º 26
0
    public override void Init()
    {
        base.Init();
        wanderState        = new WanderState(this);
        shootState         = new ShootState(this, enemyObj.shootRate);
        investigationState = new InvestigateState(this);
        retreatState       = new Retreat(this, minHealthForRetreat);
        hideState          = new HideState(this);
        bombAvoidState     = new BombAvoid(this);
        refillAmmoState    = new RefifllAmmo(this);
        stunnedState       = new StunnedState(this);

        shootState.AddTransition(() =>
        {
            if (!enemyObj.enemySight.IsPlayerInSight())
            {
                investigationState.waitBeforeGoingToPoint = 0;
                investigationState.investigationPoint     = Player.Instance.transform.position;
                Diagnostic.Instance.AddLog(enemyObj.gameObject, "Lost sight of player, going to check last known position");

                return(true);
            }
            return(false);
        }, investigationState);

        shootState.AddTransition(() =>
        {
            if (enemyObj.rifle.Ammo <= 0)
            {
                var allPacks = GameManager.Instance.GetAvailableAmmoPacks();
                if (allPacks.Count == 0)
                {
                    Diagnostic.Instance.AddLog(enemyObj.gameObject, "Out of ammo, no packs around, going to hide!");
                    return(true);
                }
            }
            return(false);
        }, hideState);

        shootState.AddTransition(() =>
        {
            if (enemyObj.rifle.Ammo <= 0)
            {
                var allPacks = GameManager.Instance.GetAvailableAmmoPacks();
                if (allPacks.Count > 0)
                {
                    refillAmmoState.allPacks = allPacks.ToArray();
                    refillAmmoState.playerLastKnowsPosition = Player.Instance.transform.position;
                    Diagnostic.Instance.AddLog(enemyObj.gameObject, "Out of ammo, going to refill!");
                    return(true);
                }
            }
            return(false);
        }, refillAmmoState);

        investigationState.AddTransition(() => {
            return(investigationState.done);
        }, wanderState);

        refillAmmoState.AddTransition(() =>
        {
            if (enemyObj.rifle.Ammo <= 0)
            {
                var allPacks = GameManager.Instance.GetAvailableAmmoPacks();
                if (allPacks.Count == 0)
                {
                    Diagnostic.Instance.AddLog(enemyObj.gameObject, "No ammo boxe available, will hide!");

                    return(true);
                }
            }

            return(false);
        }, hideState);

        refillAmmoState.AddTransition(() =>
        {
            if (enemyObj.rifle.Ammo > 0)
            {
                if (refillAmmoState.playerLastKnowsPosition != null)
                {
                    Diagnostic.Instance.AddLog(enemyObj.gameObject, "Go ammo, going to check last player known position");

                    investigationState.investigationPoint = refillAmmoState.playerLastKnowsPosition.Value;
                    return(true);
                }
            }

            return(false);
        }, investigationState);

        refillAmmoState.AddTransition(() =>
        {
            if (enemyObj.rifle.Ammo > 0)
            {
                if (refillAmmoState.playerLastKnowsPosition == null)
                {
                    Diagnostic.Instance.AddLog(enemyObj.gameObject, "Go ammo, don't know where player is, will wander around");

                    return(true);
                }
            }

            return(false);
        }, wanderState);

        //If health is ok and retreat has a player known pos, go investigate
        retreatState.AddTransition(() => {
            if (enemyObj.health.GetHealth() >= minHealthForRetreat)
            {
                if (retreatState.playerLastKnowsPosition != null)
                {
                    investigationState.investigationPoint = retreatState.playerLastKnowsPosition.Value;
                }

                Diagnostic.Instance.AddLog(enemyObj.gameObject, "Feeling better, go to check last investigation point");

                return(true);
            }

            return(false);
        }, investigationState);

        //If health is ok and retreat has no player known pos, go patrol

        retreatState.AddTransition(() => {
            if (enemyObj.health.GetHealth() >= minHealthForRetreat)
            {
                if (retreatState.playerLastKnowsPosition == null)
                {
                    Diagnostic.Instance.AddLog(enemyObj.gameObject, "Feeling better, go to back to wander");
                    return(true);
                }
            }

            return(false);
        }, wanderState);

        retreatState.AddTransition(() =>
        {
            if (enemyObj.health.GetHealth() < minHealthForRetreat)
            {
                var packs = GameManager.Instance.GetAvailableHealthPacks();

                if (packs.Count == 0 && !hideState.isHiding)
                {
                    Diagnostic.Instance.AddLog(enemyObj.gameObject, "Go a healthpack, but still feel crap, will go hide");
                }

                return(packs.Count == 0 && !hideState.isHiding);
            }
            return(false);
        }, hideState);


        //Will come out of hiding only when a health pack is available again
        hideState.AddTransition(() => {
            var packs = GameManager.Instance.GetAvailableHealthPacks();

            if (packs.Count > 0 && enemyObj.health.GetHealth() < retreatState.minHealthForRetreat)
            {
                retreatState.allPacks = packs.ToArray();
                Diagnostic.Instance.AddLog(enemyObj.gameObject, "Healthpack is available, going to get it!");

                return(true);
            }

            return(false);
        }, retreatState);

        //Will come out of hiding only when a ammo pack is available again
        hideState.AddTransition(() => {
            var packs = GameManager.Instance.GetAvailableAmmoPacks();
            if (packs.Count > 0 && enemyObj.health.GetHealth() >= retreatState.minHealthForRetreat)
            {
                refillAmmoState.allPacks = packs.ToArray();
                Diagnostic.Instance.AddLog(enemyObj.gameObject, "Ammo box is available, going to get it!");

                return(true);
            }

            return(false);
        }, refillAmmoState);

        bombAvoidState.AddTransitionDynamicState(() =>
        {
            return(bombAvoidState.readyToGo);
        },
                                                 () => { return(stateMachine.previousState); });

        stunnedState.AddTransition(() =>
        {
            if (!stunnedState.isStunned)
            {
                investigationState.investigationPoint = enemyObj.transform.position;

                return(true);
            }

            return(false);
        },
                                   investigationState);

        //Soldier will respond to alarm
        Enemy.OnAlarmSent += GoInvestigateSOS;
        stateMachine.SetState(wanderState);
    }
Exemplo n.º 27
0
 private void OnEnable()
 {
     npc         = this.GetComponent <NPC_BaseClass>();
     wanderState = this.GetComponent <WanderState>();
     avoidState  = this.GetComponent <AvoidState>();
 }
Exemplo n.º 28
0
 private void Awake()
 {
     wanderstate = new WanderState(this);
     flowerstate = new FlowerState(this);
     hoverstate  = new HoverState(this);
 }
Exemplo n.º 29
0
    public override void Init()
    {
        base.Init();
        wanderState        = new WanderState(this);
        shootState         = new ShootState(this, enemyObj.shootRate);
        investigationState = new InvestigateState(this);
        stunnedState       = new StunnedState(this);
        meleeAttackState   = new MeleeAttackState(this);
        refillAmmoState    = new RefifllAmmo(this);
        retreatState       = new Retreat(this, minHealthForRetreat);

        qMark = Resources.Load <Sprite>("StateIcons\\what");

        wanderState.AddTransition(() =>
        {
            if (enemyObj.enemySight.IsPlayerInSight() && enemyObj.rifle.Ammo > 0)
            {
                Diagnostic.Instance.AddLog(enemyObj.gameObject, "See the player, shooting!");

                return(true);
            }
            return(false);
        }, shootState);

        wanderState.AddTransition(() =>
        {
            if (enemyObj.rifle.Ammo <= 0)
            {
                var packs = GameManager.Instance.GetAvailableAmmoPacks();
                if (packs.Count > 0)
                {
                    if (stateMachine.GetCurrentState() != refillAmmoState)
                    {
                        refillAmmoState.allPacks = packs.ToArray();
                        Diagnostic.Instance.AddLog(enemyObj.gameObject, "No ammo, got nothing to do, going to get some");
                        return(true);
                    }
                }
            }
            return(false);
        }, refillAmmoState);

        wanderState.AddTransition(() =>
        {
            if (enemyObj.health.GetHealth() < minHealthForRetreat)
            {
                var packs = GameManager.Instance.GetAvailableHealthPacks();
                if (packs.Count > 0)
                {
                    if (stateMachine.GetCurrentState() != retreatState)
                    {
                        retreatState.allPacks = packs.ToArray();

                        Diagnostic.Instance.AddLog(enemyObj.gameObject, "Low health, got nothing to do, going to get some");
                        return(true);
                    }
                }
            }
            return(false);
        }, retreatState);

        wanderState.AddTransition(() =>
        {
            if (enemyObj.rifle.Ammo <= 0)
            {
                var packs = GameManager.Instance.GetAvailableAmmoPacks();
                if (packs.Count > 0)
                {
                    if (stateMachine.GetCurrentState() != refillAmmoState)
                    {
                        Diagnostic.Instance.AddLog(enemyObj.gameObject, "No ammo, got nothing to do, going to get some");
                        return(true);
                    }
                }
            }
            return(false);
        }, refillAmmoState);

        wanderState.AddTransition(() =>
        {
            if (enemyObj.enemySight.IsPlayerInSight() && enemyObj.rifle.Ammo <= 0)
            {
                Diagnostic.Instance.AddLog(enemyObj.gameObject, "See the player, no ammo, will attack with hands!");

                return(true);
            }
            return(false);
        }, meleeAttackState);

        refillAmmoState.AddTransition(() =>
        {
            if (enemyObj.rifle.Ammo > 0)
            {
                if (refillAmmoState.playerLastKnowsPosition == null)
                {
                    Diagnostic.Instance.AddLog(enemyObj.gameObject, "Go ammo, don't know where player is, will wander around");
                    return(true);
                }
            }

            return(false);
        }, wanderState);

        refillAmmoState.AddTransition(() =>
        {
            if (enemyObj.enemySight.IsPlayerInSight())
            {
                Diagnostic.Instance.AddLog(enemyObj.gameObject, "Saw player, no time for refill ammo, attack!");
                return(true);
            }

            return(false);
        }, meleeAttackState);

        retreatState.AddTransition(() =>
        {
            if (enemyObj.enemySight.IsPlayerInSight())
            {
                Diagnostic.Instance.AddLog(enemyObj.gameObject, "Saw player, no time for get healthpack, attack!");
                return(true);
            }

            return(false);
        }, shootState);

        retreatState.AddTransition(() =>
        {
            //If the health was restored OR health is low but no packs available, go back wandering
            if (enemyObj.health.GetHealth() > minHealthForRetreat ||
                (enemyObj.health.GetHealth() <= minHealthForRetreat && GameManager.Instance.GetAvailableHealthPacks().Count == 0))
            {
                Diagnostic.Instance.AddLog(enemyObj.gameObject, "Feeling better, going to stroll around...");
                return(true);
            }

            return(false);
        }, wanderState);

        shootState.AddTransition(() =>
        {
            if (!enemyObj.enemySight.IsPlayerInSight())
            {
                investigationState.waitBeforeGoingToPoint = 0;
                investigationState.investigationPoint     = Player.Instance.transform.position;
                shootTimer = 15.0f;
                Diagnostic.Instance.AddLog(enemyObj.gameObject, "Lost sight of player, going to check last known psition (and keep shooting, why not)");

                return(true);
            }
            return(false);
        }, investigationState);

        shootState.AddTransition(() => {
            return(enemyObj.rifle.Ammo <= 0);
        }, meleeAttackState);

        meleeAttackState.AddTransition(() => {
            if (meleeAttackState.playerLastKnownPosition != null)
            {
                investigationState.investigationPoint = meleeAttackState.playerLastKnownPosition.Value;
                return(true);
            }

            return(false);
        }, investigationState);

        investigationState.AddTransition(() => {
            if (enemyObj.enemySight.IsPlayerInSight())
            {
                Diagnostic.Instance.AddLog(enemyObj.gameObject, "See the player, shooting!");

                return(true);
            }
            return(false);
        }, shootState);

        investigationState.AddTransition(() => {
            return(investigationState.done);
        }, wanderState);

        stunnedState.AddTransition(() =>
        {
            if (!stunnedState.isStunned)
            {
                investigationState.investigationPoint = enemyObj.transform.position;

                return(true);
            }

            return(false);
        },
                                   investigationState);


        //Beserk will respond to alarm
        Enemy.OnAlarmSent += GoInsestigateSOS;
        stateMachine.SetState(wanderState);
    }
Exemplo n.º 30
0
 private void Awake()
 {
     evadeState    = new EvadeState(this);
     approachState = new ApproachState(this);
     wanderState   = new WanderState(this);
 }
Exemplo n.º 31
0
 protected MobEntity()
 {
     Speed        = 4;
     CurrentState = new WanderState();
 }
Exemplo n.º 32
0
 public override void OnEnable()
 {
     guaranteeAnimatorAndNavMesh();
     wanderState  = this.GetComponent <WanderState>();
     currentState = wanderState;
 }