示例#1
0
        public void AdvanceQuestState(NWPlayer oPC, int questID)
        {
            if (!oPC.IsPlayer)
            {
                return;
            }

            PCQuestStatus questStatus = _db.PCQuestStatus.Single(x => x.PlayerID == oPC.GlobalID && x.QuestID == questID);

            if (questStatus == null)
            {
                oPC.SendMessage("You have not accepted this quest yet.");
                return;
            }

            if (questStatus.CompletionDate != null)
            {
                return;
            }

            Quest quest = questStatus.Quest;

            // Find the next quest state.
            foreach (QuestState nextState in quest.QuestStates)
            {
                if (nextState.Sequence == questStatus.CurrentQuestState.Sequence + 1)
                {
                    // Either complete the quest or move to the new state.
                    if (nextState.IsFinalState)
                    {
                        RequestRewardSelectionFromPC(oPC, questID);
                        return;
                    }
                    else
                    {
                        _.AddJournalQuestEntry(quest.JournalTag, nextState.JournalStateID, oPC.Object, FALSE);
                        questStatus.CurrentQuestStateID = nextState.QuestStateID;
                        oPC.SendMessage("Objective for quest '" + quest.Name + "' complete! Check your journal for information on the next objective.");
                        _db.SaveChanges();

                        CreateExtendedQuestDataEntries(questStatus, questID, nextState.Sequence);
                        return;
                    }
                }
            }

            // Shouldn't reach this point unless configuration for the quest is broken.
            oPC.SendMessage("There was an error advancing you to the next objective for quest '" + quest.Name + "'. Please inform an admin this quest is bugged. (QuestID = " + questID + ")");
        }
示例#2
0
        private void RequestRewardSelectionFromPC(NWPlayer oPC, int questID)
        {
            if (!oPC.IsPlayer)
            {
                return;
            }

            Quest quest = _db.Quests.Single(x => x.QuestID == questID);

            if (quest.AllowRewardSelection)
            {
                oPC.SetLocalInt("QST_REWARD_SELECTION_QUEST_ID", questID);
                _dialog.StartConversation(oPC, oPC, "QuestRewardSelection");
            }
            else
            {
                QuestState lastState = quest.QuestStates.ElementAt(quest.QuestStates.Count - 1);
                _.AddJournalQuestEntry(quest.JournalTag, lastState.JournalStateID, oPC.Object, FALSE);
                CompleteQuest(oPC, questID, null);
            }
        }
示例#3
0
        public void CompleteQuest(NWPlayer player, int questID, ItemVO selectedItem)
        {
            if (!player.IsPlayer)
            {
                return;
            }

            Quest         quest   = _db.Quests.Single(x => x.QuestID == questID);
            PCQuestStatus pcState = _db.PCQuestStatus.Single(x => x.PlayerID == player.GlobalID && x.QuestID == questID);

            QuestState finalState = null;

            foreach (QuestState questState in quest.QuestStates)
            {
                if (questState.IsFinalState)
                {
                    finalState = questState;
                    break;
                }
            }

            if (finalState == null)
            {
                player.SendMessage("Could not find final state of quest. Please notify an admin this quest is bugged. (QuestID: " + questID + ")");
                return;
            }

            pcState.CurrentQuestStateID = finalState.QuestStateID;
            pcState.CompletionDate      = DateTime.UtcNow;

            if (selectedItem == null)
            {
                foreach (QuestRewardItem reward in quest.QuestRewardItems)
                {
                    _.CreateItemOnObject(reward.Resref, player.Object, reward.Quantity);
                }
            }
            else
            {
                _.CreateItemOnObject(selectedItem.Resref, player.Object, selectedItem.Quantity, "");
            }

            if (quest.RewardGold > 0)
            {
                _.GiveGoldToCreature(player.Object, quest.RewardGold);
            }

            if (quest.RewardXP > 0)
            {
                // TODO: Skill-related exp rewards??
            }

            if (quest.RewardKeyItemID != null)
            {
                _keyItem.GivePlayerKeyItem(player, (int)quest.RewardKeyItemID);
            }

            if (quest.RemoveStartKeyItemAfterCompletion && quest.StartKeyItemID != null)
            {
                _keyItem.RemovePlayerKeyItem(player, (int)quest.StartKeyItemID);
            }

            if (!string.IsNullOrWhiteSpace(quest.MapNoteTag))
            {
                _mapPin.DeleteMapPin(player, "QST_MAP_NOTE_" + questID);
            }

            if (quest.RewardFame > 0)
            {
                PCRegionalFame fame = _db.PCRegionalFames.Single(x => x.PlayerID == player.GlobalID && x.FameRegionID == quest.FameRegionID);
                fame.Amount += quest.RewardFame;
            }

            player.SendMessage("Quest '" + quest.Name + "' complete!");
            _db.SaveChanges();
        }
示例#4
0
        public void AcceptQuest(NWPlayer oPC, int questID)
        {
            if (!oPC.IsPlayer)
            {
                return;
            }

            PCQuestStatus status = _db.PCQuestStatus.Single(x => x.PlayerID == oPC.GlobalID && x.QuestID == questID);

            if (status != null)
            {
                if (status.CompletionDate != null)
                {
                    oPC.SendMessage("You have already completed this quest.");
                    return;
                }
                else
                {
                    oPC.SendMessage("You have already accepted this quest.");
                    return;
                }
            }


            Quest quest = _db.Quests.Single(x => x.QuestID == questID);

            if (!DoesPlayerMeetPrerequisites(oPC, quest.QuestPrerequisites))
            {
                oPC.SendMessage("You do not meet the prerequisites necessary to accept this quest.");
                return;
            }

            if (!DoesPlayerHaveRequiredKeyItems(oPC, quest.QuestStates.ElementAt(0).QuestRequiredKeyItemLists))
            {
                oPC.SendMessage("You do not have the required key items to accept this quest.");
                return;
            }

            PCRegionalFame fame = _db.PCRegionalFames.Single(x => x.PlayerID == oPC.GlobalID && x.FameRegionID == quest.FameRegionID);

            if (fame.Amount < quest.RequiredFameAmount)
            {
                oPC.SendMessage("You do not have enough fame to accept this quest.");
                return;
            }

            status = new PCQuestStatus();
            foreach (QuestState state in quest.QuestStates)
            {
                if (state.Sequence == 1)
                {
                    status.CurrentQuestStateID = state.QuestStateID;
                    break;
                }
            }

            if (status.CurrentQuestState == null)
            {
                oPC.SendMessage("There was an error accepting the quest '" + quest.Name + "'. Please inform an admin this quest is bugged. (QuestID: " + questID + ")");
                return;
            }

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

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

            status.QuestID  = quest.QuestID;
            status.PlayerID = oPC.GlobalID;
            _db.PCQuestStatus.Add(status);
            _db.SaveChanges();

            CreateExtendedQuestDataEntries(status, questID, 1);

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