예제 #1
0
        private async void LoadDatabase()
        {
            await Delay(5000);

            Exports["ghmattimysql"].execute("SELECT * FROM loadout;", new object[] {  }, new Action <dynamic>((loadout) =>
            {
                if (loadout.Count != 0)
                {
                    WeaponClass wp;
                    foreach (var row in loadout)
                    {
                        try
                        {
                            JObject ammo = Newtonsoft.Json.JsonConvert.DeserializeObject(row.ammo.ToString());
                            JArray comp  = Newtonsoft.Json.JsonConvert.DeserializeObject(row.components.ToString());
                            int charId   = -1;
                            if (row.charidentifier != null)
                            {
                                charId = row.charidentifier;
                            }
                            Dictionary <string, int> amunition = new Dictionary <string, int>();
                            List <string> components           = new List <string>();
                            foreach (JProperty ammos in ammo.Properties())
                            {
                                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, charId);
                            ItemDatabase.userWeapons[wp.getId()] = wp;
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(ex.Message);
                        }
                    }
                }
            }));
        }
예제 #2
0
        private void getInventory([FromSource] Player source)
        {
            string steamId = "steam:" + source.Identifiers["steam"];

            Debug.WriteLine(steamId);

            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 = ?;", new[] { steamId }, 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;
                        }
                        wp = new WeaponClass(int.Parse(row.id.ToString()), row.identifier.ToString(), row.name.ToString(), amunition, components, auused);
                        ItemDatabase.userWeapons[wp.getId()] = wp;
                    }

                    source.TriggerEvent("vorpInventory:giveLoadout", weaponsinvento);
                }
            }));
        }
예제 #3
0
        private async void LoadDatabase()
        {
            await Delay(2000);

            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) =>
                    {
                        if (uinvento.Count == 0)
                        {
                            Debug.WriteLine("No users inventory");
                        }
                        else
                        {
                            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) =>
                    {
                        if (weaponsinvento.Count == 0)
                        {
                            Debug.WriteLine("There is no loadout on server database");
                        }
                        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;
                                }
                                wp = new WeaponClass(int.Parse(row.id.ToString()), row.identifier.ToString(), row.name.ToString(), amunition, components, auused);
                                userWeapons.Add(wp.getId(), wp);
                            }
                        }
                    }));
                }
            }));
        }
예제 #4
0
        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, Item> userinv = new Dictionary <string, Item>();
            List <WeaponClass>        userwep = new List <WeaponClass>();

            if (inventory != null)
            {
                Dictionary <string, int> ITEMS = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, int> >(inventory);
                foreach (var item in ITEMS)
                {
                    userinv.Add(item.Key, new Item(item.Key, ItemDatabase.svItems[item.Key].Label, ItemDatabase.svItems[item.Key].Type, ItemDatabase.svItems[item.Key].Model, item.Value, ItemDatabase.svItems[item.Key].Limit, ItemDatabase.svItems[item.Key].Weight, ItemDatabase.svItems[item.Key].CanUse, ItemDatabase.svItems[item.Key].CanRemove, ItemDatabase.svItems[item.Key].DropOnDeath));
                }
                ItemDatabase.usersInventory[steamId] = userinv;
            }
            else
            {
                ItemDatabase.usersInventory[steamId] = userinv;
            }

            source.TriggerEvent("vorpInventory:giveInventory", 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;
                        }
                        wp = new WeaponClass(int.Parse(row.id.ToString()), row.identifier.ToString(), row.name.ToString(), amunition, components, auused, charIdentifier);
                        ItemDatabase.userWeapons[wp.getId()] = wp;
                    }

                    source.TriggerEvent("vorpInventory:giveLoadout", weaponsinvento);
                }
            }));
        }