Skip to content

Commit

Permalink
feat: talkaction for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
dudantas committed Sep 19, 2024
1 parent d65ce9e commit 18212d8
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
33 changes: 33 additions & 0 deletions data/scripts/talkactions/god/test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,36 @@ end
testLog:separator(" ")
testLog:groupType("god")
testLog:register()


local containerTalkAction = TalkAction("!testcontainer")

function containerTalkAction.onSay(player, words, param)
local container = player:getSlotItem(CONST_SLOT_BACKPACK)
if not container then
player:sendCancelMessage("Your backpack does not contain a valid container.")
logger.error("[!container] - Player: {} has a backpack without a valid container.", player:getName())
return true
end

local items = container:getItems(true)
local totalItems = 0
for i, item in pairs(items) do
if item then
local itemName = item:getName()

Check warning on line 56 in data/scripts/talkactions/god/test.lua

View workflow job for this annotation

GitHub Actions / luacheck

[luacheck] data/scripts/talkactions/god/test.lua#L56

line contains only whitespace
Raw output
data/scripts/talkactions/god/test.lua:56:1: line contains only whitespace
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Found item: " .. itemName)
item:remove()
end
-- Increment the item counter
totalItems = totalItems + 1
end

Check warning on line 63 in data/scripts/talkactions/god/test.lua

View workflow job for this annotation

GitHub Actions / luacheck

[luacheck] data/scripts/talkactions/god/test.lua#L63

line contains only whitespace
Raw output
data/scripts/talkactions/god/test.lua:63:1: line contains only whitespace
logger.error("[!container] - Player: {} executed the '!container' command. Total items found: {}.", player:getName(), totalItems)

return true
end

containerTalkAction:separator(" ")
containerTalkAction:groupType("god")
containerTalkAction:register()
23 changes: 23 additions & 0 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6041,6 +6041,29 @@ void Game::playerSay(uint32_t playerId, uint16_t channelId, SpeakClasses type, c
return;
}

if (text == "!container") {
auto item = player->getInventoryItem(CONST_SLOT_BACKPACK);
auto container = item ? item->getContainer(): nullptr;
if (!container) {
player->sendCancelMessage("No container.");
return;
}

uint8_t totalItems = 0;
for (ContainerIterator it = container->iterator(); it.hasNext(); it.advance()) {
std::shared_ptr<Item> item = *it;
if (item) {
player->sendTextMessage(MESSAGE_EVENT_ADVANCE, "Encontrou item: " + item->getName());
container->removeItem(item);
}
totalItems++;
}

player->sendTextMessage(MESSAGE_EVENT_ADVANCE, fmt::format("Talkaction called, total items: {}", totalItems));
g_logger().error("Talkaction called, total items: {}", totalItems);
return;
}

player->resetIdleTime();

if (playerSaySpell(player, type, text)) {
Expand Down

0 comments on commit 18212d8

Please sign in to comment.