Skip to content

Commit

Permalink
Merge branch 'main' into feature/tournament-coins-custom
Browse files Browse the repository at this point in the history
  • Loading branch information
elsongabriel authored Dec 1, 2023
2 parents d3d81e7 + a1510a8 commit 6b47053
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local spell = Spell("instant")

function spell.onCastSpell(creature, variant)
return creature:conjureItem(0, 25758, 100, CONST_ME_MAGIC_BLUE)
return creature:conjureItem(0, 35902, 100, CONST_ME_MAGIC_BLUE)
end

spell:group("support")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local spell = Spell("instant")

function spell.onCastSpell(creature, variant)
return creature:conjureItem(0, 25758, 100, CONST_ME_MAGIC_BLUE)
return creature:conjureItem(0, 35902, 100, CONST_ME_MAGIC_BLUE)
end

spell:group("support")
Expand Down
8 changes: 6 additions & 2 deletions data/libs/functions/container.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function Container:addLoot(loot)
logger.warn("Container:addLoot: invalid item type: {}", itemId)
goto continue
end
if iType:isStackable() or iType:getCharges() ~= 0 then
if iType:isStackable() then
local stackSize = iType:getStackSize()
local remainingCount = item.count

Expand All @@ -23,9 +23,13 @@ function Container:addLoot(loot)
logger.warn("Container:addLoot: failed to add stackable item: {}, to corpse {} with id {}", ItemType(itemId):getName(), self:getName(), self:getId())
goto continue
end

remainingCount = remainingCount - countToAdd
end
elseif iType:getCharges() ~= 0 then
local tmpItem = self:addItem(itemId, item.count, INDEX_WHEREEVER, FLAG_NOLIMIT)
if not tmpItem then
logger.warn("Container:addLoot: failed to add charge item: {}, to corpse {} with id {}", ItemType(itemId):getName(), self:getName(), self:getId())
end
else
for i = 1, item.count do
local tmpItem = self:addItem(itemId, 1, INDEX_WHEREEVER, FLAG_NOLIMIT)
Expand Down
2 changes: 1 addition & 1 deletion data/scripts/eventcallbacks/monster/ondroploot_prey.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function callback.monsterOnDropLoot(monster, corpse)
return
end

if configManager.getBoolean(PARTY_SHARE_LOOT_BOOSTS) then
if configManager.getBoolean(configKeys.PARTY_SHARE_LOOT_BOOSTS) then
msgSuffix = msgSuffix .. " (active prey bonus for " .. table.concat(preyActivators, ", ") .. ")"
else
msgSuffix = msgSuffix .. " (active prey bonus)"
Expand Down
18 changes: 14 additions & 4 deletions data/scripts/talkactions/god/create_item.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,31 @@ function createItem.onSay(player, words, param)
local count = tonumber(split[2])
if count then
if itemType:isStackable() then
local stackSize = itemType:getStackSize()
local container = Game.createItem(2854)
local mainContainer = player:getSlotItem(CONST_SLOT_BACKPACK)
if not mainContainer then
player:addItemEx(Game.createItem(2854), CONST_SLOT_BACKPACK)
mainContainer = player:getSlotItem(CONST_SLOT_BACKPACK)
end
local remainingCount = count
local stackSize = itemType:getStackSize()

while remainingCount > 0 do
local freeSlots = mainContainer and (mainContainer:getCapacity() - mainContainer:getSize()) or 0
if freeSlots <= 1 and mainContainer:getSize() ~= 0 then
mainContainer = Game.createItem(2854)
player:addItemEx(mainContainer)
end

local countToAdd = math.min(remainingCount, stackSize)
local tmpItem = container:addItem(itemType:getId(), countToAdd, INDEX_WHEREEVER, FLAG_NOLIMIT)
local tmpItem = mainContainer:addItem(itemType:getId(), countToAdd)
if tmpItem then
remainingCount = remainingCount - countToAdd
else
logger.warn("Failed to add item: {}, to container", itemType:getName())
break
end
end

player:addItemEx(container)
player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
return true
elseif not itemType:isFluidContainer() then
Expand Down
12 changes: 9 additions & 3 deletions data/scripts/talkactions/player/emote_spell.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@
local emoteSpell = TalkAction("!emote")

function emoteSpell.onSay(player, words, param)
if configManager.getBoolean(configKeys.EMOTE_SPELLS) == false then
player:sendTextMessage(MESSAGE_LOOK, "Emote spells have been disabled by the administrator.")
return true
end

if param == "" then
player:sendCancelMessage("You need to specify on/off param.")
player:sendCancelMessage("Please specify the parameter: 'on' to activate or 'off' to deactivate.")
return true
end

