Ejemplo n.º 1
0
    void MakeFSM()
    {
        PatrolState patrol = new PatrolState();
        ChaseState  chase  = new ChaseState();
        AttackState attack = new AttackState();
        DeadState   dead   = new DeadState();
        IdleState   idle   = new IdleState();
        MoveState   move   = new MoveState();

        patrol.AddTransition(Transition.SawEnemy, chase);
        patrol.AddTransition(Transition.NoHP, dead);

        chase.AddTransition(Transition.LostEnemy, patrol);
        chase.AddTransition(Transition.ReachEnemy, attack);
        chase.AddTransition(Transition.NoHP, dead);

        attack.AddTransition(Transition.LostEnemy, patrol);
        attack.AddTransition(Transition.SawEnemy, chase);
        attack.AddTransition(Transition.NoHP, dead);

        AddState(StateID.Patrol, patrol);
        AddState(StateID.Chase, chase);
        AddState(StateID.Attack, attack);
        AddState(StateID.Dead, dead);



        m_stateMachine.Start(patrol);
    }
Ejemplo n.º 2
0
    private void ConstructFSM()
    {
        //Get the list of points
        pointList = GameObject.FindGameObjectsWithTag("WanderPoint");

        Transform[] waypoints = new Transform[pointList.Length];
        int         i         = 0;

        foreach (GameObject obj in pointList)
        {
            waypoints[i] = obj.transform;
            i++;
        }

        //Add Transition and State Pairs
        PatrolState patrol = new PatrolState(waypoints, this);

        //If the tank sees the player while patrolling, move to chasing state
        patrol.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        //If the tank loses health while patrolling, move to dead state
        patrol.AddTransition(Transition.NoHealth, FSMStateID.Dead);
        patrol.AddTransition(Transition.HalfHealth, FSMStateID.Rage);

        ChaseState chase = new ChaseState(waypoints, this);

        //If the tank loses the player while chasing, move to patrol state
        chase.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
        //If the tank reaches the player while attacking, move to attack state
        chase.AddTransition(Transition.ReachPlayer, FSMStateID.Attacking);
        //If the tank loses health while patrolling, move to dead state
        chase.AddTransition(Transition.NoHealth, FSMStateID.Dead);
        chase.AddTransition(Transition.HalfHealth, FSMStateID.Rage);

        AttackState attack = new AttackState(waypoints, this);

        //If the tank loses the player while attacking, move to patrol state
        attack.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
        //If the player is within sight while attacking, move to chase state
        attack.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        //If the tank loses health while attacking, move to dead state
        attack.AddTransition(Transition.NoHealth, FSMStateID.Dead);
        attack.AddTransition(Transition.HalfHealth, FSMStateID.Rage);

        DeadState dead = new DeadState(this);

        //When there is no health, go to dead state
        dead.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        RageState rage = new RageState(this);

        rage.AddTransition(Transition.NoHealth, FSMStateID.Dead);
        rage.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);

        //Add states to the state list
        AddFSMState(patrol);
        AddFSMState(chase);
        AddFSMState(attack);
        AddFSMState(dead);
        AddFSMState(rage);
    }
Ejemplo n.º 3
0
    private void MakeFSM()
    {
        PatrolState patrol = new PatrolState(player, transform, path);

        patrol.AddTransition(Transition.GuardPlayer, StateID.GuardID);

        GuardState guard = new GuardState(player, transform);

        guard.AddTransition(Transition.AutoPatrol, StateID.PatrolID);
        guard.AddTransition(Transition.ChasingPlayer, StateID.ChasingID);

        ChaseState chase = new ChaseState(player, transform);

        chase.AddTransition(Transition.GuardPlayer, StateID.GuardID);
        chase.AddTransition(Transition.AttackPlayer, StateID.AttackID);

        AttackState attack = new AttackState(player, transform);

        attack.AddTransition(Transition.GuardPlayer, StateID.GuardID);
        attack.AddTransition(Transition.ChasingPlayer, StateID.ChasingID);

        fsm = new FSMSystem();

        fsm.AddState(patrol);
        fsm.AddState(guard);
        fsm.AddState(chase);
        fsm.AddState(attack);
    }
Ejemplo n.º 4
0
    private void MakeFSM(Soldier soldier)
    {
        LookupState lookupState = new LookupState(soldier.gameObject);

        lookupState.AddTransition(Transition.FoundEnemy, StateID.ForwardEnemy);
        lookupState.AddTransition(Transition.HpEmpty, StateID.Dead);

        ForwardState forwardState = new ForwardState(soldier.gameObject);

        forwardState.AddTransition(Transition.LostEnemy, StateID.LookupEnemy);
        forwardState.AddTransition(Transition.CanAttackEnemy, StateID.AttackEnemy);
        forwardState.AddTransition(Transition.HpEmpty, StateID.Dead);

        AttackState attackState = new AttackState(soldier.gameObject);

        attackState.AddTransition(Transition.LostEnemy, StateID.LookupEnemy);
        attackState.AddTransition(Transition.HpEmpty, StateID.Dead);

        DeadState deadState = new DeadState(soldier.gameObject);

        deadState.AddTransition(Transition.HpRemain, StateID.LookupEnemy);

        fsm = new FSMSystem();
        fsm.AddState(lookupState);
        fsm.AddState(forwardState);
        fsm.AddState(attackState);
        fsm.AddState(deadState);
    }
