public QuestInfo(int questId, int characterId, IQuestScript script, int?databaseQuestId) { QuestId = questId; CharacterId = characterId; Script = script; DatabaseQuestId = databaseQuestId; Monsters = new Dictionary <int, short>(); }
/// <inheritdoc /> public void Initialize(IPlayerEntity player) { IEnumerable <QuestInfo> playerQuests = _database.Quests.Where(x => x.CharacterId == player.PlayerData.Id) .AsNoTracking() .AsEnumerable() .Select(x => { IQuestScript questScript = _gameResources.Quests.GetValueOrDefault(x.QuestId); if (questScript == null) { return(null); } var quest = new QuestInfo(x.QuestId, x.CharacterId, questScript, x.Id) { IsChecked = x.IsChecked, IsFinished = x.Finished, StartTime = x.StartTime, IsPatrolDone = x.IsPatrolDone }; if (questScript.EndConditions.Monsters != null && questScript.EndConditions.Monsters.Any()) { quest.Monsters = new Dictionary <int, short> { { _gameResources.GetDefinedValue(questScript.EndConditions.Monsters.ElementAtOrDefault(0)?.Id), (short)x.MonsterKilled1 }, { _gameResources.GetDefinedValue(questScript.EndConditions.Monsters.ElementAtOrDefault(1)?.Id), (short)x.MonsterKilled2 } }; } return(quest); }) .Where(x => x != null); player.QuestDiary = new QuestDiaryComponent(playerQuests); }
public QuestInfo(int questId, int characterId, IQuestScript script) : this(questId, characterId, script, default) { }
/// <inheritdoc /> public void OpenNpcDialog(IPlayerEntity player, uint npcObjectId, string dialogKey, int questId = 0) { var npc = player.FindEntity <INpcEntity>(npcObjectId); if (npc == null) { _logger.LogError($"Cannot find NPC with id: {npcObjectId}."); return; } _logger.LogTrace($"{npc.Object.Name}: '{dialogKey}'/{questId}"); if (string.IsNullOrEmpty(dialogKey)) { if (npc.Quests.Any()) { IEnumerable <IQuestScript> availableQuests = npc.Quests.Where(x => _questSystem.CanStartQuest(player, npc, x)); if (availableQuests.Count() == 1) { IQuestScript firstQuest = availableQuests.First(); var questState = _questSystem.CanStartQuest(player, npc, firstQuest) ? QuestStateType.Suggest : QuestStateType.End; _questSystem.ProcessQuest(player, npc, firstQuest, questState); return; } } IEnumerable <IQuestScript> questsToBeFinished = player.QuestDiary.ActiveQuests.Where(x => npc.Object.Name.Equals(x.Script.EndCharacter, StringComparison.OrdinalIgnoreCase)).Select(x => x.Script); if (questsToBeFinished.Any()) { _questSystem.ProcessQuest(player, npc, questsToBeFinished.First(), QuestStateType.End); return; } if (!npc.NpcData.HasDialog) { _logger.LogError($"NPC '{npc.Object.Name}' doesn't have a dialog."); return; } SendNpcDialog(player, npc, npc.NpcData.Dialog.IntroText, npc.NpcData.Dialog.Links); } else { if (questId != 0) { // Check if the quest exists for the current NPC IQuestScript quest = npc.Quests.FirstOrDefault(x => x.Id == questId); if (quest == null) { // If not, check if the npc is the end character of player's active quest quest = player.QuestDiary.ActiveQuests.Where(x => x.QuestId == questId && npc.Object.Name.Equals(x.Script.EndCharacter, StringComparison.OrdinalIgnoreCase)).Select(x => x.Script).FirstOrDefault(); if (quest == null) { _logger.LogError($"Cannot find quest with id '{questId}' at npc '{npc}' for player '{player}'."); return; } } _questSystem.ProcessQuest(player, npc, quest, dialogKey.ToEnum <QuestStateType>()); } else { if (!npc.NpcData.HasDialog) { _logger.LogError($"NPC '{npc.Object.Name}' doesn't have a dialog."); return; } if (dialogKey == DialogConstants.Bye) { _chatPacketFactory.SendChatTo(npc, player, npc.NpcData.Dialog.ByeText); _npcDialogPacketFactory.SendCloseDialog(player); return; } else { DialogLink dialogLink = npc.NpcData.Dialog.Links?.FirstOrDefault(x => x.Id == dialogKey); if (dialogLink == null) { _logger.LogError($"Cannot find dialog key: '{dialogKey}' for NPC '{npc.Object.Name}'."); return; } SendNpcDialog(player, npc, dialogLink.Texts, npc.NpcData.Dialog.Links); } } } }