示例#1
0
        public async Task UpdateSharePrice(Transaction transaction)
        {
            Company company = new Company(await db.getJObjectAsync(transaction.ticker, "companies"));

            double newPrice = ((double)transaction.shares / (double)company.shares * (transaction.price - company.SharePrice)) + company.SharePrice;

            company.SharePrice = newPrice;
            await db.SetFieldAsync(transaction.ticker, "SharePrice", company.SharePrice, "companies");
        }
        public async Task paySalaries(int year)
        {
            Collection <JObject> companies = await __database.getJObjects("companies");

            foreach (JObject x in companies)
            {
                Company company = new Company(x);
                string  owner   = null;
                foreach (string c in company.employee.Keys)
                {
                    if (company.employee[c].position.level == 99)
                    {
                        owner = c;
                    }
                }
                double ownermoney = double.Parse((string)await __database.GetFieldAsync(owner, "money", "users"));
                foreach (string c in company.employee.Keys)
                {
                    if (company.Money - company.employee[c].salary >= 0)
                    {
                        company.Money -= company.employee[c].salary;
                        await __database.SetFieldAsync(c, "money", (double.Parse((string)await __database.GetFieldAsync(c, "money", "users"))) + company.employee[c].salary, "users");
                    }
                    else if (ownermoney - company.employee[c].salary >= 0)
                    {
                        ownermoney -= company.employee[c].salary;
                        await __database.SetFieldAsync(c, "money", (double.Parse((string)await __database.GetFieldAsync(c, "money", "users"))) + company.employee[c].salary, "users");
                    }
                    else
                    {
                        await __commands.sendDMTask(c, $"The CEO of company {company.name} has been unable to pay your salary");
                    }
                }
                await __database.SetJObjectAsync(company.SerializeIntoJObject(), "companies");

                await __database.SetFieldAsync(owner, "money", ownermoney, "users");
            }
        }
        public async Task AdvanceAllAsync(SocketGuild guild, int amount)
        {
            IGuild guildx = (IGuild)guild;
            IReadOnlyCollection <IGuildUser> users = await guildx.GetUsersAsync();

            foreach (IGuildUser x in users)
            {
                if (x.IsBot)
                {
                    continue;
                }
                string ageTemporary;
                int    age;
                ageTemporary = (string)await __database.GetFieldAsync(x.Id.ToString(), "age", "users");

                if (ageTemporary == null)
                {
                    Random rand = new Random(); //Set up a RNG
                    age = rand.Next(20, 25);    //Get num between 20 and 25
                }
                else
                {
                    age = int.Parse(ageTemporary);
                }
                int ageNew = age + amount;
                await __database.SetFieldAsync(x.Id.ToString(), "age", ageNew, "users");

                int    pp;
                string ppTemporary;
                ppTemporary = (string)await __database.GetFieldAsync(x.Id.ToString(), "pp", "users");

                if (ppTemporary == null)
                {
                    pp = 0;
                }
                else
                {
                    pp = int.Parse(ppTemporary);
                }
                int newpp = pp - (int)Math.Floor(((double.Parse(pp.ToString()) / 100) * amount));
                await __database.SetFieldAsync(x.Id.ToString(), "pp", newpp, "users");

                int    expectancy;
                string expectancyTemporary;
                expectancyTemporary = (string)await __database.GetFieldAsync(x.Id.ToString(), "expectancy", "users");

                if (expectancyTemporary == null)
                {
                    Random rand = new Random();      //Set up a RNG
                    expectancy = rand.Next(90, 130); //Get num between 90 and 130
                    await __database.SetFieldAsync(x.Id.ToString(), "expectancy", expectancy, "users");
                }
                else
                {
                    expectancy = int.Parse(expectancyTemporary);
                }
                if (ageNew >= expectancy)
                {
                    await KillAsync(x);
                }
                string money = (string)await __database.GetFieldAsync(x.Id.ToString(), "money", "users");

                double moneyd;
                if (money == null)
                {
                    moneyd = 50000;
                    await __database.SetFieldAsync <double>(x.Id.ToString(), "money", moneyd, "users");
                }
                else
                {
                    moneyd = (1300 * amount) + double.Parse(money);
                    await __database.SetFieldAsync <double>(x.Id.ToString(), "money", moneyd, "users");
                }
            }
        }