Ejemplo n.º 5
0
    //Construct the Finite State Machine for the AI Car behavior
    private void ConstructFSM()
    {
        //Get the list of points
        pointList = GameObject.FindGameObjectsWithTag("WandarPoints");

        Transform[] waypoints = new Transform[pointList.Length];
        int i = 0;
        foreach (GameObject obj in pointList)
        {
            waypoints[i] = obj.transform;
            i++;
        }

        PatrolState patrol = new PatrolState(waypoints);
        patrol.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        patrol.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        ChaseState chase = new ChaseState(waypoints);
        chase.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
        chase.AddTransition(Transition.ReachPlayer, FSMStateID.Attacking);
        chase.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        AttackState attack = new AttackState(waypoints);
        attack.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
        attack.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        attack.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        DeadState dead = new DeadState();
        dead.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        AddFSMState(patrol);
        AddFSMState(chase);
        AddFSMState(attack);
        AddFSMState(dead);
    }
Ejemplo n.º 6
0
    public void MakeFSM()
    {
        IdleState idle = new IdleState();

        idle.AddTransition(Transition.SawPlayer, StateID.AttackingState);
        idle.AddTransition(Transition.LostPlayer, StateID.MovingState);

        MoveState move = new MoveState();

        move.AddTransition(Transition.SawPlayer, StateID.AttackingState);

        AttackState attack = new AttackState();

        attack.AddTransition(Transition.LostPlayer, StateID.MovingState);
        attack.AddTransition(Transition.IdleTransition, StateID.IdleStateID);

        DefendState defend = new DefendState();

        EvadeState evade = new EvadeState();

        WinState win = new WinState();

        DeathState death = new DeathState();



        fsm = new FSMSystem();
        fsm.AddState(move);
        fsm.AddState(attack);
        fsm.AddState(idle);
        fsm.AddState(defend);
        fsm.AddState(evade);
        fsm.AddState(win);
        fsm.AddState(death);
    }
    public override void StartFSM()
    {
        _idleState   = new IdleState <states>(this, flags, _treeStartPoint);
        _followState = new FollowState <states>(this, myLeader, flags, _treeStartPoint, stopDist);
        _attackState = new AttackState <states>(this, flags, _treeStartPoint);
        _escapeState = new EscapeState <states>(this, flags, _treeStartPoint);
        _reloadState = new ReloadState <states>(this, flags, _treeStartPoint);

        fsm = new FSM <states>(_idleState);

        _idleState.AddTransition(states.Follow, _followState);
        _idleState.AddTransition(states.Attack, _attackState);
        _idleState.AddTransition(states.Escape, _escapeState);
        _idleState.AddTransition(states.Reload, _reloadState);

        _followState.AddTransition(states.Idle, _idleState);
        _followState.AddTransition(states.Attack, _attackState);
        _followState.AddTransition(states.Escape, _escapeState);
        _followState.AddTransition(states.Reload, _reloadState);

        _attackState.AddTransition(states.Idle, _idleState);
        _attackState.AddTransition(states.Follow, _followState);
        _attackState.AddTransition(states.Escape, _escapeState);
        _attackState.AddTransition(states.Reload, _reloadState);

        _reloadState.AddTransition(states.Idle, _idleState);
        _reloadState.AddTransition(states.Attack, _attackState);
        _reloadState.AddTransition(states.Follow, _followState);
        _reloadState.AddTransition(states.Escape, _escapeState);

        _escapeState.AddTransition(states.Idle, _idleState);
        _escapeState.AddTransition(states.Follow, _followState);

        fsm.SetState(_idleState);
    }
    private void ConstructFSM()
    {
        //Get the list of points
        //pointList = GameObject.FindGameObjectsWithTag("PatrolPoint");

        //Transform[] waypoints = new Transform[pointList.Length];
        //int i = 0;
        //foreach(GameObject obj in pointList)
        //{
        //    waypoints[i] = obj.transform;
        //    i++;
        //}

        int pointlength = Random.Range(3, 5);

        Debug.Log("pointlength = " + pointlength);
        Transform[] waypoints       = new Transform[pointlength];
        float       maxdistance     = 50;
        float       mindistance     = -30;
        GameObject  partpointparent = new GameObject();

        partpointparent.transform.position = role.transform.position;
        partpointparent.name = role.name + "[partolpoints]";

        for (int i = 0; i < pointlength; i++)
        {
            Vector3    pos = new Vector3(role.transform.position.x + CreatPatrolRange(maxdistance, mindistance), 0, role.transform.position.z + CreatPatrolRange(maxdistance, mindistance));
            GameObject go  = new GameObject();
            go.transform.position = pos;
            go.transform.parent   = partpointparent.transform;;
            waypoints[i]          = go.transform;
        }
        Debug.Log("waypoints length -> " + waypoints.Length);

        PatrolState patrol = new PatrolState(waypoints);

        patrol.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        patrol.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        ChaseState chase = new ChaseState(waypoints);

        chase.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
        chase.AddTransition(Transition.ReachPlayer, FSMStateID.Attacking);
        chase.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        AttackState attack = new AttackState(waypoints);

        attack.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
        attack.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        attack.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        DeadState dead = new DeadState();

        dead.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        AddFSMState(patrol);
        AddFSMState(chase);
        AddFSMState(attack);
        AddFSMState(dead);
    }
