aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_inventoryaction.cpp
diff options
context:
space:
mode:
authorElias Fleckenstein <54945686+EliasFleckenstein03@users.noreply.github.com>2020-11-04 16:44:42 +0100
committerGitHub <noreply@github.com>2020-11-04 16:44:42 +0100
commit5d9ae5a91c544fc7fbd475decf47cef7e09ef8fc (patch)
treec980d614fec4a5495798be3e79e033229062c3cd /src/script/lua_api/l_inventoryaction.cpp
parent28f6a79706b088c37268a59d90878220dc4ef9c7 (diff)
parent3af10766fd2b58b068e970266724d7eb10e9316b (diff)
downloaddragonfireclient-5d9ae5a91c544fc7fbd475decf47cef7e09ef8fc.tar.xz
Merge branch 'master' into master
Diffstat (limited to 'src/script/lua_api/l_inventoryaction.cpp')
-rw-r--r--src/script/lua_api/l_inventoryaction.cpp47
1 files changed, 23 insertions, 24 deletions
diff --git a/src/script/lua_api/l_inventoryaction.cpp b/src/script/lua_api/l_inventoryaction.cpp
index 516d6d3b2..f65137465 100644
--- a/src/script/lua_api/l_inventoryaction.cpp
+++ b/src/script/lua_api/l_inventoryaction.cpp
@@ -43,9 +43,9 @@ int LuaInventoryAction::l_apply(lua_State *L)
std::ostringstream os(std::ios::binary);
o->m_action->serialize(os);
-
+
std::istringstream is(os.str(), std::ios_base::binary);
-
+
InventoryAction *a = InventoryAction::deSerialize(is);
getClient(L)->inventoryAction(a);
@@ -69,29 +69,30 @@ int LuaInventoryAction::l_to(lua_State *L)
int LuaInventoryAction::l_craft(lua_State *L)
{
LuaInventoryAction *o = checkobject(L, 1);
-
+
if (o->m_action->getType() != IAction::Craft)
return 0;
-
+
std::string locStr;
InventoryLocation loc;
-
+
locStr = readParam<std::string>(L, 2);
-
+
try {
loc.deSerialize(locStr);
dynamic_cast<ICraftAction *>(o->m_action)->craft_inv = loc;
- } catch (SerializationError &) {}
-
+ } catch (SerializationError &) {
+ }
+
return 0;
}
int LuaInventoryAction::l_set_count(lua_State *L)
{
LuaInventoryAction *o = checkobject(L, 1);
-
+
s16 count = luaL_checkinteger(L, 2);
-
+
switch (o->m_action->getType()) {
case IAction::Move:
((IMoveAction *)o->m_action)->count = count;
@@ -103,7 +104,7 @@ int LuaInventoryAction::l_set_count(lua_State *L)
((ICraftAction *)o->m_action)->count = count;
break;
}
-
+
return 0;
}
@@ -127,23 +128,25 @@ LuaInventoryAction::~LuaInventoryAction()
delete m_action;
}
-void LuaInventoryAction::readFullInventoryLocationInto(lua_State *L, InventoryLocation *loc, std::string *list, s16 *index)
+void LuaInventoryAction::readFullInventoryLocationInto(
+ lua_State *L, InventoryLocation *loc, std::string *list, s16 *index)
{
try {
loc->deSerialize(readParam<std::string>(L, 2));
std::string l = readParam<std::string>(L, 3);
*list = l;
- *index = luaL_checkinteger(L, 4);
- } catch (SerializationError &) {}
+ *index = luaL_checkinteger(L, 4) - 1;
+ } catch (SerializationError &) {
+ }
}
int LuaInventoryAction::create_object(lua_State *L)
{
IAction type;
std::string typeStr;
-
+
typeStr = readParam<std::string>(L, 1);
-
+
if (typeStr == "move")
type = IAction::Move;
else if (typeStr == "drop")
@@ -206,11 +209,7 @@ void LuaInventoryAction::Register(lua_State *L)
}
const char LuaInventoryAction::className[] = "InventoryAction";
-const luaL_Reg LuaInventoryAction::methods[] = {
- luamethod(LuaInventoryAction, apply),
- luamethod(LuaInventoryAction, from),
- luamethod(LuaInventoryAction, to),
- luamethod(LuaInventoryAction, craft),
- luamethod(LuaInventoryAction, set_count),
- {0,0}
-};
+const luaL_Reg LuaInventoryAction::methods[] = {luamethod(LuaInventoryAction, apply),
+ luamethod(LuaInventoryAction, from), luamethod(LuaInventoryAction, to),
+ luamethod(LuaInventoryAction, craft),
+ luamethod(LuaInventoryAction, set_count), {0, 0}};