From ea4679ea3280244739c1628117d63bc48e79b602 Mon Sep 17 00:00:00 2001 From: Sarah Wesker Date: Sun, 7 Apr 2024 12:30:36 -0400 Subject: [PATCH] fix account manager / fix broadcast / add getWaypoints --- data/talkactions/scripts/broadcast.lua | 2 +- src/game.cpp | 2 +- src/luagame.cpp | 15 +++++++++++++++ src/lualoot.cpp | 22 ++++++++++++++++++++++ src/luascript.cpp | 1 + src/monsters.h | 2 ++ src/protocolgame.cpp | 4 ++-- 7 files changed, 44 insertions(+), 4 deletions(-) diff --git a/data/talkactions/scripts/broadcast.lua b/data/talkactions/scripts/broadcast.lua index 55c1a84..8dd3087 100644 --- a/data/talkactions/scripts/broadcast.lua +++ b/data/talkactions/scripts/broadcast.lua @@ -3,7 +3,7 @@ function onSay(player, words, param) print("> " .. player:getName() .. " broadcasted: \"" .. param .. "\".") for _, targetPlayer in ipairs(Game.getPlayers()) do - targetPlayer:sendPrivateMessage(player, param, TALKTYPE_BROADCAST) + targetPlayer:sendTextMessage(MESSAGE_STATUS_WARNING, param) end return false end diff --git a/src/game.cpp b/src/game.cpp index 29cc209..4095fdf 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -3457,7 +3457,7 @@ void Game::playerSay(uint32_t playerId, uint16_t channelId, SpeakClasses type, s return; } - if (g_config[ConfigKeysBoolean::ACCOUNT_MANAGER] && player->isAccountManager()) { + if (player->isAccountManager()) { if (player->isMuted() > 0) { player->removeMessageBuffer(); } diff --git a/src/luagame.cpp b/src/luagame.cpp index b075e91..9152908 100644 --- a/src/luagame.cpp +++ b/src/luagame.cpp @@ -637,6 +637,19 @@ int luaGameSaveAccountStorageValues(lua_State* L) return 1; } + +int luaGameGetWaypoints(lua_State* L) +{ + // Game.getWaypoints() + lua_createtable(L, g_game.map.waypoints.size(), 0); + + for (const auto& [name, position] : g_game.map.waypoints) { + pushPosition(L, position); + setMetatable(L, -1, "Position"); + lua_setfield(L, -2, name.c_str()); + } + return 1; +} } // namespace void LuaScriptInterface::registerGame() @@ -690,4 +703,6 @@ void LuaScriptInterface::registerGame() registerMethod("Game", "getAccountStorageValue", luaGameGetAccountStorageValue); registerMethod("Game", "setAccountStorageValue", luaGameSetAccountStorageValue); registerMethod("Game", "saveAccountStorageValues", luaGameSaveAccountStorageValues); + + registerMethod("Game", "getWaypoints", luaGameGetWaypoints); } diff --git a/src/lualoot.cpp b/src/lualoot.cpp index 4675eaa..6be23c1 100644 --- a/src/lualoot.cpp +++ b/src/lualoot.cpp @@ -88,6 +88,19 @@ int luaLootSetChance(lua_State* L) return 1; } +int luaLootSetMinCount(lua_State* L) +{ + // loot:setMinCount(min) + Loot* loot = getUserdata(L, 1); + if (loot) { + loot->lootBlock.countmin = getInteger(L, 2); + pushBoolean(L, true); + } else { + lua_pushnil(L); + } + return 1; +} + int luaLootSetMaxCount(lua_State* L) { // loot:setMaxCount(max) @@ -152,4 +165,13 @@ void LuaScriptInterface::registerLoot() registerMetaMethod("Loot", "__gc", luaDeleteLoot); registerMetaMethod("Loot", "__close", luaDeleteLoot); registerMethod("Loot", "delete", luaDeleteLoot); + + registerMethod("Loot", "setId", luaLootSetId); + registerMethod("Loot", "setMinCount", luaLootSetMaxCount); + registerMethod("Loot", "setMaxCount", luaLootSetMaxCount); + registerMethod("Loot", "setSubType", luaLootSetSubType); + registerMethod("Loot", "setChance", luaLootSetChance); + registerMethod("Loot", "setActionId", luaLootSetActionId); + registerMethod("Loot", "setDescription", luaLootSetDescription); + registerMethod("Loot", "addChildLoot", luaLootAddChildLoot); } diff --git a/src/luascript.cpp b/src/luascript.cpp index cfab07b..5623cec 100644 --- a/src/luascript.cpp +++ b/src/luascript.cpp @@ -1043,6 +1043,7 @@ void Lua::pushLoot(lua_State* L, const std::vector& lootList) setField(L, "itemId", lootBlock.id); setField(L, "chance", lootBlock.chance); setField(L, "subType", lootBlock.subType); + setField(L, "minCount", lootBlock.countmin); setField(L, "maxCount", lootBlock.countmax); setField(L, "actionId", lootBlock.actionId); setField(L, "text", lootBlock.text); diff --git a/src/monsters.h b/src/monsters.h index 63e8c73..a4e3649 100644 --- a/src/monsters.h +++ b/src/monsters.h @@ -11,6 +11,7 @@ const uint32_t MAX_LOOTCHANCE = 100000; struct LootBlock { uint16_t id; + uint32_t countmin; uint32_t countmax; uint32_t chance; @@ -23,6 +24,7 @@ struct LootBlock LootBlock() { id = 0; + countmin = 1; countmax = 1; chance = 0; diff --git a/src/protocolgame.cpp b/src/protocolgame.cpp index 03957b1..67bbd02 100644 --- a/src/protocolgame.cpp +++ b/src/protocolgame.cpp @@ -1350,7 +1350,7 @@ void ProtocolGame::parseEnableSharedPartyExperience(NetworkMessage& msg) void ProtocolGame::parseModalWindowAnswer(NetworkMessage& msg) { - if (isOTCv8) { + if (!isOTCv8) { return; } @@ -2181,7 +2181,7 @@ void ProtocolGame::sendInventoryItem(slots_t slot, const Item* item) void ProtocolGame::sendModalWindow(const ModalWindow& modalWindow) { - if (isOTCv8) { + if (!isOTCv8) { return; }