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 global functions #1917

Closed
Closed
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions data-canary/scripts/globalevents/save_interval.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
local SAVE_INTERVAL_TYPE = configManager.getString(configKeys.SAVE_INTERVAL_TYPE)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see why moving this to the scripts if it's something shared... And you broke the naming convention.

local SAVE_INTERVAL_CONFIG_TIME = configManager.getNumber(configKeys.SAVE_INTERVAL_TIME)
local SAVE_INTERVAL_TIME = 0
if SAVE_INTERVAL_TYPE == "second" then
SAVE_INTERVAL_TIME = 1000
elseif SAVE_INTERVAL_TYPE == "minute" then
SAVE_INTERVAL_TIME = 60 * 1000
elseif SAVE_INTERVAL_TYPE == "hour" then
SAVE_INTERVAL_TIME = 60 * 60 * 1000
end

local function serverSave(interval)
if configManager.getBoolean(configKeys.TOGGLE_SAVE_INTERVAL_CLEAN_MAP) then
cleanMap()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
local SAVE_INTERVAL_TYPE = configManager.getString(configKeys.SAVE_INTERVAL_TYPE)
local SAVE_INTERVAL_CONFIG_TIME = configManager.getNumber(configKeys.SAVE_INTERVAL_TIME)
local SAVE_INTERVAL_TIME = 0
if SAVE_INTERVAL_TYPE == "second" then
SAVE_INTERVAL_TIME = 1000
elseif SAVE_INTERVAL_TYPE == "minute" then
SAVE_INTERVAL_TIME = 60 * 1000
elseif SAVE_INTERVAL_TYPE == "hour" then
SAVE_INTERVAL_TIME = 60 * 60 * 1000
end

local function serverSave(interval)
if configManager.getBoolean(configKeys.TOGGLE_SAVE_INTERVAL_CLEAN_MAP) then
cleanMap()
Expand Down
86 changes: 0 additions & 86 deletions data/global.lua
Original file line number Diff line number Diff line change
Expand Up @@ -109,27 +109,6 @@ if not _G.PlayerDelayPotion then
_G.PlayerDelayPotion = {}
end

table.contains = function(array, value)
for _, targetColumn in pairs(array) do
if targetColumn == value then
return true
end
end
return false
end

-- for use of: data\scripts\globalevents\customs\save_interval.lua
SAVE_INTERVAL_TYPE = configManager.getString(configKeys.SAVE_INTERVAL_TYPE)
SAVE_INTERVAL_CONFIG_TIME = configManager.getNumber(configKeys.SAVE_INTERVAL_TIME)
SAVE_INTERVAL_TIME = 0
if SAVE_INTERVAL_TYPE == "second" then
SAVE_INTERVAL_TIME = 1000
elseif SAVE_INTERVAL_TYPE == "minute" then
SAVE_INTERVAL_TIME = 60 * 1000
elseif SAVE_INTERVAL_TYPE == "hour" then
SAVE_INTERVAL_TIME = 60 * 60 * 1000
end

