Example #1
0
        protected override void OnDeactivate()
        {
            currentTarget = null;
            if (currentCommand?.Type == CommandTypes.Attack)
            {
                ((Attack)currentCommand).Target = null;
            }

            currentCommand = null;
            hateTable.Clear();
        }
Example #2
0
        private void DoNormal()
        {
            currentTarget = GetCurrentTarget();
            if (currentTarget != null && (npc.DistanceToActor(currentTarget) > 500 || (currentTarget.Status.Dead && !currentTarget.Status.Recovering)))
            {
                hateTable.TryRemove(currentTarget.ActorID, out int removed);
                currentTarget = null;
            }
            if (currentCommand == null)
            {
                if (currentTarget == null)
                {
                    period = 1000;
                    if (!HasVisiblePlayer())
                    {
                        sleepCounter++;
                        if (sleepCounter > 100)
                        {
                            Deactivate();
                            sleepCounter = 0;
                        }
                    }
                    else
                    {
                        sleepCounter = 0;
                    }

                    CheckAggro();
                    if (npc.MoveRange > 0 || (npc.DistanceToPoint(npc.X_Ori, npc.Y_Ori, npc.Z_Ori) > npc.MoveRange && npc.MoveRange > 0))
                    {
                        if (Global.Random.Next(0, 99) < 30)
                        {
                            Vec3 vec            = Vec3.Zero;
                            int  shouldDistance = 75;
                            int  dis            = npc.DistanceToPoint(npc.X_Ori, npc.Y_Ori, npc.Z_Ori);
                            if (dis > npc.MoveRange)
                            {
                                int   deltaX   = npc.X_Ori - npc.X;
                                int   deltaY   = npc.Y_Ori - npc.Y;
                                float distance = (float)(Math.Sqrt(deltaX * deltaX + deltaY * deltaY));
                                vec.X = deltaX / distance;
                                vec.Y = deltaY / distance;
                                if (dis < shouldDistance)
                                {
                                    shouldDistance = dis;
                                }
                            }
                            else
                            {
                                ushort dir = (ushort)Global.Random.Next(0, 359);
                                vec = dir.DirectionToVector();
                            }
                            if (shouldDistance > 15)
                            {
                                vec   *= shouldDistance;
                                vec.X += npc.X;
                                vec.Y += npc.Y;
                                var points = from p in map.HeightMapBuilder.GetZ((short)vec.X, (short)vec.Y)
                                             orderby Math.Abs(npc.Z - p.Key)
                                             select p;

                                currentCommand = new Move(this, npc, (short)vec.X, (short)vec.Y, points.FirstOrDefault().Key);
                            }
                        }
                    }
                }
                else
                {
                    period = 400;
                    if (npc.DistanceToActor(currentTarget) <= GetCurrentCastRange(currentTarget))
                    {
                        currentCommand = new Attack(this, npc, currentTarget);
                    }
                    else
                    {
                        currentCommand = new Chase(this, npc, currentTarget);
                    }
                }
            }
            else
            {
                if (currentTarget == null)
                {
                    CheckAggro();
                }

                currentCommand.Target = currentTarget;
                if (currentCommand.Status == CommandStatus.Running)
                {
                    currentCommand.Update();
                }
                else
                {
                    currentCommand = null;
                }
            }
        }