public static void CollectMaterials() { foreach (var data in Core.GlobalData.Buildings) { if (data.UpgStart == 0 && data.ProdStart != 0) { var def = Definitions.BuildingDef.Items.Item.First(n => n.DefId == data.DefId); if (def.Type != "factory") { continue; } var defs = def.Levels.Level.First(n => n.Id == data.Level); var started = TimeUtils.FromUnixTime(data.ProdStart); // var prodtime = defs.ProdOutputs.ProdOutput[data.ProdId - 1]; //todo add this! if ((TimeUtils.FixedUTCTime - started).TotalSeconds > defs.ProdOutputs.ProdOutput[0].Time) { Logger.Info( string.Format( Localization.BUILDINGS_COLLECTING, defs.ProdOutputs.ProdOutput[0].Amount, MaterialDB.GetLocalizedName(defs.ProdOutputs.ProdOutput[0].MaterialId))); Networking.AddTask(new Task.FinishBuildingProducingTask(data.InstId)); data.ProdStart = 0; } } } }
private string GetInventory() { var builder = new StringBuilder(); if (Core.GlobalData != null) { if (Core.GlobalData.Inventory != null) { foreach (var item in Core.GlobalData.Inventory.Where(n => n.Amount != 0)) { builder.AppendLine($"{MaterialDB.GetLocalizedName(item.Id)} - {item.Amount}"); } } else { builder.Append(PrivateLocal.TELEGRAM_EXCEPTION_NULL_INVENTORY); } } else { builder.Append(PrivateLocal.TELEGRAM_EXCEPTION_NULL_INVENTORY); } return(builder.ToString()); }
public static BindingList <Item> GetItems() { var ret = new BindingList <Item>(); if (Core.GlobalData == null) { return(ret); } if (Core.GlobalData.Inventory == null) { return(ret); } foreach (var item in Core.GlobalData.Inventory) { if (item.Amount == 0) { continue; } var pitem = new Item(); pitem.ID = item.Id; pitem.Name = MaterialDB.GetLocalizedName(item.Id); pitem.Amount = item.Amount; ret.Add(pitem); } return(ret); }
public static void CollectBarrel() { var nearestev = TimeUtils.GetCurrentEvent().Barrel.Integer.Value; var barrelcontroller = Definitions.BarrelDef.Items.Item.Where(n => n.DefId == nearestev).First(); var nextbarrel = BarrelController.GetNextBarrel(barrelcontroller); if (nextbarrel.Definition.Id != 0) { Logger.Info( string.Format( Localization.BARREL_COLLECTING_ITEM, nextbarrel.Amount, MaterialDB.GetLocalizedName(nextbarrel.Definition.Id))); if (Core.GlobalData.Inventory.FirstOrDefault(n => n.Id == nextbarrel.Definition.Id) != null) { Core.GlobalData.Inventory.First(n => n.Id == nextbarrel.Definition.Id).Amount += nextbarrel.Amount; } else { Core.GlobalData.Inventory.Add( new Item { Amount = nextbarrel.Amount, Id = nextbarrel.Definition.Id }); } } else { Logger.Info(string.Format(Localization.BARREL_COLLECTING_SAILORS, nextbarrel.Amount)); } Networking.AddTask( new Task.ConfirmBarrelTask( barrelcontroller.DefId, nextbarrel.get_type(), nextbarrel.Amount, nextbarrel.Definition.Id, Core.GlobalData.Level)); }
public static void ProduceFactories() { foreach (var data in Core.GlobalData.Buildings) { if (data.UpgStart == 0 && data.ProdStart == 0) { var def = Definitions.BuildingDef.Items.Item.First(n => n.DefId == data.DefId); if (def.Type != "factory") { continue; } var needed = def.Levels.Level.FirstOrDefault(n => n.Id == data.Level); if (needed == null) { continue; } if (data.DefId == 11) { // This is a machinery if (Core.Config.autothresholdworkshop) { // Mechanical part if (Core.GlobalData.GetAmountItem(33) < Core.Config.thresholdmechanical) { var prodid = 1; var enough = true; var mat = needed.ProdOutputs.ProdOutput.Where(n => n.Id == 1).FirstOrDefault(); if (mat == null) { continue; } foreach (var prod in mat.Inputs.Input) { if (Core.GlobalData.GetAmountItem(prod.Id) < prod.Amount) { enough = false; } } if (enough) { foreach (var inp in mat.Inputs.Input) { Core.GlobalData.Inventory.First(n => n.Id == inp.Id).Amount -= inp.Amount; } Logger.Info( string.Format( Localization.FACTORIES_STARTED_PROD, MaterialDB.GetLocalizedName(mat.MaterialId))); Networking.AddTask(new Task.StartBuildingProducingTask(data.InstId, prodid)); data.ProdStart = TimeUtils.GetEpochTime(); continue; } // This will work } // Fuel if (Core.GlobalData.GetAmountItem(180) < Core.Config.thresholdfuel) { var prodid = 2; var enough = true; var mat = needed.ProdOutputs.ProdOutput.Where(n => n.Id == prodid).FirstOrDefault(); if (mat == null) { continue; } foreach (var prod in mat.Inputs.Input) { if (Core.GlobalData.GetAmountItem(prod.Id) < prod.Amount) { enough = false; } } if (enough) { foreach (var inp in mat.Inputs.Input) { Core.GlobalData.Inventory.First(n => n.Id == inp.Id).Amount -= inp.Amount; } Logger.Info( string.Format( Localization.FACTORIES_STARTED_PROD, MaterialDB.GetLocalizedName(mat.MaterialId))); Networking.AddTask(new Task.StartBuildingProducingTask(data.InstId, prodid)); data.ProdStart = TimeUtils.GetEpochTime(); continue; } } // todo CHECK FOR LEVEL!!! // Concrete if (data.Level >= 5) { if (Core.GlobalData.GetAmountItem(182) < Core.Config.thresholdconcrete) { var prodid = 3; var enough = true; var mat = needed.ProdOutputs.ProdOutput.Where(n => n.Id == prodid).FirstOrDefault(); if (mat == null) { continue; } foreach (var prod in mat.Inputs.Input) { if (Core.GlobalData.GetAmountItem(prod.Id) < prod.Amount) { enough = false; } } if (enough) { foreach (var inp in mat.Inputs.Input) { Core.GlobalData.Inventory.First(n => n.Id == inp.Id).Amount -= inp.Amount; } Logger.Info( string.Format( Localization.FACTORIES_STARTED_PROD, MaterialDB.GetLocalizedName(mat.MaterialId))); Networking.AddTask(new Task.StartBuildingProducingTask(data.InstId, prodid)); data.ProdStart = TimeUtils.GetEpochTime(); } } } } else { var prodid = 0; var matid = 0; var thresholdconc = 0; switch (Core.Config.workshoptype) { case WorkshopType.Concrete: { matid = 182; prodid = 3; thresholdconc = Core.Config.thresholdconcrete; } break; case WorkshopType.Fuel: { matid = 180; prodid = 2; thresholdconc = Core.Config.thresholdfuel; } break; case WorkshopType.MechanicalPart: { matid = 33; prodid = 1; thresholdconc = Core.Config.thresholdmechanical; break; } } if (prodid == 3 && data.Level < 5) { continue; } if (Core.GlobalData.GetAmountItem(matid) < thresholdconc || thresholdconc == 0) { var enough = true; var mat = needed.ProdOutputs.ProdOutput.Where(n => n.Id == prodid).FirstOrDefault(); if (mat == null) { continue; } foreach (var prod in mat.Inputs.Input) { if (Core.GlobalData.GetAmountItem(prod.Id) < prod.Amount) { enough = false; } } if (enough) { foreach (var inp in mat.Inputs.Input) { Core.GlobalData.Inventory.First(n => n.Id == inp.Id).Amount -= inp.Amount; } Logger.Info( string.Format( Localization.FACTORIES_STARTED_PROD, MaterialDB.GetLocalizedName(mat.MaterialId))); Networking.AddTask(new Task.StartBuildingProducingTask(data.InstId, prodid)); data.ProdStart = TimeUtils.GetEpochTime(); } } } // Don't need another shit continue; } // lets start? // DO WE HAVE ENOUGH RESOURCES var ok = true; var inputs = needed.ProdOutputs.ProdOutput; var Dict = new Dictionary <long, long>(); foreach (var input in inputs) { foreach (var inp in input.Inputs.Input) { var ourmat = Core.GlobalData.Inventory.FirstOrDefault(n => n.Id == inp.Id); if (ourmat == null) { ok = false; } else { if (ourmat.Amount >= inp.Amount) { if (Dict.ContainsKey(inp.Id)) { Dict[inp.Id] += inp.Amount; } else { Dict.Add(inp.Id, inp.Amount); } } else { ok = false; } } } if (MaterialDB.GetItem(input.MaterialId).Name == "wood") { var amount = Core.GlobalData.Inventory.FirstOrDefault(n => n.Id == input.MaterialId); if (amount != null && Core.Config.woodlimit != 0) { if (amount.Amount > Core.Config.woodlimit) { ok = false; } } } if (MaterialDB.GetItem(input.MaterialId).Name == "iron") { var amount = Core.GlobalData.Inventory.FirstOrDefault(n => n.Id == input.MaterialId); if (amount != null && Core.Config.ironlimit != 0) { if (amount.Amount > Core.Config.ironlimit) { ok = false; } } } if (MaterialDB.GetItem(input.MaterialId).Name == "stone") { var amount = Core.GlobalData.Inventory.FirstOrDefault(n => n.Id == input.MaterialId); if (amount != null && Core.Config.stonelimit != 0) { if (amount.Amount > Core.Config.stonelimit) { ok = false; } } } } if (ok) { foreach (var inp in Dict) { Core.GlobalData.Inventory.First(n => n.Id == inp.Key).Amount -= (int)inp.Value; } Logger.Info( string.Format( Localization.FACTORIES_STARTED_PROD, MaterialDB.GetLocalizedName(needed.ProdOutputs.ProdOutput[0].MaterialId))); Networking.AddTask(new Task.StartBuildingProducingTask(data.InstId, data.ProdId)); data.ProdStart = TimeUtils.GetEpochTime(); } } } }