Beispiel #1
0
        /// <summary>
        ///  进入站立状态,当前的玩家显示掷筛子
        /// </summary>
        /// <param name="e"></param>
        /// <param name="lastState"></param>
        public override void Enter(Event e, FSM.State lastState)
        {
            _controller = UIControllerManager.Instance.GetController <UIBattleController>();

            if (_Content.CurrentPlayerIndex != 0)
            {
                if (null != _controller)
                {
                    _controller.ShowCraps(false);
                }

                if (GameModel.GetInstance.isPlayNet == false)
                {
                    BattleController.Instance.Send_RequestRoll();
                }
            }
            else
            {
                if (null != _controller)
                {
                    _controller.ShowCraps(true);
                }
            }
            //每次进入这个接口就开始转换人物角色
            Console.WriteLine("lalalalla----换人啦");
            var args = new GameEventRoleTurnChanged(_Content.CurrentPlayerIndex);

            GameEventManager.Instance.FireEvent(args);
        }
Beispiel #2
0
 public Station(string theName, FSM.State theState, float theSpeed)
 {
     name  = theName;
     state = theState;
     speed = theSpeed;
     queue = new Queue <Capsule>();
 }
Beispiel #3
0
    void Transition(FSM.Trigger trigger)
    {
        switch (currentState)
        {
        case FSM.State.Patrol:
            if (trigger == FSM.Trigger.EnemySighted)
            {
                // Enemy sighted, transition to chase mode
                currentState = FSM.State.Chase;
            }
            break;

        case FSM.State.Chase:
            if (trigger == FSM.Trigger.EnemyDisappeared)
            {
                // Enemy disappeared, transition to return mode
                currentState = FSM.State.Return;
            }
            break;

        case FSM.State.Return:
            if (trigger == FSM.Trigger.ReachedBase)
            {
                // Reached base, transition to patrol mode
                currentState = FSM.State.Patrol;
            }
            else if (trigger == FSM.Trigger.EnemySighted)
            {
                // Eneemy sighted, transition to chase mode
                currentState = FSM.State.Chase;
            }
            break;
        }
        ;
    }
Beispiel #4
0
    Dictionary <int, FSM.State> LoadStates(IEnumerable states, Coord size)
    {
        Dictionary <int, FSM.State> statesContainer = new Dictionary <int, FSM.State>();

        //Carrega o dicionário de estados
        foreach (XElement stateData in states)
        {
            int    stateId   = (int)stateData.Attribute("id");
            string stateName = (string)stateData.Attribute("name");

            FSM.State stateCaster = new FSM.State(stateId, stateName, size);
            if ((string)stateData.Attribute("accepting") == "true")
            {
                stateCaster.marked = true;
            }


            if ((string)stateData.Attribute("initial") == "true")
            {
                initialState = stateCaster;
            }


            statesContainer.Add(stateId, stateCaster);
        }

        return(statesContainer);
    }
Beispiel #5
0
    public void SpawnCapsule(FSM.State state, string stateOfMatter)
    {
        GameObject parent      = Instantiate(goldenCapsule);
        Material   theMaterial = null;

        switch (stateOfMatter)
        {
        case "solid":
            theMaterial = solidCapsuleMaterial;
            break;

        case "liquid":
            theMaterial = liquidCapsuleMaterial;
            break;

        case "gas":
            theMaterial = gasCapsuleMaterial;
            break;

        default:
            Debug.Log("Material not found for " + stateOfMatter + " (SpawnCapsule)");
            break;
        }

        Capsule theCapsule = new Capsule(Instantiate(goldenCapsule, parent.transform), state, stateOfMatter, theMaterial);

        theCapsule.capsuleObject.transform.SetPositionAndRotation(theCapsule.capsuleObject.transform.position, Quaternion.Euler(new Vector3(90f, 0, 0)));
        theFSM.activeCapsules.Add(theCapsule);
    }
