public ItemDatabase() { Exports["ghmattimysql"].execute("SELECT * FROM items", new Action <dynamic>((result) => { if (result.Count == 0) { Debug.WriteLine("There`re no items in database"); } else { items = result; foreach (dynamic item in items) { svItems.Add(item.item.ToString(), new Items(item.item, item.label, int.Parse(item.limit.ToString()), item.can_remove, item.type, item.usable)); } Exports["ghmattimysql"].execute("SELECT identifier,inventory FROM characters", new Action <dynamic>((uinvento) => { foreach (var userInventory in uinvento) { //Carga del inventario string user = userInventory.identifier.ToString(); Dictionary <string, ItemClass> userinv = new Dictionary <string, ItemClass>(); List <WeaponClass> userwep = new List <WeaponClass>(); if (userInventory.inventory != null) { dynamic thing = Newtonsoft.Json.JsonConvert.DeserializeObject <dynamic>(userInventory.inventory); foreach (dynamic itemname in items) { if (thing[itemname.item.ToString()] != null) { ItemClass item = new ItemClass(int.Parse(thing[itemname.item.ToString()].ToString()), int.Parse(itemname.limit.ToString()), itemname.label, itemname.item, itemname.type, itemname.usable, itemname.can_remove); userinv.Add(itemname.item.ToString(), item); } } usersInventory.Add(user, userinv); } else { usersInventory.Add(user, userinv); } } })); Exports["ghmattimysql"].execute("SELECT * FROM loadout", new Action <dynamic>((weaponsinvento) => { WeaponClass wp; foreach (var row in weaponsinvento) { JObject ammo = Newtonsoft.Json.JsonConvert.DeserializeObject(row.ammo.ToString()); JArray comp = Newtonsoft.Json.JsonConvert.DeserializeObject(row.components.ToString()); Dictionary <string, int> amunition = new Dictionary <string, int>(); List <string> components = new List <string>(); foreach (JProperty ammos in ammo.Properties()) { //Debug.WriteLine(ammos.Name); amunition.Add(ammos.Name, int.Parse(ammos.Value.ToString())); } foreach (JToken x in comp) { components.Add(x.ToString()); } bool auused = false; if (row.used == 1) { auused = true; } wp = new WeaponClass(int.Parse(row.id.ToString()), row.identifier.ToString(), row.name.ToString(), amunition, components, auused); userWeapons.Add(wp.getId(), wp); } })); } })); }
private void getInventory([FromSource] Player source) { string steamId = "steam:" + source.Identifiers["steam"]; dynamic CoreUser = CORE.getUser(int.Parse(source.Handle)).getUsedCharacter; int charIdentifier = CoreUser.charIdentifier; string inventory = CoreUser.inventory; Dictionary <string, ItemClass> userinv = new Dictionary <string, ItemClass>(); List <WeaponClass> userwep = new List <WeaponClass>(); if (inventory != null) { dynamic thing = Newtonsoft.Json.JsonConvert.DeserializeObject <dynamic>(inventory); foreach (dynamic itemname in ItemDatabase.items) { if (thing[itemname.item.ToString()] != null) { ItemClass item = new ItemClass(int.Parse(thing[itemname.item.ToString()].ToString()), int.Parse(itemname.limit.ToString()), itemname.label, itemname.item, itemname.type, itemname.usable, itemname.can_remove); userinv.Add(itemname.item.ToString(), item); } } ItemDatabase.usersInventory[steamId] = userinv; } else { ItemDatabase.usersInventory[steamId] = userinv; } source.TriggerEvent("vorpInventory:giveInventory", inventory); //Exports["ghmattimysql"].execute("SELECT identifier,inventory FROM characters WHERE identifier = ?;", new[] { steamId }, new Action<dynamic>((uinvento) => //{ // if (uinvento.Count == 0) // { // Debug.WriteLine("No users inventory"); // Dictionary<string, ItemClass> items = new Dictionary<string, ItemClass>(); // ItemDatabase.usersInventory.Add(steamId, items); // Si no existe le metemos en la caché para tenerlo preparado para recibir cosas // } // else // { // //Carga del inventario // Dictionary<string, ItemClass> userinv = new Dictionary<string, ItemClass>(); // List<WeaponClass> userwep = new List<WeaponClass>(); // if (uinvento[0].inventory != null) // { // dynamic thing = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(uinvento[0].inventory); // foreach (dynamic itemname in ItemDatabase.items) // { // if (thing[itemname.item.ToString()] != null) // { // ItemClass item = new ItemClass(int.Parse(thing[itemname.item.ToString()].ToString()), int.Parse(itemname.limit.ToString()), // itemname.label, itemname.item, itemname.type, itemname.usable, itemname.can_remove); // userinv.Add(itemname.item.ToString(), item); // } // } // ItemDatabase.usersInventory[steamId] = userinv; // } // else // { // ItemDatabase.usersInventory[steamId] = userinv; // } // source.TriggerEvent("vorpInventory:giveInventory", uinvento[0].inventory); // } //})); Exports["ghmattimysql"].execute("SELECT * FROM loadout WHERE `identifier` = ? AND `charidentifier` = ?;", new object[] { steamId, charIdentifier }, new Action <dynamic>((weaponsinvento) => { if (weaponsinvento.Count == 0) { } else { WeaponClass wp; foreach (var row in weaponsinvento) { JObject ammo = Newtonsoft.Json.JsonConvert.DeserializeObject(row.ammo.ToString()); JArray comp = Newtonsoft.Json.JsonConvert.DeserializeObject(row.components.ToString()); Dictionary <string, int> amunition = new Dictionary <string, int>(); List <string> components = new List <string>(); foreach (JProperty ammos in ammo.Properties()) { //Debug.WriteLine(ammos.Name); amunition.Add(ammos.Name, int.Parse(ammos.Value.ToString())); } foreach (JToken x in comp) { components.Add(x.ToString()); } bool auused = false; if (row.used == 1) { auused = true; } bool auused2 = false; if (row.used2 == 1) { auused2 = true; } wp = new WeaponClass(int.Parse(row.id.ToString()), row.identifier.ToString(), row.name.ToString(), amunition, components, auused, auused2, charIdentifier); ItemDatabase.userWeapons[wp.getId()] = wp; } source.TriggerEvent("vorpInventory:giveLoadout", weaponsinvento); } })); }