Ejemplo n.º 9
0
    private void ConstructFSM()             //初始化拥有哪些状态,并为拥有的状态设置转化和状态ID
    {
        PatrolState tPatrolState = new PatrolState(wayPoints);

        tPatrolState.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        tPatrolState.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        ChaseState tChaseState = new ChaseState(wayPoints);

        tChaseState.AddTransition(Transition.ReachPlayer, FSMStateID.Attacking);
        tChaseState.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
        tChaseState.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        AttackState tAttackState = new AttackState(wayPoints);

        tAttackState.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        tAttackState.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
        tAttackState.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        DeadState tDeadState = new DeadState();

        tDeadState.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        AddFSMState(tPatrolState);
        AddFSMState(tPatrolState);
        AddFSMState(tPatrolState);
        AddFSMState(tPatrolState);


        Events.AddEvent(EventSign.GAME_START, DestroySelf, this);
        Events.Send(EventSign.GAME_START, new EventArg("123"));
    }
Ejemplo n.º 10
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.º 11
0
    private void ConstructFSM()
    {
        //Get the list of points
        pointList = GameObject.FindGameObjectsWithTag("WandarPoint");

        Transform[] waypoints = new Transform[pointList.Length];
        int         i         = 0;

        foreach (GameObject obj in pointList)
        {
            waypoints[i] = obj.transform;
            i++;
        }

        PatrolState patrol = new PatrolState(waypoints, this);

        patrol.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        patrol.AddTransition(Transition.LowHealth, FSMStateID.Healing);
        patrol.AddTransition(Transition.NoHealth, FSMStateID.Dead);
        patrol.AddTransition(Transition.HasBoredom, FSMStateID.Bored);

        ChaseState chase = new ChaseState(waypoints, this);

        chase.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
        chase.AddTransition(Transition.ReachPlayer, FSMStateID.Attacking);
        chase.AddTransition(Transition.LowHealth, FSMStateID.Healing);
        chase.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        AttackState attack = new AttackState(waypoints, this);

        attack.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
        attack.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        attack.AddTransition(Transition.LowHealth, FSMStateID.Healing);
        attack.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        DeadState dead = new DeadState();

        dead.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        HealState heal = new HealState(waypoints, this);

        heal.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        heal.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
        heal.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        BoredState bored = new BoredState(waypoints, this);

        bored.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        bored.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
        bored.AddTransition(Transition.LowHealth, FSMStateID.Healing);
        bored.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        AddFSMState(patrol);
        AddFSMState(chase);
        AddFSMState(attack);
        AddFSMState(dead);
        AddFSMState(heal);
        AddFSMState(bored);
    }