Beispiel #6
0
        /// <summary>
        ///  进入状态,开始游戏
        /// </summary>
        /// <param name="e"></param>
        /// <param name="lastState"></param>
        public override void Enter(Event e, FSM.State lastState)
        {
            var control = Client.UIControllerManager.Instance.GetController <Client.UI.UIBattleController>();

            control.setVisible(true);
            VirtualServer.Instance.Handle_RequestBuildRoom(133);
            SceneManager.Instance.Send_RequestEnterScene(0, null);
        }
Beispiel #7
0
 public override void Enter(Event e, FSM.State lastState)
 {
     //玩家在规定时间内,没有摇出骰子,视为放弃
     //放弃后,下名玩家 进入StayState
     //服务器通知玩家可以要骰子了
     Console.WriteLine("某玩家放弃了 玩家index = {0}", _Content.CurrentPlayerIndex);
     //告知所有玩家,新玩家开始,玩家可以摇骰子
 }
Beispiel #8
0
            public override void Transform(FSM.State input, Place output, ITransformationContext context)
            {
                var colored = output as ColoredPlace;

                if (colored != null && input.IsStartState)
                {
                    colored.Tokens.Add(context.Bag.DefaultColor, 1);
                }
            }
Beispiel #9
0
        public override void Enter(Event e, FSM.State lastState)
        {
            if (GameModel.GetInstance.isPlayNet == true)
            {
                for (var i = 0; i < Client.PlayerManager.Instance.Players.Length; i++)
                {
                    if (GameModel.GetInstance.NetCurrentPlayerId == Client.PlayerManager.Instance.Players [i].playerID)
                    {
//						Console.Error.WriteLine ("玩家的Id--------"+GameModel.GetInstance.NetCurrentPlayerId);
                        _Content.CurrentPlayerIndex = i;
                        break;
                    }
                }
            }

//			Console.Error.WriteLine ("站立状态下房间的索引值是:-------"+_Content.CurrentPlayerIndex.ToString());

            if (GameModel.GetInstance.isPlayNet == false)
            {
                _Content.CurrentPlayerIndex++;
            }

            //_Content.CurrentPlayerIndex++;
            Console.WriteLine("Enter StayState index = {0}", _Content.CurrentPlayerIndex);

            var tmpPlayers = Client.PlayerManager.Instance.Players;

            //var tmpLen = _Content.players.Length;
            if (null != tmpPlayers)
            {
                if (tmpPlayers[_Content.CurrentPlayerIndex].isEmployment == false)
                {
                    tmpPlayers [_Content.CurrentPlayerIndex].isEmployment = true;
                    _Content.CurrentPlayerIndex++;
                }
            }

            if (GameModel.GetInstance.isPlayNet == true)
            {
                //if (tmpPlayers [_Content.CurrentPlayerIndex].isNetOnline == false ||tmpPlayers [_Content.CurrentPlayerIndex].isReconectGame==true)
                //{
                //	_Content.CurrentPlayerIndex++;
                //	if (tmpPlayers [_Content.CurrentPlayerIndex].isNetOnline == false||tmpPlayers [_Content.CurrentPlayerIndex].isReconectGame==true)
                //	{
                //		_Content.CurrentPlayerIndex++;
                //		if (tmpPlayers [_Content.CurrentPlayerIndex].isNetOnline == false||tmpPlayers [_Content.CurrentPlayerIndex].isReconectGame==true)
                //		{
                //			_Content.CurrentPlayerIndex++;
                //		}
                //	}
                //}
            }

            _timer = new Counter(VirtualServer.Instance.StayStateTime);
            VirtualServer.Instance.Send_NewStayState(_Content.CurrentPlayerIndex);
        }
