Example #1
0
        public static void AcceptQuest(NWPlayer player, NWObject questOwner, int questID)
        {
            if (!player.IsPlayer)
            {
                return;
            }

            Quest quest = DataService.Single <Quest>(x => x.ID == questID);

            if (!CanAcceptQuest(player, quest, true))
            {
                return;
            }

            var questState = DataService.Single <QuestState>(x => x.QuestID == questID && x.Sequence == 1);
            var status     = new PCQuestStatus
            {
                CurrentQuestStateID = questState.ID
            };

            // Give temporary key item at start of quest.
            if (quest.StartKeyItemID != null)
            {
                KeyItemService.GivePlayerKeyItem(player, (int)quest.StartKeyItemID);
            }

            if (!string.IsNullOrWhiteSpace(quest.MapNoteTag))
            {
                MapPinService.AddWaypointMapPin(player, quest.MapNoteTag, quest.Name, "QST_MAP_NOTE_" + questID);
            }

            status.QuestID  = quest.ID;
            status.PlayerID = player.GlobalID;
            DataService.SubmitDataChange(status, DatabaseActionType.Insert);
            CreateExtendedQuestDataEntries(status);

            _.AddJournalQuestEntry(quest.JournalTag, 1, player.Object, FALSE);
            player.SendMessage("Quest '" + quest.Name + "' accepted. Refer to your journal for more information on this quest.");


            if (!string.IsNullOrWhiteSpace(quest.OnAcceptRule) && questOwner != null)
            {
                var rule = GetQuestRule(quest.OnAcceptRule);

                string[] args = null;
                if (!string.IsNullOrWhiteSpace(quest.OnAcceptArgs))
                {
                    args = quest.OnAcceptArgs.Split(',');
                }
                rule.Run(player, questOwner, questID, args);
            }
        }
Example #2
0
        /// <summary>
        /// Accepts a quest for a player. This updates their journal entry and marks all necessary flags
        /// on the player.
        /// </summary>
        /// <param name="player">The player who is accepting the quest.</param>
        /// <param name="questOwner">The quest giver object.</param>
        /// <param name="questID">The ID number of the quest to accept.</param>
        public static void AcceptQuest(NWPlayer player, NWObject questOwner, int questID)
        {
            if (!player.IsPlayer)
            {
                return;
            }

            // Retrieve quest from the cache.
            Quest quest = DataService.Single <Quest>(x => x.ID == questID);

            // Check whether player can accept the quest. Send a message if they can't.
            if (!CanAcceptQuest(player, quest, true))
            {
                return;
            }

            // By this point, it's assumed the player will accept the quest.
            // However, if this quest is repeatable we must first update the existing entry.
            var status = DataService.SingleOrDefault <PCQuestStatus>(x => x.QuestID == questID &&
                                                                     x.PlayerID == player.GlobalID);
            bool foundExisting = status != null;

            // Didn't find an existing state so we'll create a new object.
            if (status == null)
            {
                status = new PCQuestStatus();
            }
            else
            {
                status.CompletionDate = null;
            }

            // Retrieve the first quest state for this quest.
            var questState = DataService.Single <QuestState>(x => x.QuestID == questID && x.Sequence == 1);

            status.CurrentQuestStateID = questState.ID;

            // Give temporary key item at start of quest.
            if (quest.StartKeyItemID != null)
            {
                KeyItemService.GivePlayerKeyItem(player, (int)quest.StartKeyItemID);
            }

            // Add a map pin if specified by the quest.
            if (!string.IsNullOrWhiteSpace(quest.MapNoteTag))
            {
                MapPinService.AddWaypointMapPin(player, quest.MapNoteTag, quest.Name, "QST_MAP_NOTE_" + questID);
            }

            status.QuestID  = quest.ID;
            status.PlayerID = player.GlobalID;

            // Insert or update player's quest status.
            DataService.SubmitDataChange(status, foundExisting ? DatabaseActionType.Update : DatabaseActionType.Insert);

            // Create extended quest entries, if necessary.
            CreateExtendedQuestDataEntries(status);

            // Add the journal entry to the player.
            _.AddJournalQuestEntry(quest.JournalTag, 1, player.Object, FALSE);

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

            // If this quest runs any custom rules, do those now.
            if (!string.IsNullOrWhiteSpace(quest.OnAcceptRule) && questOwner != null)
            {
                var rule = GetQuestRule(quest.OnAcceptRule);

                string[] args = null;
                if (!string.IsNullOrWhiteSpace(quest.OnAcceptArgs))
                {
                    args = quest.OnAcceptArgs.Split(',');
                }
                rule.Run(player, questOwner, questID, args);
            }

            // Notify to subscribers that a quest has just been accepted.
            MessageHub.Instance.Publish(new OnQuestAccepted(player, questID));
        }