Пример #1
0
        /// <summary>
        /// Returns true if player can complete this quest. Returns false otherwise.
        /// </summary>
        /// <param name="player">The player to check</param>
        /// <returns>true if player can complete, false otherwise</returns>
        private bool CanComplete(NWGameObject player)
        {
            // Has the player even accepted this quest?
            var playerID = GetGlobalID(player);
            var pcStatus = QuestProgressRepo.Get(playerID, QuestID);

            if (pcStatus == null)
            {
                return(false);
            }

            // Is the player on the final state of this quest?
            if (pcStatus.CurrentState != GetStates().Count())
            {
                return(false);
            }

            var state = GetState(pcStatus.CurrentState);

            // Are all objectives complete?
            foreach (var objective in state.GetObjectives())
            {
                if (!objective.IsComplete(player, QuestID))
                {
                    return(false);
                }
            }

            // Met all requirements. We can complete this quest.
            return(true);
        }
        public bool MeetsPrerequisite(NWGameObject player)
        {
            var playerID = GetGlobalID(player);
            var quest    = QuestProgressRepo.Get(playerID, _questID);

            return(quest.TimesCompleted > 0);
        }
Пример #3
0
        public void Initialize(NWGameObject player, string questID)
        {
            var playerID = GetGlobalID(player);
            var status   = QuestProgressRepo.Get(playerID, questID);
            var progress = new QuestProgress.KillProgress
            {
                NPCGroupID = _group,
                Remaining  = _amount
            };

            status.KillProgresses.Add(progress);
            QuestProgressRepo.Set(playerID, status);
        }
        public void Initialize(NWGameObject player, string questID)
        {
            var playerID = GetGlobalID(player);
            var status   = QuestProgressRepo.Get(playerID, questID);

            var itemProgress = new QuestProgress.ItemProgress
            {
                Resref    = _resref,
                Remaining = _quantity
            };

            status.ItemProgresses.Add(itemProgress);
            QuestProgressRepo.Set(playerID, status);
        }
Пример #5
0
        /// <summary>
        /// Completes a quest for a player. If a reward is selected, that reward will be given to the player.
        /// Otherwise, all rewards configured for this quest will be given to the player.
        /// </summary>
        /// <param name="player">The player completing the quest.</param>
        /// <param name="questSource">The source of the quest completion</param>
        /// <param name="selectedReward">The reward selected by the player</param>
        internal void Complete(NWGameObject player, NWGameObject questSource, IQuestReward selectedReward)
        {
            if (!GetIsPlayer(player))
            {
                return;
            }
            if (!CanComplete(player))
            {
                return;
            }

            var playerID = GetGlobalID(player);
            var pcState  = QuestProgressRepo.Get(playerID, QuestID);

            // Mark player as being on the last state of the quest.
            pcState.CurrentState = GetStates().Count();
            pcState.TimesCompleted++;

            // No selected reward, simply give all available rewards to the player.
            if (selectedReward == null)
            {
                foreach (var reward in Rewards)
                {
                    reward.GiveReward(player);
                }
            }
            // There is a selected reward. Give that reward and any rewards which are not selectable to the player.
            else
            {
                // Non-selectable rewards (gold, GP, etc) are granted to the player.
                foreach (var reward in Rewards.Where(x => !x.IsSelectable))
                {
                    reward.GiveReward(player);
                }

                selectedReward.GiveReward(player);
            }

            QuestProgressRepo.Set(playerID, pcState);

            foreach (var action in _onCompleteActions)
            {
                action.Invoke(player, questSource);
            }

            SendMessageToPC(player, "Quest '" + Name + "' complete!");
            RemoveJournalQuestEntry(JournalTag, player, false);

            Publish.CustomEvent(player, QuestEventPrefix.OnQuestAdvanced, new QuestCompleted(player, QuestID));
        }
