Skip to content

Commit

Permalink
Merge branch 'main' into fixWarSystem
Browse files Browse the repository at this point in the history
  • Loading branch information
Luan Luciano authored Dec 6, 2023
2 parents 993e368 + 779b479 commit 1be012a
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 10 deletions.
2 changes: 2 additions & 0 deletions data-otservbr-global/scripts/actions/door/custom_door.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ function customDoor.onUse(player, item, fromPosition, target, toPosition, isHotk
for index, value in ipairs(CustomDoorTable) do
if value.closedDoor == item.itemid then
item:transform(value.openDoor)
item:getPosition():sendSingleSoundEffect(SOUND_EFFECT_TYPE_ACTION_OPEN_DOOR)
return true
end
end
for index, value in ipairs(CustomDoorTable) do
if value.openDoor == item.itemid then
item:transform(value.closedDoor)
item:getPosition():sendSingleSoundEffect(SOUND_EFFECT_TYPE_ACTION_CLOSE_DOOR)
return true
end
end
Expand Down
6 changes: 6 additions & 0 deletions data-otservbr-global/scripts/actions/door/key_door.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function keyDoor.onUse(player, item, fromPosition, target, toPosition, isHotkey)
for index, value in ipairs(KeyDoorTable) do
if value.closedDoor == item.itemid then
item:transform(value.openDoor)
item:getPosition():sendSingleSoundEffect(SOUND_EFFECT_TYPE_ACTION_OPEN_DOOR)
return true
end
end
Expand All @@ -46,6 +47,7 @@ function keyDoor.onUse(player, item, fromPosition, target, toPosition, isHotkey)
return false
end
item:transform(value.closedDoor)
item:getPosition():sendSingleSoundEffect(SOUND_EFFECT_TYPE_ACTION_CLOSE_DOOR)
return true
end
end
Expand All @@ -60,8 +62,12 @@ function keyDoor.onUse(player, item, fromPosition, target, toPosition, isHotkey)
if item.actionid == target.actionid then
if value.lockedDoor == target.itemid then
target:transform(value.openDoor)
item:getPosition():sendSingleSoundEffect(SOUND_EFFECT_TYPE_ACTION_OPEN_DOOR)
return true
elseif table.contains({ value.openDoor, value.closedDoor }, target.itemid) then
if value.openDoor == item.itemid then
item:getPosition():sendSingleSoundEffect(SOUND_EFFECT_TYPE_ACTION_CLOSE_DOOR)
end
target:transform(value.lockedDoor)
return true
end
Expand Down
1 change: 1 addition & 0 deletions data-otservbr-global/scripts/actions/door/level_door.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function levelDoor.onUse(player, item, fromPosition, target, toPosition, isHotke
if value.closedDoor == item.itemid then
if item.actionid > 0 and player:getLevel() >= item.actionid - 1000 then
item:transform(value.openDoor)
item:getPosition():sendSingleSoundEffect(SOUND_EFFECT_TYPE_ACTION_OPEN_DOOR)
player:teleportTo(toPosition, true)
return true
else
Expand Down
1 change: 1 addition & 0 deletions data-otservbr-global/scripts/actions/door/quest_door.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function questDoor.onUse(player, item, fromPosition, target, toPosition, isHotke
if value.closedDoor == item.itemid then
if item.actionid > 0 and player:getStorageValue(item.actionid) ~= -1 then
item:transform(value.openDoor)
item:getPosition():sendSingleSoundEffect(SOUND_EFFECT_TYPE_ACTION_OPEN_DOOR)
player:teleportTo(toPosition, true)
return true
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,13 @@ function closingDoor.onStepOut(creature, item, position, fromPosition)
for index, value in ipairs(LevelDoorTable) do
if value.openDoor == item.itemid then
item:transform(value.closedDoor)
item:getPosition():sendSingleSoundEffect(SOUND_EFFECT_TYPE_ACTION_CLOSE_DOOR)
end
end
for index, value in ipairs(QuestDoorTable) do
if value.openDoor == item.itemid then
item:transform(value.closedDoor)
item:getPosition():sendSingleSoundEffect(SOUND_EFFECT_TYPE_ACTION_CLOSE_DOOR)
end
end
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ local encounter = Encounter("Magma Bubble", {
function encounter:onReset(position)
encounter:removeMonsters()
bossZone:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("The Magma Bubble has been defeated. You have %i seconds to leave the room.", config.timeToLeftAfterKill))
addEvent(function(zn)
self:addEvent(function(zn)
zn:refresh()
zn:removePlayers()
end, config.timeToLeftAfterKill * 1000, bossZone)
Expand Down
11 changes: 5 additions & 6 deletions data/libs/encounters_lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -83,26 +83,25 @@ function Encounter:resetConfig(config)
self.registered = false
self.global = config.global or false
self.timeToSpawnMonsters = ParseDuration(config.timeToSpawnMonsters or "3s")
self.events = {}
self.events = Set()
end

---@param callable function The callable function for the event
---@param delay number The delay time for the event
function Encounter:addEvent(callable, delay, ...)
local index = #self.events + 1
local event = addEvent(function(callable, ...)
pcall(callable, ...)
table.remove(self.events, index)
self.events:remove(event)
end, ParseDuration(delay), callable, ...)
table.insert(self.events, index, event)
self.events:insert(event)
end

---Cancels all the events associated with the encounter
function Encounter:cancelEvents()
for _, event in ipairs(self.events) do
for event in self.events:iter() do
stopEvent(event)
end
self.events = {}
self.events = Set()
end

---Returns the stage of the encounter by the given stage number
Expand Down
3 changes: 3 additions & 0 deletions data/libs/functions/set.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ function Set:insert(key)
end

function Set:remove(key)
if not self:contains(key) then
return
end
key = self:__key(key)
self.values[key] = nil
end
Expand Down
4 changes: 1 addition & 3 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3942,9 +3942,7 @@ std::map<uint32_t, uint32_t> &Player::getAllItemTypeCount(std::map<uint32_t, uin

std::map<uint16_t, uint16_t> &Player::getAllSaleItemIdAndCount(std::map<uint16_t, uint16_t> &countMap) const {
for (const auto item : getAllInventoryItems(false, true)) {
if (!item->hasImbuements()) {
countMap[item->getID()] += item->getItemCount();
}
countMap[item->getID()] += item->getItemCount();
}

return countMap;
Expand Down

0 comments on commit 1be012a

Please sign in to comment.