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

improve: adjustment in player event #1860

Merged
merged 6 commits into from
Nov 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 34 additions & 20 deletions data/events/scripts/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ local storeItemID = {
-- Players cannot throw items on teleports if set to true
local blockTeleportTrashing = true

local config = {
local configPush = {
maxItemsPerSeconds = 1,
exhaustTime = 2000,
}
Expand Down Expand Up @@ -80,8 +80,8 @@ local function antiPush(player, item, count, fromPosition, toPosition, fromCylin
pushDelay[playerId].items = 0
end

if pushDelay[playerId].items > config.maxItemsPerSeconds then
pushDelay[playerId].time = currentTime + config.exhaustTime
if pushDelay[playerId].items > configPush.maxItemsPerSeconds then
pushDelay[playerId].time = currentTime + configPush.exhaustTime
end

if pushDelay[playerId].time > currentTime then
Expand Down Expand Up @@ -197,6 +197,10 @@ local function useConcoctionTime(player)
end

function Player:onLookInBattleList(creature, distance)
if not creature then
return false
end

local description = "You see " .. creature:getDescription(distance)
if creature:isMonster() then
local master = creature:getMaster()
Expand All @@ -223,6 +227,8 @@ function Player:onLookInBattleList(creature, distance)
self:sendTextMessage(MESSAGE_LOOK, description)
end

local exhaust = {}

function Player:onMoveItem(item, count, fromPosition, toPosition, fromCylinder, toCylinder)
if item:getActionId() == IMMOVABLE_ACTION_ID then
self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
Expand All @@ -237,8 +243,8 @@ function Player:onMoveItem(item, count, fromPosition, toPosition, fromCylinder,
end

-- Players cannot throw items on teleports
if blockTeleportTrashing and toPosition.x ~= CONTAINER_POSITION then
local thing = Tile(toPosition):getItemByType(ITEM_TYPE_TELEPORT)
if blockTeleportTrashing and tile and toPosition.x ~= CONTAINER_POSITION then
local thing = tile:getItemByType(ITEM_TYPE_TELEPORT)
if thing then
self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
self:getPosition():sendMagicEffect(CONST_ME_POFF)
Expand All @@ -247,7 +253,6 @@ function Player:onMoveItem(item, count, fromPosition, toPosition, fromCylinder,
end

-- SSA exhaust
local exhaust = {}
if toPosition.x == CONTAINER_POSITION and toPosition.y == CONST_SLOT_NECKLACE and item:getId() == ITEM_STONE_SKIN_AMULET then
local playerId = self:getId()
if exhaust[playerId] then
Expand All @@ -256,16 +261,18 @@ function Player:onMoveItem(item, count, fromPosition, toPosition, fromCylinder,
end
exhaust[playerId] = true
addEvent(function(id)
exhaust[id] = false
exhaust[id] = nil
end, 2000, playerId)
return true
end

-- Bath tube
local toTile = Tile(toCylinder:getPosition())
local topDownItem = toTile:getTopDownItem()
if topDownItem and table.contains({ BATHTUB_EMPTY, BATHTUB_FILLED }, topDownItem:getId()) then
return false
if toTile then
local topDownItem = toTile:getTopDownItem()
if topDownItem and table.contains({ BATHTUB_EMPTY, BATHTUB_FILLED }, topDownItem:getId()) then
return false
end
end

-- Handle move items to the ground
Expand Down Expand Up @@ -315,10 +322,12 @@ function Player:onMoveItem(item, count, fromPosition, toPosition, fromCylinder,

-- The player also shouldn't be able to insert items into the boss corpse
local tileCorpse = Tile(container:getPosition())
for index, value in ipairs(tileCorpse:getItems() or {}) do
if value:getAttribute(ITEM_ATTRIBUTE_CORPSEOWNER) == 2 ^ 31 - 1 and value:getName() == container:getName() then
self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
return false
if tileCorpse then
for index, value in ipairs(tileCorpse:getItems() or {}) do
if value:getAttribute(ITEM_ATTRIBUTE_CORPSEOWNER) == 2 ^ 31 - 1 and value:getName() == container:getName() then
self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
return false
end
end
end
end
Expand Down Expand Up @@ -399,8 +408,12 @@ function Player:onMoveCreature(creature, fromPosition, toPosition)
return true
end

local function hasPendingReport(name, targetName, reportType)
name = self:getName():gsub("%s+", "_")
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
Expand All @@ -411,8 +424,8 @@ local function hasPendingReport(name, targetName, reportType)
end

function Player:onReportRuleViolation(targetName, reportType, reportReason, comment, translation)
name = self:getName()
if hasPendingReport(name, targetName, reportType) then
local name = self:getName()
if hasPendingReport(self:getGuid(), targetName, reportType) then
self:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your report is being processed.")
return
end
Expand Down Expand Up @@ -621,10 +634,11 @@ function Player:onChangeZone(zone)

if configManager.getBoolean(configKeys.STAMINA_PZ) then
if zone == ZONE_PROTECTION then
if self:getStamina() < 2520 then
local stamina = self:getStamina()
if stamina < 2520 then
if not event then
local delay = configManager.getNumber(configKeys.STAMINA_ORANGE_DELAY)
if self:getStamina() > 2400 and self:getStamina() <= 2520 then
if stamina > 2400 and stamina <= 2520 then
delay = configManager.getNumber(configKeys.STAMINA_GREEN_DELAY)
end

Expand Down