Beispiel #10
0
        /// <summary>
        /// 进入状态,获取卡牌id,显示卡牌
        /// </summary>
        /// <param name="e"></param>
        /// <param name="lastState"></param>
        public override void Enter(Event e, FSM.State lastState)
        {
            var info = e as SelectEvent;

            _cardID = info.cardID;

            //测试股票
//			var i = new Random ();
//			var cad= i.Next (0, 26);	20003
//			if (PlayerManager.Instance.IsHostPlayerTurn () == true)
//			{
//				_cardID =20001 ;

//				Count++;
//
//				if (Count >= (int)SpecialCardType.InnerHealthType)
//				{
//					Count= (int)SpecialCardType.InnerHealthType;
//				}
//
//				_cardID =Count;
//
//			}
//			else
//			{
//				_cardID =50001;
//			}

//			Count++;
//
//			if (Count < 5)
//			{
//				_cardID =20001 ;
//			}
//			else
//			{
//				_cardID =50001;
//				if (Count > 8)
//				{
//					Count = 0;
//				}
//			}
//			var value = MathUtility.Random (50001, 50032);
//			_cardID = (int)SpecialCardType.GiveChildType;
            if (GameModel.GetInstance.isPlayNet == false)            //不联网或者是机器人玩
            {
                //_cardID = (int)SpecialCardType.GiveChildType;
                CardManager.Instance.OpenCard(_cardID);
            }
            else
            {
                CardManager.Instance.OpenCard((int)GameModel.GetInstance.ShowCardType);
            }
        }
Beispiel #11
0
    public WaitState(float duration = 1.0f, FSM.State nextState = null)
    {
        this.OnUpdate = UpdateWaitState;
        this.Duration = duration;

        if (nextState == null)
        {
            nextState = this;
        }

        this.NextState = nextState;
    }
 protected override FSM BuildStateMachine()
 {
     STATE_MOVING = new FSM.State(OnMovingUpdate, OnMovingEnter)
     {
         Name = "Moving"
     };
     STATE_TURNING = new WaitState(TurnTime, STATE_MOVING)
     {
         Name = "Turning", OnExit = OnTurningExit
     };
     return(new FSM(STATE_MOVING));
 }
Beispiel #13
0
        public override void Enter(Event e, FSM.State lastState)
        {
            //  Console.WriteLine("Enter UpGradeState");

            if (_Content.players[_Content.CurrentPlayerIndex].Level == PlayerLevel.Inner)
            {
                VirtualServer.Instance.Send_NewSuccessState();
            }
            else
            {
                VirtualServer.Instance.Send_NewUpGradeState();
            }
        }
    public TransitionCamera()
    {
        STATE_FOLLOWING = new FSM.State(OnFollowing)
        {
            Name = "Following"
        };
        STATE_TRANSITIONING = new FSM.State(OnTransitioning, OnTransitionStart, OnTransitionCompleted)
        {
            Name = "Transitioning"
        };

        behavior = new FSM(STATE_FOLLOWING);
    }
Beispiel #15
0
        /// <summary>
        /// 进入状态,获取卡牌id,显示卡牌
        /// </summary>
        /// <param name="e"></param>
        /// <param name="lastState"></param>
        public override void Enter(Event e, FSM.State lastState)
        {
            var info = e as SelectEvent;

            _cardID = info.cardID;

            //测试股票
            //			var i = new Random ();
            //			var cad= i.Next (0, 26);	20003
            //			if (PlayerManager.Instance.IsHostPlayerTurn () == true)
            //			{
            //				_cardID =20001 ;
            //				Count++;
            //				if (Count >= (int)SpecialCardType.InnerHealthType)
            //				{
            //					Count= (int)SpecialCardType.InnerHealthType;
            //				}
            //				_cardID =Count;
            //			}
            //			else
            //			{
            //				_cardID =50001;
            //			}
            //			Count++;
            //			if (Count < 5)
            //			{
            //				_cardID =20001 ;
            //			}
            //			else
            //			{
            //				_cardID =50001;
            //				if (Count > 8)
            //				{
            //					Count = 0;
            //				}
            //			}
            if (GameModel.GetInstance.isPlayNet == false)//单人模式
            {
                //_cardID = (int)SpecialCardType.InnerStudyType;
                //if(PlayerManager.Instance.IsHostPlayerTurn())
                //_cardID = 30021;

                Console.Warning.WriteLine("当前单人模式,卡牌ID:" + _cardID.ToString());
                CardManager.Instance.OpenCard(_cardID);
            }
            else            //联网模式
            {
                Console.WriteLine("当前联网模式,卡牌的类型:" + GameModel.GetInstance.ShowCardType);
                CardManager.Instance.OpenCard((int)GameModel.GetInstance.ShowCardType);
            }
        }
