Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add EventCallbacks for item movement restrictions #3111

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
2 changes: 1 addition & 1 deletion data-otservbr-global/npc/testserver_assistant.lua
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ local function creatureSayCallback(npc, creature, type, message)
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setMessage(MESSAGE_GREET, "Hey |PLAYERNAME|. I'm Testserver Assistant and I can give {money}, {experience} and {blessing} which will be useful for testing on " .. configManager.getString(configKeys.SERVER_NAME) .. " server." .. " You can too to back to level 8 with {reset}.")
npcHandler:setMessage(MESSAGE_GREET, "Hey |PLAYERNAME|. I'm Testserver Assistant and I can give {money}, {experience} and {blessing} which will be useful for testing on " .. SERVER_NAME .. " server." .. " You can too to back to level 8 with {reset}.")
npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true)

-- npcType registering the npcConfig table
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
local callback = EventCallback("CultsOnItemMoved")

function callback.onItemMoved(item, count, fromPosition, toPosition, fromCylinder, toCylinder)
local fromPos = Position(33023, 31904, 14)
local toPos = Position(33052, 31932, 15)

if player:getPosition():isInRange(fromPos, toPos) and item:getId() == 23729 then
local tile = Tile(toPosition)
if not tile then
return
end

local tileBoss = tile:getTopCreature()
if not (tileBoss and tileBoss:isMonster()) then
return
end

local bossName = tileBoss:getName():lower()
if bossName == "the remorseless corruptor" then
tileBoss:addHealth(-17000)
tileBoss:remove()

local monster = Game.createMonster("The Corruptor of Souls", toPosition)
if not monster then
return
end

monster:registerEvent("CheckTile")

local storedHealth = Game.getStorageValue("healthSoul")
if storedHealth > 0 then
monster:addHealth(-(monster:getHealth() - storedHealth))
end

Game.setStorageValue("CheckTile", os.time() + 30)
item:remove(1)
elseif bossName == "the corruptor of souls" then
Game.setStorageValue("CheckTile", os.time() + 30)
item:remove(1)
end
end
end

callback:register()
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
local callback = EventCallback("SecretOnItemMoved")

function callback.onItemMoved(item, count, fromPosition, toPosition, fromCylinder, toCylinder)
if toPosition == Position(32460, 32928, 7) and item.itemid == 3578 then
toPosition:sendMagicEffect(CONST_ME_HEARTS)
player:say("You feed the turtle, now you may pass.", TALKTYPE_MONSTER_SAY)
Game.setStorageValue(Storage.Quest.U11_80.TheSecretLibrary.SmallIslands.Turtle, os.time() + 10 * 60)
item:remove(1)
end
end

