Ejemplo n.º 1
0
        public User(GameClient baseClient, int UserId)
        {
            if (!Database.CheckUserExist(UserId))
            {
                throw new KeyNotFoundException("User " + UserId + " not found in database!");
            }

            if (!Database.CheckUserExtExists(UserId))
            {
                Database.CreateUserExt(UserId);
                NewPlayer = true;
            }


            EquipedCompetitionGear = new CompetitionGear(UserId);
            EquipedJewelry         = new Jewelry(UserId);

            Id       = UserId;
            Username = Database.GetUsername(UserId);

            Administrator = Database.CheckUserIsAdmin(Username);
            Moderator     = Database.CheckUserIsModerator(Username);

            chatViolations = Database.GetChatViolations(UserId);
            x      = Database.GetPlayerX(UserId);
            y      = Database.GetPlayerY(UserId);
            charId = Database.GetPlayerCharId(UserId);

            Facing          = PacketBuilder.DIRECTION_DOWN;
            experience      = Database.GetExperience(UserId);
            money           = Database.GetPlayerMoney(UserId);
            bankMoney       = Database.GetPlayerBankMoney(UserId);
            questPoints     = Database.GetPlayerQuestPoints(UserId);
            subscribed      = Database.IsUserSubscribed(UserId);
            subscribedUntil = Database.GetUserSubscriptionExpireDate(UserId);
            profilePage     = Database.GetPlayerProfile(UserId);
            privateNotes    = Database.GetPlayerNotes(UserId);
            hunger          = Database.GetPlayerHunger(UserId);
            thirst          = Database.GetPlayerThirst(UserId);
            tired           = Database.GetPlayerTiredness(UserId);

            if (Ranch.IsRanchOwned(this.Id))
            {
                if (this.Subscribed)
                {
                    OwnedRanch = Ranch.GetRanchOwnedBy(this.Id);
                }
                else // idk what it does here ...
                {
                    OwnedRanch = null;
                    Ranch.GetRanchOwnedBy(this.Id).OwnerId = -1;
                }
            }

            Gender         = Database.GetGender(UserId);
            MailBox        = new Mailbox(this);
            Highscores     = new Highscore(this);
            Awards         = new Award(this);
            MutePlayer     = new MutedPlayers(this);
            TrackedItems   = new Tracking(this);
            HorseInventory = new HorseInventory(this);

            // Generate SecCodes


            SecCodeSeeds[0] = (byte)GameServer.RandomNumberGenerator.Next(40, 60);
            SecCodeSeeds[1] = (byte)GameServer.RandomNumberGenerator.Next(40, 60);
            SecCodeSeeds[2] = (byte)GameServer.RandomNumberGenerator.Next(40, 60);
            SecCodeInc      = (byte)GameServer.RandomNumberGenerator.Next(40, 60);


            Friends        = new Friends(this);
            LoginTime      = DateTime.UtcNow;
            LoggedinClient = baseClient;
            Inventory      = new PlayerInventory(this);
            Quests         = new PlayerQuests(this);

            // Get auctions
            foreach (Auction auction in Auction.AuctionRooms)
            {
                foreach (Auction.AuctionEntry auctionEntry in auction.AuctionEntries)
                {
                    if (auctionEntry.HighestBidder == this.Id)
                    {
                        Auction.AuctionBid bid = new Auction.AuctionBid();
                        bid.BidUser     = this;
                        bid.BidAmount   = auctionEntry.HighestBid;
                        bid.AuctionItem = auctionEntry;

                        if (bid.BidAmount > 0)
                        {
                            Bids.Add(bid);
                            auctionEntry.Bidders.Add(bid);
                        }
                    }
                }
            }
        }