Ejemplo n.º 12
0
    private void ConstructFSM()
    {
        //Get the list of points
        //   pointList = GameObject.FindGameObjectsWithTag("WandarPoint");
        var pointList = gameObject.transform.Cast <Transform>().Where(c => c.gameObject.tag == "WandarPoint").Select(c => c.gameObject).ToArray();

        Transform[] waypoints = new Transform[pointList.Length];
        int         i         = 0;


        foreach (GameObject obj in pointList)
        {
            obj.GetComponent <Transform>().position = transform.position + new Vector3(Random.onUnitSphere.x * 5,
                                                                                       Random.onUnitSphere.y * 5, Random.onUnitSphere.z * 5);
            waypoints[i] = obj.transform;
            //	waypoints[i].position = new Vector3(Random.insideUnitSphere.x * 5,
            //	                                    Random.insideUnitSphere.z * 5, Random.insideUnitSphere.z * 5);

            i++;
        }

        PatrolState patrol = new PatrolState(waypoints);

        patrol.AddTransition(FSMTransition.PlayerSeen, StateID.Chasing);
        patrol.AddTransition(FSMTransition.NoHealth, StateID.Dead);
        patrol.SetStateDistances(chaseStartDist, attackStartDist);
        patrol.SetSpeed(speed / 2, rotationSpeed / 2);
        patrol.SetBounds(patrolBounds.x, patrolBounds.y, patrolBounds.z);

        ChaseState chase = new ChaseState(waypoints);

        chase.AddTransition(FSMTransition.PlayerLost, StateID.Patrolling);
        chase.AddTransition(FSMTransition.PlayerReached, StateID.Attacking);
        chase.AddTransition(FSMTransition.NoHealth, StateID.Dead);
        chase.SetStateDistances(chaseStartDist, attackStartDist);
        chase.SetSpeed(speed, rotationSpeed);

        AttackState attack = new AttackState(waypoints);

        attack.AddTransition(FSMTransition.PlayerLost, StateID.Patrolling);
        attack.AddTransition(FSMTransition.PlayerSeen, StateID.Chasing);
        attack.AddTransition(FSMTransition.NoHealth, StateID.Dead);
        attack.SetStateDistances(chaseStartDist, attackStartDist);
        attack.SetSpeed(speed, rotationSpeed);
        attack.kamikaze = this.kamikaze;

        DeadState dead = new DeadState();

        dead.AddTransition(FSMTransition.NoHealth, StateID.Dead);

        AddFSMState(patrol);
        AddFSMState(chase);
        AddFSMState(attack);
        AddFSMState(dead);

        //Start patrolling at given points
        patrol.FindNextPoint();
    }
Ejemplo n.º 13
0
    private void ConstructFSM()
    {
        //Get the list of points
        pointList = GameObject.FindGameObjectsWithTag("WandarPoint");

        Transform[] waypoints = new Transform[pointList.Length];
        int         i         = 0;

        foreach (GameObject obj in pointList)
        {
            waypoints[i] = obj.transform;
            i++;
        }

        PatrolState patrol = new PatrolState(waypoints);

        patrol.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        patrol.AddTransition(Transition.NoHealth, FSMStateID.Dead);
        patrol.AddTransition(Transition.Panic, FSMStateID.Fleeing);

        ChaseState chase = new ChaseState(waypoints);

        chase.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
        chase.AddTransition(Transition.ReachPlayer, FSMStateID.Attacking);
        chase.AddTransition(Transition.NoHealth, FSMStateID.Dead);
        chase.AddTransition(Transition.Panic, FSMStateID.Fleeing);

        AttackState attack = new AttackState(waypoints);

        attack.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
        attack.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        attack.AddTransition(Transition.NoHealth, FSMStateID.Dead);
        attack.AddTransition(Transition.Panic, FSMStateID.Fleeing);
        attack.AddTransition(Transition.TooCloseTooPlayer, FSMStateID.Evade);

        DeadState dead = new DeadState();

        dead.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        FleeState flee = new FleeState();

        flee.AddTransition(Transition.NoHealth, FSMStateID.Dead);
        flee.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);

        EvadeState evade = new EvadeState();

        evade.AddTransition(Transition.NoHealth, FSMStateID.Dead);
        evade.AddTransition(Transition.OutOfEvadingRange, FSMStateID.Patrolling);

        AddFSMState(patrol);
        AddFSMState(chase);
        AddFSMState(attack);
        AddFSMState(dead);
        AddFSMState(flee);
        AddFSMState(evade);
    }
Ejemplo n.º 14
0
    private void ConstructFSM()
    {
        PatrolState patrol = new PatrolState(this);

        patrol.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        patrol.AddTransition(Transition.ReachPlayer, FSMStateID.Attacking);
        patrol.AddTransition(Transition.NoHealth, FSMStateID.Dead);
        patrol.AddTransition(Transition.GotBored, FSMStateID.Bored);
        patrol.AddTransition(Transition.WantsTimeOff, FSMStateID.OffDuty);
        patrol.AddTransition(Transition.Hurt, FSMStateID.Repairing);
        patrol.AddTransition(Transition.WantsToHide, FSMStateID.Hiding);

        ChaseState chase = new ChaseState(this);

        chase.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
        chase.AddTransition(Transition.ReachPlayer, FSMStateID.Attacking);
        chase.AddTransition(Transition.NoHealth, FSMStateID.Dead);
        chase.AddTransition(Transition.Hurt, FSMStateID.Repairing);

        AttackState attack = new AttackState(this);

        attack.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
        attack.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        attack.AddTransition(Transition.NoHealth, FSMStateID.Dead);
        attack.AddTransition(Transition.Hurt, FSMStateID.Repairing);

        OffDutyState offduty = new OffDutyState(rigidbody.transform, this);

        offduty.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        offduty.AddTransition(Transition.RestedLongEnough, FSMStateID.Patrolling);
        offduty.AddTransition(Transition.NoHealth, FSMStateID.Dead);
        offduty.AddTransition(Transition.WantsToHide, FSMStateID.Hiding);

        RepairState repair = new RepairState(this);

        repair.AddTransition(Transition.Healed, FSMStateID.Patrolling);
        repair.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        HideState hide = new HideState(this);

        hide.AddTransition(Transition.ReachPlayer, FSMStateID.Attacking);
        hide.AddTransition(Transition.RestedLongEnough, FSMStateID.Patrolling);

        DeadState dead = new DeadState();

        dead.AddTransition(Transition.NoHealth, FSMStateID.Dead);


        AddFSMState(patrol);
        AddFSMState(chase);
        AddFSMState(attack);
        AddFSMState(offduty);
        AddFSMState(repair);
        AddFSMState(hide);
        AddFSMState(dead);
    }
