public void CMD_CreateFactory(Client player, ProductType type) { if (API.getPlayerAclGroup(player) != "Admin") { player.sendChatMessage("~r~ERROR: ~w~Only admins can use this command."); return; } // generate id Guid factoryID; do { factoryID = Guid.NewGuid(); } while (Main.Factories.FirstOrDefault(f => f.ID == factoryID) != null); // create factory & save Factory newFactory = new Factory(factoryID, player.position, type); Main.Factories.Add(newFactory); newFactory.CreateEntities(); newFactory.Save(); }
public void Courier_Init() { ResourceFolder = API.getResourceFolder(); // Load settings if (API.hasSetting("saveInterval")) { SaveInterval = API.getSetting <int>("saveInterval"); } if (API.hasSetting("worldPropLife")) { WorldPropLife = API.getSetting <int>("worldPropLife"); } if (API.hasSetting("factoryProductInterval")) { FactoryProductInterval = API.getSetting <int>("factoryProductInterval"); } if (API.hasSetting("factoryMaxAutoStock")) { FactoryMaxAutoStock = API.getSetting <int>("factoryMaxAutoStock"); } if (API.hasSetting("buyerSaleInterval")) { BuyerSaleInterval = API.getSetting <int>("buyerSaleInterval"); } if (API.hasSetting("buyerMinStockPercentage")) { BuyerMinStockPercentage = API.getSetting <int>("buyerMinStockPercentage"); } // Print settings API.consoleOutput("-> Save Interval: {0}", TimeSpan.FromSeconds(SaveInterval).ToString(@"hh\:mm\:ss")); API.consoleOutput("-> Dropped Item Lifetime: {0}", TimeSpan.FromMinutes(WorldPropLife).ToString(@"hh\:mm\:ss")); API.consoleOutput("-> Factory Product Interval: {0}", TimeSpan.FromSeconds(FactoryProductInterval).ToString(@"hh\:mm\:ss")); API.consoleOutput("-> Factory Max. Auto Stock: {0}", FactoryMaxAutoStock); API.consoleOutput("-> Buyer Sale Interval: {0}", TimeSpan.FromSeconds(BuyerSaleInterval).ToString(@"hh\:mm\:ss")); API.consoleOutput("-> Buyer Min. Stock Percentage: {0}%", BuyerMinStockPercentage); // Load factories string factoryDir = ResourceFolder + Path.DirectorySeparatorChar + "FactoryData"; if (!Directory.Exists(factoryDir)) { Directory.CreateDirectory(factoryDir); } foreach (string file in Directory.EnumerateFiles(factoryDir, "*.json")) { Factory newFactory = JsonConvert.DeserializeObject <Factory>(File.ReadAllText(file)); Factories.Add(newFactory); newFactory.CreateEntities(); } API.consoleOutput("Loaded {0} factories.", Factories.Count); // Load buyers string buyerDir = ResourceFolder + Path.DirectorySeparatorChar + "BuyerData"; if (!Directory.Exists(buyerDir)) { Directory.CreateDirectory(buyerDir); } foreach (string file in Directory.EnumerateFiles(buyerDir, "*.json")) { Buyer newBuyer = JsonConvert.DeserializeObject <Buyer>(File.ReadAllText(file)); Buyers.Add(newBuyer); newBuyer.CreateEntities(); } API.consoleOutput("Loaded {0} buyers.", Buyers.Count); // Start world cleaner WorldCleaner = API.startTimer(60000, false, () => { foreach (WorldProduct product in DroppedProduct) { if (DateTime.Now.Subtract(product.SpawnTime).TotalMinutes >= WorldPropLife) { product.DeleteEntities(); } } DroppedProduct.RemoveAll(p => DateTime.Now.Subtract(p.SpawnTime).TotalMinutes >= WorldPropLife); }); }