Beispiel #16
0
    private void Start()
    {
        FSMUpdater.Create();
        machine = new FSM(this);

        stateA = (pFSM, owner) => {
            Debug.Log("StateA");
        };

        stateB = (pFSM, owner) => {
            Debug.Log("StateB");
        };
        machine.PushState(stateA);
    }
Beispiel #17
0
    public bool RandomSpawn(FSM.State theState, string theStateOfMatter)
    {
        bool  spawned = false;
        float convertedSpawnFrequency = spawnFrequency * 0.001f;

        // 1 = 0.1% chance of spawning

        float randomNumber = Random.Range(0.000f, 1.000f);

        if (randomNumber < convertedSpawnFrequency)
        {
            SpawnCapsule(theState, theStateOfMatter);
            spawned = true;
        }
        return(spawned);
    }
Beispiel #18
0
        public override void Enter(Event e, FSM.State lastState)
        {
            var player     = _Content.players[_Content.CurrentPlayerIndex];
            var level      = player.Level;
            var pointCount = _PointsCount(level);

            player.CurrentPos = (player.CurrentPos + player.RollPoints) % pointCount;

            var actionName = _GetActionName(level, player.CurrentPos);

            _action = ActionFactory.Instance.Create(actionName, player);
            _action.Start();

            Console.WriteLine("currentPos : " + player.CurrentPos + " actionName :" + actionName);

            _timer = new Counter(VirtualServer.Instance.SelectStateTime);
            Console.WriteLine("Enter SelectState");
        }
Beispiel #19
0
    protected override FSM BuildStateMachine()
    {
        STATE_MOVING = new FSM.State(OnMovingUpdate)
        {
            Name = "Moving", OnExit = StopCar
        };
        STATE_AIMING = new TimedState(3.0f, OnAimUpdate)
        {
            Name    = "Aiming",
            OnEnter = StartAiming
        };
        STATE_SHOOTING = new WaitState(2, STATE_MOVING)
        {
            Name = "Shooting", OnEnter = Shoot, OnExit = SelectRandomDirection
        };

        return(new FSM(STATE_NO_ACTION));
    }
    public override void _Ready()
    {
        cannon             = GetNode <Position2D>("Cannon");
        animationPlayer    = GetNode <AnimationPlayer>("AnimationPlayer");
        bulletCaseParticle = GetNode <CPUParticles2D>("BulletCaseParticle");
        shootSound         = GetNode <AudioStreamPlayer2D>("ShootAudioPlayer");


        STATE_READY = new FSM.State(WeaponReadyUpdate)
        {
            Name = "Ready"
        };
        STATE_TIMEOUT = new WaitState(TimeoutDuration, STATE_READY)
        {
            Name = "Reloading"
        };
        machine = new FSM(STATE_READY);
    }
Beispiel #21
0
        void CreateMovingState()
        {
            mMovingState = (pFSM, pGameObject) => {
                Action _action = mPlan.Peek();
                if (_action.target == null)
                {
                    mActor.OnMovingFailed(_action);
                    mStateMachine.PopAndPush(mIdleState);
                    return;
                }

                if (mActor.MoveAgent(_action))
                {
                    mActor.OnMovingFinished(_action);
                    mStateMachine.PopState();
                }
            };
        }
Beispiel #22
0
    public Capsule(GameObject theCapsuleObject, FSM.State theCurrentState, string theStateOfMatter, Material theMaterial, string theGUID = "null")
    {
        capsuleObject = theCapsuleObject;
        currentState  = theCurrentState;
        stateOfMatter = theStateOfMatter;

        theCapsuleObject.GetComponent <MeshRenderer>().material = theMaterial;
        material = theMaterial;

        capsuleGUID = "Capsule-" + System.Guid.NewGuid().ToString().Split('-')[0];

        inProlog = true;
        inMain   = false;
        inEpilog = false;

        timer = 0f;

        inQueue = false;
    }
