示例#1
0
文件: Data.cs 项目: prashanthm121/DEA
        static Data()
        {
            try
            {
                Credentials = JsonConvert.DeserializeObject <Credentials>(File.ReadAllText(Config.MainDirectory + @"src\Credentials.json"));
                Armour      = JsonConvert.DeserializeObject <Armour[]>(File.ReadAllText(Config.MainDirectory + @"src\Data\Items\Armour.json"));
                Crates      = JsonConvert.DeserializeObject <Crate[]>(File.ReadAllText(Config.MainDirectory + @"src\Data\Items\Crates.json"));
                Fish        = JsonConvert.DeserializeObject <Fish[]>(File.ReadAllText(Config.MainDirectory + @"src\Data\Items\Fish.json"));
                Guns        = JsonConvert.DeserializeObject <Gun[]>(File.ReadAllText(Config.MainDirectory + @"src\Data\Items\Guns.json"));
                Knives      = JsonConvert.DeserializeObject <Knife[]>(File.ReadAllText(Config.MainDirectory + @"src\Data\Items\Knives.json"));
                Meat        = JsonConvert.DeserializeObject <Meat[]>(File.ReadAllText(Config.MainDirectory + @"src\Data\Items\Meat.json"));
                Miscellanea = JsonConvert.DeserializeObject <Item[]>(File.ReadAllText(Config.MainDirectory + @"src\Data\Items\Miscellanea.json"));
            }
            catch (IOException e)
            {
                Logger.Log(LogSeverity.Critical, "Error while loading up data, please fix this issue and restart the bot", e.Message);
                Console.ReadKey();
                Environment.Exit(0);
            }

            Food       = (Fish as Food[]).Concat(Meat).ToArray();
            Weapons    = (Guns as Weapon[]).Concat(Knives).ToArray();
            CrateItems = (Weapons as CrateItem[]).Concat(Armour).OrderByDescending(x => x.CrateOdds).ToArray();
            Items      = Miscellanea.Concat(Crates).Concat(CrateItems).Concat(Food).ToArray();

            CrateItemOdds   = CrateItems.Sum(x => x.CrateOdds);
            FishAcquireOdds = Fish.Sum(x => x.AcquireOdds);
            MeatAcquireOdds = Meat.Sum(x => x.AcquireOdds);
        }
示例#2
0
文件: Data.cs 项目: Lunerr/dea2cs
        static Data()
        {
            try
            {
                Armour      = JsonConvert.DeserializeObject <Armour[]>(File.ReadAllText(Config.MainDirectory + "src/Data/Items/Armour.json"));
                Crates      = JsonConvert.DeserializeObject <Crate[]>(File.ReadAllText(Config.MainDirectory + "src/Data/Items/Crates.json"));
                Fish        = JsonConvert.DeserializeObject <Fish[]>(File.ReadAllText(Config.MainDirectory + "src/Data/Items/Fish.json"));
                Guns        = JsonConvert.DeserializeObject <Gun[]>(File.ReadAllText(Config.MainDirectory + "src/Data/Items/Guns.json"));
                Knives      = JsonConvert.DeserializeObject <Knife[]>(File.ReadAllText(Config.MainDirectory + "src/Data/Items/Knives.json"));
                Meat        = JsonConvert.DeserializeObject <Meat[]>(File.ReadAllText(Config.MainDirectory + "src/Data/Items/Meat.json"));
                Miscellanea = JsonConvert.DeserializeObject <Item[]>(File.ReadAllText(Config.MainDirectory + "src/Data/Items/Miscellanea.json"));
            }
            catch (IOException e)
            {
                #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                Logger.LogAsync(LogSeverity.Critical, $"Error while loading up data, please fix this issue and restart the bot: {e.Message}");
                Console.ReadKey();
                Environment.Exit(0);
            }

            Food       = (Fish as Food[]).Concat(Meat).ToArray();
            Weapons    = (Guns as Weapon[]).Concat(Knives).ToArray();
            CrateItems = (Weapons as CrateItem[]).Concat(Armour).OrderByDescending(x => x.CrateOdds).ToArray();
            Items      = Miscellanea.Concat(Crates).Concat(CrateItems).Concat(Food).ToArray();

            CrateItemOdds   = CrateItems.Sum(x => x.CrateOdds);
            FishAcquireOdds = Fish.Sum(x => x.AcquireOdds);
            MeatAcquireOdds = Meat.Sum(x => x.AcquireOdds);
        }