/// <summary> /// Send Housing Items depending on last refresh. /// </summary> /// <param name="player"></param> /// <param name="nowTicks"></param> public static void UpdatePlayerHousing(GamePlayer player, long nowTicks) { // If no house update needed exit. if (player.CurrentRegion == null || !player.CurrentRegion.HousingEnabled) { return; } // Get All House in Region IDictionary <int, House> housesDict = HouseMgr.GetHouses(player.CurrentRegionID); List <House> houses = new List <House>(); // Build Vincinity List foreach (House h in housesDict.Values) { House house = h; if (house != null && player.IsWithinRadius(house, HousingConstants.HouseViewingDistance)) { houses.Add(house); } } try { // Clean Cache foreach (Tuple <ushort, ushort> houseKey in player.Client.HouseUpdateArray.Keys) { House house = HouseMgr.GetHouse(houseKey.Item1, houseKey.Item2); // We have a House in cache that is not in vincinity if (!houses.Contains(house) && (nowTicks - player.Client.HouseUpdateArray[new Tuple <ushort, ushort>(house.RegionID, (ushort)house.HouseNumber)]) >= GetPlayerItemUpdateInterval()) { long dummy; player.Client.HouseUpdateArray.TryRemove(new Tuple <ushort, ushort>(house.RegionID, (ushort)house.HouseNumber), out dummy); } } } catch (Exception e) { if (log.IsErrorEnabled) { log.ErrorFormat("Error while Cleaning House cache for Player : {0}, Exception : {1}", player.Name, e); } } try { // Now Send remaining houses foreach (House lhouse in houses) { House house = lhouse; // Get last update time long lastUpdate; if (player.Client.HouseUpdateArray.TryGetValue(new Tuple <ushort, ushort>(house.RegionID, (ushort)house.HouseNumber), out lastUpdate)) { // This House Needs Update if ((nowTicks - lastUpdate) >= GetPlayerItemUpdateInterval()) { player.Client.Out.SendHouse(house); player.Client.Out.SendGarden(house); if (house.IsOccupied) { player.Client.Out.SendHouseOccupied(house, true); } } } else { // Not in cache, House entering in range ! player.Client.Out.SendHouse(house); player.Client.Out.SendGarden(house); if (house.IsOccupied) { player.Client.Out.SendHouseOccupied(house, true); } } } } catch (Exception e) { if (log.IsErrorEnabled) { log.ErrorFormat("Error while updating Houses for Player : {0}, Exception : {1}", player.Name, e); } } }