Beispiel #23
0
    protected override FSM BuildStateMachine()
    {
        STATE_IDLE = new FSM.State(OnIdleUpdate, OnIdleStart)
        {
            Name = "Idle"
        };
        STATE_RUN = new FSM.State(OnRunUpdate, OnRunStart, OnRunEnd)
        {
            Name = "Run"
        };
        STATE_JUMP = new FSM.State(OnJumpUpdate, OnJumpStart, OnJumpEnded)
        {
            Name = "Jump"
        };
        STATE_FALL = new FSM.State(OnFallUpdate, OnFallStart, OnFallEnd)
        {
            Name = "Fall"
        };
        STATE_HURT = new TimedState(HitDuration, OnHurtUpdate)
        {
            Name    = "Hurt",
            OnEnter = OnHurtEnter,
            OnExit  = OnHurtExit
        };

        STATE_DASH = new FSM.State(OnDashUpdate, OnDashStart, OnDashEnded)
        {
            Name = "Dash"
        };

        STATE_VULNERABLE      = new FSM.State();
        STATE_HURT_INVINCIBLE = new WaitState(HitInvencibility, STATE_VULNERABLE)
        {
            Name    = "Hurt_Invincible",
            OnEnter = OnHurtInvincibleEnter,
            OnExit  = OnHurtInvincibleExit
        };

        invencibilityMachine = new FSM(STATE_VULNERABLE);

        return(new FSM(STATE_IDLE));
    }
Beispiel #24
0
    // Use this for initialization
    void Start()
    {
        mFSM = new FSM();
        FSM.State state = mFSM.AddState("A");
        state.SetEnterMethod(delegate() { Debug.Log("Enter A " + a); });
        state.SetTickMethod(delegate(float dt) { });
        state.SetExitMethod(delegate() { Debug.Log("Exit A " + a); });

        state = mFSM.AddState("B");
        state.SetEnterMethod(delegate() { Debug.Log("Enter B" + a); });
        state.SetTickMethod(delegate(float dt) { });
        state.SetExitMethod(delegate() { Debug.Log("Exit B " + a); });

        mFSM.addTransition("A", "B", "!(A2B1 & (A2B1 | A2B2)) & !OK");
        mFSM.addTransition("B", "A", "(B2A | B2A)");

        mFSM.Begin();

        InvokeRepeating("Test", 3.0f, 6.0f);
    }
Beispiel #25
0
        // Agent States
        // The agent only has three states:
        // Idle : During which the agent is looking for something to do
        // Moving : When the agent is travelling to a location where the next action can be executed
        // Perform : When the agent is actually performing the action
        void CreateIdleState()
        {
            mIdleState = (pFSM, pGameObject) => {
                var _currentState = mActor.GetCurrentState();
                var _goalState    = mActor.GetGoalState();

                Plan _plan = mPlanner.CreatePlan(this, mAvailableActions, _currentState, _goalState);
                if (_plan != null)
                {
                    mPlan = _plan;
                    mActor.OnPlanFound(_goalState, _plan);

                    mStateMachine.PopAndPush(mPerformState);
                }
                else
                {
                    mActor.OnPlanFailed(_goalState);
                    mStateMachine.PopAndPush(mIdleState);
                }
            };
        }
Beispiel #26
0
    void Start()
    {
        navMeshAgent = GetComponent <NavMeshAgent> ();

        // Set default state to patrol
        currentState = FSM.State.Patrol;

        // Set index to default
        nextWaypoint = 0;

        // Sanity check
        if (waypointList.Length == 0)
        {
            Debug.Log("ERROR: the waypoint list is empty. Check to see if waypoints were added via Unity inspector.");
            return;
        }

        if (playerMovement == null)
        {
            playerMovement = GetComponent <PlayerMovement>();
        }
    }
Beispiel #27
0
    void SwitchState(FSM.State newState)
    {
        currentState = newState;
        switch (currentState)
        {
        case FSM.State.Patrol:
            agentLight.color = Color.white;
            break;

        case FSM.State.Chase:
            agentLight.color = Color.red;
            break;

        case FSM.State.Return:
            agentLight.color = Color.white;
            break;

        case FSM.State.Pacified:
            agentLight.color = Color.magenta;
            break;
        }
        ;
    }
