-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
--------- Co-authored-by: Zbizu <Zbizu@users.noreply.github.com>
- Loading branch information
1 parent
74c9f8f
commit d50730a
Showing
26 changed files
with
485 additions
and
258 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
Quest = {} | ||
Quest.__index = Quest | ||
|
||
function Quest:register() | ||
local quests = Game.getQuests() | ||
local missions = Game.getMissions() | ||
|
||
self.id = #quests + 1 | ||
|
||
for _, mission in pairs(self.missions) do | ||
mission.id = #missions + 1 | ||
mission.questId = self.id | ||
missions[mission.id] = setmetatable(mission, Mission) | ||
end | ||
|
||
quests[self.id] = self | ||
return true | ||
end | ||
|
||
function Quest:isStarted(player) | ||
return player:getStorageValue(self.storageId) >= self.storageValue | ||
end | ||
|
||
function Quest:isCompleted(player) | ||
for _, mission in pairs(self.missions) do | ||
if not mission:isCompleted(player) then | ||
return false | ||
end | ||
end | ||
return true | ||
end | ||
|
||
function Quest:getMissions(player) | ||
local missions = {} | ||
for _, mission in pairs(self.missions) do | ||
if mission:isStarted(player) then | ||
missions[#missions + 1] = mission | ||
end | ||
end | ||
return missions | ||
end | ||
|
||
function Quest:isTracking(key, value) | ||
if self.storageId == key and value == self.storageValue then | ||
return true | ||
end | ||
|
||
for _, mission in pairs(self.missions) do | ||
if mission.storageId == key and value >= mission.startValue and value <= mission.endValue then | ||
return true | ||
end | ||
end | ||
return false | ||
end | ||
|
||
Mission = {} | ||
Mission.__index = Mission | ||
|
||
function Mission:isStarted(player) | ||
local value = player:getStorageValue(self.storageId) | ||
if value < self.startValue then | ||
return false | ||
end | ||
|
||
if not self.ignoreEndValue and value > self.endValue then | ||
return false | ||
end | ||
|
||
return true | ||
end | ||
|
||
function Mission:isCompleted(player) | ||
if self.ignoreEndValue then | ||
return player:getStorageValue(self.storageId) >= self.endValue | ||
end | ||
return player:getStorageValue(self.storageId) == self.endValue | ||
end | ||
|
||
function Mission:getName(player) | ||
if self:isCompleted(player) then | ||
return string.format("%s (Completed)", self.name) | ||
end | ||
return self.name | ||
end | ||
|
||
function Mission:getDescription(player) | ||
local descriptionType = type(self.description) | ||
if descriptionType == "function" then | ||
return self.description(player) | ||
end | ||
|
||
local value = player:getStorageValue(self.storageId) | ||
if descriptionType == "string" then | ||
local description = self.description:gsub("|STATE|", value) | ||
description = self.description:gsub("\\n", "\n") | ||
return description | ||
end | ||
|
||
if descriptionType == "table" then | ||
if self.ignoreEndValue then | ||
for current = self.endValue, self.startValue, -1 do | ||
if value >= current then | ||
return self.description[current] | ||
end | ||
end | ||
else | ||
for current = self.endValue, self.startValue, -1 do | ||
if value == current then | ||
return self.description[current] | ||
end | ||
end | ||
end | ||
end | ||
|
||
return "An error has occurred, please contact a gamemaster." | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
local cleanTrackedQuests = CreatureEvent("cleanTrackedQuests") | ||
|
||
function cleanTrackedQuests.onLogout(player) | ||
Game.getTrackedQuests()[player:getId()] = nil | ||
return true | ||
end | ||
|
||
cleanTrackedQuests:register() |
29 changes: 29 additions & 0 deletions
29
data/scripts/eventcallbacks/player/default_onUpdateStorage.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
local lastQuestUpdate = {} | ||
|
||
local ec = EventCallback | ||
|
||
ec.onUpdateStorage = function(player, key, value, oldValue, isLogin) | ||
if isLogin then | ||
return | ||
end | ||
|
||
local playerId = player:getId() | ||
local now = os.mtime() | ||
if not lastQuestUpdate[playerId] then | ||
lastQuestUpdate[playerId] = now | ||
end | ||
|
||
if lastQuestUpdate[playerId] - now <= 0 and Game.isQuestStorage(key, value, oldValue) then | ||
lastQuestUpdate[playerId] = os.mtime() + 100 | ||
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your questlog has been updated.") | ||
end | ||
|
||
local trackedQuests = Game.getTrackedQuests()[playerId] or {} | ||
for mission, quest in pairs(trackedQuests) do | ||
if quest:isTracking(key, value) then | ||
player:sendUpdateQuestTracker(mission) | ||
end | ||
end | ||
end | ||
|
||
ec:register() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.