Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Game.getOutfits(playerSex) and Game.getMounts() #1673

Closed
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions data/libs/functions/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -647,3 +647,19 @@ function Player:setFiendish()
end
return false
end

function Player.addAddonToAllOutfits(self, addon)
for sex = 0, 1 do
local outfits = Game.getOutfits(sex)
for outfit = 1, #outfits do
self:addOutfitAddon(outfits[outfit].lookType, addon)
end
end
end

function Player.addAllMounts(self)
local mounts = Game.getMounts()
for mount = 1, #mounts do
self:addMount(mounts[mount].id)
end
end
240 changes: 1 addition & 239 deletions data/scripts/talkactions/god/add_addons.lua
Original file line number Diff line number Diff line change
@@ -1,242 +1,6 @@
-- /addaddons playername

local addons = TalkAction("/addaddons")
local looktypes = {

-- Female Outfits
136,
137,
138,
139,
140,
141,
142,
147,
148,
149,
150,
155,
156,
157,
158,
252,
269,
270,
279,
288,
324,
329,
336,
366,
431,
433,
464,
466,
471,
513,
514,
542,
575,
578,
618,
620,
632,
635,
636,
664,
666,
683,
694,
696,
698,
724,
732,
745,
749,
759,
845,
852,
874,
885,
900,
909,
929,
956,
958,
963,
965,
967,
969,
971,
973,
975,
1020,
1024,
1043,
1050,
1057,
1070,
1095,
1103,
1128,
1147,
1162,
1174,
1187,
1203,
1205,
1207,
1211,
1244,
1246,
1252,
1271,
1280,
1283,
1289,
1293,
1323,
1332,
1339,
1372,
1383,
1385,
1387,
1416,
1437,
1445,
1450,
1456,
1461,
1490,
1501,
1569,
1576,
1582,
1598,
1613,
1619,
1663,
1676,
1681,

-- Male Outfits
128,
129,
130,
131,
132,
133,
134,
143,
144,
145,
146,
151,
152,
153,
154,
251,
268,
273,
278,
289,
325,
328,
335,
367,
430,
432,
463,
465,
472,
512,
516,
541,
574,
577,
610,
619,
633,
634,
637,
665,
667,
684,
695,
697,
699,
725,
733,
746,
750,
760,
846,
853,
873,
884,
899,
908,
931,
955,
957,
962,
964,
966,
968,
970,
972,
974,
1021,
1023,
1042,
1051,
1056,
1069,
1094,
1102,
1127,
1146,
1161,
1173,
1186,
1202,
1204,
1206,
1210,
1243,
1245,
1251,
1270,
1279,
1282,
1288,
1292,
1322,
1331,
1338,
1371,
1382,
1384,
1386,
1415,
1436,
1444,
1449,
1457,
1460,
1489,
1500,
1568,
1575,
1581,
1597,
1612,
1618,
1662,
1675,
1680,
}

function addons.onSay(player, words, param)
-- create log
Expand All @@ -263,9 +27,7 @@ function addons.onSay(player, words, param)
return true
end

for i = 1, #looktypes do
target:addOutfitAddon(looktypes[i], 3)
end
target:addAddonToAllOutfits(3)

player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "All addons unlocked for " .. target:getName() .. ".")
target:sendTextMessage(MESSAGE_EVENT_ADVANCE, "All of your addons have been unlocked!")
Expand Down
4 changes: 1 addition & 3 deletions data/scripts/talkactions/god/add_mounts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ function mounts.onSay(player, words, param)
return true
end

for i = 1, 217 do
target:addMount(i)
end
target:addAllMounts()

player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "All mounts unlocked for: " .. target:getName())
target:sendTextMessage(MESSAGE_EVENT_ADVANCE, "All of your mounts have been unlocked!")
Expand Down
39 changes: 39 additions & 0 deletions src/lua/functions/core/game/game_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -766,3 +766,42 @@
lua_pop(L, 1);
return 1;
}

int GameFunctions::luaGameGetOutfits(lua_State* L) {
// Game.getOutfits(playerSex)
if (!isNumber(L, 1)) {
lua_pushnil(L);
return 1;
}

PlayerSex_t playerSex = getNumber<PlayerSex_t>(L, 1);
if (playerSex > PLAYERSEX_LAST) {
lua_pushnil(L);
return 1;
}

const auto outfits = Outfits::getInstance().getOutfits(playerSex);
lua_createtable(L, outfits.size(), 0);

int index = 0;
for (const auto &outfit : outfits) {
pushOutfit(L, &outfit);

Check failure on line 788 in src/lua/functions/core/game/game_functions.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-20.04-linux-release

cannot convert ‘const std::shared_ptr<Outfit>*’ to ‘const Outfit_t&’

Check failure on line 788 in src/lua/functions/core/game/game_functions.cpp

View workflow job for this annotation

GitHub Actions / windows-2022-windows-release

'void LuaFunctionsLoader::pushOutfit(lua_State *,const Outfit_t &)': cannot convert argument 2 from 'const std::shared_ptr<Outfit> *' to 'const Outfit_t &'

Check failure on line 788 in src/lua/functions/core/game/game_functions.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-20.04-linux-debug

cannot convert ‘const std::shared_ptr<Outfit>*’ to ‘const Outfit_t&’

Check failure on line 788 in src/lua/functions/core/game/game_functions.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-22.04-linux-release

cannot convert ‘const std::shared_ptr<Outfit>*’ to ‘const Outfit_t&’

Check failure on line 788 in src/lua/functions/core/game/game_functions.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-22.04-linux-debug

cannot convert ‘const std::shared_ptr<Outfit>*’ to ‘const Outfit_t&’
dudantas marked this conversation as resolved.
Show resolved Hide resolved
lua_rawseti(L, -2, ++index);
}

return 1;
}