Beispiel #28
0
        void CreatePerformState()
        {
            mPerformState = (pFSM, pGameObject) => {
                Action _action = mPlan.Peek();

                if (_action.IsDone())
                {
                    mActor.OnActionFinished(_action);
                    mPlan.Dequeue();

                    if (!HasActionPlan())
                    {
                        mStateMachine.PopAndPush(mIdleState);
                        mActor.OnActionsFinished();
                        return;
                    }
                }

                _action = mPlan.Peek();
                bool inRange = _action.IsRanged() ? _action.IsInRange() : true;

                if (inRange)
                {
                    bool success = _action.Perform(gameObject);

                    if (!success)
                    {
                        mStateMachine.PopAndPush(mIdleState);
                        mActor.OnActionFailed(_action);
                    }
                }
                else
                {
                    mStateMachine.PushState(mMovingState);
                }
            };
        }
    private void PlanAction(int steps = 5, int tries = 5)
    {
        List <FSM.Event> eventPlan = new List <FSM.Event>();
        int maxScore = -1;

        for (int i = 0; i < tries; i++)
        {
            FSM.State        imaginaryState = supervisorio.currentState;
            List <FSM.Event> tryPlan        = new List <FSM.Event>();

            for (int j = 0; j < steps; j++)
            {
                //print(i + "" + j + " Started--- "+ imaginaryState);
                List <FSM.Event> feasible = supervisorio.FeasibleEvents(imaginaryState, true);

                if (feasible.Count > 0)
                {
                    FSM.Event tryEvent = feasible[UnityEngine.Random.Range(0, feasible.Count)];
                    //print(i + "" + j + " Did--- " + tryEvent);

                    tryPlan.Add(tryEvent);

                    imaginaryState = supervisorio.ImagineEvent(tryEvent, imaginaryState);
                    //print(i + "" + j + " Ended--- " + imaginaryState);
                }
            }

            if (EvaluatePlan(tryPlan, steps) > maxScore)
            {
                maxScore  = EvaluatePlan(tryPlan, steps);
                eventPlan = tryPlan;
            }
        }
        //print("Score: " + maxScore);
        myPlan = eventPlan;
    }
