public static void RemoveObject(WorldObject worldObject) { Landblock block = GetLandblock(worldObject.Position.LandblockId, true); block.RemoveWorldObject(worldObject.Guid, false); }
/// <summary> /// gets the landblock specified, creating it if it is not already loaded. will create all /// adjacent landblocks if propogate is true (outdoor world roaming). /// </summary> private static Landblock GetLandblock(LandblockId landblockId, bool propogate) { int x = landblockId.LandblockX; int y = landblockId.LandblockY; // standard check/lock/recheck pattern if (landblocks[x, y] == null) { lock (landblockMutex) { if (landblocks[x, y] == null) { // load up this landblock Landblock block = new Landblock(landblockId); landblocks[x, y] = block; bool autoLoad = propogate && landblockId.MapScope == Entity.Enum.MapScope.Outdoors; if (x > 0) { SetAdjacency(landblockId, landblockId.West, Adjacency.West, autoLoad); if (y > 0) { SetAdjacency(landblockId, landblockId.SouthWest, Adjacency.SouthWest, autoLoad); } if (y < 255) { SetAdjacency(landblockId, landblockId.NorthWest, Adjacency.NorthWest, autoLoad); } } if (x < 255) { SetAdjacency(landblockId, landblockId.East, Adjacency.East, autoLoad); if (y > 0) { SetAdjacency(landblockId, landblockId.SouthEast, Adjacency.SouthEast, autoLoad); } if (y < 255) { SetAdjacency(landblockId, landblockId.NorthEast, Adjacency.NorthEast, autoLoad); } } if (y > 0) { SetAdjacency(landblockId, landblockId.South, Adjacency.South, autoLoad); } if (y < 255) { SetAdjacency(landblockId, landblockId.North, Adjacency.North, autoLoad); } // kick off the landblock use time thread block.StartUseTime(); } } } return(landblocks[x, y]); }
public static void AddObject(WorldObject worldObject) { Landblock block = GetLandblock(worldObject.Position.LandblockId, true); block.AddWorldObject(worldObject); }
/// <summary> /// Queues a landblock for thread-safe unloading /// </summary> public static void AddToDestructionQueue(Landblock landblock) { destructionQueue.Add(landblock); }
public static ActionChain GetAddObjectChain(WorldObject worldObject) { Landblock block = GetLandblock(worldObject.Location.LandblockId, true); return(block.GetAddWorldObjectChain(worldObject)); }
public static bool json2sql_landblock(FileInfo fi, string[] lines = null, DirectoryInfo outputFolder = null) { // read json into gdle spawnmap Landblock result = null; if (lines == null) { if (!GDLELoader.TryLoadLandblock(fi.FullName, out result)) { Console.WriteLine($"Failed to parse {fi.FullName}"); return(false); } } else { if (!GDLELoader.TryLoadLandblock(lines, out result)) { Console.WriteLine($"Failed to parse landblock"); return(false); } } // convert to sql landblock instances if (!GDLEConverter.TryConvert(result, out var landblockInstances, out var landblockInstanceLinks)) { Console.WriteLine($"Failed to convert {fi.FullName}"); return(false); } // link up instances // TODO: move this to TryConvert foreach (var link in landblockInstanceLinks) { var parent = landblockInstances.FirstOrDefault(i => i.Guid == link.ParentGuid); if (parent == null) { Console.WriteLine($"Couldn't find parent guid for {link.ParentGuid:X8}"); continue; } parent.LandblockInstanceLink.Add(link); var child = landblockInstances.FirstOrDefault(i => i.Guid == link.ChildGuid); if (child == null) { Console.WriteLine($"Couldn't find child guid for {link.ChildGuid:X8}"); continue; } child.IsLinkChild = true; } // output to sql try { if (LandblockSQLWriter == null) { LandblockSQLWriter = new LandblockSQLWriter(); LandblockSQLWriter.WeenieNames = IDToString.Reader.GetIDToNames("WeenieName.txt"); } foreach (var landblockInstance in landblockInstances) { if (landblockInstance.LastModified == DateTime.MinValue) { landblockInstance.LastModified = DateTime.UtcNow; } } foreach (var landblockInstanceLink in landblockInstanceLinks) { if (landblockInstanceLink.LastModified == DateTime.MinValue) { landblockInstanceLink.LastModified = DateTime.UtcNow; } } StreamWriter sqlFile = null; string sqlFilename = null; MemoryStream memoryStream = null; if (lines == null) { sqlFilename = LandblockSQLWriter.GetDefaultFileName(landblockInstances[0]); var sqlFolder = outputFolder ?? fi.Directory; sqlFile = new StreamWriter(sqlFolder.FullName + Path.DirectorySeparatorChar + sqlFilename); } else { memoryStream = new MemoryStream(); sqlFile = new StreamWriter(memoryStream); } LandblockSQLWriter.CreateSQLDELETEStatement(landblockInstances, sqlFile); sqlFile.WriteLine(); LandblockSQLWriter.CreateSQLINSERTStatement(landblockInstances, sqlFile); sqlFile.Close(); if (lines != null) { Output = memoryStream.ToString(); return(true); } Console.WriteLine($"Converted {fi.FullName} to {fi.DirectoryName}{Path.DirectorySeparatorChar}{sqlFilename}"); } catch (Exception e) { Console.WriteLine(e); Console.WriteLine($"Failed to convert {fi.FullName}"); return(false); } return(true); }
public int CardEventDispatched(Card card) { Debug.Log(card.type); if (selected == null) { return(1); } if (playerMaterialCount < card.cost) { return(2); } Landblock lb = selected.GetComponent <Landblock>(); Block block = lb.block; switch (card.type) { case CardType.QUARANTINE: { block.quarantined(); playerMaterialCount += card.cost; break; } case CardType.STOP_WORKING: { if (block.type != BlockType.FACTORY) { return(3); } block.stopWorking(); playerMaterialCount += card.cost; break; } case CardType.START_WORKING: { if (block.type != BlockType.FACTORY) { return(3); } block.startWorking(); playerMaterialCount += card.cost; break; } case CardType.SPECIAL_AID: { block.aided(); playerMaterialCount += card.cost; break; } case CardType.TAXING: { playerMaterialCount += block.taxed(); playerMaterialCount += card.cost; break; } default: break; } return(0); }