2011-11-19 01:12:17 +01:00
|
|
|
/*
|
2012-01-02 17:58:37 +01:00
|
|
|
* Copyright (c) 2010-2012 OTClient <https://github.com/edubart/otclient>
|
2011-11-19 01:12:17 +01:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "luavaluecasts.h"
|
2012-07-14 03:10:24 +02:00
|
|
|
#include <framework/luaengine/luainterface.h>
|
2011-11-19 01:12:17 +01:00
|
|
|
|
2012-07-05 14:38:48 +02:00
|
|
|
int push_luavalue(const Outfit& outfit)
|
2011-11-19 01:12:17 +01:00
|
|
|
{
|
|
|
|
g_lua.newTable();
|
2012-01-10 01:36:18 +01:00
|
|
|
g_lua.pushInteger(outfit.getId());
|
2011-11-19 01:12:17 +01:00
|
|
|
g_lua.setField("type");
|
2012-10-05 21:13:50 +02:00
|
|
|
g_lua.pushInteger(outfit.getAuxId());
|
|
|
|
g_lua.setField("auxType");
|
2011-11-19 01:12:17 +01:00
|
|
|
g_lua.pushInteger(outfit.getAddons());
|
|
|
|
g_lua.setField("addons");
|
|
|
|
g_lua.pushInteger(outfit.getHead());
|
|
|
|
g_lua.setField("head");
|
|
|
|
g_lua.pushInteger(outfit.getBody());
|
|
|
|
g_lua.setField("body");
|
|
|
|
g_lua.pushInteger(outfit.getLegs());
|
|
|
|
g_lua.setField("legs");
|
|
|
|
g_lua.pushInteger(outfit.getFeet());
|
|
|
|
g_lua.setField("feet");
|
2012-07-15 13:49:28 +02:00
|
|
|
if(g_game.getFeature(Otc::GamePlayerMounts)) {
|
|
|
|
g_lua.pushInteger(outfit.getMount());
|
|
|
|
g_lua.setField("mount");
|
|
|
|
}
|
2012-07-05 14:38:48 +02:00
|
|
|
return 1;
|
2011-11-19 01:12:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool luavalue_cast(int index, Outfit& outfit)
|
|
|
|
{
|
|
|
|
if(g_lua.isTable(index)) {
|
|
|
|
g_lua.getField("type", index);
|
2012-01-10 01:36:18 +01:00
|
|
|
outfit.setId(g_lua.popInteger());
|
2012-10-05 21:13:50 +02:00
|
|
|
g_lua.getField("auxType", index);
|
|
|
|
outfit.setAuxId(g_lua.popInteger());
|
2011-11-19 01:12:17 +01:00
|
|
|
g_lua.getField("addons", index);
|
|
|
|
outfit.setAddons(g_lua.popInteger());
|
|
|
|
g_lua.getField("head", index);
|
|
|
|
outfit.setHead(g_lua.popInteger());
|
|
|
|
g_lua.getField("body", index);
|
|
|
|
outfit.setBody(g_lua.popInteger());
|
|
|
|
g_lua.getField("legs", index);
|
|
|
|
outfit.setLegs(g_lua.popInteger());
|
|
|
|
g_lua.getField("feet", index);
|
|
|
|
outfit.setFeet(g_lua.popInteger());
|
2012-07-15 13:49:28 +02:00
|
|
|
if(g_game.getFeature(Otc::GamePlayerMounts)) {
|
|
|
|
g_lua.getField("mount", index);
|
|
|
|
outfit.setMount(g_lua.popInteger());
|
|
|
|
}
|
2011-11-19 01:12:17 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-07-05 14:38:48 +02:00
|
|
|
int push_luavalue(const Position& pos)
|
2011-11-19 01:12:17 +01:00
|
|
|
{
|
2012-01-08 19:29:41 +01:00
|
|
|
if(pos.isValid()) {
|
|
|
|
g_lua.newTable();
|
|
|
|
g_lua.pushInteger(pos.x);
|
|
|
|
g_lua.setField("x");
|
|
|
|
g_lua.pushInteger(pos.y);
|
|
|
|
g_lua.setField("y");
|
|
|
|
g_lua.pushInteger(pos.z);
|
|
|
|
g_lua.setField("z");
|
|
|
|
} else
|
|
|
|
g_lua.pushNil();
|
2012-07-05 14:38:48 +02:00
|
|
|
return 1;
|
2011-11-19 01:12:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool luavalue_cast(int index, Position& pos)
|
|
|
|
{
|
|
|
|
if(g_lua.isTable(index)) {
|
|
|
|
g_lua.getField("x", index);
|
|
|
|
pos.x = g_lua.popInteger();
|
|
|
|
g_lua.getField("y", index);
|
|
|
|
pos.y = g_lua.popInteger();
|
|
|
|
g_lua.getField("z", index);
|
|
|
|
pos.z = g_lua.popInteger();
|
2012-01-08 16:42:23 +01:00
|
|
|
return true;
|
2011-11-19 01:12:17 +01:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2012-07-19 20:54:24 +02:00
|
|
|
|
|
|
|
int push_luavalue(const MarketData& data)
|
|
|
|
{
|
|
|
|
g_lua.newTable();
|
|
|
|
g_lua.pushInteger(data.category);
|
|
|
|
g_lua.setField("category");
|
|
|
|
g_lua.pushString(data.name);
|
|
|
|
g_lua.setField("name");
|
|
|
|
g_lua.pushInteger(data.requiredLevel);
|
|
|
|
g_lua.setField("requiredLevel");
|
2012-07-23 17:11:53 +02:00
|
|
|
g_lua.pushInteger(data.restrictVocation);
|
|
|
|
g_lua.setField("restrictVocation");
|
2012-07-19 20:54:24 +02:00
|
|
|
g_lua.pushInteger(data.showAs);
|
|
|
|
g_lua.setField("showAs");
|
|
|
|
g_lua.pushInteger(data.tradeAs);
|
|
|
|
g_lua.setField("tradeAs");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool luavalue_cast(int index, MarketData& data)
|
|
|
|
{
|
|
|
|
if(g_lua.isTable(index)) {
|
|
|
|
g_lua.getField("category", index);
|
|
|
|
data.category = g_lua.popInteger();
|
|
|
|
g_lua.getField("name", index);
|
|
|
|
data.name = g_lua.popString();
|
|
|
|
g_lua.getField("requiredLevel", index);
|
|
|
|
data.requiredLevel = g_lua.popInteger();
|
2012-07-23 17:11:53 +02:00
|
|
|
g_lua.getField("restrictVocation", index);
|
|
|
|
data.restrictVocation = g_lua.popInteger();
|
2012-07-19 20:54:24 +02:00
|
|
|
g_lua.getField("showAs", index);
|
|
|
|
data.showAs = g_lua.popInteger();
|
|
|
|
g_lua.getField("tradeAs", index);
|
|
|
|
data.tradeAs = g_lua.popInteger();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|