Exemplo n.º 1
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);
    }
    /// <summary>
    /// Update the aggro state of the obstacle. This method is usually called in
    /// Update(). Default behaviour is to aggro when player gets in AggroRangeEngage,
    /// and fall back to
    /// </summary>
    protected virtual void updateAggro()
    {
        if (!hasAggro)
        {
            return;
        }
        if (this.isDead())
        {
            return;
        }
        switch (this.aggroState)
        {
        case AggroState.Idle:
            if (Vector3.Distance(transform.position, player.transform.position) < this.aggroRangeEngage)
            {
                this.aggroState = AggroState.Aggro;
            }
            break;

        case AggroState.Aggro:
            if (Vector3.Distance(transform.position, player.transform.position) > this.aggroRangeFalloff)
            {
                this.aggroState = AggroState.Idle;
            }
            break;
        }
    }
Exemplo n.º 3
0
    private void Awake()
    {
        aggroState  = new AggroState(this);
        battleState = new BattleState(this);
        fightState  = new FightState(this);
        reloadState = new ReloadState(this);

        currentState = battleState;
    }
Exemplo n.º 4
0
 public void SetAggro(bool nu)
 {
     if (nu)
     {
         curState = AggroState.AGGRESSIVE;
     }
     else
     {
         curState = AggroState.PASSIVE;
     }
 }
Exemplo n.º 5
0
    private void Awake()
    {
        agent = GetComponent <aAgent>();

        idleState  = new IdleState(this);
        walkState  = new WalkState(this);
        aggroState = new AggroState(this);

        currentState = idleState;

        destination = FindObjectOfType <Castle> ().transform;
    }
Exemplo n.º 6
0
        /// <summary>
        /// Sends the notice packet (!) and switches the aggro state to "Notice"
        /// </summary>
        /// <param name="showMark"></param>
        /// <returns></returns>
        protected IEnumerable TryNotice(bool showMark, bool changeStance)
        {
            var inRange = WorldManager.Instance.GetCreaturesInRange(this.Creature, _aggroRange).FindAll(c => c.IsAttackableBy(this.Creature));

            if (inRange.Count != 0)
            {
                // Select mob and aggro
                Creature.Target = inRange[rnd.Next(0, inRange.Count)];

                _aggroState = AggroState.Notice;
                if (showMark)
                {
                    WorldManager.Instance.Broadcast(new MabiPacket(Op.CombatSetTarget, Creature.Id).PutLong(Creature.Target.Id).PutByte(1).PutString(""), SendTargets.Range, this.Creature);
                    Send.Chat(this.Creature, "!");
                }
                if (changeStance)
                {
                    this.Creature.BattleState = 1;
                    Send.ChangesStance(this.Creature);
                }

                CheckForInterrupt();

                yield return true;
            }

            yield return false;
        }
Exemplo n.º 7
0
 protected void ResetTarget()
 {
     this.Creature.Target = null;
     _aggroState = AggroState.None;
     CheckForInterrupt();
 }
Exemplo n.º 8
0
        /// <summary>
        /// Sends the aggro packet (!!) and switches the aggro state to "Aggro". 
        /// </summary>
        /// <returns></returns>
        public IEnumerable Aggro()
        {
            if (Creature.Target == null || Creature.Target.IsDead)
                foreach (var a in TryNotice(false, false))
                    yield return a;

            _aggroState = AggroState.Aggro;
            this.Creature.BattleState = 1;
            Send.ChangesStance(this.Creature);

            WorldManager.Instance.Broadcast(new MabiPacket(Op.CombatSetTarget, Creature.Id).PutLong(Creature.Target.Id).PutByte(2).PutString(""), SendTargets.Range, this.Creature);

            Send.Chat(this.Creature, "!!");

            CheckForInterrupt();

            yield return true;
        }
Exemplo n.º 9
0
 /// <summary>
 /// Update the aggro state of the obstacle. This method is usually called in 
 /// Update(). Default behaviour is to aggro when player gets in AggroRangeEngage, 
 /// and fall back to 
 /// </summary>
 protected virtual void updateAggro()
 {
     if (!hasAggro) return;
     if (this.isDead()) return;
     switch (this.aggroState)
     {
         case AggroState.Idle:
             if(Vector3.Distance(transform.position, player.transform.position) < this.aggroRangeEngage)
             {
                 this.aggroState = AggroState.Aggro;
             }
             break;
         case AggroState.Aggro:
             if (Vector3.Distance(transform.position, player.transform.position) > this.aggroRangeFalloff)
             {
                 this.aggroState = AggroState.Idle;
             }
             break;
     }
 }