Skip to content

Commit

Permalink
Merge branch 'main' into addPaymentInWar
Browse files Browse the repository at this point in the history
  • Loading branch information
Luan Luciano authored Jan 19, 2024
2 parents ad7c7f1 + e44bd19 commit 5a06b73
Show file tree
Hide file tree
Showing 24 changed files with 148 additions and 41 deletions.
2 changes: 1 addition & 1 deletion data-canary/scripts/actions/tools/magic_gold_converter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ local data = {
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)
findItem(self, self:getStoreInbox(), converterItem)
end

if cylinder and cylinder:isContainer() then
Expand Down
5 changes: 3 additions & 2 deletions data-otservbr-global/npc/emael.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ local function creatureSayCallback(npc, creature, type, message)
if player:getStorageValue(30020) == 1 then
if player:removeMoney(1000000) then
npcHandler:say("Ah, I see you killed a lot of dangerous creatures. Here's your podium of vigour!", npc, creature)
local inbox = player:getSlotItem(CONST_SLOT_STORE_INBOX)
if inbox then
local inbox = player:getStoreInbox()
local inboxItems = inbox:getItems()
if inbox and #inboxItems <= inbox:getMaxCapacity() then
local decoKit = inbox:addItem(ITEM_DECORATION_KIT, 1)
if decoKit then
decoKit:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, "Unwrap it in your own house to create a <" .. ItemType(38707):getName() .. ">.")
Expand Down
5 changes: 3 additions & 2 deletions data-otservbr-global/npc/emperor_kruzak.lua
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ local function creatureSayCallback(npc, creature, type, message)
elseif npcHandler:getTopic(playerId) == 3 then -- ARMOR/OUTFIT
if player:getStorageValue(Storage.OutfitQuest.GoldenOutfit) < 1 then
if player:getMoney() + player:getBankBalance() >= 500000000 then
local inbox = player:getSlotItem(CONST_SLOT_STORE_INBOX)
if inbox then
local inbox = player:getStoreInbox()
local inboxItems = inbox:getItems()
if inbox and #inboxItems <= inbox:getMaxCapacity() then
local decoKit = inbox:addItem(ITEM_DECORATION_KIT, 1)
local decoItemName = ItemType(31510):getName()
decoKit:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, "You bought this item in the Store.\nUnwrap it in your own house to create a " .. decoItemName .. ".")
Expand Down
6 changes: 3 additions & 3 deletions data-otservbr-global/npc/hireling.lua
Original file line number Diff line number Diff line change
Expand Up @@ -517,11 +517,11 @@ function createHirelingType(HirelingName)
local playerId = creature:getId()
local player = Player(creature)
local itType = ItemType(food_id)
local inbox = player:getSlotItem(CONST_SLOT_STORE_INBOX)

