コード例 #1
0
ファイル: PlayerDB.Data.cs プロジェクト: pzaps/Server
        public bool LoadCharacter(DatabaseConnection dbConnection, int characterSlot)
        {
            dataLock.EnterReadLock();
            bool result = false;
            string characterID = PlayerDataManager.RetrieveAccountCharacterID(dbConnection.Database, accountName, characterSlot);
            if (!string.IsNullOrEmpty(characterID)) {
                playerData = new PlayerData(characterID);
                PlayerDataManager.LoadPlayerData(dbConnection.Database, playerData);
                PlayerDataManager.LoadPlayerStatistics(dbConnection.Database, playerData);
                PlayerDataManager.LoadPlayerMissionBoardMissions(dbConnection.Database, playerData);
                PlayerDataManager.LoadPlayerStoryHelperStateSettings(dbConnection.Database, playerData);
                PlayerDataManager.LoadPlayerJobList(dbConnection.Database, playerData);
                PlayerDataManager.LoadPlayerTriggerEvents(dbConnection.Database, playerData);

                inventory = new Inventory(playerData.Inventory);
                bank = new Inventory(playerData.Bank);

                // Load available ExpKit modules
                if (string.IsNullOrEmpty(playerData.AvailableModules)) {
                    AddEnabledExpKitModules();
                } else {
                    string[] modules = playerData.AvailableModules.Split(';');
                    availableExpKitModules = new AvailableExpKitModuleCollection(modules.Length);
                    AddEnabledExpKitModules();
                    for (int i = 0; i < modules.Length; i++) {
                        if (modules[i].IsNumeric()) {
                            if (availableExpKitModules.Contains((Enums.ExpKitModules)modules[i].ToInt()) == false) {
                                availableExpKitModules.Add(new AvailableExpKitModule((Enums.ExpKitModules)modules[i].ToInt(), false));
                            }
                        }
                    }
                }

                // Load statistics - Statistics data is inherited from PlayerData
                statistics = new Statistics.PlayerStatistics(this);

                // Load mission board data
                missionBoard = new WonderMails.MissionBoard(this);
                missionBoard.LoadMissionBoardData();
                missionBoard.UpdateMissionBoard();

                // Load joblist
                jobList = new WonderMailTasks(this);
                jobList.LoadJobList(playerData.JobList);

                //load mission goals [HIGH]
                goalPoints = new List<GoalPoint>();

                // Load story helper
                storyHelper = new StoryHelper(this);

                // Load trigger events [HIGH]
                triggerEvents = new List<Events.Player.TriggerEvents.ITriggerEvent>();

                // Load player team
                team = new Recruit[playerData.TeamMembers.Length];
                for (int i = 0; i < playerData.TeamMembers.Length; i++) {
                    team[i] = new Recruit(client);
                }
                for (int i = 0; i < playerData.TeamMembers.Length; i++) {
                    if (playerData.TeamMembers[i].RecruitIndex != -1) {
                        RecruitData recruitData = PlayerDataManager.LoadPlayerRecruit(dbConnection.Database, CharID, playerData.TeamMembers[i].RecruitIndex, playerData.TeamMembers[i].UsingTempStats);
                        if (recruitData != null) {
                            team[i].LoadFromRecruitData(recruitData, playerData.TeamMembers[i].RecruitIndex);
                        } else {
                            playerData.TeamMembers[i].RecruitIndex = -1;
                        }
                    }
                }

                for (int i = 0; i < playerData.TeamMembers.Length; i++) {
                    if (team[i].RecruitIndex != -1) {
                        team[i].LoadActiveItemList();
                    }
                }

                // Set the explorer rank
                while (ExplorerRank != Enums.ExplorerRank.Guildmaster && MissionExp >= MissionManager.DetermineMissionExpRequirement(ExplorerRank + 1)) {
                    ExplorerRank++;
                }

                if (MapID.IsNumeric()) {
                    int mapNum = MapID.ToInt();
                    if (mapNum == -2) {
                        MapID = MapManager.GenerateMapID(Settings.Crossroads);
                    } else {
                        MapID = "s" + MapID;
                    }
                }
                //            if (string.IsNullOrEmpty(this.id)) {
                //                id = PlayerID.GeneratePlayerID();
                //            }
                //PlayerID.AddPlayerToIndexList(CharID, client.TcpID);

                loaded = true;
            }

            dataLock.ExitReadLock();
            return result;
        }
コード例 #2
0
        /// <summary>
        /// Takes the item slot that is in the specified inventory slot.
        /// </summary>
        /// <param name="slot">The slot.</param>
        /// <param name="amount">Amount to take.</param>
        /// <param name="ignoreSticky">if set to <c>true</c>, the item will be taken even if it is sticky.</param>
        /// <returns><c>true</c> if the item was successfully taken, otherwise <c>false</c></returns>
        public bool TakeItemSlot(int slot, int amount, bool ignoreSticky)
        {
            if (amount < 0)
            {
                return(false);
            }
            bool result = false;

            if (slot < 1 || slot > MaxInv)
            {
                return(false);
            }
            if (Inventory.ContainsKey(slot) && Inventory[slot].Num > 0)
            {
                bool TakeItem = false;
                int  itemNum  = Inventory[slot].Num;
                if (ignoreSticky || !Inventory[slot].Sticky)
                {
                    if (ItemManager.Items[itemNum].Type == Enums.ItemType.Currency || ItemManager.Items[itemNum].StackCap > 0)
                    {
                        // Is what we are trying to take away more then what they have?  If so just set it to zero
                        if (amount >= Inventory[slot].Amount)
                        {
                            TakeItem = true;
                        }
                        else
                        {
                            Inventory[slot].Amount = Inventory[slot].Amount - amount;
                            Messenger.SendInventoryUpdate(client, slot);

                            result = true;
                        }
                    }
                    else
                    {
                        TakeItem = true;

                        //n = ItemManager.Items[Inventory[i].Num].Type;
                        // Check if its not an equipable weapon, and if it isn't then take it away
                        //if ((n != Enums.ItemType.Weapon) && (n != Enums.ItemType.Armor) && (n != Enums.ItemType.Helmet) && (n != Enums.ItemType.Shield) && (n != Enums.ItemType.Legs) & (n != Enums.ItemType.Ring) & (n != Enums.ItemType.Necklace)) {
                        //    TakeItem = true;
                        //}
                    }

                    if (TakeItem == true)
                    {
                        result = true;

                        // Check to see if its held by anyone

                        if (GetItemSlotHolder(slot) > -1)//remove from all equippers
                        {
                            RemoveItem(slot, true, false);
                            Messenger.SendWornEquipment(client);
                        }

                        Inventory[slot].Num    = 0;
                        Inventory[slot].Amount = 0;
                        Inventory[slot].Sticky = false;
                        Inventory[slot].Tag    = "";
                        //mInventory[i].Dur = 0;

                        //check if it's held-in-bag, and if it was the last functional copy
                        if (ItemManager.Items[itemNum].Type == Enums.ItemType.HeldInBag && HasItem(itemNum, true) == 0)
                        {
                            for (int j = 0; j < Constants.MAX_ACTIVETEAM; j++)
                            {
                                if (team[j].Loaded)
                                {
                                    //the function auto-checks if it's in the activeItemlist to begin with
                                    team[j].RemoveFromActiveItemList(itemNum);
                                }
                            }
                        }

                        // Send the inventory update
                        Messenger.SendInventoryUpdate(client, slot);
                    }
                }
            }
            return(result);
        }