Ejemplo n.º 15
0
    private void MakeFSM()
    {
        MovementState movement = new MovementState(path);

        movement.AddTransition(Transition.NearNPC, StateID.TrackNPC);
        movement.AddTransition(Transition.AngryNPC, StateID.AggroNPC);


        PlayerNearState track = new PlayerNearState();

        track.AddTransition(Transition.RoamNPC, StateID.MovementNPC);
        track.AddTransition(Transition.InteractNPC, StateID.InteractionNPC);
        track.AddDialogue(NPCDialogue);

        InteractionState interact = new InteractionState();

        interact.AddTransition(Transition.NearNPC, StateID.TrackNPC);

        AggroState aggro = new AggroState();

        aggro.AddTransition(Transition.RoamNPC, StateID.MovementNPC);
        aggro.AddTransition(Transition.AttackNPC, StateID.DamageNPC);

        AttackState attack = new AttackState();

        attack.AddTransition(Transition.AngryNPC, StateID.AggroNPC);


        sm = new FSMSystem();
        sm.AddState(movement);
        sm.AddState(track);
        sm.AddState(interact);
        sm.AddState(aggro);
        sm.AddState(attack);
    }
Ejemplo n.º 16
0
    // The NPC has two states: FollowPath and ChasePlayer
    // If it's on the first state and SawPlayer transition is fired, it changes to ChasePlayer
    // If it's on ChasePlayerState and LostPlayer transition is fired, it returns to FollowPath
    private void MakeFSM()
    {
        FollowPathState follow = new FollowPathState(/*path*/);

        follow.AddTransition(Transition.SawPlayer, StateID.ChasingPlayer);

        ChasePlayerState chase = new ChasePlayerState();

        chase.AddTransition(Transition.LostPlayer, StateID.FollowingPath);

        PatrolState patrolState = new PatrolState(PatrolWayPoints);

        patrolState.AddTransition(Transition.Alert, StateID.AlertNpc);

        AlertState alertState = new AlertState();

        alertState.AddTransition(Transition.Attack, StateID.AttackingPlayer);
        alertState.AddTransition(Transition.Patrol, StateID.Patroling);

        AttackState attackState = new AttackState();

        attackState.AddTransition(Transition.Alert, StateID.AlertNpc);


        fsm = new FSMSystem();
        fsm.AddState(patrolState);
        fsm.AddState(alertState);
        fsm.AddState(attackState);
        //fsm.AddState(chase);
        //fsm.AddState(follow);

        Debug.Log("First State: " + fsm.CurrentState.ToString());
    }
Ejemplo n.º 17
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);
    }
Ejemplo n.º 18
0
    public override void StartFSM()
    {
        _leadState   = new LeadState <states>(this, flags, leadStopDistance, _treeStartPoint);
        _attackState = new AttackState <states>(this, flags, _treeStartPoint);
        _buffState   = new BuffState <states>(this, flags, _treeStartPoint);
        _escapeState = new EscapeState <states>(this, flags, _treeStartPoint);
        _idleState   = new IdleState <states>(this, flags, _treeStartPoint);
        _reloadState = new ReloadState <states>(this, flags, _treeStartPoint);

        fsm = new FSM <states>(_idleState);

        _idleState.AddTransition(states.Attack, _attackState);
        _idleState.AddTransition(states.Buff, _buffState);
        _idleState.AddTransition(states.Lead, _leadState);
        _idleState.AddTransition(states.Escape, _escapeState);
        _idleState.AddTransition(states.Reload, _reloadState);

        _leadState.AddTransition(states.Attack, _attackState);
        _leadState.AddTransition(states.Buff, _buffState);
        _leadState.AddTransition(states.Escape, _escapeState);
        _leadState.AddTransition(states.Idle, _idleState);
        _leadState.AddTransition(states.Reload, _reloadState);

        _attackState.AddTransition(states.Lead, _leadState);
        _attackState.AddTransition(states.Buff, _buffState);
        _attackState.AddTransition(states.Escape, _escapeState);
        _attackState.AddTransition(states.Idle, _idleState);
        _attackState.AddTransition(states.Reload, _reloadState);

        _reloadState.AddTransition(states.Idle, _idleState);
        _reloadState.AddTransition(states.Attack, _attackState);
        _reloadState.AddTransition(states.Buff, _buffState);
        _reloadState.AddTransition(states.Lead, _leadState);
        _reloadState.AddTransition(states.Escape, _escapeState);

        _buffState.AddTransition(states.Lead, _leadState);
        _buffState.AddTransition(states.Attack, _attackState);
        _buffState.AddTransition(states.Escape, _escapeState);
        _buffState.AddTransition(states.Idle, _idleState);
        _buffState.AddTransition(states.Reload, _reloadState);

        _escapeState.AddTransition(states.Idle, _idleState);
        _escapeState.AddTransition(states.Lead, _leadState);

        fsm.SetState(_idleState);
    }