int GameFunctions::luaGameGetMounts(lua_State* L) {
// Game.getMounts()
const auto mounts = g_game().mounts.getMounts();
lua_createtable(L, mounts.size(), 0);

int index = 0;
for (const auto &mount : mounts) {
dudantas marked this conversation as resolved.
Show resolved Hide resolved
pushMount(L, &mount);

Check failure on line 802 in src/lua/functions/core/game/game_functions.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-20.04-linux-release

cannot convert ‘const std::shared_ptr<Mount>*’ to ‘std::shared_ptr<Mount>’

Check failure on line 802 in src/lua/functions/core/game/game_functions.cpp

View workflow job for this annotation

GitHub Actions / windows-2022-windows-release

'void LuaFunctionsLoader::pushMount(lua_State *,const std::shared_ptr<Mount>)': cannot convert argument 2 from 'const std::shared_ptr<Mount> *' to 'const std::shared_ptr<Mount>'

Check failure on line 802 in src/lua/functions/core/game/game_functions.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-20.04-linux-debug

cannot convert ‘const std::shared_ptr<Mount>*’ to ‘std::shared_ptr<Mount>’

Check failure on line 802 in src/lua/functions/core/game/game_functions.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-22.04-linux-release

cannot convert ‘const std::shared_ptr<Mount>*’ to ‘std::shared_ptr<Mount>’

Check failure on line 802 in src/lua/functions/core/game/game_functions.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-22.04-linux-debug

cannot convert ‘const std::shared_ptr<Mount>*’ to ‘std::shared_ptr<Mount>’
lua_rawseti(L, -2, ++index);
}

return 1;
}
6 changes: 6 additions & 0 deletions src/lua/functions/core/game/game_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ class GameFunctions final : LuaScriptInterface {

registerMethod(L, "Game", "getTalkActions", GameFunctions::luaGameGetTalkActions);
registerMethod(L, "Game", "getEventCallbacks", GameFunctions::luaGameGetEventCallbacks);

registerMethod(L, "Game", "getOutfits", GameFunctions::luaGameGetOutfits);
registerMethod(L, "Game", "getMounts", GameFunctions::luaGameGetMounts);
}

private:
Expand Down Expand Up @@ -150,4 +153,7 @@ class GameFunctions final : LuaScriptInterface {

static int luaGameGetTalkActions(lua_State* L);
static int luaGameGetEventCallbacks(lua_State* L);

static int luaGameGetOutfits(lua_State* L);
static int luaGameGetMounts(lua_State* L);
};
9 changes: 9 additions & 0 deletions src/lua/functions/lua_functions_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,15 @@ void LuaFunctionsLoader::pushOutfit(lua_State* L, const Outfit_t &outfit) {
setField(L, "lookFamiliarsType", outfit.lookFamiliarsType);
}

void LuaFunctionsLoader::pushMount(lua_State* L, const std::shared_ptr<Mount> mount) {
lua_createtable(L, 0, 5);
setField(L, "name", mount->name);
setField(L, "speed", mount->speed);
setField(L, "clientId", mount->clientId);
setField(L, "id", mount->id);
setField(L, "premium", mount->premium);
}

void LuaFunctionsLoader::registerClass(lua_State* L, const std::string &className, const std::string &baseClass, lua_CFunction newFunction /* = nullptr*/) {
// className = {}
lua_newtable(L);
Expand Down
6 changes: 4 additions & 2 deletions src/lua/functions/lua_functions_loader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ class Combat;
class Creature;
class Cylinder;
class Game;
class Guild;
class InstantSpell;
class Item;
class KV;
class Mount;
class Player;
class Thing;
class Guild;
class Zone;
class KV;

#define reportErrorFunc(a) reportError(__FUNCTION__, a, true)

Expand Down Expand Up @@ -150,6 +151,7 @@ class LuaFunctionsLoader {
static void pushInstantSpell(lua_State* L, const InstantSpell &spell);
static void pushPosition(lua_State* L, const Position &position, int32_t stackpos = 0);
static void pushOutfit(lua_State* L, const Outfit_t &outfit);
static void pushMount(lua_State* L, const std::shared_ptr<Mount> mount);

static void setField(lua_State* L, const char* index, lua_Number value) {
lua_pushnumber(L, value);
Expand Down
Loading