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 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 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; } } } }
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 override global::System.Data.DataSet Clone() { MaterialDB cln = ((MaterialDB)(base.Clone())); cln.InitVars(); cln.SchemaSerializationMode = this.SchemaSerializationMode; return(cln); }
public void TestMethod1() { MaterialDB materialDB = new MaterialDB(); string id = "3"; Material material = materialDB.GetById <Material>(id); Console.WriteLine(material); }
public void TestMethod1() { MaterialDB materialDB = new MaterialDB(); var list = materialDB.GetAll <Material>(); foreach (var item in list) { Console.WriteLine(item); } }
public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(global::System.Xml.Schema.XmlSchemaSet xs) { MaterialDB ds = new MaterialDB(); global::System.Xml.Schema.XmlSchemaComplexType type = new global::System.Xml.Schema.XmlSchemaComplexType(); global::System.Xml.Schema.XmlSchemaSequence sequence = new global::System.Xml.Schema.XmlSchemaSequence(); global::System.Xml.Schema.XmlSchemaAny any = new global::System.Xml.Schema.XmlSchemaAny(); any.Namespace = ds.Namespace; sequence.Items.Add(any); type.Particle = sequence; global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable(); if (xs.Contains(dsSchema.TargetNamespace)) { global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream(); global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream(); try { global::System.Xml.Schema.XmlSchema schema = null; dsSchema.Write(s1); for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext();) { schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current)); s2.SetLength(0); schema.Write(s2); if ((s1.Length == s2.Length)) { s1.Position = 0; s2.Position = 0; for (; ((s1.Position != s1.Length) && (s1.ReadByte() == s2.ReadByte()));) { ; } if ((s1.Position == s1.Length)) { return(type); } } } } finally { if ((s1 != null)) { s1.Close(); } if ((s2 != null)) { s2.Close(); } } } xs.Add(dsSchema); return(type); }
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 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 global::System.Xml.Schema.XmlSchemaComplexType GetTypedTableSchema(global::System.Xml.Schema.XmlSchemaSet xs) { global::System.Xml.Schema.XmlSchemaComplexType type = new global::System.Xml.Schema.XmlSchemaComplexType(); global::System.Xml.Schema.XmlSchemaSequence sequence = new global::System.Xml.Schema.XmlSchemaSequence(); MaterialDB ds = new MaterialDB(); global::System.Xml.Schema.XmlSchemaAny any1 = new global::System.Xml.Schema.XmlSchemaAny(); any1.Namespace = "http://www.w3.org/2001/XMLSchema"; any1.MinOccurs = new decimal(0); any1.MaxOccurs = decimal.MaxValue; any1.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax; sequence.Items.Add(any1); global::System.Xml.Schema.XmlSchemaAny any2 = new global::System.Xml.Schema.XmlSchemaAny(); any2.Namespace = "urn:schemas-microsoft-com:xml-diffgram-v1"; any2.MinOccurs = new decimal(1); any2.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax; sequence.Items.Add(any2); global::System.Xml.Schema.XmlSchemaAttribute attribute1 = new global::System.Xml.Schema.XmlSchemaAttribute(); attribute1.Name = "namespace"; attribute1.FixedValue = ds.Namespace; type.Attributes.Add(attribute1); global::System.Xml.Schema.XmlSchemaAttribute attribute2 = new global::System.Xml.Schema.XmlSchemaAttribute(); attribute2.Name = "tableTypeName"; attribute2.FixedValue = "MaterialsDataTable"; type.Attributes.Add(attribute2); type.Particle = sequence; global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable(); if (xs.Contains(dsSchema.TargetNamespace)) { global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream(); global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream(); try { global::System.Xml.Schema.XmlSchema schema = null; dsSchema.Write(s1); for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext();) { schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current)); s2.SetLength(0); schema.Write(s2); if ((s1.Length == s2.Length)) { s1.Position = 0; s2.Position = 0; for (; ((s1.Position != s1.Length) && (s1.ReadByte() == s2.ReadByte()));) { ; } if ((s1.Position == s1.Length)) { return(type); } } } } finally { if ((s1 != null)) { s1.Close(); } if ((s2 != null)) { s2.Close(); } } } xs.Add(dsSchema); return(type); }
public List <WorkShopMaterial> GetMaterials() { MaterialDB MD = new MaterialDB(); return(MD.GetMaterials());; }
public void CreateMaterial(tbl_Material M) { MaterialDB MD = new MaterialDB(); MD.CreateMaterial(M); }
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)); }