local inbox = player:getStoreInbox()
local inboxItems = inbox:getItems()
if player:getFreeCapacity() < itType:getWeight(1) then
npcHandler:say("Sorry, but you don't have enough capacity.", npc, creature)
elseif not inbox then
elseif not inbox or #inboxItems > inbox:getMaxCapacity() then
player:getPosition():sendMagicEffect(CONST_ME_POFF)
npcHandler:say("Sorry, you don't have enough room on your inbox", npc, creature)
elseif not player:removeMoneyBank(15000) then
Expand Down
5 changes: 3 additions & 2 deletions data-otservbr-global/npc/king_tibianus.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ local function creatureSayCallback(npc, creature, type, message)
elseif npcHandler:getTopic(playerId) == 3 then -- ARMOR/OUTFIT
if player:getStorageValue(Storage.OutfitQuest.GoldenOutfit) < 1 then
if player:getMoney() + player:getBankBalance() >= 500000000 then
local inbox = player:getSlotItem(CONST_SLOT_STORE_INBOX)
if inbox then
local inbox = player:getStoreInbox()
local inboxItems = inbox:getItems()
if inbox and #inboxItems <= inbox:getMaxCapacity() then
local decoKit = inbox:addItem(ITEM_DECORATION_KIT, 1)
local decoItemName = ItemType(31510):getName()
decoKit:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, "Unwrap it in your own house to create a " .. decoItemName .. ".")
Expand Down
5 changes: 3 additions & 2 deletions data-otservbr-global/npc/queen_eloise.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ local function creatureSayCallback(npc, creature, type, message)
elseif npcHandler:getTopic(playerId) == 3 then -- ARMOR/OUTFIT
if player:getStorageValue(Storage.OutfitQuest.GoldenOutfit) < 1 then
if player:getMoney() + player:getBankBalance() >= 500000000 then
local inbox = player:getSlotItem(CONST_SLOT_STORE_INBOX)
if inbox then
local inbox = player:getStoreInbox()
local inboxItems = inbox:getItems()
if inbox and #inboxItems <= inbox:getMaxCapacity() then
local decoKit = inbox:addItem(ITEM_DECORATION_KIT, 1)
local decoItemName = ItemType(31510):getName()
decoKit:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, "You bought this item in the Store.\nUnwrap it in your own house to create a " .. decoItemName .. ".")
Expand Down
7 changes: 5 additions & 2 deletions data-otservbr-global/npc/walter_jaeger.lua
Original file line number Diff line number Diff line change
Expand Up @@ -281,14 +281,17 @@ local function processItemInboxPurchase(player, name, id)
return false
end

local inbox = player:getSlotItem(CONST_SLOT_STORE_INBOX)
if inbox then
local inbox = player:getStoreInbox()
local inboxItems = inbox:getItems()
if inbox and #inboxItems <= inbox:getMaxCapacity() then
local decoKit = inbox:addItem(ITEM_DECORATION_KIT, 1)
if decoKit then
decoKit:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, "You bought this item with the Walter Jaeger.\nUnwrap it in your own house to create a <" .. name .. ">.")
decoKit:setCustomAttribute("unWrapId", id)
return true
end
else
player:sendTextMessage(MESSAGE_INFO_DESCR, "Please make sure you have free slots in your store inbox.")
end