Beispiel #30
0
 protected override void _OnExit(Event e, FSM.State nextState)
 {
 }
    // ------------------------------------------------------------------ 
    // Desc: 
    // ------------------------------------------------------------------ 

    void InitFSM () {

        // ======================================================== 
        // setup states
        // ======================================================== 

        // idle
        FSM.State state_idle = new FSM.State( "Idle", 
                                              new Action_OnIdle(this), 
                                              new Action_RandomAnim(4.0f, 4.0f, this.anim, new string[]{"idle1","idle2"} ),
                                              null );
        // seekPlayers
        FSM.State state_seekPlayers = new FSM.State( "SeekPlayers", 
                                                     new Action_PlayAnim(this.anim,"moveForward"), 
                                                     new Action_MoveToNearestAlivedPlayer(0.5f,this), 
                                                     new Action_StopMoving(this) );
        // attack
        FSM.State state_attack = new FSM.State( "Attack", 
                                                new Action_Attack(this.anim), 
                                                null,
                                                null );
        // get hit
        FSM.State state_onStun = new FSM.State( "OnStun", 
                                               new Action_ActOnStun(this), 
                                               null,
                                               null );
        // on dead
        FSM.State state_onDead = new FSM.State( "OnDead",
                                                new Action_ActOnDead(this), 
                                                null, // TODO: dead clean up
                                                null );
        // dead
        FSM.State state_dead = new FSM.State( "Dead",
                                              new Action_CleanDeadBody(this.gameObject), 
                                              null,
                                              null );

        // ======================================================== 
        // condition 
        // ======================================================== 

        FSM.Condition cond_isPlayerInAttackRange = new Condition_isPlayerInAttackRange(this,30.0f,this.attackDistance);
        FSM.Condition cond_isAttacking = new Condition_isAttacking(this);
        FSM.Condition cond_isOnStun = new Condition_isOnStun(this);
        FSM.Condition cond_noHP = new Condition_noHP(this.zombieInfo);
        // TODO: FSM.Condition cond_isStunning = new Condition_isStunning(this);

        // ======================================================== 
        // setup transitions
        // ======================================================== 

        // idle to ...
        state_idle.AddTransition( new FSM.Transition( state_onDead,
                                                      cond_noHP,
                                                      null ) );
        state_idle.AddTransition( new FSM.Transition( state_onStun,
                                                      cond_isOnStun,
                                                      null ) );
        state_idle.AddTransition( new FSM.Transition( state_seekPlayers, 
                                                      new Condition_playerInRange( this.transform, 20.0f ), 
                                                      null ) );

        // seekPlayers to ...
        state_seekPlayers.AddTransition( new FSM.Transition( state_onDead,
                                                             cond_noHP,
                                                             null ) );
        state_seekPlayers.AddTransition( new FSM.Transition( state_onStun,
                                                             cond_isOnStun,
                                                             null ) );
        state_seekPlayers.AddTransition( new FSM.Transition( state_attack,
                                                             cond_isPlayerInAttackRange,
                                                             null ) );
        state_seekPlayers.AddTransition( new FSM.Transition( state_idle, 
                                                             new FSM.Condition_not( new Condition_playerInRange( this.transform, 40.0f ) ) , 
                                                             null ) );
        // attack to ...
        state_attack.AddTransition( new FSM.Transition( state_onDead,
                                                        cond_noHP,
                                                        null ) );
        state_attack.AddTransition( new FSM.Transition( state_onStun,
                                                        cond_isOnStun,
                                                        null ) );
        state_attack.AddTransition( new FSM.Transition ( state_idle, 
                                                         new FSM.Condition_not(cond_isAttacking),
                                                         null ) );
        // on hit to ...
        state_onStun.AddTransition( new FSM.Transition( state_onDead,
                                                       cond_noHP,
                                                       null ) );
        state_onStun.AddTransition( new FSM.Transition ( state_idle, 
                                                        new FSM.Condition_not(new Condition_isStunning(this) ),
                                                        null ) );
        state_onStun.AddTransition( new FSM.Transition ( state_onStun, 
                                                         cond_isOnStun,
                                                         null ) );

        // on dead to ...
        state_onDead.AddTransition( new FSM.Transition( state_dead,
                                                        new FSM.Condition_waitForSeconds(this.deadBodyKeepTime),
                                                        null ) );

        // init fsm
        fsm.init(state_idle);
    }
Beispiel #32
0
    // ------------------------------------------------------------------ 
    // Desc: 
    // ------------------------------------------------------------------ 

    void InitFSM () {

        FSM.Condition cond_isPlayerInAttackRange = new Condition_isPlayerInAttackRange(this,60.0f,1.5f);
        FSM.Condition cond_isAttacking = new Condition_isAttacking(this);
        FSM.Condition cond_noHP = new Condition_noHP(this.zombieInfo);

        // ======================================================== 
        // setup states
        // ======================================================== 

        // seekPlayers
        FSM.State state_seekPlayers = new FSM.State( "SeekPlayers", 
                                                     new Action_PlayAnim(this.anim,"walk"), 
                                                     new Action_MoveToNearestAlivedPlayer(0.01f,this), 
                                                     new Action_StopMoving(this) );
        // attack
        FSM.State state_attack = new FSM.State( "Attack", 
                                                new Action_Attack(this), 
                                                null,
                                                null );
        // dead
        FSM.State state_dead = new FSM.State( "Dead",
                                              new Action_ActOnDead(this), 
                                              null,
                                              null );

        // ======================================================== 
        // setup transitions
        // ======================================================== 

        // seek to ...
        state_seekPlayers.AddTransition( new FSM.Transition( state_dead,
                                                             cond_noHP,
                                                             null ) );
        state_seekPlayers.AddTransition( new FSM.Transition( state_attack,
                                                             cond_isPlayerInAttackRange,
                                                             null ) );
        // attack to ...
        state_attack.AddTransition( new FSM.Transition( state_dead,
                                                        cond_noHP,
                                                        null ) );
        state_attack.AddTransition( new FSM.Transition( state_seekPlayers,
                                                        new FSM.Condition_not(cond_isAttacking),
                                                        null ) );

        //
        fsm.init(state_seekPlayers);
    }