Ejemplo n.º 19
0
    private void BuildFSM() //Crea los estados, y las trancisiones que llevan a otros estados.
    {
        IdleState idle = new IdleState(this);

        idle.AddTransition(TransitionID.StartRoaming, StateID.Roaming);
        idle.AddTransition(TransitionID.SawTarget, StateID.ChasingTarget);
        idle.AddTransition(TransitionID.StartHurt, StateID.Hurt);
        idle.AddTransition(TransitionID.Dying, StateID.Dead);

        RoamState roam = new RoamState(this);

        roam.AddTransition(TransitionID.SawTarget, StateID.ChasingTarget);
        roam.AddTransition(TransitionID.StopRoaming, StateID.Idle);
        roam.AddTransition(TransitionID.StartHurt, StateID.Hurt);
        roam.AddTransition(TransitionID.Dying, StateID.Dead);

        ChaseTargetState chaseTarget = new ChaseTargetState(this);

        chaseTarget.AddTransition(TransitionID.LostTarget, StateID.Roaming);
        chaseTarget.AddTransition(TransitionID.StartHurt, StateID.Hurt);
        chaseTarget.AddTransition(TransitionID.InRange, StateID.Attack);
        chaseTarget.AddTransition(TransitionID.Dying, StateID.Dead);

        AttackState attack = new AttackState(this);

        attack.AddTransition(TransitionID.OutRange, StateID.ChasingTarget);
        attack.AddTransition(TransitionID.Dying, StateID.Dead);

        HurtState hurt = new HurtState(this);

        hurt.AddTransition(TransitionID.StopHurt, StateID.ChasingTarget);
        hurt.AddTransition(TransitionID.Dying, StateID.Dead);

        DeadState dead = new DeadState(this);

        dead.AddTransition(TransitionID.Healed, StateID.ChasingTarget);

        fsm = new FSM();
        fsm.AddState(roam);
        fsm.AddState(idle);
        fsm.AddState(chaseTarget);
        fsm.AddState(attack);
        fsm.AddState(hurt);
        fsm.AddState(dead);
    }
Ejemplo n.º 20
0
    private void MakeFSM()
    {
        int i = Random.Range(0, 3);

        mFSM = new FSMSystem();
        if (i == 0)
        {
            PatrolState patrol = new PatrolState(gameObject, mFSM);
            patrol.AddTransition(Transition.CanAttack, StateID.Attack);
            patrol.AddTransition(Transition.SeeTarget, StateID.Chase);

            ChaseState chase = new ChaseState(gameObject, mFSM);
            chase.AddTransition(Transition.CanAttack, StateID.Attack);
            chase.AddTransition(Transition.LostTarget, StateID.Patrol);

            AttackState attack = new AttackState(gameObject, mFSM);
            attack.AddTransition(Transition.LostTarget, StateID.Patrol);
            attack.AddTransition(Transition.SeeTarget, StateID.Chase);

            mFSM.AddState(patrol, chase, attack);
        }
        if (i == 1)
        {
            ChaseState chase = new ChaseState(gameObject, mFSM);
            chase.AddTransition(Transition.CanAttack, StateID.Attack);
            chase.AddTransition(Transition.LostTarget, StateID.Patrol);

            AttackState attack = new AttackState(gameObject, mFSM);
            attack.AddTransition(Transition.LostTarget, StateID.Patrol);
            attack.AddTransition(Transition.SeeTarget, StateID.Chase);

            mFSM.AddState(chase, attack);
        }
        if (i == 2)
        {
            PatrolState patrol = new PatrolState(gameObject, mFSM);
            patrol.AddTransition(Transition.CanAttack, StateID.Attack);
            patrol.AddTransition(Transition.SeeTarget, StateID.Chase);
            AttackState attack = new AttackState(gameObject, mFSM);
            attack.AddTransition(Transition.LostTarget, StateID.Patrol);
            attack.AddTransition(Transition.SeeTarget, StateID.Chase);
            mFSM.AddState(patrol, attack);
        }
    }
