예제 #1
0
        /// <summary>
        /// Adds a player name to the tax collector list.
        /// </summary>
        /// <param name="playerName"></param>
        public override TaxCollector AddTaxCollector(string playerName)
        {
            Debug.Assert(playerName != null, "playerName must not be null.");

            lock ( locker )
            {
                if (TaxCollectorNames.Contains(playerName))
                {
                    return(null);
                }

                NonQuery(
                    "INSERT INTO TaxCollectors (WorldId, PlayerName)" +
                    "VALUES (@0, @1)",
                    Main.worldID, playerName);

                var tc = new TaxCollector(playerName);
                TaxCollectors.Add(tc);
                TaxCollectorNames.Add(playerName);
                return(tc);
            }
        }
예제 #2
0
        /// <summary>
        ///     Loads the houses and shops.
        /// </summary>
        public override void Load()
        {
            lock ( locker )
            {
                Houses.Clear();
                using (var connection = new MySqlConnection(ConnectionString))
                    using (var command = QueryCommand(connection, "SELECT * FROM Houses WHERE WorldId = @0", Main.worldID))
                        using (var reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                var ownerName = reader.Get <string>("OwnerName");
                                var name      = reader.Get <string>("Name");
                                var x         = reader.Get <int>("X");
                                var y         = reader.Get <int>("Y");
                                var x2        = reader.Get <int>("X2");
                                var y2        = reader.Get <int>("Y2");
                                var debt      = (decimal)reader.Get <long>("Debt");
                                var lastTaxed = DateTime.Parse(reader.Get <string>("LastTaxed"));
                                var forSale   = reader.Get <int>("ForSale") == 1;
                                var salePrice = reader.Get <string>("SalePrice");

                                var house = new House(ownerName, name, x, y, x2, y2)
                                {
                                    Debt      = debt,
                                    LastTaxed = lastTaxed,
                                    ForSale   = forSale,
                                    SalePrice = salePrice
                                };
                                using (var connection2 = new MySqlConnection(ConnectionString))
                                    using (var command2 = QueryCommand(connection2,
                                                                       "SELECT Username FROM HouseHasUser " +
                                                                       "WHERE OwnerName = @0 AND HouseName = @1 AND WorldId = @2",
                                                                       ownerName, name, Main.worldID))
                                        using (var reader2 = command2.ExecuteReader())
                                        {
                                            while (reader2.Read())
                                            {
                                                var username = reader2.Get <string>("Username");
                                                house.AllowedUsernames.Add(username);
                                            }
                                        }
                                Houses.Add(house);
                            }
                        }

                Shops.Clear();
                using (var connection = new MySqlConnection(ConnectionString))
                    using (var command = QueryCommand(connection, "SELECT * FROM Shops WHERE WorldID = @0", Main.worldID))
                        using (var reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                var ownerName = reader.Get <string>("OwnerName");
                                var name      = reader.Get <string>("Name");
                                var x         = reader.Get <int>("X");
                                var y         = reader.Get <int>("Y");
                                var x2        = reader.Get <int>("X2");
                                var y2        = reader.Get <int>("X2");
                                var chestX    = reader.Get <int>("ChestX");
                                var chestY    = reader.Get <int>("ChestY");
                                var isOpen    = reader.Get <int>("IsOpen") == 1;
                                var message   = reader.Get <string>("Message");

                                var shop = new Shop(ownerName, name, x, y, x2, y2, chestX, chestY)
                                {
                                    IsOpen  = isOpen,
                                    Message = message
                                };
                                using (var connection2 = new MySqlConnection(ConnectionString))
                                    using (var command2 = QueryCommand(connection2,
                                                                       "SELECT * FROM ShopHasItem WHERE OwnerName = @0 AND ShopName = @1 AND WorldId = @2",
                                                                       ownerName, name, Main.worldID))
                                        using (var reader2 = command2.ExecuteReader())
                                        {
                                            while (reader2.Read())
                                            {
                                                var index     = reader2.Get <int>("ItemIndex");
                                                var itemId    = reader2.Get <int>("ItemId");
                                                var stackSize = reader2.Get <int>("StackSize");
                                                var prefixId  = (byte)reader2.Get <int>("PrefixId");
                                                shop.Items.Add(new ShopItem(index, itemId, stackSize, prefixId));
                                            }
                                        }
                                using (var connection2 = new MySqlConnection(ConnectionString))
                                    using (var command2 = QueryCommand(connection2,
                                                                       "SELECT * FROM ShopHasPrice WHERE OwnerName = @0 AND ShopName = @1 AND WorldId = @2",
                                                                       ownerName, name, Main.worldID))
                                        using (var reader2 = command2.ExecuteReader())
                                        {
                                            while (reader2.Read())
                                            {
                                                var itemId          = reader2.Get <int>("ItemId");
                                                var unitPriceString = reader2.Get <string>("UnitPrice");
                                                shop.UnitPrices[itemId] = new PriceInfo(unitPriceString);
                                            }
                                        }
                                Shops.Add(shop);
                            }
                        }

                //load in tax collectors.
                TaxCollectors.Clear();
                TaxCollectorNames.Clear();
                using (var connection = new MySqlConnection(ConnectionString))
                    using (var command = QueryCommand(connection, "SELECT * FROM TaxCollectors WHERE WorldID = @0", Main.worldID))
                        using (var reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                var playerName = reader.Get <string>("PlayerName");
                                var tc         = new TaxCollector(playerName);
                                TaxCollectors.Add(tc);
                                TaxCollectorNames.Add(playerName);
                            }
                        }
            }
        }