Skip to content

Commit

Permalink
chore: organizing libraries and function locations (opentibiabr#2191)
Browse files Browse the repository at this point in the history
Organized the libs in the core folder and moved some functions to their
correct files.

---------

Co-authored-by: GitHub Actions <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Elson Costa <[email protected]>
  • Loading branch information
3 people authored Feb 8, 2024
1 parent d237b8e commit 1a7a67b
Show file tree
Hide file tree
Showing 41 changed files with 429 additions and 473 deletions.
1 change: 0 additions & 1 deletion data-canary/lib/core/load.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
dofile(DATA_DIRECTORY .. "/lib/core/storages.lua")
dofile(DATA_DIRECTORY .. "/lib/core/constants.lua")
dofile(DATA_DIRECTORY .. "/lib/core/quests.lua")
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
STACKPOS_GROUND = 0
STACKPOS_FIRST_ITEM_ABOVE_GROUNDTILE = 1
STACKPOS_SECOND_ITEM_ABOVE_GROUNDTILE = 2
STACKPOS_THIRD_ITEM_ABOVE_GROUNDTILE = 3
STACKPOS_FOURTH_ITEM_ABOVE_GROUNDTILE = 4
STACKPOS_FIFTH_ITEM_ABOVE_GROUNDTILE = 5
STACKPOS_TOP_CREATURE = 253
STACKPOS_TOP_FIELD = 254
STACKPOS_TOP_MOVABLE_ITEM_OR_CREATURE = 255

THING_TYPE_PLAYER = CREATURETYPE_PLAYER + 1
THING_TYPE_MONSTER = CREATURETYPE_MONSTER + 1
THING_TYPE_NPC = CREATURETYPE_NPC + 1

CONTAINER_POSITION = 0xFFFF
ROSHAMUUL_MORTAR_THROWN = 20200
ROSHAMUUL_KILLED_FRAZZLEMAWS = 20201
ROSHAMUUL_KILLED_SILENCERS = 20202
Expand Down
1 change: 1 addition & 0 deletions data-otservbr-global/lib/core/load.lua
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
dofile(DATA_DIRECTORY .. "/lib/core/storages.lua")
dofile(DATA_DIRECTORY .. "/lib/core/constants.lua")
dofile(DATA_DIRECTORY .. "/lib/core/quests.lua")
8 changes: 2 additions & 6 deletions data-otservbr-global/lib/lib.lua
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
-- Core API functions implemented in Lua
-- Load storages first
dofile(DATA_DIRECTORY .. "/lib/core/load.lua")

-- Tables library
dofile(DATA_DIRECTORY .. "/lib/tables/load.lua")

-- Others library
dofile(DATA_DIRECTORY .. "/lib/others/load.lua")

-- Quests library
dofile(DATA_DIRECTORY .. "/lib/quests/quest.lua")

-- Vip System library
dofile(DATA_DIRECTORY .. "/lib/vip/vip_system.lua")
-- Tables library
dofile(DATA_DIRECTORY .. "/lib/tables/load.lua")
3 changes: 0 additions & 3 deletions data-otservbr-global/lib/others/bath_tube.lua

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dofile(CORE_DIRECTORY .. "/libs/vocation.lua")
dofile(CORE_DIRECTORY .. "/libs/functions/vocation.lua")

Dawnport = {
skillsLimit = {
Expand Down
4 changes: 2 additions & 2 deletions data-otservbr-global/lib/others/load.lua
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
dofile(DATA_DIRECTORY .. "/lib/others/dawnport_lib.lua")
dofile(DATA_DIRECTORY .. "/lib/others/bath_tube.lua")
dofile(DATA_DIRECTORY .. "/lib/others/dawnport.lua")
dofile(DATA_DIRECTORY .. "/lib/others/vip_system.lua")
File renamed without changes.
120 changes: 0 additions & 120 deletions data/libs/daily_reward/player.lua

This file was deleted.

File renamed without changes.
36 changes: 4 additions & 32 deletions data/libs/functions/constants.lua
Original file line number Diff line number Diff line change
@@ -1,37 +1,9 @@
CONTAINER_POSITION = 0xFFFF
ROSHAMUUL_MORTAR_THROWN = 20200
ROSHAMUUL_KILLED_FRAZZLEMAWS = 20201
ROSHAMUUL_KILLED_SILENCERS = 20202
ROSHAMUUL_GOLD_RECORD = 20203

SPIKE_FAME_POINTS = 27890

SPIKE_UPPER_PACIFIER_MAIN = 27891
SPIKE_UPPER_PACIFIER_DAILY = 27892
SPIKE_UPPER_MOUND_MAIN = 27893
SPIKE_UPPER_MOUND_DAILY = 27894
SPIKE_UPPER_TRACK_MAIN = 27895
SPIKE_UPPER_TRACK_DAILY = 27896
SPIKE_UPPER_KILL_MAIN = 27897
SPIKE_UPPER_KILL_DAILY = 27898

SPIKE_MIDDLE_CHARGE_MAIN = 27899
SPIKE_MIDDLE_CHARGE_DAILY = 27900
SPIKE_MIDDLE_MUSHROOM_MAIN = 27901
SPIKE_MIDDLE_MUSHROOM_DAILY = 27902
SPIKE_MIDDLE_NEST_MAIN = 27903
SPIKE_MIDDLE_NEST_DAILY = 27904
SPIKE_MIDDLE_KILL_MAIN = 27905
SPIKE_MIDDLE_KILL_DAILY = 27906

SPIKE_LOWER_PARCEL_MAIN = 27907
SPIKE_LOWER_PARCEL_DAILY = 27908
SPIKE_LOWER_UNDERCOVER_MAIN = 27909
SPIKE_LOWER_UNDERCOVER_DAILY = 27910
SPIKE_LOWER_LAVA_MAIN = 27911
SPIKE_LOWER_LAVA_DAILY = 27912
SPIKE_LOWER_KILL_MAIN = 27913
SPIKE_LOWER_KILL_DAILY = 27914
-- Items
BATHTUB_EMPTY = 26076
BATHTUB_FILLED = 26077
BATHTUB_FILLED_NOTMOVABLE = 26100

BAG_YOU_DESIRE = 34109
PRIMAL_BAG = 39546
Expand Down
21 changes: 21 additions & 0 deletions data/libs/functions/container.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,24 @@ function Container:addLoot(loot)
::continue::
end
end

function Container:addRewardBossItems(itemList)
for itemId, lootInfo in pairs(itemList) do
local iType = ItemType(itemId)
if iType then
local itemCount = lootInfo.count
local charges = iType:getCharges()
if charges > 0 then
itemCount = charges
logger.debug("Adding item with 'id' to the reward container, item charges {}", iType:getId(), charges)
end
if iType:isStackable() or iType:getCharges() ~= 0 then
self:addItem(itemId, itemCount, INDEX_WHEREEVER, FLAG_NOLIMIT)
else
for i = 1, itemCount do
self:addItem(itemId, 1, INDEX_WHEREEVER, FLAG_NOLIMIT)
end
end
end
end
end
21 changes: 21 additions & 0 deletions data/libs/functions/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1163,3 +1163,24 @@ function toboolean(value)
return false
end
end

-- Utility to combine onDeath event with a "kill" event for a player with a party (or not).
function onDeathForParty(creature, player, func)
if not player or not player:isPlayer() then
return
end

local participants = Participants(player, true)
for _, participant in ipairs(participants) do
func(creature, participant)
end
end

function onDeathForDamagingPlayers(creature, func)
for key, value in pairs(creature:getDamageMap()) do
local player = Player(key)
if player then
func(creature, player)
end
end
end
2 changes: 2 additions & 0 deletions data/libs/functions/load.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
-- Load core functions
dofile(CORE_DIRECTORY .. "/libs/functions/bit.lua")
dofile(CORE_DIRECTORY .. "/libs/functions/bitwise_flags.lua")
dofile(CORE_DIRECTORY .. "/libs/functions/combat.lua")
dofile(CORE_DIRECTORY .. "/libs/functions/constants.lua")
dofile(CORE_DIRECTORY .. "/libs/functions/container.lua")
Expand All @@ -11,6 +12,7 @@ dofile(CORE_DIRECTORY .. "/libs/functions/game.lua")
dofile(CORE_DIRECTORY .. "/libs/functions/item.lua")
dofile(CORE_DIRECTORY .. "/libs/functions/itemtype.lua")
dofile(CORE_DIRECTORY .. "/libs/functions/lever.lua")
dofile(CORE_DIRECTORY .. "/libs/functions/modal_window_helper.lua")
dofile(CORE_DIRECTORY .. "/libs/functions/monster.lua")
dofile(CORE_DIRECTORY .. "/libs/functions/monstertype.lua")
dofile(CORE_DIRECTORY .. "/libs/functions/party.lua")
Expand Down
File renamed without changes.
74 changes: 74 additions & 0 deletions data/libs/functions/monster.lua
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,77 @@ function Monster.setFiendish(self, position, player)
logger.info("Player {} {} with name {} and id {} on position {}", player:getName(), success, self:getName(), self:getId(), self:getPosition():toString())
return true
end

function Monster.setReward(self, enable)
if enable then
if not self:getType():isRewardBoss() then
error("Rewards can only be enabled to rewards bosses.")
return false
end
_G.GlobalBosses[self:getId()] = {}
self:registerEvent("BossDeath")
self:registerEvent("BossThink")
else
_G.GlobalBosses[self:getId()] = nil
self:unregisterEvent("BossDeath")
self:unregisterEvent("BossThink")
end
return true
end

function Monster:setRewardBoss()
if self:getType():isRewardBoss() then
self:setReward(true)
end
end

local equipmentBags = {
BAG_YOU_DESIRE,
PRIMAL_BAG,
BAG_YOU_COVET,
}
do
local function isEquipment(itemType)
if table.contains(equipmentBags, itemType:getId()) then
return true
end

local t = itemType:getType()
local equipmentTypes = {
ITEM_TYPE_ARMOR,
ITEM_TYPE_AMULET,
ITEM_TYPE_BOOTS,
ITEM_TYPE_HELMET,
ITEM_TYPE_LEGS,
ITEM_TYPE_RING,
ITEM_TYPE_SHIELD,
ITEM_TYPE_AXE,
ITEM_TYPE_CLUB,
ITEM_TYPE_DISTANCE,
ITEM_TYPE_SWORD,
ITEM_TYPE_WAND,
ITEM_TYPE_QUIVER,
}
return table.contains(equipmentTypes, t)
end

function MonsterType.getBossReward(self, lootFactor, topScore, equipmentOnly, lootTable)
if configManager.getNumber(configKeys.RATE_LOOT) <= 0 then
return lootTable or {}
end

return self:generateLootRoll({
factor = lootFactor,
gut = false,
filter = function(itemType, unique)
if unique and not topScore then
return false
end
if equipmentOnly then
return not unique and isEquipment(itemType)
end
return true
end,
}, lootTable)
end
end
Loading

0 comments on commit 1a7a67b

Please sign in to comment.