From 25f1b0fd95b8343b3a687b837100a81156200640 Mon Sep 17 00:00:00 2001 From: Filip Maj Date: Sun, 20 Feb 2022 12:39:34 -0500 Subject: [PATCH] Added debug script for setting quest completion --- Data/scripts/commands/gm/completedQuest.lua | 58 ++++++++++++++++++++ Map Server/Actors/Chara/Player/Player.cs | 22 +++++++- Map Server/Actors/Quest/QuestStateManager.cs | 18 +++++- 3 files changed, 94 insertions(+), 4 deletions(-) create mode 100644 Data/scripts/commands/gm/completedQuest.lua diff --git a/Data/scripts/commands/gm/completedQuest.lua b/Data/scripts/commands/gm/completedQuest.lua new file mode 100644 index 00000000..dd11b49b --- /dev/null +++ b/Data/scripts/commands/gm/completedQuest.lua @@ -0,0 +1,58 @@ +require("global"); + +properties = { + permissions = 0, + parameters = "dd", + description = +[[ +Sets if a quest is completed. +!completedQuest true/false +]], +} + +function onTrigger(player, argc, questId, flag) + + print("HEY"); + local messageID = MESSAGE_TYPE_SYSTEM_ERROR; + local sender = "[completedQuest] "; + local message = "Error"; + + if (argc < 1) then + return; + end + + local questId = tonumber(questId); + local flag = flag or nil; + + -- Fail if not valid questId + if (questId < 110001 or questId > 110001 + 2048) then + player:SendMessage(messageID, sender, "Invalid questId entered"); + return; + end + + -- Getting + if (arc == 1) then + player:SendMessage(messageID, sender, string.format("Quest %d completion is set to: %s", questId, tostring(player:IsQuestCompleted(questId)))); + return; + -- Setting + else + -- Fail if not valid flag + if (not flag == nil) then + player:SendMessage(messageID, sender, "Invalid flag entered"); + else + local boolFlag = false; + + if (flag == "true" or flag == "1" or flag == "on" or flag == "O") then + boolFlag = true; + elseif (flag == "false" or flag == "0" or flag == "off" or flag == "X") then + boolFlag = false; + elseif flag == "flip" or flag == "toggle" then + boolFlag = not player:IsQuestCompleted(questId); + end + + player:SetQuestComplete(questId, boolFlag); + player:SendMessage(messageID, sender, string.format("Quest %d completion set to: %s", questId, tostring(player:IsQuestCompleted(questId)))); + return; + end + end +end \ No newline at end of file diff --git a/Map Server/Actors/Chara/Player/Player.cs b/Map Server/Actors/Chara/Player/Player.cs index 814c3607..143cb108 100644 --- a/Map Server/Actors/Chara/Player/Player.cs +++ b/Map Server/Actors/Chara/Player/Player.cs @@ -1169,8 +1169,7 @@ namespace Meteor.Map.Actors private void SendCompletedQuests(ushort from, ushort to) { - Bitstream completed = questStateManager.GetCompletedBitstream(); - byte[] data = completed.GetSlice(from, to); + byte[] data = questStateManager.GetCompletionSliceBytes(from, to); SetActorPropetyPacket completedQuestWorkUpdate = new SetActorPropetyPacket(from, to, "playerWork/journal"); completedQuestWorkUpdate.AddBitfield(Utils.MurmurHash2("playerWork.questScenarioComplete", 0), data); @@ -1661,6 +1660,25 @@ namespace Meteor.Map.Actors return false; } + public bool IsQuestCompleted(uint id) + { + return questStateManager.IsQuestComplete(id); + } + + public void SetQuestComplete(uint id, bool flag) + { + if (flag) + { + Quest currentQuest = GetQuest(id); + if (currentQuest != null) + { + CompleteQuest(currentQuest); + return; + } + } + questStateManager.ForceQuestCompleteFlag(id, flag); + } + public Quest GetQuest(uint id) { for (int i = 0; i < questScenario.Length; i++) diff --git a/Map Server/Actors/Quest/QuestStateManager.cs b/Map Server/Actors/Quest/QuestStateManager.cs index 1bc0bebd..3bc6c0ec 100644 --- a/Map Server/Actors/Quest/QuestStateManager.cs +++ b/Map Server/Actors/Quest/QuestStateManager.cs @@ -156,9 +156,23 @@ namespace Meteor.Map.Actors.QuestNS return ActiveQuests.FindAll(quest => quest.IsQuestENPC(player, npc)).ToArray(); } - public Bitstream GetCompletedBitstream() + public byte[] GetCompletionSliceBytes(ushort from, ushort to) { - return CompletedQuestsBitfield; + return CompletedQuestsBitfield.GetSlice(from, to); + } + + public bool IsQuestComplete(uint questId) + { + return CompletedQuestsBitfield.Get(questId - SCENARIO_START); + } + + public void ForceQuestCompleteFlag(uint questId, bool flag) + { + if (flag) + CompletedQuestsBitfield.Set(questId - SCENARIO_START); + else + CompletedQuestsBitfield.Clear(questId - SCENARIO_START); + ComputeAvailable(); } } }