-- Increase Stamina when Attacking Trainer
staminaBonus = {
target = "Training Machine",
Expand All @@ -138,68 +117,3 @@ staminaBonus = {
eventsTrainer = {}, -- stamina in trainers
eventsPz = {}, -- stamina in Pz
}

FAMILIARSNAME = {
"sorcerer familiar",
"knight familiar",
"druid familiar",
"paladin familiar",
}

function addStamina(playerId, ...)
-- Creature:onTargetCombat
if playerId then
local player = Player(playerId)
if configManager.getBoolean(configKeys.STAMINA_TRAINER) then
if not player then
staminaBonus.eventsTrainer[playerId] = nil
else
local target = player:getTarget()
if not target or target:getName() ~= staminaBonus.target then
staminaBonus.eventsTrainer[playerId] = nil
else
player:setStamina(player:getStamina() + staminaBonus.bonus)
player:sendTextMessage(MESSAGE_STATUS, string.format("%i of stamina has been refilled.", configManager.getNumber(configKeys.STAMINA_TRAINER_GAIN)))
staminaBonus.eventsTrainer[playerId] = addEvent(addStamina, staminaBonus.period, playerId)
end
end
end
return not configManager.getBoolean(configKeys.STAMINA_TRAINER)
end

-- Player:onChangeZone
local localPlayerId, delay = ...

if localPlayerId and delay then
if not staminaBonus.eventsPz[localPlayerId] then
return false
end
stopEvent(staminaBonus.eventsPz[localPlayerId])

local player = Player(localPlayerId)
if not player then
staminaBonus.eventsPz[localPlayerId] = nil
return false
end

local actualStamina = player:getStamina()

if actualStamina > 2400 and actualStamina < 2520 then
delay = configManager.getNumber(configKeys.STAMINA_GREEN_DELAY) * 60 * 1000 -- Stamina Green 12 min.
elseif actualStamina == 2520 then
player:sendTextMessage(
MESSAGE_STATUS,
"You are no longer refilling stamina, \z
because your stamina is already full."
)
staminaBonus.eventsPz[localPlayerId] = nil
return false
end

player:setStamina(player:getStamina() + configManager.getNumber(configKeys.STAMINA_PZ_GAIN))
player:sendTextMessage(MESSAGE_STATUS, string.format("%i of stamina has been refilled.", configManager.getNumber(configKeys.STAMINA_PZ_GAIN)))
staminaBonus.eventsPz[localPlayerId] = addEvent(addStamina, delay, nil, localPlayerId, delay)
return true
end
return false
end
67 changes: 67 additions & 0 deletions data/libs/functions/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1167,3 +1167,70 @@ function toboolean(value)
return false
end
end

function addStamina(playerId, ...)
-- Creature:onTargetCombat
if playerId then
local player = Player(playerId)
if configManager.getBoolean(configKeys.STAMINA_TRAINER) then
if not player then
staminaBonus.eventsTrainer[playerId] = nil
else
local target = player:getTarget()
if not target or target:getName() ~= staminaBonus.target then
staminaBonus.eventsTrainer[playerId] = nil
else
player:setStamina(player:getStamina() + staminaBonus.bonus)
player:sendTextMessage(MESSAGE_STATUS, string.format("%i of stamina has been refilled.", configManager.getNumber(configKeys.STAMINA_TRAINER_GAIN)))
staminaBonus.eventsTrainer[playerId] = addEvent(addStamina, staminaBonus.period, playerId)
end
end
end
return not configManager.getBoolean(configKeys.STAMINA_TRAINER)
end

-- Player:onChangeZone
local localPlayerId, delay = ...

if localPlayerId and delay then
if not staminaBonus.eventsPz[localPlayerId] then
return false
end
stopEvent(staminaBonus.eventsPz[localPlayerId])

local player = Player(localPlayerId)
if not player then
staminaBonus.eventsPz[localPlayerId] = nil
return false
end

local actualStamina = player:getStamina()

if actualStamina > 2400 and actualStamina < 2520 then
delay = configManager.getNumber(configKeys.STAMINA_GREEN_DELAY) * 60 * 1000 -- Stamina Green 12 min.
elseif actualStamina == 2520 then
player:sendTextMessage(
MESSAGE_STATUS,
"You are no longer refilling stamina, \z
because your stamina is already full."
)
staminaBonus.eventsPz[localPlayerId] = nil
return false
end

player:setStamina(player:getStamina() + configManager.getNumber(configKeys.STAMINA_PZ_GAIN))
player:sendTextMessage(MESSAGE_STATUS, string.format("%i of stamina has been refilled.", configManager.getNumber(configKeys.STAMINA_PZ_GAIN)))
staminaBonus.eventsPz[localPlayerId] = addEvent(addStamina, delay, nil, localPlayerId, delay)
return true
end
return false
end

table.contains = function(array, value)
for _, targetColumn in pairs(array) do
if targetColumn == value then
return true
end
end
return false
end