private void btn_removeitem_Click(object sender, EventArgs e) { var much = (int)this.num_removenum.Value; if (much <= 0) { return; } if (this.dataGridView4.CurrentRow != null) { if (dataGridView4.CurrentRow != null) { var picked = (GUIBinds.InventoryGrid.InventoryBinding.Item)dataGridView4.CurrentRow.DataBoundItem; var wehave = picked.Amount; if (wehave != 0 && wehave >= much) { var item = MaterialDB.GetItem(picked.ID); Logger.Info(string.Format(PrivateLocal.INVENTORY_REMOVED, much, item.Name)); Networking.AddTask(new Task.RemoveMaterialTask(item.DefId, much)); Core.GlobalData.Inventory.First(n => n.Id == item.DefId).Amount -= much; } } } }
public static Upgradeable GetBestUpgPlace(string itemname, int sailors, Config.UpgradablyStrategy upgradablestrategy) { var mat = MaterialDB.GetItem(itemname).DefId; var needed = new List <UpgradeableDefenition.Item>(); foreach (var item in Definitions.UpgrDef.Items.Item) { if (item.MaterialId == mat) { needed.Add(item); } } var sito = needed.Where( shtItem => Core.GlobalData.Upgradeables.FirstOrDefault( n => n.DefId == shtItem.DefId && n.Amount != 0 && n.Progress < n.Amount || n.DefId == shtItem.DefId && shtItem.MaxLevel == 1 && shtItem.EventId == 0) != null); var p = sito.ToDictionary( shtItem => shtItem, shtItem => Core.GlobalData.Upgradeables.First(n => n.DefId == shtItem.DefId)); var best = new Dictionary <Upgradeable, decimal>(); foreach (var up in p) { if (up.Key.Levels.Level.First(n => n.Id == up.Value.Level).Sailors > sailors) { continue; } if (upgradablestrategy == Config.UpgradablyStrategy.Loot) { var itemFirst = up.Key.Levels.Level.First(n => n.Id == up.Value.Level); var time = (decimal)itemFirst.TravelTime; var koef = itemFirst.MaterialKoef; var timepercoin = koef / time; best.Add(up.Value, timepercoin); } else { var koef = (decimal)up.Key.Levels.Level.First(n => n.Id == up.Value.Level).MaterialKoef; var timepercoin = koef / sailors; best.Add(up.Value, timepercoin); } } var bestplace = best.OrderBy(n => n.Value).LastOrDefault(); return(bestplace.Key); }
private static void Main(string[] args) { Console.WriteLine("BarrelTest"); var token = File.ReadAllText("token.txt"); Core.ServerToken = token; Events.SyncFailedEvent.SyncFailed.OnSyncFailedEvent += Kicked_OnWrongSession; for (var i = 7; i < 200; i++) { kicked = false; var attempts = 0; Console.WriteLine("Testing inverval = " + i); Networking.Login(); while (true) { Thread.Sleep(i * 1000); if (!kicked) { var barrelid = TimeUtils.GetCurrentEvent().Barrel.Integer.Value; var bar = Barrels.BarrelController.GetNextBarrel( Definitions.BarrelDef.Items.Item.Where(n => n.DefId == 21).First()); if (bar.Definition.Id != 0) { Console.WriteLine( $"Barrel! Collecting {bar.Amount} {MaterialDB.GetItem(bar.Definition.Id).Name}"); } Networking.AddTask( new Task.ConfirmBarrelTask( (int)barrelid, bar.get_type(), bar.Amount, bar.Definition.Id, Core.GlobalData.Level)); attempts++; } else { File.WriteAllText(i.ToString(), attempts.ToString()); break; } } } }
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(); } } } }
public int GetAmountItem(string name) { return(this.GetAmountItem(MaterialDB.GetItem(name).DefId)); }