return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ local data = {
local function finditem(self, cylinder, conv)
if cylinder == 0 then
cylinder = self:getSlotItem(CONST_SLOT_BACKPACK)
finditem(self, self:getSlotItem(CONST_SLOT_STORE_INBOX), conv)
finditem(self, self:getStoreInbox(), conv)
end

if cylinder and cylinder:isContainer() then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,41 @@ local config = {
exitPosition = Position(31971, 32325, 10),
}

local entrancesTiles = {
{ x = 31937, y = 32324, z = 10 },
{ x = 31937, y = 32325, z = 10 },
{ x = 31937, y = 32326, z = 10 },
{ x = 31951, y = 32310, z = 10 },
{ x = 31952, y = 32309, z = 10 },
{ x = 31952, y = 32310, z = 10 },
{ x = 31953, y = 32309, z = 10 },
{ x = 31953, y = 32310, z = 10 },
{ x = 31954, y = 32310, z = 10 },
{ x = 31954, y = 32311, z = 10 },
{ x = 31955, y = 32311, z = 10 },
{ x = 31956, y = 32309, z = 10 },
{ x = 31956, y = 32310, z = 10 },
{ x = 31956, y = 32311, z = 10 },
{ x = 31957, y = 32308, z = 10 },
{ x = 31957, y = 32309, z = 10 },
{ x = 31957, y = 32310, z = 10 },
{ x = 31951, y = 32339, z = 10 },
{ x = 31952, y = 32339, z = 10 },
{ x = 31953, y = 32339, z = 10 },
{ x = 31953, y = 32340, z = 10 },
{ x = 31954, y = 32340, z = 10 },
{ x = 31955, y = 32340, z = 10 },
{ x = 31955, y = 32341, z = 10 },
{ x = 31969, y = 32323, z = 10 },
{ x = 31969, y = 32324, z = 10 },
{ x = 31969, y = 32325, z = 10 },
{ x = 31969, y = 32326, z = 10 },
{ x = 31969, y = 32327, z = 10 },
{ x = 31970, y = 32323, z = 10 },
{ x = 31970, y = 32324, z = 10 },
{ x = 31970, y = 32326, z = 10 },
}

local zone = Zone("boss." .. toKey(config.bossName))
local encounter = Encounter("Brain Head", {
zone = zone,
Expand Down Expand Up @@ -99,7 +134,10 @@ function teleportBoss.onStepIn(creature, item, position, fromPosition)
player:sendBosstiaryCooldownTimer()
end

teleportBoss:aid(30407)
for _, registerPosition in ipairs(entrancesTiles) do
teleportBoss:position(registerPosition)
end

teleportBoss:type("stepin")
teleportBoss:register()

Expand Down
19 changes: 10 additions & 9 deletions data/libs/functions/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ function Player.getSubjectVerb(self, past)
end

function Player.findItemInInbox(self, itemId)
local inbox = self:getSlotItem(CONST_SLOT_STORE_INBOX)
local inbox = self:getStoreInbox()
local items = inbox:getItems()
for _, item in pairs(items) do
if item:getId() == itemId then
Expand Down Expand Up @@ -556,7 +556,7 @@ function Player.updateHazard(self)
end

function Player:addItemStoreInboxEx(item, movable, setOwner)
local inbox = self:getSlotItem(CONST_SLOT_STORE_INBOX)
local inbox = self:getStoreInbox()
if not movable then
item:setOwner(self)
item:setAttribute(ITEM_ATTRIBUTE_STORE, systemTime())
Expand Down Expand Up @@ -631,16 +631,17 @@ function Player:calculateLootFactor(monster)
}
end

function Player:setExhaustion(key, seconds)
return self:setStorageValue(key, os.time() + seconds)
function Player:setExhaustion(scope, seconds)
return self:kv():scoped("exhaustion"):set(scope, os.time() + seconds)
end

function Player:getExhaustion(key)
return math.max(self:getStorageValue(key) - os.time(), 0)
function Player:getExhaustion(scope)
local exhaustionKV = self:kv():scoped("exhaustion"):get(scope) or 0
return math.max(exhaustionKV - os.time(), 0)
end

function Player:hasExhaustion(key)
return self:getExhaustion(key) > 0 and true or false
function Player:hasExhaustion(scope)
return self:getExhaustion(scope) > 0 and true or false
end

function Player:setFiendish()
Expand All @@ -662,7 +663,7 @@ function Player:setFiendish()
end

function Player:findItemInInbox(itemId, name)
local inbox = self:getSlotItem(CONST_SLOT_STORE_INBOX)
local inbox = self:getStoreInbox()
local items = inbox:getItems()
for _, item in pairs(items) do
if item:getId() == itemId and (not name or item:getName() == name) then
Expand Down
14 changes: 8 additions & 6 deletions data/libs/hireling_lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ local function checkHouseAccess(hireling)

-- Player is not invited anymore, return to lamp
logger.debug("Returning Hireling: {} to owner '{}' Inbox", hireling:getName(), player:getName())
local inbox = player:getSlotItem(CONST_SLOT_STORE_INBOX)
local inbox = player:getStoreInbox()
if not inbox then
return false
end
Expand Down Expand Up @@ -359,8 +359,9 @@ function Hireling:returnToLamp(player_id)
return owner:sendTextMessage(MESSAGE_FAILURE, "You do not have enough capacity.")
end

local inbox = owner:getSlotItem(CONST_SLOT_STORE_INBOX)
if not inbox then
local inbox = owner:getStoreInbox()
local inboxItems = inbox:getItems()
if not inbox or #inboxItems > inbox:getMaxCapacity() then
owner:getPosition():sendMagicEffect(CONST_ME_POFF)
return owner:sendTextMessage(MESSAGE_FAILURE, "You don't have enough room in your inbox.")
end
Expand Down Expand Up @@ -537,8 +538,9 @@ function Player:addNewHireling(name, sex)
return false
end

local inbox = self:getSlotItem(CONST_SLOT_STORE_INBOX)
if not inbox then
local inbox = self:getStoreInbox()
local inboxItems = inbox:getItems()
if not inbox or #inboxItems > inbox:getMaxCapacity() then
self:getPosition():sendMagicEffect(CONST_ME_POFF)
self:sendTextMessage(MESSAGE_FAILURE, "You don't have enough room in your inbox.")
return false
Expand Down Expand Up @@ -628,7 +630,7 @@ function Player:hasHirelings()
end

function Player:findHirelingLamp(hirelingId)
local inbox = self:getSlotItem(CONST_SLOT_STORE_INBOX)
local inbox = self:getStoreInbox()
if not inbox then
return nil
end
Expand Down
2 changes: 1 addition & 1 deletion data/modules/scripts/blessings/blessings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ Blessings.DropLoot = function(player, corpse, chance, skulled)
end
end
if skulled and Blessings.Config.SkulledDeathLoseStoreItem then
local inbox = player:getSlotItem(CONST_SLOT_STORE_INBOX)
local inbox = player:getStoreInbox()
local toBeDeleted = {}
if inbox and inbox:getSize() > 0 then
for i = 0, inbox:getSize() do
Expand Down
5 changes: 3 additions & 2 deletions data/modules/scripts/daily_reward/daily_reward.lua
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,9 @@ function Player.selectDailyReward(self, msg)
end

-- Adding items to store inbox
local inbox = self:getSlotItem(CONST_SLOT_STORE_INBOX)
if not inbox then
local inbox = self:getStoreInbox()
local inboxItems = inbox:getItems()
if not inbox or #inboxItems > inbox:getMaxCapacity() then
self:sendError("You do not have enough space in your store inbox.")
return false
end
Expand Down
11 changes: 7 additions & 4 deletions data/modules/scripts/gamestore/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1573,8 +1573,9 @@ function GameStore.processStackablePurchase(player, offerId, offerCount, offerNa
return error({ code = 0, message = "Please make sure you have free capacity to hold this item." })
end

local inbox = player:getSlotItem(CONST_SLOT_STORE_INBOX)
if inbox then
local inbox = player:getStoreInbox()
local inboxItems = inbox:getItems()
if inbox and #inboxItems <= inbox:getMaxCapacity() then
if (isKeg and offerCount > 500) or offerCount > 100 then
local parcel = inbox:addItem(PARCEL_ID, 1)
parcel:setAttribute(ITEM_ATTRIBUTE_STORE, systemTime())
Expand Down Expand Up @@ -1624,12 +1625,14 @@ function GameStore.processHouseRelatedPurchase(player, offer)
return (itemId >= ITEM_HEALTH_CASK_START and itemId <= ITEM_HEALTH_CASK_END) or (itemId >= ITEM_MANA_CASK_START and itemId <= ITEM_MANA_CASK_END) or (itemId >= ITEM_SPIRIT_CASK_START and itemId <= ITEM_SPIRIT_CASK_END)
end

local inbox = player:getSlotItem(CONST_SLOT_STORE_INBOX)
local itemIds = offer.itemtype
if type(itemIds) ~= "table" then
itemIds = { itemIds }
end
if inbox then

local inbox = player:getStoreInbox()
local inboxItems = inbox:getItems()
if inbox and #inboxItems <= inbox:getMaxCapacity() then
for _, itemId in ipairs(itemIds) do
local decoKit = inbox:addItem(ITEM_DECORATION_KIT, 1)
if decoKit then
Expand Down
2 changes: 1 addition & 1 deletion data/scripts/talkactions/god/inbox_command.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function inboxCommand.onSay(player, words, param)
player:getPosition():sendMagicEffect(CONST_ME_TUTORIALSQUARE)
local target = Creature(param[1])
if target then
local inbox = target:getSlotItem(CONST_SLOT_STORE_INBOX)
local inbox = target:getStoreInbox()
local inboxSize = inbox:getSize()
if inbox and inboxSize > 0 then
if param[2] == "remove" then
Expand Down
5 changes: 3 additions & 2 deletions data/scripts/talkactions/player/reward.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ local function sendExerciseRewardModal(player)
return true
end

local inbox = player:getSlotItem(CONST_SLOT_STORE_INBOX)
if inbox and inbox:getEmptySlots() > 0 and player:getFreeCapacity() >= iType:getWeight() then
local inbox = player:getStoreInbox()
local inboxItems = inbox:getItems()
if inbox and #inboxItems <= inbox:getMaxCapacity() and player:getFreeCapacity() >= iType:getWeight() then
local item = inbox:addItem(it.id, it.charges)
if item then
item:setActionId(IMMOVABLE_ACTION_ID)
Expand Down
14 changes: 14 additions & 0 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5350,6 +5350,10 @@ int32_t Player::getPerfectShotDamage(uint8_t range, bool useCharges) const {
continue;
}

if (!itemType.abilities->perfectShotRange) {
continue;
}

if (itemType.abilities->perfectShotRange == range) {
result += itemType.abilities->perfectShotDamage;
uint16_t charges = item->getCharges();
Expand Down Expand Up @@ -7809,6 +7813,16 @@ std::shared_ptr<Container> Player::getLootPouch() {
return container;
}

std::shared_ptr<Container> Player::getStoreInbox() const {
auto thing = getThing(CONST_SLOT_STORE_INBOX);
if (!thing) {
return nullptr;
}

auto storeInbox = thing->getContainer();
return storeInbox ? storeInbox : nullptr;
}

bool Player::hasPermittedConditionInPZ() const {
static const std::unordered_set<ConditionType_t> allowedConditions = {
CONDITION_ENERGY,
Expand Down
2 changes: 2 additions & 0 deletions src/creatures/players/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2552,6 +2552,8 @@ class Player final : public Creature, public Cylinder, public Bankable {

bool hasPermittedConditionInPZ() const;

std::shared_ptr<Container> getStoreInbox() const;

private:
friend class PlayerLock;
std::mutex mutex;
Expand Down
4 changes: 4 additions & 0 deletions src/items/containers/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ std::ostringstream &Container::getContentDescription(std::ostringstream &os, boo
return os;
}

uint32_t Container::getMaxCapacity() const {
return m_maxItems;
}

bool Container::isStoreInbox() const {
return getID() == ITEM_STORE_INBOX;
}
Expand Down
2 changes: 2 additions & 0 deletions src/items/containers/container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ class Container : public Item, public Cylinder {
bool unserializeItemNode(OTB::Loader &loader, const OTB::Node &node, PropStream &propStream, Position &itemPosition) override;
std::string getContentDescription(bool oldProtocol);

uint32_t getMaxCapacity() const;

size_t size() const {
return itemlist.size();
}
Expand Down
17 changes: 17 additions & 0 deletions src/lua/functions/creatures/player/player_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4156,3 +4156,20 @@ int PlayerFunctions::luaPlayerKV(lua_State* L) {
setMetatable(L, -1, "KV");
return 1;
}

int PlayerFunctions::luaPlayerGetStoreInbox(lua_State* L) {
// player:getStoreInbox()
const auto &player = getUserdataShared<Player>(L, 1);
if (!player) {
lua_pushnil(L);
return 1;
}

if (auto item = player->getStoreInbox()) {
pushUserdata<Item>(L, item);
setItemMetatable(L, -1, item);
} else {
pushBoolean(L, false);
}
return 1;
}
Loading

0 comments on commit 5a06b73

Please sign in to comment.