Ejemplo n.º 21
0
    void Start()
    {
        Fsm = new FSMSystem();
        ChaseState Chase = new ChaseState(Fsm);

        Chase.AddTransition(Transition.AttackPlayer, StateID.Attack);
        Fsm.AddStateID(Chase);
        AttackState Attack = new AttackState(Fsm);

        Attack.AddTransition(Transition.NoChasePlayer, StateID.Chase);
        Fsm.AddStateID(Attack);
    }
Ejemplo n.º 22
0
    //FSM构建方法
    private void ConstructFSM()
    {
        //存放所有路点
        pointList = GameObject.FindGameObjectsWithTag("PatrolPoint");
        //所有路点的transform
        Transform[] waypoints = new Transform[pointList.Length];
        int         i         = 0;

        foreach (GameObject obj in pointList)
        {
            waypoints[i] = obj.transform;
            i++;
        }
        //描述AI的状态转换图
        PatrolState patrol = new PatrolState(waypoints);

        patrol.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        patrol.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        ChaseState chase = new ChaseState(waypoints);

        chase.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
        chase.AddTransition(Transition.ReachPlayer, FSMStateID.Attacking);
        chase.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        AttackState attack = new AttackState(waypoints);

        attack.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
        attack.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        attack.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        DeadState dead = new DeadState();

        dead.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        AddFSMState(patrol);
        AddFSMState(chase);
        AddFSMState(attack);
        AddFSMState(dead);
    }
Ejemplo n.º 23
0
    private void ConstructFSM()
    {
        IdleState idle = new IdleState();

        idle.AddTransition(Transition.SawPlayer, FSMStateID.Attacking);

        AttackState attack = new AttackState();

        attack.AddTransition(Transition.LostPlayer, FSMStateID.Idling);

        AddFSMState(idle);
        AddFSMState(attack);
    }
Ejemplo n.º 24
0
    private void ConstructFSM()
    {
        PatrolState patrol = new PatrolState(this);

        patrol.AddTransition(Transition.SawPlayer, FSMStateID.Attacking);


        AttackState attack = new AttackState(this);

        attack.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);

        AddFSMState(patrol);
        AddFSMState(attack);
    }
Ejemplo n.º 25
0
    private void makeFSM()
    {
        fsm = new FSMSystem();

        FollowState followState = new FollowState(GameManager.Instance.Player,
                                                  GameManager.Instance.Player.GetComponent <Ship>(), speed, NpcType.Enemy);

        followState.AddTransition(Transition.Follow_Attack, StateID.EnemyAttackStateID);

        attackState = new AttackState(gunTipPosition, Vector3.forward * speed,
                                      Resources.Load("Prefabs/shot_prefab") as GameObject, id);
        attackState.AddTransition(Transition.Attack_Follow, StateID.BotFollowStateID);

        fsm.AddState(followState);
        fsm.AddState(attackState);
    }
    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);
    }
Ejemplo n.º 27
0
    //实例 FSMSystem
    void InitFSM()
    {
        fsm = new FSMSystem();

        //实例 FSMState
        FSMState patrolState = new PatrolState(fsm);
        FSMState chaseState  = new ChaseState(fsm);
        FSMState attackState = new AttackState(fsm);

        //添加状态
        fsm.AddState(patrolState);
        fsm.AddState(chaseState);
        fsm.AddState(attackState);

        //添加转换条件
        //Reason方法所在的状态添加转换条件
        //chaseState.AddTransition(Transition.ClosePalyer, StateID.Attack);  可以转换到攻击状态,因为转换的Reason方法在Chase状态中
        //attackState.AddTransition(Transition.ClosePalyer, StateID.Attack);  不可以转换攻击状态,因为转换的Reason方法在Chase状态中
        patrolState.AddTransition(Transition.SeePlayer, StateID.Chase);
        chaseState.AddTransition(Transition.LostPlayer, StateID.Patrol);
        chaseState.AddTransition(Transition.ClosePalyer, StateID.Attack);
        attackState.AddTransition(Transition.LostPlayer, StateID.Chase);
    }
Ejemplo n.º 28
0
    private void Start()
    {
        fsmManager = new FSMManager <GameObject>();

        StateBase <GameObject> patrolState = new  PatrolState(fsmManager);

        patrolState.AddTransition(Transition.SeeEnemy, StateID.ChaseState);

        StateBase <GameObject> chaseState = new ChaseState(fsmManager);

        chaseState.AddTransition(Transition.LostEnemy, StateID.PatrolState);
        chaseState.AddTransition(Transition.ChaseUpEnemy, StateID.AttackState);

        StateBase <GameObject> attackState = new AttackState(fsmManager);

        attackState.AddTransition(Transition.SeeEnemy, StateID.ChaseState);

        fsmManager.AddState(patrolState);
        fsmManager.AddState(chaseState);
        fsmManager.AddState(attackState);

        fsmManager.InitState(patrolState);
    }
