Skip to content

Commit

Permalink
refactor: script improvements and remove unused config (#2242)
Browse files Browse the repository at this point in the history
  • Loading branch information
omarcopires authored Feb 19, 2024
1 parent 1c4bea7 commit aa797ff
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 116 deletions.
2 changes: 0 additions & 2 deletions config.lua.dist
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ onlyPremiumAccount = false
-- Customs
-- NOTE: weatherRain = true, activates weather raining effects
-- NOTE: thunderEffect = true, activates thunder effects
-- NOTE: allConsoleLog = true, show all message logs
-- NOTE: stashMoving = true, stow an container inside your stash
-- NOTE: depotChest, the non-stackable items will be moved to the selected depot chest(I - XVIII).
-- NOTE: autoBank = true, the dropped coins from monsters will be automatically deposited to your bank account.
Expand All @@ -241,7 +240,6 @@ onlyPremiumAccount = false
-- NOTE: randomMonsterSpawn = true, will enable monsters from the same spawn to be randomized between them, thus making a variable hunt
weatherRain = false
thunderEffect = false
allConsoleLog = false
stashMoving = false
depotChest = 4
autoLoot = false
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,74 +1,57 @@
local ThreatenedDreams = Storage.Quest.U11_40.ThreatenedDreams
local periods = {
[LIGHT_STATE_NIGHT] = "Night",
[LIGHT_STATE_DAY] = "Day",
[LIGHT_STATE_SUNRISE] = "Sunrise",
[LIGHT_STATE_SUNSET] = "Sunset",
}
local config = {
-- createByType day / night
[1] = { -- create in night
bushId = 25783,
createItem = LIGHT_STATE_NIGHT,
removeItem = LIGHT_STATE_SUNRISE,
pos = Position(33497, 32196, 7),
herbId = 5953,
herbWeight = 1,
storage = ThreatenedDreams.Mission03.RavenHerbTimer,
},
bushId = 25783,
createItem = LIGHT_STATE_NIGHT,
removeItem = LIGHT_STATE_SUNRISE,
pos = Position(33497, 32196, 7),
herbId = 5953,
herbWeight = 1,
storage = ThreatenedDreams.Mission03.RavenHerbTimer,
}

local createRavenHerb = GlobalEvent("createRavenHerb")

function createRavenHerb.onPeriodChange(period, light)
local time = getWorldTime()

if configManager.getBoolean(configKeys.ALL_CONSOLE_LOG) then
logger.info("Starting {} Current light is {} and it's {} Tibian Time", periods[period], light, getFormattedWorldTime(time))
end
for index, item in pairs(config) do
if item.createItem == period then -- Adding
local createItem = Game.createItem(item.bushId, 1, item.pos)
createItem:setActionId(item.storage)
if createItem then
item.pos:sendMagicEffect(CONST_ME_BIGPLANTS)
end
elseif item.removeItem == period then -- Removing
local target = Tile(item.pos):getItemById(item.bushId)
if target then
item.pos:removeItem(item.bushId, CONST_ME_BIGPLANTS)
end
local pos = config.pos
if config.createItem == period then
local createItem = Game.createItem(config.bushId, 1, pos)
if createItem then
pos:sendMagicEffect(CONST_ME_BIGPLANTS)
end
elseif config.removeItem == period then
local target = Tile(pos):getItemById(config.bushId)
if target then
pos:removeItem(config.bushId, CONST_ME_BIGPLANTS)
end
end

return true
end

createRavenHerb:register()

local ravenHerb = Action()

function ravenHerb.onUse(player, item, fromPosition, target, toPosition, isHotkey)
local herbConfig = config[1]
local message = "You have found a " .. getItemName(herbConfig.herbId) .. "."
local message = "You have found a " .. getItemName(config.herbId) .. "."
local backpack = player:getSlotItem(CONST_SLOT_BACKPACK)

if not backpack or backpack:getEmptySlots(true) < 1 then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, message .. " But you have no room to take it.")
return true
end
if (player:getFreeCapacity() / 100) < herbConfig.herbWeight then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, message .. ". Weighing " .. herbConfig.herbWeight .. " oz, it is too heavy for you to carry.")

if (player:getFreeCapacity() / 100) < config.herbWeight then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, message .. ". Weighing " .. config.herbWeight .. " oz, it is too heavy for you to carry.")
return true
end

if player:getStorageValue(herbConfig.storage) > os.time() then
if player:getStorageValue(config.storage) > os.time() then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "The raven herb cannot be collected right now.")
return true
end

player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have found a " .. getItemName(herbConfig.herbId) .. ".")
player:setStorageValue(herbConfig.storage, os.time() + 60 * 30 * 1000) -- Can be collected on next cycle
player:addItem(herbConfig.herbId, 1)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, message)
player:setStorageValue(config.storage, os.time() + 60 * 30 * 1000)
player:addItem(config.herbId, 1)
return true
end

Expand Down
30 changes: 30 additions & 0 deletions data-otservbr-global/scripts/world_changes/spawns_npc_by_time.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
local npcSpawns = {
{ name = "Ghostly Wolf", spawnPeriod = LIGHT_STATE_SUNSET, despawnPeriod = LIGHT_STATE_SUNRISE, position = { x = 33332, y = 32052, z = 7 } },
{ name = "Talila", spawnPeriod = LIGHT_STATE_SUNSET, despawnPeriod = LIGHT_STATE_SUNRISE, position = { x = 33504, y = 32222, z = 7 } },
{ name = "Valindara", spawnPeriod = LIGHT_STATE_SUNRISE, despawnPeriod = LIGHT_STATE_SUNSET, position = { x = 33504, y = 32222, z = 7 } },
}

local spawnsNpcByTime = GlobalEvent("SpawnsNpcByTime")

function spawnsByTimeEvent.onPeriodChange(period)
for _, npcSpawn in ipairs(npcSpawns) do
if npcSpawn.spawnPeriod == period then
local spawnNpc = Game.createNpc(npcSpawn.name, npcSpawn.position)
if spawnNpc then
spawnNpc:setMasterPos(npcSpawn.position)
npcSpawn.position:sendMagicEffect(CONST_ME_TELEPORT)
logger.info("[NPC Spawn] {} has spawned", npcSpawn.name)
end
elseif npcSpawn.despawnPeriod == period then
local despawnNpc = Npc(npcSpawn.name)
if despawnNpc then
despawnNpc:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
despawnNpc:remove()
logger.info("[NPC Despawn] {} has despawned", npcSpawn.name)
end
end
end
return true
end

spawnsNpcByTime:register()
1 change: 0 additions & 1 deletion src/config/config_enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ enum ConfigKey_t : uint16_t {
ALLOW_BLOCK_SPAWN,
ALLOW_CHANGEOUTFIT,
ALLOW_RELOAD,
ALL_CONSOLE_LOG,
AUTH_TYPE,
AUTOBANK,
AUTOLOOT,
Expand Down
1 change: 0 additions & 1 deletion src/config/configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ bool ConfigManager::load() {

loadBoolConfig(L, WEATHER_RAIN, "weatherRain", false);
loadBoolConfig(L, WEATHER_THUNDER, "thunderEffect", false);
loadBoolConfig(L, ALL_CONSOLE_LOG, "allConsoleLog", false);
loadBoolConfig(L, TOGGLE_FREE_QUEST, "toggleFreeQuest", true);
loadBoolConfig(L, AUTOLOOT, "autoLoot", false);
loadBoolConfig(L, AUTOBANK, "autoBank", false);
Expand Down

0 comments on commit aa797ff

Please sign in to comment.