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; } }
private void Awake() { aggroState = new AggroState(this); battleState = new BattleState(this); fightState = new FightState(this); reloadState = new ReloadState(this); currentState = battleState; }
public void SetAggro(bool nu) { if (nu) { curState = AggroState.AGGRESSIVE; } else { curState = AggroState.PASSIVE; } }
private void Awake() { agent = GetComponent <aAgent>(); idleState = new IdleState(this); walkState = new WalkState(this); aggroState = new AggroState(this); currentState = idleState; destination = FindObjectOfType <Castle> ().transform; }
/// <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; }
protected void ResetTarget() { this.Creature.Target = null; _aggroState = AggroState.None; CheckForInterrupt(); }
/// <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; }
/// <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; } }