Exemplo n.º 1
0
        public void ProcessVotes()
        {
            FiefdomActions.Edicts.Clear();
            FiefdomActions.MarketTax = 0;
            List <bool> votes = FiefdomActions.CountVotes();

            for (int i = 0; i < FiefdomActions.Ballots.Count; i++)
            {
                string   edict    = FiefdomActions.Ballots[i];
                String[] splitted = edict.Split();
                if (splitted[0] == "Market" || splitted[0] == "Levy")
                {
                    FiefdomActions.Edicts.Add(new Edict {
                        Type = splitted[0], Target = splitted[1], Amount = int.Parse(splitted[2]), Passed = votes[i]
                    });
                }
                if (splitted[0] == "Tax")
                {
                    if (votes[i])
                    {
                        FiefdomActions.MarketTax += int.Parse(splitted[1]);
                    }
                    FiefdomActions.Edicts.Add(new Edict {
                        Type = "Tax", Amount = int.Parse(splitted[1]), Passed = votes[i]
                    });
                }
            }
            FiefdomActions.Ballots.Clear();
            FiefdomActions.ClearVote();
            FiefdomActions.Ballots.Add(FiefdomActions.CreateVote());
            FiefdomActions.Ballots.Add(FiefdomActions.CreateVote());
            FiefdomActions.Ballots.Add(FiefdomActions.CreateVote());
        }
Exemplo n.º 2
0
        public static void NewGameInstance()
        {
            using (var db = new FiefContext())
            {
                if (db.GameState.FirstOrDefault() == null)
                {
                    db.GameState.Add(new GameState {
                        Day = 1, Season = 1, Year = 1
                    });
                }

                if (db.Market.ToList().Count == 0)
                {
                    db.Market.Add(new Market {
                        Type = "Wood", Price = 100
                    });
                    db.Market.Add(new Market {
                        Type = "Stone", Price = 100
                    });
                    db.Market.Add(new Market {
                        Type = "Food", Price = 100
                    });
                }
                db.SaveChanges();
            }
            FiefdomActions.Ballots.Add(FiefdomActions.CreateVote());
            FiefdomActions.Ballots.Add(FiefdomActions.CreateVote());
            FiefdomActions.Ballots.Add(FiefdomActions.CreateVote());
        }
Exemplo n.º 3
0
        public async Task UpdateClients()
        {
            GameState     gameState;
            List <Market> baseMarket;
            Fief          fief;

            using (var db = new FiefContext())
            {
                gameState  = db.GameState.FirstOrDefault();
                baseMarket = db.Market.ToList();
                List <Market> buyPrice  = new List <Market>();
                List <Market> sellPrice = new List <Market>();

                for (int i = 0; i < baseMarket.Count; i++)
                {
                    buyPrice.Add(new Market
                    {
                        Type  = baseMarket[i].Type,
                        Price = FiefdomActions.GetMarketBuyPrice(baseMarket[i].Type, baseMarket[i].Price)
                    });
                    sellPrice.Add(new Market
                    {
                        Type  = baseMarket[i].Type,
                        Price = FiefdomActions.GetMarketSellPrice(baseMarket[i].Type, baseMarket[i].Price)
                    });
                }

                foreach (string client in FiefdomUpdate.ConnectedUsers)
                {
                    fief = db.Fiefdom.Where(f => f.SessionId == client).Include("FiefdomPlot").Include("FiefdomResources").FirstOrDefault();
                    if (fief != null)
                    {
                        await _hubContext.Clients.Client(client).SendAsync("RecieveFiefdomData", fief, gameState,
                                                                           new GameValues
                        {
                            Ballots    = FiefdomActions.Ballots,
                            Edicts     = FiefdomActions.Edicts,
                            MarketTax  = FiefdomActions.MarketTax,
                            baseMarket = baseMarket,
                            buyMarket  = buyPrice,
                            sellMarket = sellPrice
                        });
                    }
                }
            }
        }
Exemplo n.º 4
0
        public static List <bool> CountVotes()
        {
            List <bool> votes = new List <bool> {
            };

            using (var db = new FiefContext())
            {
                Random rnd     = new Random();
                var    fiefdom = db.Fiefdom.Include("FiefdomPlot").Include("FiefdomResources").ToList();
                int    ballot1 = 0;
                int    ballot2 = 0;
                int    ballot3 = 0;
                foreach (var fief in fiefdom)
                {
                    int influence = FiefdomActions.GetInfluence(fief);

                    if (fief.Ballot1 == "Fore")
                    {
                        ballot1 += influence;
                    }
                    else if (fief.Ballot1 == "Nay")
                    {
                        ballot1 -= influence;
                    }
                    if (fief.Ballot2 == "Fore")
                    {
                        ballot2 += influence;
                    }
                    else if (fief.Ballot2 == "Nay")
                    {
                        ballot2 -= influence;
                    }
                    if (fief.Ballot3 == "Fore")
                    {
                        ballot3 += influence;
                    }
                    else if (fief.Ballot3 == "Nay")
                    {
                        ballot3 -= influence;
                    }
                }
                if (ballot1 == 0)
                {
                    if (rnd.Next(1, 1000) % 2 == 1)
                    {
                        ballot1++;
                    }
                    else
                    {
                        ballot1--;
                    }
                }
                if (ballot2 == 0)
                {
                    if (rnd.Next(1, 1000) % 2 == 1)
                    {
                        ballot2++;
                    }
                    else
                    {
                        ballot2--;
                    }
                }
                if (ballot3 == 0)
                {
                    if (rnd.Next(1, 1000) % 2 == 1)
                    {
                        ballot3++;
                    }
                    else
                    {
                        ballot3--;
                    }
                }
                votes.Add(ballot1 > 0);
                votes.Add(ballot2 > 0);
                votes.Add(ballot3 > 0);

                db.SaveChanges();
            }
            return(votes);
        }