Ejemplo n.º 29
0
    private void ConstructFSM()
    {
        //Get the list of points
        //   pointList = GameObject.FindGameObjectsWithTag("WandarPoint");
        var pointList = gameObject.transform.Cast<Transform>().Where(c => c.gameObject.tag == "WandarPoint").Select(c => c.gameObject).ToArray();

        Transform[] waypoints = new Transform[pointList.Length];
        int i = 0;

        foreach (GameObject obj in pointList)
        {
            obj.GetComponent<Transform>().position = transform.position + new Vector3(Random.onUnitSphere.x * 5,
                                                                 Random.onUnitSphere.y * 5, Random.onUnitSphere.z * 5);
            waypoints[i] = obj.transform;
            //	waypoints[i].position = new Vector3(Random.insideUnitSphere.x * 5,
            //	                                    Random.insideUnitSphere.z * 5, Random.insideUnitSphere.z * 5);

            i++;
        }

        PatrolState patrol = new PatrolState(waypoints);
        patrol.AddTransition(FSMTransition.PlayerSeen, StateID.Chasing);
        patrol.AddTransition(FSMTransition.NoHealth, StateID.Dead);
        patrol.SetStateDistances(chaseStartDist, attackStartDist);
        patrol.SetSpeed(speed / 2, rotationSpeed / 2);
        patrol.SetBounds(patrolBounds.x, patrolBounds.y, patrolBounds.z);

        ChaseState chase = new ChaseState(waypoints);
        chase.AddTransition(FSMTransition.PlayerLost, StateID.Patrolling);
        chase.AddTransition(FSMTransition.PlayerReached, StateID.Attacking);
        chase.AddTransition(FSMTransition.NoHealth, StateID.Dead);
        chase.SetStateDistances(chaseStartDist, attackStartDist);
        chase.SetSpeed(speed, rotationSpeed);

        AttackState attack = new AttackState(waypoints);
        attack.AddTransition(FSMTransition.PlayerLost, StateID.Patrolling);
        attack.AddTransition(FSMTransition.PlayerSeen, StateID.Chasing);
        attack.AddTransition(FSMTransition.NoHealth, StateID.Dead);
        attack.SetStateDistances(chaseStartDist, attackStartDist);
        attack.SetSpeed(speed, rotationSpeed);
        attack.kamikaze = this.kamikaze;

        DeadState dead = new DeadState();
        dead.AddTransition(FSMTransition.NoHealth, StateID.Dead);

        AddFSMState(patrol);
        AddFSMState(chase);
        AddFSMState(attack);
        AddFSMState(dead);

        //Start patrolling at given points
        patrol.FindNextPoint();
    }
Ejemplo n.º 30
0
    private void ConstructFSM()
    {
        pointList = GameObject.FindGameObjectsWithTag("WayPoint");
        //
        //Creating a wapoint transform array for each state
        //
        Transform[] waypoints = new Transform[pointList.Length];
        int         i         = 0;

        foreach (GameObject obj in pointList)
        {
            waypoints[i] = obj.transform;
            i++;
        }
        //
        //Create States
        //
        HideState   hide   = new HideState(waypoints);
        AttackState attack = new AttackState(waypoints);


        //Create the Dead state
        DeadState dead = new DeadState(waypoints);
        //there are no transitions out of the dead state

        PatrolState patrol = new PatrolState(waypoints);
        FleeState   flee   = new FleeState(waypoints);

        //add transitions OUT of the attack state
        attack.AddTransition(Transition.NoHealth, FSMStateID.Dead);
        if (AI1)
        {
            attack.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
            attack.AddTransition(Transition.LowHealth, FSMStateID.Fleeing);
        }

        if (AI2)
        {
            attack.AddTransition(Transition.LostPlayer, FSMStateID.Hiding);
        }

        attack.AddTransition(Transition.LowHealth, FSMStateID.Fleeing);

        //add transitions OUT of the hide state
        hide.AddTransition(Transition.SawPlayer, FSMStateID.Attacking);
        hide.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        //add transitions OUT of the patrol state
        patrol.AddTransition(Transition.SawPlayer, FSMStateID.Attacking);
        patrol.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        //add transitions OUT of the flee state
        if (AI1)
        {
            flee.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
        }
        if (AI2)
        {
            flee.AddTransition(Transition.LostPlayer, FSMStateID.Hiding);
        }
        flee.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        //Add state to the state list
        if (AI1)
        {
            AddFSMState(patrol);
        }

        if (AI2)
        {
            AddFSMState(hide);
        }

        AddFSMState(attack);
        AddFSMState(dead);
    }