Skip to content

Commit

Permalink
[Bug] fixes some things and miscellaneous adjusts (#484)
Browse files Browse the repository at this point in the history
• Added missing magic gold converter id
• Fixed "MESSAGE_INFO_DESCR" not exists to correct enum "MESSAGE_EVENT_ADVANCE"
• Added a function to check if the pack running is the global one and added checks to only run some codes in the global pack
• Fixed to Hireling Lamp so it cannot be moved
• Indented "gamestore.lua" script for tab and removed several whitespace
  • Loading branch information
beats-dh authored Dec 8, 2022
1 parent 50faf3f commit e7ab37a
Show file tree
Hide file tree
Showing 9 changed files with 4,613 additions and 4,521 deletions.
3 changes: 1 addition & 2 deletions data-canary/scripts/actions/tools/gold_converter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ local goldConverter = Action()

function goldConverter.onUse(player, item, fromPosition, target, toPosition, isHotkey)
local coin = config[target.itemid]

if not coin then
return false
end
Expand All @@ -32,5 +31,5 @@ function goldConverter.onUse(player, item, fromPosition, target, toPosition, isH
return true
end

goldConverter:id(23722)
goldConverter:id(23722, 25719)
goldConverter:register()
79 changes: 79 additions & 0 deletions data-canary/scripts/actions/tools/magic_gold_converter.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
local data = {
converterIds = {
[28525] = 28526,
[28526] = 28525,
},
coins = {
[ITEM_GOLD_COIN] = ITEM_PLATINUM_COIN,
[ITEM_PLATINUM_COIN] = ITEM_CRYSTAL_COIN
}
}

local function findItem(self, cylinder, converterItem)
if cylinder == 0 then
cylinder = self:getSlotItem(CONST_SLOT_BACKPACK)
findItem(self, self:getSlotItem(CONST_SLOT_STORE_INBOX), converterItem)
end

if cylinder and cylinder:isContainer() then
for i = 0, cylinder:getSize() - 1 do
local item = cylinder:getItem(i)
if item:isContainer() then
if findItem(self, Container(item.uid), converterItem) then
-- Breaks the recursion from going into the next items in this cylinder
return true
end
else
for fromid, toid in pairs(data.coins) do
if item:getId() == fromid and item:getCount() == 100 then
item:remove()
if not cylinder:addItem(toid, 1) then
player:addItem(toid, 1)
end

converterItem:setAttribute(ITEM_ATTRIBUTE_CHARGES, converterItem:getAttribute(ITEM_ATTRIBUTE_CHARGES) - 1)
return true
end
end
end
end
-- End of items in this cylinder, returning to parent cylinder or finishing iteration
return false
end
end

local function startConversion(playerId, itemId)
local player = Player(playerId)
if player ~= nil then
local converting = addEvent(startConversion, 300, playerId, itemId)
local item = player:getItemById(itemId,true)
if player:getItemCount(itemId) >= 1 then
if item:hasAttribute(ITEM_ATTRIBUTE_CHARGES) then
local charges_n = item:getAttribute(ITEM_ATTRIBUTE_CHARGES)
if charges_n >= 1 then
if player:getItemCount(ITEM_GOLD_COIN) >= 100 or player:getItemCount(ITEM_PLATINUM_COIN) >= 100 then
findItem(player, 0, item)
end
else
item:remove(1)
stopEvent(converting)
end
end
else
stopEvent(converting)
end
end
return true
end

local magicGoldConverter = Action()

function magicGoldConverter.onUse(player, item, fromPosition, target, toPosition, isHotkey)
item:transform(data.converterIds[item.itemId])
item:decay()
startConversion(player:getId(), 28526)
return true
end

magicGoldConverter:id(28525, 28526)
magicGoldConverter:register()
4 changes: 2 additions & 2 deletions data-canary/scripts/creaturescripts/free_quest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ local function playerFreeQuestStart(playerId, index)
for i = 1, 5 do
index = index + 1
if not questTable[index] then
player:sendTextMessage(MESSAGE_INFO_DESCR, "Player FreeQuest is complete.")
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Player FreeQuest is complete.")
player:setStorageValue(Storage.FreeQuests, stage)
return
end
Expand All @@ -34,7 +34,7 @@ function freeQuests.onLogin(player)
return true
end

player:sendTextMessage(MESSAGE_INFO_DESCR, "Player FreeQuest in progress..")
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Player FreeQuest in progress..")
addEvent(playerFreeQuestStart, 500, player:getId(), 0)
return true
end
Expand Down
62 changes: 33 additions & 29 deletions data/events/scripts/monster.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ function Monster:onDropLoot(corpse)
end
end


for i = 1, #monsterLoot do
local item = corpse:createLootItem(monsterLoot[i], charmBonus, preyChanceBoost)
if self:getName():lower() == Game.getBoostedCreature():lower() then
Expand All @@ -41,7 +40,7 @@ function Monster:onDropLoot(corpse)
if self:getName():lower() == (Game.getBoostedCreature()):lower() then
text = ("Loot of %s: %s (boosted loot)"):format(mType:getNameDescription(), corpse:getContentDescription())
else
text = ("Loot of %s: %s"):format(mType:getNameDescription(), corpse:getContentDescription())
text = ("Loot of %s: %s"):format(mType:getNameDescription(), corpse:getContentDescription())
end
if preyChanceBoost ~= 100 then
text = text .. " (active prey bonus)"
Expand Down Expand Up @@ -73,11 +72,14 @@ function Monster:onSpawn(position)
self:setReward(true)
end

if self:getName():lower() == "cobra scout" or
self:getName():lower() == "cobra vizier" or
self:getName():lower() == "cobra assassin" then
if getGlobalStorageValue(GlobalStorage.CobraBastionFlask) >= os.time() then
self:setHealth(self:getMaxHealth() * 0.75)
-- We won't run anything from here on down if we're opening the global pack
if IsRunningGlobalDatapack() then
if self:getName():lower() == "cobra scout" or
self:getName():lower() == "cobra vizier" or
self:getName():lower() == "cobra assassin" then
if getGlobalStorageValue(GlobalStorage.CobraBastionFlask) >= os.time() then
self:setHealth(self:getMaxHealth() * 0.75)
end
end
end

Expand All @@ -92,34 +94,36 @@ function Monster:onSpawn(position)
end
end

if self:getName():lower() == 'iron servant replica' then
local chance = math.random(100)
if Game.getStorageValue(GlobalStorage.ForgottenKnowledge.MechanismDiamond) >= 1
and Game.getStorageValue(GlobalStorage.ForgottenKnowledge.MechanismGolden) >= 1 then
if chance > 30 then
local chance2 = math.random(2)
if chance2 == 1 then
if IsRunningGlobalDatapack() then
if self:getName():lower() == 'iron servant replica' then
local chance = math.random(100)
if Game.getStorageValue(GlobalStorage.ForgottenKnowledge.MechanismDiamond) >= 1
and Game.getStorageValue(GlobalStorage.ForgottenKnowledge.MechanismGolden) >= 1 then
if chance > 30 then
local chance2 = math.random(2)
if chance2 == 1 then
Game.createMonster('diamond servant replica', self:getPosition(), false, true)
elseif chance2 == 2 then
Game.createMonster('golden servant replica', self:getPosition(), false, true)
end
self:remove()
end
return true
end
if Game.getStorageValue(GlobalStorage.ForgottenKnowledge.MechanismDiamond) >= 1 then
if chance > 30 then
Game.createMonster('diamond servant replica', self:getPosition(), false, true)
elseif chance2 == 2 then
self:remove()
end
end
if Game.getStorageValue(GlobalStorage.ForgottenKnowledge.MechanismGolden) >= 1 then
if chance > 30 then
Game.createMonster('golden servant replica', self:getPosition(), false, true)
self:remove()
end
self:remove()
end
return true
end
if Game.getStorageValue(GlobalStorage.ForgottenKnowledge.MechanismDiamond) >= 1 then
if chance > 30 then
Game.createMonster('diamond servant replica', self:getPosition(), false, true)
self:remove()
end
end
if Game.getStorageValue(GlobalStorage.ForgottenKnowledge.MechanismGolden) >= 1 then
if chance > 30 then
Game.createMonster('golden servant replica', self:getPosition(), false, true)
self:remove()
end
end
return true
end
end
end
68 changes: 35 additions & 33 deletions data/events/scripts/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -455,44 +455,46 @@ function Player:onMoveItem(item, count, fromPosition, toPosition, fromCylinder,
end

function Player:onItemMoved(item, count, fromPosition, toPosition, fromCylinder, toCylinder)
-- Cults of Tibia begin
local frompos = Position(33023, 31904, 14) -- Checagem
local topos = Position(33052, 31932, 15) -- Checagem
local removeItem = false
if self:getPosition():isInRange(frompos, topos) and item:getId() == 23729 then
local tileBoss = Tile(toPosition)
if tileBoss and tileBoss:getTopCreature() and tileBoss:getTopCreature():isMonster() then
if tileBoss:getTopCreature():getName():lower() == 'the remorseless corruptor' then
tileBoss:getTopCreature():addHealth(-17000)
tileBoss:getTopCreature():remove()
local monster = Game.createMonster('The Corruptor of Souls', toPosition)
if not monster then
return false
end
removeItem = true
monster:registerEvent('CheckTile')
if Game.getStorageValue('healthSoul') > 0 then
monster:addHealth(-(monster:getHealth() - Game.getStorageValue('healthSoul')))
if IsRunningGlobalDatapack() then
-- Cults of Tibia begin
local frompos = Position(33023, 31904, 14) -- Checagem
local topos = Position(33052, 31932, 15) -- Checagem
local removeItem = false
if self:getPosition():isInRange(frompos, topos) and item:getId() == 23729 then
local tileBoss = Tile(toPosition)
if tileBoss and tileBoss:getTopCreature() and tileBoss:getTopCreature():isMonster() then
if tileBoss:getTopCreature():getName():lower() == 'the remorseless corruptor' then
tileBoss:getTopCreature():addHealth(-17000)
tileBoss:getTopCreature():remove()
local monster = Game.createMonster('The Corruptor of Souls', toPosition)
if not monster then
return false
end
removeItem = true
monster:registerEvent('CheckTile')
if Game.getStorageValue('healthSoul') > 0 then
monster:addHealth(-(monster:getHealth() - Game.getStorageValue('healthSoul')))
end
Game.setStorageValue('CheckTile', os.time()+30)
elseif tileBoss:getTopCreature():getName():lower() == 'the corruptor of souls' then
Game.setStorageValue('CheckTile', os.time()+30)
removeItem = true
end
Game.setStorageValue('CheckTile', os.time()+30)
elseif tileBoss:getTopCreature():getName():lower() == 'the corruptor of souls' then
Game.setStorageValue('CheckTile', os.time()+30)
removeItem = true
end
if removeItem then
item:remove(1)
end
end
if removeItem then
item:remove(1)
end
-- Cults of Tibia end
end
-- Cults of Tibia end
return true
end

function Player:onMoveCreature(creature, fromPosition, toPosition)
local player = creature:getPlayer()
if player and onExerciseTraining[player:getId()] and self:getGroup():hasFlag(PlayerFlag_CanPushAllCreatures) == false then
self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
return false
return false
end
return true
end
Expand All @@ -510,13 +512,13 @@ end
function Player:onReportRuleViolation(targetName, reportType, reportReason, comment, translation)
local name = self:getName()
if hasPendingReport(name, targetName, reportType) then
self:sendTextMessage(MESSAGE_REPORT, "Your report is being processed.")
self:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your report is being processed.")
return
end

local file = io.open(string.format("%s/reports/players/%s-%s-%d.txt", CORE_DIRECTORY, name, targetName, reportType), "a")
if not file then
self:sendTextMessage(MESSAGE_REPORT,
self:sendTextMessage(MESSAGE_EVENT_ADVANCE,
"There was an error when processing your report, please contact a gamemaster.")
return
end
Expand All @@ -533,7 +535,7 @@ function Player:onReportRuleViolation(targetName, reportType, reportReason, comm
end
io.write("------------------------------\n")
io.close(file)
self:sendTextMessage(MESSAGE_REPORT, string.format("Thank you for reporting %s. Your report \z
self:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("Thank you for reporting %s. Your report \z
will be processed by %s team as soon as possible.", targetName, configManager.getString(configKeys.SERVER_NAME)))
return
end
Expand All @@ -547,7 +549,7 @@ function Player:onReportBug(message, position, category)
local file = io.open(string.format("%s/reports/bugs/%s/report.txt", CORE_DIRECTORY, name), "a")

if not file then
self:sendTextMessage(MESSAGE_REPORT,
self:sendTextMessage(MESSAGE_EVENT_ADVANCE,
"There was an error when processing your report, please contact a gamemaster.")
return true
end
Expand All @@ -563,7 +565,7 @@ function Player:onReportBug(message, position, category)
io.write("Comment: " .. message .. "\n")
io.close(file)

self:sendTextMessage(MESSAGE_REPORT,
self:sendTextMessage(MESSAGE_EVENT_ADVANCE,
"Your report has been sent to " .. configManager.getString(configKeys.SERVER_NAME) .. ".")
return true
end
Expand Down Expand Up @@ -737,7 +739,7 @@ end

function Player:onGainSkillTries(skill, tries)
-- Dawnport skills limit
if isSkillGrowthLimited(self, skill) then
if IsRunningGlobalDatapack() and isSkillGrowthLimited(self, skill) then
return 0
end
if APPLY_SKILL_MULTIPLIER == false then
Expand Down
8 changes: 8 additions & 0 deletions data/global.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ if startupFile ~= nil then
dofile(DATA_DIRECTORY.. "/startup/startup.lua")
end

function IsRunningGlobalDatapack()
if DATA_DIRECTORY == "data-otservbr-global" then
return true
else
return false
end
end

NOT_MOVEABLE_ACTION = 100
PARTY_PROTECTION = 1 -- Set to 0 to disable.
ADVANCED_SECURE_MODE = 1 -- Set to 0 to disable.
Expand Down
5 changes: 3 additions & 2 deletions data/items/items.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42575,8 +42575,9 @@
</attribute>
</item>
<item id="29432" article="a" name="hireling lamp">
<attribute key="description" value="This mysterious lamp summons your very own personal hireling"/>
<attribute key="wrapableto" value="23398"/>
<attribute key="weight" value="1000" />
<attribute key="description" value="This mysterious lamp summons your very own personal hireling." />
<attribute key="moveable" value="0" />
</item>
<item id="29433" article="a" name="chest">
<attribute key="containersize" value="15"/>
Expand Down
2 changes: 1 addition & 1 deletion data/modules/scripts/cults_of_tibia/death.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function onRecvbyte(player, msg, byte)
if player then
if IsRunningGlobalDatapack() and player then
local storageDeathFake = player:getStorageValue(Storage.CultsOfTibia.Barkless.Death)
if storageDeathFake == 1 then
player:setStorageValue(Storage.CultsOfTibia.Barkless.Death, 0)
Expand Down
Loading

0 comments on commit e7ab37a

Please sign in to comment.