callback:register()
113 changes: 0 additions & 113 deletions data/events/scripts/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -371,49 +371,6 @@ function Player:onMoveItem(item, count, fromPosition, toPosition, fromCylinder,
end

function Player:onItemMoved(item, count, fromPosition, toPosition, fromCylinder, toCylinder)
if IsRunningGlobalDatapack() then
-- The Secret Library Quest
if toPosition == Position(32460, 32928, 7) and item.itemid == 3578 then
toPosition:sendMagicEffect(CONST_ME_HEARTS)
self:say("You feed the turtle, now you may pass.", TALKTYPE_MONSTER_SAY)
Game.setStorageValue(Storage.Quest.U11_80.TheSecretLibrary.SmallIslands.Turtle, os.time() + 10 * 60)
item:remove(1)
end

-- Cults of Tibia begin
local frompos = Position(33023, 31904, 14)
local topos = Position(33052, 31932, 15)
local removeItem = false
if self:getPosition():isInRange(frompos, topos) and item:getId() == 23729 then
local tile = Tile(toPosition)
if tile then
local tileBoss = tile:getTopCreature()
if tileBoss and tileBoss:isMonster() then
if tileBoss:getName():lower() == "the remorseless corruptor" then
tileBoss:addHealth(-17000)
tileBoss:remove()
local monster = Game.createMonster("The Corruptor of Souls", toPosition)
if not monster then
return false
end
removeItem = true
monster:registerEvent("CheckTile")
if Game.getStorageValue("healthSoul") > 0 then
monster:addHealth(-(monster:getHealth() - Game.getStorageValue("healthSoul")))
end
Game.setStorageValue("CheckTile", os.time() + 30)
elseif tileBoss:getName():lower() == "the corruptor of souls" then
Game.setStorageValue("CheckTile", os.time() + 30)
removeItem = true
end
end
end
if removeItem then
item:remove(1)
end
end
-- Cults of Tibia end
end
return true
end

Expand All @@ -426,80 +383,10 @@ function Player:onMoveCreature(creature, fromPosition, toPosition)
return true
end

local function hasPendingReport(playerGuid, targetName, reportType)
local player = Player(playerGuid)
if not player then
return false
end
local name = player:getName():gsub("%s+", "_")
FS.mkdir_p(string.format("%s/reports/players/%s", CORE_DIRECTORY, name))
local file = io.open(string.format("%s/reports/players/%s-%s-%d.txt", CORE_DIRECTORY, name, targetName, reportType), "r")
if file then
io.close(file)
return true
end
return false
end

function Player:onReportRuleViolation(targetName, reportType, reportReason, comment, translation)
local name = self:getName()
if hasPendingReport(self:getGuid(), targetName, reportType) then
self:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your report is being processed.")
return
end

local file = io.open(string.format("%s/reports/players/%s-%s-%d.txt", CORE_DIRECTORY, name, targetName, reportType), "a")
if not file then
self:sendTextMessage(MESSAGE_EVENT_ADVANCE, "There was an error when processing your report, please contact a gamemaster.")
return
end

io.output(file)
io.write("------------------------------\n")
io.write("Reported by: " .. name .. "\n")
io.write("Target: " .. targetName .. "\n")
io.write("Type: " .. reportType .. "\n")
io.write("Reason: " .. reportReason .. "\n")
io.write("Comment: " .. comment .. "\n")
if reportType ~= REPORT_TYPE_BOT then
io.write("Translation: " .. translation .. "\n")
end
io.write("------------------------------\n")
io.close(file)
self:sendTextMessage(
MESSAGE_EVENT_ADVANCE,
string.format(
"Thank you for reporting %s. Your report \z
will be processed by %s team as soon as possible.",
targetName,
configManager.getString(configKeys.SERVER_NAME)
)
)
return
end

function Player:onReportBug(message, position, category)
local name = self:getName():gsub("%s+", "_")
FS.mkdir_p(string.format("%s/reports/bugs/%s", CORE_DIRECTORY, name))
local file = io.open(string.format("%s/reports/bugs/%s/report.txt", CORE_DIRECTORY, name), "a")

if not file then
self:sendTextMessage(MESSAGE_EVENT_ADVANCE, "There was an error when processing your report, please contact a gamemaster.")
return true
end

io.output(file)
io.write("------------------------------\n")
io.write("Name: " .. name)
if category == BUG_CATEGORY_MAP then
io.write(" [Map position: " .. position.x .. ", " .. position.y .. ", " .. position.z .. "]")
end
local playerPosition = self:getPosition()
io.write(" [Player Position: " .. playerPosition.x .. ", " .. playerPosition.y .. ", " .. playerPosition.z .. "]\n")
io.write("Comment: " .. message .. "\n")
io.close(file)

self:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your report has been sent to " .. configManager.getString(configKeys.SERVER_NAME) .. ".")
return true
end

Expand Down
5 changes: 0 additions & 5 deletions data/global.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ DIRECTIONS_TABLE = {
DIRECTION_NORTHEAST,
}

SERVER_NAME = configManager.getString(configKeys.SERVER_NAME)
SERVER_MOTD = configManager.getString(configKeys.SERVER_MOTD)

AUTH_TYPE = configManager.getString(configKeys.AUTH_TYPE)

-- Bestiary charm
GLOBAL_CHARM_GUT = 120 -- 20% more chance to get creature products from looting
GLOBAL_CHARM_SCAVENGE = 125 -- 25% more chance to get creature products from skinning
Expand Down
3 changes: 3 additions & 0 deletions data/libs/functions/constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ BATHTUB_FILLED_NOTMOVABLE = 26100
BAG_YOU_DESIRE = 34109
PRIMAL_BAG = 39546
BAG_YOU_COVET = 43895

SERVER_NAME = configManager.getString(configKeys.SERVER_NAME)
AUTH_TYPE = configManager.getString(configKeys.AUTH_TYPE)
29 changes: 29 additions & 0 deletions data/scripts/eventcallbacks/player/on_report_bug.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
local callback = EventCallback("PlayerOnReportBug")

function callback.playerOnReportBug(player, message, position, category)
local name = player:getName()
local filePath = string.format("%s/reports/bugs/%s.txt", CORE_DIRECTORY, name)
local file = io.open(filePath, "a")

if not file then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "There was an error when processing your report, please contact a gamemaster.")
return true
end

