public bool FlipCoin(long userId, out bool ifHaveEnoufMoney)
        {
            Random random = new Random();

            person           = _modelPerson.GetPerson(userId);
            ifHaveEnoufMoney = true;
            if (person.gold < flipCoinCost)
            {
                ifHaveEnoufMoney = false;
                return(false);
            }

            if (new Random().Next(0, flipCoinCost) > (flipCoinCost / 2))
            {
                person.gold -= flipCoinCost;
                _modelPerson.Update(person);
                return(false);
            }
            else
            {
                person.gold += flipCoinCost;
                _modelPerson.Update(person);
                return(true);
            }
        }
Exemple #2
0
        public bool TryIfGuildMaster(long userId)
        {
            Guild  g      = GuildGet(userId);
            Person person = modelPerson.GetPerson(userId);

            if (g == null)
            {
                return(false);
            }
            if (g.master == person.personNick)
            {
                return(true);
            }
            return(false);
        }
        public List <Person> WarStart(out List <Person> peopleOld)
        {
            peopleOld = _modelPerson.GetObjects();
            List <Person> people = _modelPerson.GetObjects();

            List <Person> fractionImpire = new List <Person>();
            List <Person> fractionImpireAtt = new List <Person>();
            List <Person> fractionImpireDef = new List <Person>();
            int           impLvlAtt = 0, impLvlDef = 0, impAtt = 0, impDef = 0;

            List <Person> fractionRepublic    = new List <Person>();
            List <Person> fractionRepublicAtt = new List <Person>();
            List <Person> fractionRepublicDef = new List <Person>();

            List <Person> winer1 = new List <Person>();
            List <Person> loser1 = new List <Person>();
            List <Person> winer2 = new List <Person>();
            List <Person> loser2 = new List <Person>();

            Inventory[] items1 = null;
            Inventory[] items2 = null;

            List <Guild> allGuilds = modelGuild.GetObjects();
            List <Guild> impGuilds = new List <Guild>();
            List <Guild> repGuilds = new List <Guild>();

            List <Guild> winer1Guilds = new List <Guild>();
            List <Guild> winer2Guilds = new List <Guild>();
            int          repLvlAtt = 0, repLvlDef = 0, repAtt = 0, repDef = 0;

            int cash1 = 0, cash2 = 0, winer1Lvl = 1, winer2Lvl = 1;

            foreach (Person person in people)
            {
                if (person.fraction == null || person.lvl < 10)
                {
                    continue;
                }
                Person personFull = _modelPerson.GetPerson(person.id);
                if (person.fraction == person.GetAlliance())
                {
                    fractionImpire.Add(personFull);
                    if (personFull.stateOfWar == true)
                    {
                        impAtt    += personFull.atack + _modelPerson.atackAdditional(personFull.id);
                        impLvlAtt += personFull.lvl;
                        fractionImpireAtt.Add(person);
                    }
                    else if (personFull.stateOfWar == false)
                    {
                        impDef    += personFull.def + _modelPerson.defAdditional(personFull.id);
                        impLvlDef += personFull.lvl;
                        fractionImpireDef.Add(person);
                    }
                }
                else if (person.fraction == person.GetRepublic())
                {
                    fractionRepublic.Add(personFull);
                    if (personFull.stateOfWar == true)
                    {
                        repAtt    += personFull.atack + _modelPerson.atackAdditional(personFull.id);
                        repLvlAtt += personFull.lvl;
                        fractionRepublicAtt.Add(person);
                    }
                    else if (personFull.stateOfWar == false)
                    {
                        repDef    += personFull.def + _modelPerson.defAdditional(personFull.id);
                        repLvlDef += personFull.lvl;
                        fractionRepublicDef.Add(person);
                    }
                }
                //personFull.exp += _modelPerson.AddToPersonExp(person.lvl, person.GetMultiplierExp()) * 2;
                //person.changes = true;
            }

            foreach (Guild guild in allGuilds)
            {
                if (guild.fraction == 0)
                {
                    impGuilds.Add(guild);
                }
                else if (guild.fraction == 1)
                {
                    repGuilds.Add(guild);
                }
            }

            {
                if (impAtt >= repDef)
                {
                    cash1        = GetGoldPerson(ref fractionRepublic);
                    cash1       += GetGoldGuild(ref repGuilds);
                    items1       = null;
                    winer1       = fractionImpireAtt;
                    winer1Lvl    = (impLvlAtt == 0)? 1 : impLvlAtt;
                    winer1Guilds = impGuilds;
                }
                else
                {
                    cash1        = GetGoldPerson(ref fractionImpireAtt);
                    items1       = GetIteams(ref fractionImpireAtt);
                    winer1       = fractionRepublicDef;
                    winer1Lvl    = (repLvlDef == 0) ? 1 : repLvlDef;
                    winer1Guilds = repGuilds;
                }

                if (repAtt >= impDef)
                {
                    cash2        = GetGoldPerson(ref fractionImpire);
                    cash2       += GetGoldGuild(ref impGuilds);
                    items2       = null;
                    winer2       = fractionRepublicAtt;
                    winer2Lvl    = (repLvlAtt == 0) ? 1 : repLvlAtt;
                    winer2Guilds = repGuilds;
                }
                else
                {
                    cash2        = GetGoldPerson(ref fractionRepublicAtt);
                    items2       = GetIteams(ref fractionRepublicAtt);
                    winer2       = fractionImpireDef;
                    winer2Lvl    = (impLvlDef == 0) ? 1 : impLvlDef;
                    winer2Guilds = impGuilds;
                }
            }

            SetGoldForWiner(cash1 / winer1Lvl, items1, winer1, winer1Guilds);
            SetGoldForWiner(cash2 / winer2Lvl, items2, winer2, winer2Guilds);

            CleanWarStatus(people);

            return(_modelPerson.GetObjects());
        }