Exemple #1
0
        public static NPC MoveInteractService(string service, string lfs)
        {
            NpcDest dest = FindNearestService(service);

            if (dest == null)
            {
                throw new ServiceNotFountException(service);
            }

            // Move to NPC
            // If it failed it throw exception. I know :)
            MoveToDest(dest.Waypoint, lfs, "Moving to NPC: '" + dest.Npc.Name + "'");

            // Interact with NPC and select given service
            LuaHelper.TargetUnitByName(dest.Npc.Name);
            InteractNpc(dest.Npc.Name, false, lfs);

            return(dest.Npc);
        }
Exemple #2
0
        private static NpcDest FindNearestService(string service)
        {
            List <NPC> list        = new List <NPC>();
            int        cid         = ProcessManager.Player.ContinentID;
            string     player_zone = (string)ProcessManager.Player.ZoneText;
            Vector3D   loc         = (Vector3D)ProcessManager.Player.Location.Clone();

            // First check if service local
            try
            {
                ZoneServices local_srv = DataManager.ZoneList[player_zone];

                if (local_srv != null)
                {
                    // Now check if service local
                    list = local_srv.LocalServices[service];
                }
            } catch
            {
                // Its not local service
            }



            if (list == null)
            {
                // Otherwise look the whole list
                foreach (GameObject obj in DataManager.CurWoWVersion.GameObjData.Values)
                {
                    if (obj.ObjType == DataManager.GameObjectTypes.ITEM)
                    {
                        continue;
                    }

                    NPC npc = (NPC)obj;

                    if (npc.Services.ContainsKey(service))
                    {
                        list.Add(npc);
                    }
                }
            }

            if (list.Count == 0)
            {
                return(null);
            }

            // Find closest
            float   dist = float.MaxValue;
            NpcDest res  = null;

            foreach (NPC npc in list)
            {
                // Check if NPC on the same continent/zone
                if (!player_zone.Equals(npc.ZoneText))
                {
                    throw new MultiZoneNotSupportedException();
                }

                res = new NpcDest();

                float d1 = loc.GetDistanceTo(npc.BasePosition);

                if (d1 < dist)
                {
                    res.Init(npc, npc.BasePosition);
                    dist = d1;
                }

                foreach (ZoneWp z in npc.Coordinates.Values)
                {
                    if (!z.Name.Equals(player_zone))
                    {
                        continue;
                    }

                    foreach (Vector3D v in z.List)
                    {
                        // Calculate straight distance to each NPC waypoints
                        float dist1 = loc.GetDistanceTo(v);
                        if (dist1 < dist)
                        {
                            dist = dist1;
                            res.Init(npc, v);
                        }
                    }
                }
            }

            return(res);
        }