Пример #6
0
        public bool IsComplete(NWGameObject player, string questID)
        {
            var playerID = GetGlobalID(player);
            var status   = QuestProgressRepo.Get(playerID, questID);

            foreach (var progress in status.KillProgresses)
            {
                if (progress.Remaining > 0)
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #7
0
        /// <summary>
        /// Accepts a quest using the configured settings.
        /// </summary>
        /// <param name="player">The player accepting the quest.</param>
        /// <param name="questSource">The source of the quest giver</param>
        internal void Accept(NWGameObject player, NWGameObject questSource)
        {
            if (!GetIsPlayer(player))
            {
                return;
            }

            if (!CanAccept(player))
            {
                return;
            }

            var playerID = GetGlobalID(player);

            // By this point, it's assumed the player will accept the quest.
            var status = QuestProgressRepo.Get(playerID, QuestID);

            // Retrieve the first quest state for this quest.
            status.CurrentState = 1;
            status.QuestID      = QuestID;

            // Insert or update player's quest status.
            QuestProgressRepo.Set(playerID, status);

            var state = GetState(1);

            foreach (var objective in state.GetObjectives())
            {
                objective.Initialize(player, QuestID);
            }

            // Add the journal entry to the player.
            AddJournalQuestEntry(JournalTag, 1, player, false);

            // Notify them that they've accepted a quest.
            SendMessageToPC(player, "Quest '" + Name + "' accepted. Refer to your journal for more information on this quest.");

            // Run any quest-specific code.
            foreach (var action in _onAcceptActions)
            {
                action.Invoke(player, questSource);
            }

            // Notify to subscribers that a quest has just been accepted.
            Publish.CustomEvent(player, QuestEventPrefix.OnQuestAccepted, new QuestAccepted(player, QuestID));
        }
Пример #8
0
        /// <summary>
        /// Returns true if player can accept this quest. Returns false otherwise.
        /// </summary>
        /// <param name="player">The player to check</param>
        /// <returns>true if player can accept, false otherwise</returns>
        private bool CanAccept(NWGameObject player)
        {
            // Retrieve the player's current quest status for this quest.
            // If they haven't accepted it yet, this will be null.
            var playerID = GetGlobalID(player);
            var status   = QuestProgressRepo.Get(playerID, QuestID);

            // If the status is null, it's assumed that the player hasn't accepted it yet.
            if (status != null)
            {
                // If the quest isn't repeatable, prevent the player from accepting it after it's already been completed.
                if (status.TimesCompleted > 0)
                {
                    // If it's repeatable, then we don't care if they've already completed it.
                    if (!IsRepeatable)
                    {
                        SendMessageToPC(player, "You have already completed this quest.");
                        return(false);
                    }
                }
                // If the player already accepted the quest, prevent them from accepting it again.
                else
                {
                    SendMessageToPC(player, "You have already accepted this quest.");
                    return(false);
                }
            }

            // Check whether the player meets all necessary prerequisites.
            foreach (var prereq in Prerequisites)
            {
                if (!prereq.MeetsPrerequisite(player))
                {
                    SendMessageToPC(player, "You do not meet the prerequisites necessary to accept this quest.");
                    return(false);
                }
            }

            return(true);
        }
Пример #9
0
        /// <summary>
        /// Advances the player to the next quest state.
        /// </summary>
        /// <param name="player">The player advancing to the next quest state</param>
        /// <param name="questSource">The source of quest advancement</param>
        internal void Advance(NWGameObject player, NWGameObject questSource)
        {
            if (!GetIsPlayer(player))
            {
                return;
            }

            // Retrieve the player's current quest state.
            var playerID    = GetGlobalID(player);
            var questStatus = QuestProgressRepo.Get(playerID, QuestID);

            // Can't find a state? Notify the player they haven't accepted the quest.
            if (questStatus.CurrentState <= 0)
            {
                SendMessageToPC(player, "You have not accepted this quest yet.");
                return;
            }

            // If this quest has already been completed, exit early.
            // This is used in case a module builder incorrectly configures a quest.
            // We don't want to risk giving duplicate rewards.
            if (questStatus.TimesCompleted > 0 && !IsRepeatable)
            {
                return;
            }

            var currentState = GetState(questStatus.CurrentState);
            var lastState    = GetStates().Last();

            // If this is the last state, the assumption is that it's time to complete the quest.
            if (currentState == lastState)
            {
                RequestRewardSelectionFromPC(player, questSource);
            }
            else
            {
                // Progress player's quest status to the next state.
                questStatus.CurrentState++;
                var nextState = GetState(questStatus.CurrentState);

                // Update the player's journal
                AddJournalQuestEntry(JournalTag, questStatus.CurrentState, player, false);

                // Notify the player they've progressed.
                SendMessageToPC(player, "Objective for quest '" + Name + "' complete! Check your journal for information on the next objective.");

                // Submit all of these changes to the cache/DB.
                QuestProgressRepo.Set(playerID, questStatus);

                // Create any extended data entries for the next state of the quest.
                foreach (var objective in nextState.GetObjectives())
                {
                    objective.Initialize(player, QuestID);
                }

                // Run any quest-specific code.
                foreach (var action in _onAdvanceActions)
                {
                    action.Invoke(player, questSource, questStatus.CurrentState);
                }

                // Notify to subscribers that the player has advanced to the next state of the quest.
                Publish.CustomEvent(player, QuestEventPrefix.OnQuestAdvanced, new QuestAdvanced(player, QuestID, questStatus.CurrentState));
            }
        }