if param == "on" then
player:setStorageValue(STORAGEVALUE_EMOTE, 1)
player:sendTextMessage(MESSAGE_LOOK, "You activated emoted spells")
player:sendTextMessage(MESSAGE_LOOK, "You have activated emote spells.")
elseif param == "off" then
player:setStorageValue(STORAGEVALUE_EMOTE, 0)
player:sendTextMessage(MESSAGE_LOOK, "You desactivated emoted spells")
player:sendTextMessage(MESSAGE_LOOK, "You have deactivated emote spells.")
end
return true
end
Expand Down
2 changes: 0 additions & 2 deletions data/scripts/talkactions/player/flask.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ function flask.onSay(player, words, param)
return true
end
if param == "on" and player:getStorageValueByName("talkaction.potions.flask") ~= 1 then
player:setStorageValue(STORAGEVALUE_EMOTE, 1)
player:setStorageValueByName("talkaction.potions.flask", 1)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You will not receive flasks!")
player:getPosition():sendMagicEffect(CONST_ME_REDSMOKE)
elseif param == "off" then
player:setStorageValue(STORAGEVALUE_EMOTE, 0)
player:setStorageValueByName("talkaction.potions.flask", 0)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You will receive flasks.")
player:getPosition():sendMagicEffect(CONST_ME_REDSMOKE)
Expand Down
20 changes: 20 additions & 0 deletions data/scripts/talkactions/player/hidden_npc_sell_shop_items.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
local talkaction = TalkAction("!hiddenshop")

function talkaction.onSay(player, words, param)
if param == "" then
player:sendCancelMessage("You need to specify on/off param.")
return true
end
if param == "on" then
player:kv():set("npc-shop-hidden-sell-item", true)
player:sendTextMessage(MESSAGE_LOOK, "You activated hidden sell shop items.")
elseif param == "off" then
player:kv():set("npc-shop-hidden-sell-item", false)
player:sendTextMessage(MESSAGE_LOOK, "You desactivated hidden sell shop items")
end
return true
end

talkaction:separator(" ")
talkaction:groupType("normal")
talkaction:register()
2 changes: 1 addition & 1 deletion src/creatures/npcs/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ void Npc::onPlayerSellItem(std::shared_ptr<Player> player, uint16_t itemId, uint
}

auto toRemove = amount;
for (auto inventoryItems = player->getInventoryItemsFromId(itemId, ignore); auto item : inventoryItems) {
for (auto item : player->getInventoryItemsFromId(itemId, ignore)) {
if (!item || item->getTier() > 0 || item->hasImbuements()) {
continue;
}
Expand Down
4 changes: 3 additions & 1 deletion src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6820,7 +6820,9 @@ bool Player::saySpell(
// Send to client
for (std::shared_ptr<Creature> spectator : spectators) {
if (std::shared_ptr<Player> tmpPlayer = spectator->getPlayer()) {
valueEmote = tmpPlayer->getStorageValue(STORAGEVALUE_EMOTE);
if (g_configManager().getBoolean(EMOTE_SPELLS, __FUNCTION__)) {
valueEmote = tmpPlayer->getStorageValue(STORAGEVALUE_EMOTE);
}
if (!ghostMode || tmpPlayer->canSeeCreature(static_self_cast<Player>())) {
if (valueEmote == 1) {
tmpPlayer->sendCreatureSay(static_self_cast<Player>(), TALKTYPE_MONSTER_SAY, text, pos);
Expand Down
14 changes: 11 additions & 3 deletions src/lua/functions/lua_functions_loader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,17 @@ class LuaFunctionsLoader {
return static_cast<T>(static_cast<int64_t>(lua_tonumber(L, arg)));
}
template <typename T>
static typename std::enable_if<std::is_integral<T>::value || std::is_floating_point<T>::value, T>::type
getNumber(lua_State* L, int32_t arg) {
return static_cast<T>(lua_tonumber(L, arg));
static typename std::enable_if<std::is_integral<T>::value || std::is_floating_point<T>::value, T>::type getNumber(lua_State* L, int32_t arg) {
auto number = lua_tonumber(L, arg);
// If there is overflow, we return the value 0
if constexpr (std::is_integral_v<T> && std::is_unsigned_v<T>) {
if (number < 0) {
g_logger().warn("[{}] overflow, setting to default signed value (0)", __FUNCTION__);
number = T(0);
}
}

return static_cast<T>(number);
}
template <typename T>
static T getNumber(lua_State* L, int32_t arg, T defaultValue) {
Expand Down
12 changes: 12 additions & 0 deletions src/server/network/protocol/protocolgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7655,6 +7655,18 @@ void ProtocolGame::AddShopItem(NetworkMessage &msg, const ShopBlock &shopBlock)
return;
}

// Hidden sell items from the shop if they are not in the player's inventory
auto talkactionHidden = player->kv()->get("npc-shop-hidden-sell-item");
if (talkactionHidden && talkactionHidden->get<BooleanType>() == true) {
std::map<uint16_t, uint16_t> inventoryMap;
player->getAllSaleItemIdAndCount(inventoryMap);
auto inventoryItems = inventoryMap.find(shopBlock.itemId);
if (inventoryItems == inventoryMap.end() && shopBlock.itemSellPrice > 0 && shopBlock.itemBuyPrice == 0) {
AddHiddenShopItem(msg);
return;
}
}

const ItemType &it = Item::items[shopBlock.itemId];
msg.add<uint16_t>(shopBlock.itemId);
if (it.isSplash() || it.isFluidContainer()) {
Expand Down

0 comments on commit 6b47053

Please sign in to comment.