Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Luan Luciano committed Nov 26, 2023
1 parent 8100402 commit 96b1101
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 86 deletions.
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)
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

0 comments on commit 96b1101

Please sign in to comment.