/// <summary> /// Loads the backing store landblock structure<para /> /// This function is thread safe /// </summary> /// <param name="blockCellID">Any landblock + cell ID within the landblock</param> public static Landblock get_landblock(uint blockCellID) { // client implementation /*if (Landblocks == null || Landblocks.Count == 0) * return null; * * if (!LandDefs.inbound_valid_cellid(cellID) || cellID >= 0x100) * return null; * * var local_lcoord = LandDefs.blockid_to_lcoord(LoadedCellID); * var global_lcoord = LandDefs.gid_to_lcoord(cellID); * * var xDiff = ((int)global_lcoord.Value.X + 8 * MidRadius - (int)local_lcoord.Value.X) / 8; * var yDiff = ((int)global_lcoord.Value.Y + 8 * MidRadius - (int)local_lcoord.Value.Y) / 8; * * if (xDiff < 0 || yDiff < 0 || xDiff < MidWidth || yDiff < MidWidth) * return null; * * return Landblocks[yDiff + xDiff * MidWidth];*/ var landblockID = blockCellID | 0xFFFF; // check if landblock is already cached if (Landblocks.TryGetValue(landblockID, out var landblock)) { return(landblock); } lock (landblockMutex) { // check if landblock is already cached, this time under the lock. if (Landblocks.TryGetValue(landblockID, out landblock)) { return(landblock); } // if not, load into cache landblock = new Landblock(DBObj.GetCellLandblock(landblockID)); if (Landblocks.TryAdd(landblockID, landblock)) { landblock.PostInit(); // ensure landblock manager loaded var lbid = new LandblockId(landblockID); if (!LandblockManager.IsLoaded(lbid)) { // this can happen from encounter spawns sliding down walkable slopes... //log.Debug($"{landblockID:X8} requested from LScape, but not loaded from LandblockManager, adding"); LandblockManager.GetLandblock(lbid, false, false); } } else { Landblocks.TryGetValue(landblockID, out landblock); } return(landblock); } }
public House GetDungeonHouse() { var landblockId = new LandblockId(House.DungeonLandblockID); var isLoaded = LandblockManager.IsLoaded(landblockId); if (!isLoaded) { return(null); } var loaded = LandblockManager.GetLandblock(landblockId, false); var wos = loaded.GetWorldObjectsForPhysicsHandling(); return(wos.FirstOrDefault(wo => wo.WeenieClassId == House.WeenieClassId) as House); }
public House GetHouse() { if (HouseInstance == null) { return(House); } var houseGuid = HouseInstance.Value; var landblock = (ushort)((houseGuid >> 12) & 0xFFFF); var landblockId = new LandblockId((uint)(landblock << 16 | 0xFFFF)); var isLoaded = LandblockManager.IsLoaded(landblockId); if (!isLoaded) { return(House); } var loaded = LandblockManager.GetLandblock(landblockId, false); return(loaded.GetObject(new ObjectGuid(houseGuid)) as House); }