file:write("------------------------------\n")
file:write(string.format("Name: %s", name))

if category == BUG_CATEGORY_MAP then
file:write(string.format(" [Map position: %d, %d, %d]", position.x, position.y, position.z))
end

local playerPosition = player:getPosition()
file:write(string.format(" [Player Position: %d, %d, %d]\n", playerPosition.x, playerPosition.y, playerPosition.z))
file:write(string.format("Comment: %s\n", message))
file:write("------------------------------\n")
file:close()

player:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("Your report has been sent to %s.", SERVER_NAME))
end

callback:register()
36 changes: 36 additions & 0 deletions data/scripts/eventcallbacks/player/on_report_rule_violation.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
local callback = EventCallback("PlayerOnReportRuleViolation")

function callback.playerOnReportRuleViolation(player, targetName, reportType, reportReason, comment, translation)
local name = player:getName()
local filePath = string.format("%s/reports/players/%s-%s-%d.txt", CORE_DIRECTORY, name, targetName, reportType)
local file = io.open(filePath, "r")
if file then
io.close(file)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your report is being processed.")
return
end

file = io.open(filePath, "a")
if not file then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "There was an error when processing your report, please contact a gamemaster.")
return
end

file:write("------------------------------\n")
file:write(string.format("Reported by: %s\n", name))
file:write(string.format("Target: %s\n", targetName))
file:write(string.format("Type: %d\n", reportType))
file:write(string.format("Reason: %s\n", reportReason))
file:write(string.format("Comment: %s\n", comment))

if reportType ~= REPORT_TYPE_BOT then
file:write(string.format("Translation: %s\n", translation))
end

file:write("------------------------------\n")
file:close()

player:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("Thank you for reporting %s. Your report will be processed by %s team as soon as possible.", targetName, SERVER_NAME))
end

callback:register()
2 changes: 1 addition & 1 deletion data/scripts/talkactions/player/reward.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ local function sendExerciseRewardModal(player)
if item then
item:setActionId(IMMOVABLE_ACTION_ID)
item:setAttribute(ITEM_ATTRIBUTE_STORE, systemTime())
item:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, string.format("You won this exercise weapon as a reward to be a %s player. Use it in a dummy!\nHave a nice game..", configManager.getString(configKeys.SERVER_NAME)))
item:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, string.format("You won this exercise weapon as a reward to be a %s player. Use it in a dummy!\nHave a nice game..", SERVER_NAME))
else
player:sendTextMessage(MESSAGE_LOOK, "You need to have capacity and empty slots to receive.")
return
Expand Down
Loading