public IEnumerable <T> GetNearFriends <T>(Vector3 position, int distance) where T : WowUnit => WowObjects.OfType <T>() .Where(e => e.Guid != PlayerGuid && !e.IsDead && !e.IsNotAttackable && WowInterface.HookManager.GetUnitReaction(Player, e) == WowUnitReaction.Friendly && e.Position.GetDistance(position) < distance);
public void UpdateObject(WowObjectType wowObjectType, IntPtr baseAddress) { WowObjects.RemoveAll(e => e.BaseAddress == baseAddress); switch (wowObjectType) { case WowObjectType.Gameobject: WowObjects.Add(ReadWowGameobject(baseAddress, wowObjectType)); break; case WowObjectType.Dynobject: WowObjects.Add(ReadWowDynobject(baseAddress, wowObjectType)); break; case WowObjectType.Unit: WowObjects.Add(ReadWowUnit(baseAddress, wowObjectType)); break; case WowObjectType.Player: WowObjects.Add(ReadWowPlayer(baseAddress, wowObjectType)); break; default: WowObjects.Add(ReadWowObject(baseAddress, wowObjectType)); break; } }
private void CachePois() { IEnumerable <WowGameobject> wowGameobjects = wowObjects.OfType <WowGameobject>(); IEnumerable <WowUnit> wowUnits = wowObjects.OfType <WowUnit>(); // Remember Ore/Herb positions for farming foreach (WowGameobject gameobject in wowGameobjects.Where(e => Enum.IsDefined(typeof(OreNode), e.DisplayId))) { WowInterface.Db.CacheOre(MapId, (OreNode)gameobject.DisplayId, gameobject.Position); } foreach (WowGameobject gameobject in wowGameobjects.Where(e => Enum.IsDefined(typeof(HerbNode), e.DisplayId))) { WowInterface.Db.CacheHerb(MapId, (HerbNode)gameobject.DisplayId, gameobject.Position); } // Remember Mailboxes foreach (WowGameobject gameobject in wowGameobjects.Where(e => e.GameobjectType == WowGameobjectType.Mailbox)) { WowInterface.Db.CachePoi(MapId, PoiType.Mailbox, gameobject.Position); } // Remember Auctioneers foreach (WowUnit unit in wowUnits.Where(e => e.IsAuctioneer)) { WowInterface.Db.CachePoi(MapId, PoiType.Auctioneer, unit.Position); } // Remember Fishingspots and places where people fished at foreach (WowGameobject gameobject in wowGameobjects.Where(e => e.GameobjectType == WowGameobjectType.FishingHole || e.GameobjectType == WowGameobjectType.FishingBobber)) { WowUnit originUnit = WowObjects.OfType <WowUnit>().FirstOrDefault(e => e.Guid == gameobject.CreatedBy); // dont cache positions too close to eachother if (originUnit != null && !WowInterface.Db.TryGetPointsOfInterest(MapId, PoiType.FishingSpot, originUnit.Position, 5.0, out IEnumerable <Vector3> pois)) { WowInterface.Db.CachePoi(MapId, PoiType.FishingSpot, originUnit.Position); } } // Remember Vendors foreach (WowUnit unit in wowUnits.Where(e => e.IsVendor)) { WowInterface.Db.CachePoi(MapId, PoiType.Vendor, unit.Position); } // Remember Repair Vendors foreach (WowUnit unit in wowUnits.Where(e => e.IsRepairVendor)) { WowInterface.Db.CachePoi(MapId, PoiType.Repair, unit.Position); } }
public T GetWowObjectByGuid <T>(ulong guid) where T : WowObject => WowObjects.OfType <T>().FirstOrDefault(e => e.Guid == guid);
public WowObject GetWowObjectByGuid(ulong guid) => WowObjects.FirstOrDefault(e => e.Guid == guid);
public void UpdateWowObjects() { IsWorldLoaded = UpdateGlobalVar <int>(WowInterface.OffsetList.IsWorldLoaded) == 1; if (!IsWorldLoaded) { return; } PlayerGuid = UpdateGlobalVar <ulong>(WowInterface.OffsetList.PlayerGuid); TargetGuid = UpdateGlobalVar <ulong>(WowInterface.OffsetList.TargetGuid); LastTargetGuid = UpdateGlobalVar <ulong>(WowInterface.OffsetList.LastTargetGuid); PetGuid = UpdateGlobalVar <ulong>(WowInterface.OffsetList.PetGuid); PlayerBase = UpdateGlobalVar <IntPtr>(WowInterface.OffsetList.PlayerBase); MapId = UpdateGlobalVar <MapId>(WowInterface.OffsetList.MapId); ZoneId = UpdateGlobalVar <int>(WowInterface.OffsetList.ZoneId); if (WowInterface.XMemory.Read(WowInterface.OffsetList.ZoneText, out IntPtr zoneNamePointer)) { ZoneName = UpdateGlobalVarString(zoneNamePointer); } if (WowInterface.XMemory.Read(WowInterface.OffsetList.ZoneSubText, out IntPtr zoneSubNamePointer)) { ZoneSubName = UpdateGlobalVarString(zoneSubNamePointer); } GameState = UpdateGlobalVarString(WowInterface.OffsetList.GameState); WowObjects.Clear(); // get the current objectmanager // TODO: maybe cache it WowInterface.XMemory.Read(WowInterface.OffsetList.ClientConnection, out IntPtr clientConnection); WowInterface.XMemory.Read(IntPtr.Add(clientConnection, WowInterface.OffsetList.CurrentObjectManager.ToInt32()), out IntPtr currentObjectManager); // read the first object WowInterface.XMemory.Read(IntPtr.Add(currentObjectManager, WowInterface.OffsetList.FirstObject.ToInt32()), out IntPtr activeObjectBaseAddress); WowInterface.XMemory.Read(IntPtr.Add(activeObjectBaseAddress, WowInterface.OffsetList.WowObjectType.ToInt32()), out int activeObjectType); while (IsWorldLoaded && (activeObjectType <= 7 && activeObjectType > 0)) { WowObjectType wowObjectType = (WowObjectType)activeObjectType; WowObject obj = wowObjectType switch { WowObjectType.Container => ReadWowContainer(activeObjectBaseAddress, wowObjectType), WowObjectType.Corpse => ReadWowCorpse(activeObjectBaseAddress, wowObjectType), WowObjectType.Item => ReadWowItem(activeObjectBaseAddress, wowObjectType), WowObjectType.Dynobject => ReadWowDynobject(activeObjectBaseAddress, wowObjectType), WowObjectType.Gameobject => ReadWowGameobject(activeObjectBaseAddress, wowObjectType), WowObjectType.Player => ReadWowPlayer(activeObjectBaseAddress, wowObjectType), WowObjectType.Unit => ReadWowUnit(activeObjectBaseAddress, wowObjectType), _ => ReadWowObject(activeObjectBaseAddress, wowObjectType), }; if (obj != null) { WowObjects.Add(obj); // set the global unit properties if a guid matches it if (obj.Guid == TargetGuid) { Target = (WowUnit)obj; } if (obj.Guid == PetGuid) { Pet = (WowUnit)obj; } if (obj.Guid == LastTargetGuid) { LastTarget = (WowUnit)obj; } } WowInterface.XMemory.Read(IntPtr.Add(activeObjectBaseAddress, WowInterface.OffsetList.NextObject.ToInt32()), out activeObjectBaseAddress); WowInterface.XMemory.Read(IntPtr.Add(activeObjectBaseAddress, WowInterface.OffsetList.WowObjectType.ToInt32()), out activeObjectType); } // read the party/raid leaders guid and if there is one, the group too PartyleaderGuid = ReadPartyLeaderGuid(); if (PartyleaderGuid > 0) { PartymemberGuids = ReadPartymemberGuids(); } OnObjectUpdateComplete?.Invoke(WowObjects); }
public WowPlayer GetWowPlayerByName(string playername, StringComparison stringComparison = StringComparison.OrdinalIgnoreCase) => WowObjects.OfType <WowPlayer>().FirstOrDefault(e => e.Name.Equals(playername.ToUpper(), stringComparison));