private void InitializeFSM()
    {
        // Create Minion FSM.
        fsm = new FSM <States>();
        IdleState <States>    idleState    = new IdleState <States>(fsm, this);
        SearchState <States>  searchState  = new SearchState <States>(fsm, this);
        FlockState <States>   flockState   = new FlockState <States>(fsm, this, _flockingEntity);
        PursuitState <States> pursuitState = new PursuitState <States>(fsm, this);
        FleeState <States>    fleeState    = new FleeState <States>(fsm, this);

        // [EVERYONE] Idle Transitions.
        idleState.AddTransition(States.FLOCKING, flockState);
        idleState.AddTransition(States.SEARCHING, searchState);
        idleState.AddTransition(States.PURSUIT, pursuitState);

        pursuitState.AddTransition(States.FLEE, fleeState);
        pursuitState.AddTransition(States.FLOCKING, flockState);
        pursuitState.AddTransition(States.IDLE, idleState);

        fleeState.AddTransition(States.IDLE, idleState);
        fleeState.AddTransition(States.PURSUIT, pursuitState);


        // [BOSS] Search Transitions.
        searchState.AddTransition(States.IDLE, idleState);
        searchState.AddTransition(States.PURSUIT, pursuitState);

        // [MINIONS] Flocking Transitions.
        flockState.AddTransition(States.IDLE, idleState);
        flockState.AddTransition(States.PURSUIT, pursuitState);

        fsm.SetInitState(idleState);
    }
Ejemplo n.º 2
0
    private void ConstructFSM()
    {
        FSMState patrol = new PatrolState(this);

        patrol.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        patrol.AddTransition(Transition.ReachedPlayer, FSMStateID.Attacking);
        AddFSMState(patrol);

        FSMState chase = new ChaseState();

        chase.AddTransition(Transition.LostPlayer, FSMStateID.Searching);
        chase.AddTransition(Transition.ReachedPlayer, FSMStateID.Attacking);
        AddFSMState(chase);

        FSMState search = new SearchState(this);

        search.AddTransition(Transition.GiveUpSearching, FSMStateID.Patrolling);
        search.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        AddFSMState(search);

        FSMState attack = new AttackState(this);

        attack.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        attack.AddTransition(Transition.LostPlayer, FSMStateID.Searching);
        AddFSMState(attack);
    }
Ejemplo n.º 3
0
    private void Start()
    {
        //Agarro el model
        _model = GetComponent <Model>();

        //Creo la FSM
        _fsm = new FSM <string>();

        //Creo los estados
        IdleState <string>   idle   = new IdleState <string>(this);
        PatrolState <string> patrol = new PatrolState <string>(Waypoints, transform, this);
        ShootState <string>  shoot  = new ShootState <string>(this);
        AlertState <string>  alert  = new AlertState <string>(this, Sight, ExclamationMark);
        SearchState <string> search = new SearchState <string>(this);

        //Creo las transiciones
        idle.AddTransition(_patrolKey, patrol);
        idle.AddTransition(_shootKey, shoot);
        idle.AddTransition(_alertKey, alert);
        idle.AddTransition(_searchKey, search);
        idle.AddTransition(_idleKey, idle); //se tienen a si mismos por si llega a tener que volverse a ejecutar con el random

        patrol.AddTransition(_idleKey, idle);
        patrol.AddTransition(_shootKey, shoot);
        patrol.AddTransition(_alertKey, alert);
        patrol.AddTransition(_searchKey, search);

        alert.AddTransition(_idleKey, idle);
        alert.AddTransition(_shootKey, shoot);
        alert.AddTransition(_patrolKey, patrol);
        alert.AddTransition(_alertKey, alert);
        alert.AddTransition(_searchKey, search);

        search.AddTransition(_searchKey, search);
        search.AddTransition(_idleKey, idle);
        search.AddTransition(_shootKey, shoot);
        search.AddTransition(_patrolKey, patrol);
        search.AddTransition(_alertKey, alert);

        //diccionario de todos los estados de idle para la roulette
        _statesRoulette = new Dictionary <string, int>();
        _statesRoulette.Add(_idleKey, 30);
        _statesRoulette.Add(_patrolKey, 70);
        _statesRoulette.Add(_searchKey, 50);

        //inicializo la FSM
        _fsm.SetInitialState(idle);

        //Inicializo los nodos del Desicion Tree
        ActionNode _shootActionNode       = new ActionNode(ChangeToShootState); //Aca pasarle función
        ActionNode _alertActionNode       = new ActionNode(ChangeToAlertState);
        ActionNode _randomStateActionNode = new ActionNode(ChangeToRandomState);

        _isFirstTimeQuestionNode    = new QuestionNode(Sight.SawTargetOnce, _shootActionNode, _alertActionNode);
        _isSeeingPlayerQuestionNode = new QuestionNode(Sight.IsSeeingTarget, _isFirstTimeQuestionNode, _randomStateActionNode);

        Sight.SawTarget.AddListener(ExecuteTree);

        // Roulette
        _actionRoulette = new Roulette <string>();
    }