Skip to content

Commit

Permalink
fixes in levers and other fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
elsongabriel committed Nov 6, 2023
1 parent 22f32c3 commit a1a7977
Show file tree
Hide file tree
Showing 18 changed files with 64 additions and 104 deletions.
1 change: 1 addition & 0 deletions data-otservbr-global/monster/bosses/custodian.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ monster.loot = {
{ id = 281, chance = 28000 }, -- giant shimmering pearl (green)
{ name = "cobra crest", chance = 11000 },
{ name = "skull helmet", chance = 7500 },
{ name = "cobra club", chance = 100 },
}

monster.attacks = {
Expand Down
2 changes: 1 addition & 1 deletion data-otservbr-global/scripts/actions/other/cask_kegs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function flasks.onUse(player, item, fromPosition, target, toPosition, isHotkey)
return false
end

local charges = target:getCharges()
local charges = item:getCharges()
local itemCount = item:getCount()
local recharged = itemCount

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function dangerousDepthPesticide.onUse(player, item, fromPosition, target, toPos
return true
end

if not target or not target:isItem() then
if (target == nil) or not target:isItem() then
return false
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local config = {
bossName = "The Last Lore Keeper",
timeToFightAgain = 14 * 24, -- In hour
timeToFightAgain = 14 * 24, -- In days
timeToDefeat = 17, -- In minutes
playerPositions = {
{ pos = Position(32018, 32844, 14), teleport = Position(31984, 32851, 14), effect = CONST_ME_TELEPORT },
Expand Down Expand Up @@ -61,17 +61,7 @@ function forgottenKnowledgeLastLore.onUse(player, item, fromPosition, target, to
return true
end

if creature:getStorageValue(config.storage) > os.time() then
local info = lever:getInfoPositions()
for _, v in pairs(info) do
local newPlayer = v.creature
if newPlayer then
newPlayer:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You or a member in your team have to wait " .. config.timeToFightAgain / 24 .. " days to face " .. config.bossName .. " again!")
if newPlayer:getStorageValue(config.storage) > os.time() then
newPlayer:getPosition():sendMagicEffect(CONST_ME_POFF)
end
end
end
if not lever:canUseLever(player, config.bossName, config.timeToFightAgain) then
return false
end
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,7 @@ function forgottenKnowledgeTenebris.onUse(player, item, fromPosition, target, to
return true
end

if creature:getStorageValue(config.storage) > os.time() then
local info = lever:getInfoPositions()
for _, v in pairs(info) do
local newPlayer = v.creature
if newPlayer then
newPlayer:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You or a member in your team have to wait " .. config.timeToFightAgain .. " hours to face " .. config.bossName .. " again!")
if newPlayer:getStorageValue(config.storage) > os.time() then
newPlayer:getPosition():sendMagicEffect(CONST_ME_POFF)
end
end
end
if not lever:canUseLever(player, config.bossName, config.timeToFightAgain) then
return false
end
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,7 @@ function forgottenKnowledgeThorn.onUse(player, item, fromPosition, target, toPos
return true
end

if creature:getStorageValue(config.storage) > os.time() then
local info = lever:getInfoPositions()
for _, v in pairs(info) do
local newPlayer = v.creature
if newPlayer then
newPlayer:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You or a member in your team have to wait " .. config.timeToFightAgain .. " hours to face " .. config.bossName .. " again!")
if newPlayer:getStorageValue(config.storage) > os.time() then
newPlayer:getPosition():sendMagicEffect(CONST_ME_POFF)
end
end
end
if not lever:canUseLever(player, config.bossName, config.timeToFightAgain) then
return false
end
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,7 @@ function forgottenKnowledgeGuardianLever.onUse(player, item, fromPosition, targe
return true
end

if creature:getStorageValue(config.storage) > os.time() then
local info = lever:getInfoPositions()
for _, v in pairs(info) do
local newPlayer = v.creature
if newPlayer then
newPlayer:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You or a member in your team have to wait " .. config.timeToFightAgain .. " hours to face " .. config.bossName .. " again!")
if newPlayer:getStorageValue(config.storage) > os.time() then
newPlayer:getPosition():sendMagicEffect(CONST_ME_POFF)
end
end
end
if not lever:canUseLever(player, config.bossName, config.timeToFightAgain) then
return false
end
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,7 @@ function dreamCourtsLever.onUse(player, item, fromPosition, target, toPosition,
creature:sendTextMessage(MESSAGE_EVENT_ADVANCE, "All the players need to be level " .. config.requiredLevel .. " or higher.")
return false
end
if creature:getStorageValue(config.storage) > os.time() then
local info = lever:getInfoPositions()
for _, v in pairs(info) do
local newPlayer = v.creature
if newPlayer then
newPlayer:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You or a member in your team have to wait " .. config.timeToFightAgain .. " hours to face " .. bossToday .. " again!")
if newPlayer:getStorageValue(config.storage) > os.time() then
newPlayer:getPosition():sendMagicEffect(CONST_ME_POFF)
end
end
end
if not lever:canUseLever(player, bossToday, config.timeToFightAgain) then
return false
end
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,10 @@ local function serverSave(interval)
end

saveServer()
local message = "Server save complete. Next save in %d %ss!"
local messageSingle = "Server save complete. Next save in %d %s!"
local message = string.format(SAVE_INTERVAL_CONFIG_TIME > 1 and "Server save complete. Next save in %d %ss!" or "Server save complete. Next save in %d %s!", SAVE_INTERVAL_CONFIG_TIME, SAVE_INTERVAL_TYPE)
Game.broadcastMessage(message, MESSAGE_GAME_HIGHLIGHT)
logger.info(message)
Webhook.sendMessage("Server save", message, WEBHOOK_COLOR_WARNING)
if SAVE_INTERVAL_CONFIG_TIME > 1 then
Game.broadcastMessage(string.format(message, SAVE_INTERVAL_CONFIG_TIME, SAVE_INTERVAL_TYPE), MESSAGE_GAME_HIGHLIGHT)
logger.info(string.format(message, SAVE_INTERVAL_CONFIG_TIME, SAVE_INTERVAL_TYPE))
else
Game.broadcastMessage(string.format(messageSingle, SAVE_INTERVAL_CONFIG_TIME, SAVE_INTERVAL_TYPE), MESSAGE_GAME_HIGHLIGHT)
logger.info(string.format(messageSingle, SAVE_INTERVAL_CONFIG_TIME, SAVE_INTERVAL_TYPE))
end
end

local save = GlobalEvent("save")
Expand Down
2 changes: 1 addition & 1 deletion data/events/scripts/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ function Player:onMoveItem(item, count, fromPosition, toPosition, fromCylinder,
exhaust[playerId] = true
addEvent(function()
exhaust[playerId] = false
end, 2000, playerId)
end, 2000)
return true
end

Expand Down
10 changes: 5 additions & 5 deletions data/items/items.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51930,11 +51930,11 @@
<attribute key="defense" value="31"/>
<attribute key="weight" value="6300"/>
<attribute key="imbuementslot" value="2">
<attribute key="elemental damage" value="3"/>
<attribute key="life leech" value="3"/>
<attribute key="mana leech" value="3"/>
<attribute key="critical hit" value="3"/>
<attribute key="skillboost sword" value="3"/>
<attribute key="elemental damage" value="3"/>
<attribute key="life leech" value="3"/>
<attribute key="mana leech" value="3"/>
<attribute key="critical hit" value="3"/>
<attribute key="skillboost sword" value="3"/>
</attribute>
</item>
<item id="30399" name="cobra wand">
Expand Down
12 changes: 1 addition & 11 deletions data/libs/functions/bosslever.lua
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,7 @@ function BossLever:onUse(player)
return false
end

if self:lastEncounterTime(creature) > os.time() then
local info = lever:getInfoPositions()
for _, v in pairs(info) do
local newPlayer = v.creature
if newPlayer then
newPlayer:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You or a member in your team have to wait " .. self.timeToFightAgain / 60 / 60 .. " hours to face " .. self.name .. " again!")
if self:lastEncounterTime(newPlayer) > os.time() then
newPlayer:getPosition():sendMagicEffect(CONST_ME_POFF)
end
end
end
if not lever:canUseLever(player, self.name, self.timeToFightAgain / 60 / 60) then
return false
end
self.onUseExtra(creature)
Expand Down
13 changes: 13 additions & 0 deletions data/libs/functions/lever.lua
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,16 @@ function Lever.setCooldownAllPlayers(self, bossName, value)
end
end
end

function Lever.canUseLever(self, player, bossName, timeToFightAgain)
local info = self:getInfoPositions()
for _, v in pairs(info) do
local newPlayer = v.creature
if newPlayer and not newPlayer:canFightBoss(bossName) then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You or a member in your team have to wait " .. timeToFightAgain .. " hours to face " .. bossName .. " again!")
newPlayer:getPosition():sendMagicEffect(CONST_ME_POFF)
return false
end
end
return true
end
13 changes: 10 additions & 3 deletions data/libs/functions/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ function Player:removeMoneyBank(amount)
-- Removes player inventory money
self:removeMoney(amount)

self:sendTextMessage(MESSAGE_TRADE, ("Paid %d gold from inventory."):format(amount))
if amount > 0 then
self:sendTextMessage(MESSAGE_TRADE, ("Paid %d gold from inventory."):format(amount))
end
return true

-- The player doens't have all the money with him
Expand All @@ -238,7 +240,9 @@ function Player:removeMoneyBank(amount)
-- Removes player bank money
Bank.debit(self, remains)

self:sendTextMessage(MESSAGE_TRADE, ("Paid %s from inventory and %s gold from bank account. Your account balance is now %s gold."):format(FormatNumber(moneyCount), FormatNumber(amount - moneyCount), FormatNumber(self:getBankBalance())))
if amount > 0 then
self:sendTextMessage(MESSAGE_TRADE, ("Paid %s from inventory and %s gold from bank account. Your account balance is now %s gold."):format(FormatNumber(moneyCount), FormatNumber(amount - moneyCount), FormatNumber(self:getBankBalance())))
end
return true
end
self:setBankBalance(bankCount - amount)
Expand Down Expand Up @@ -677,5 +681,8 @@ end

function Player:canFightBoss(bossNameOrId)
local cooldown = self:getBossCooldown(bossNameOrId)
return cooldown > os.time() and false or true
if cooldown > os.time() then
return false
end
return true
end
8 changes: 4 additions & 4 deletions data/modules/scripts/gamestore/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,9 @@ function parseTransferableCoins(playerId, msg)
player:removeTransferableCoinsBalance(amount)
addPlayerEvent(sendStorePurchaseSuccessful, 550, playerId, "You have transfered " .. amount .. " coins to " .. reciver .. " successfully")

-- Adding history for both reciver/sender
GameStore.insertHistory(accountId, GameStore.HistoryTypes.HISTORY_TYPE_NONE, player:getName() .. " transfered you this amount.", amount, GameStore.CoinType.Coin)
GameStore.insertHistory(player:getAccountId(), GameStore.HistoryTypes.HISTORY_TYPE_NONE, "You transfered this amount to " .. reciver, -1 * amount, GameStore.CoinType.Coin)
-- Adding history for both receiver/sender
GameStore.insertHistory(accountId, GameStore.HistoryTypes.HISTORY_TYPE_NONE, player:getName() .. " transferred you this amount.", amount, GameStore.CoinType.Coin)
GameStore.insertHistory(player:getAccountId(), GameStore.HistoryTypes.HISTORY_TYPE_NONE, "You transferred this amount to " .. reciver, -1 * amount, GameStore.CoinType.Coin)
openStore(playerId)
end

Expand Down Expand Up @@ -1995,7 +1995,7 @@ function Player.makeCoinTransaction(self, offer, desc)
op = self:removeTransferableCoinsBalance(offer.price)
end

-- When the transaction is suscessfull add to the history
-- When the transaction is successful add to the history
if op then
GameStore.insertHistory(self:getAccountId(), GameStore.HistoryTypes.HISTORY_TYPE_NONE, desc, offer.price * -1, offer.coinType)
end
Expand Down
10 changes: 5 additions & 5 deletions data/scripts/reward_chest/boss_death.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
local bossDeath = CreatureEvent("BossDeath")

function bossDeath.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
if not corpse or corpse == 0 then
return true
if not corpse then
return false
end

-- Deny summons and players
if not creature or creature:isPlayer() or creature:getMaster() then
return true
Expand All @@ -14,14 +15,13 @@ function bossDeath.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUn
-- Make sure it is a boss
if monsterType and monsterType:isRewardBoss() then
if not corpse.isContainer or not corpse:isContainer() then
if corpse.getId then
if corpse:getId() ~= nil then
logger.warn("[bossDeath.onDeath] Corpse (id: {}, name: {}) for reward boss {} is not a container.", corpse:getId(), corpse:getName(), creature:getName())
else
logger.warn("[bossDeath.onDeath] Error to get corpseId from boss: {}", creature:getName())
end
else
corpse:registerReward()
end
corpse:registerReward()
local bossId = creature:getId()
local rewardId = corpse:getAttribute(ITEM_ATTRIBUTE_DATE)

Expand Down
6 changes: 5 additions & 1 deletion data/scripts/talkactions/player/bank.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,17 @@ local transfer = TalkAction("!transfer")

function transfer.onSay(player, words, param)
local split = param:split(",")
local name = split[1]:trim()
local amount = tonumber(split[2])
if not amount or amount <= 0 and isValidMoney(amount) then
player:sendTextMessage(config.messageStyle, "Invalid amount.")
return true
end

local name = split[1]
if not name then
return true
end
name = name:trim()
local normalizedName = Game.getNormalizedPlayerName(name)
if not normalizedName then
player:sendTextMessage(config.messageStyle, "A player with name " .. name .. " does not exist.")
Expand Down
15 changes: 8 additions & 7 deletions data/scripts/talkactions/player/reward.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
local config = {
items = {
{ id = 35284, charges = 64000 },
{ id = 35279, charges = 64000 },
{ id = 35281, charges = 64000 },
{ id = 35283, charges = 64000 },
{ id = 35282, charges = 64000 },
{ id = 35280, charges = 64000 },
{ id = 35284, charges = 64000, cap = 10 },
{ id = 35279, charges = 64000, cap = 10 },
{ id = 35281, charges = 64000, cap = 10 },
{ id = 35283, charges = 64000, cap = 10 },
{ id = 35282, charges = 64000, cap = 10 },
{ id = 35280, charges = 64000, cap = 10 },
},
storage = tonumber(Storage.PlayerWeaponReward), -- storage key, player can only win once
}
Expand All @@ -24,9 +24,10 @@ local function sendExerciseRewardModal(player)
end

local inbox = player:getSlotItem(CONST_SLOT_STORE_INBOX)
if inbox and inbox:getEmptySlots() > 0 then
if inbox and inbox:getEmptySlots() > 0 and player:getFreeCapacity() >= it.cap then
local item = inbox:addItem(it.id, it.charges)
if item then
item:setActionId(IMMOVABLE_ACTION_ID)
item:setAttribute(ITEM_ATTRIBUTE_STORE, systemTime())
else
player:sendTextMessage(MESSAGE_LOOK, "You need to have capacity and empty slots to receive.")
Expand Down

0 comments on commit a1a7977

Please sign in to comment.