2012-01-06 09:48:59 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2010-2012 OTClient <https://github.com/edubart/otclient>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2011-12-03 22:41:37 +01:00
|
|
|
#include "otclient.h"
|
2011-08-15 16:11:24 +02:00
|
|
|
#include <framework/luascript/luainterface.h>
|
2011-12-03 22:41:37 +01:00
|
|
|
#include <otclient/luascript/luavaluecasts.h>
|
2011-08-26 20:00:22 +02:00
|
|
|
#include <otclient/core/game.h>
|
2011-08-29 16:14:21 +02:00
|
|
|
#include <otclient/core/tile.h>
|
|
|
|
#include <otclient/core/item.h>
|
|
|
|
#include <otclient/core/creature.h>
|
|
|
|
#include <otclient/core/player.h>
|
|
|
|
#include <otclient/core/localplayer.h>
|
|
|
|
#include <otclient/core/map.h>
|
2011-08-31 17:03:33 +02:00
|
|
|
#include <otclient/core/thingstype.h>
|
2011-08-15 21:15:49 +02:00
|
|
|
#include <otclient/core/spritemanager.h>
|
2011-08-15 16:11:24 +02:00
|
|
|
#include <otclient/net/protocollogin.h>
|
|
|
|
#include <otclient/net/protocolgame.h>
|
2011-11-10 06:29:25 +01:00
|
|
|
#include <otclient/ui/uiitem.h>
|
2011-11-14 23:32:55 +01:00
|
|
|
#include <otclient/ui/uicreature.h>
|
2011-08-29 05:04:23 +02:00
|
|
|
#include <otclient/ui/uimap.h>
|
2011-11-20 21:38:35 +01:00
|
|
|
#include <otclient/ui/uigame.h>
|
2011-11-16 08:20:14 +01:00
|
|
|
#include <otclient/core/outfit.h>
|
2011-08-15 16:11:24 +02:00
|
|
|
|
|
|
|
void OTClient::registerLuaFunctions()
|
|
|
|
{
|
2011-12-03 22:41:37 +01:00
|
|
|
Application::registerLuaFunctions();
|
|
|
|
|
2012-01-05 02:28:29 +01:00
|
|
|
g_lua.registerStaticClass("g_thingsType");
|
|
|
|
g_lua.bindClassStaticFunction("g_thingsType", "load", std::bind(&ThingsType::load, &g_thingsType, _1));
|
|
|
|
g_lua.bindClassStaticFunction("g_thingsType", "isLoaded", std::bind(&ThingsType::isLoaded, &g_thingsType));
|
|
|
|
|
|
|
|
g_lua.registerStaticClass("g_sprites");
|
|
|
|
g_lua.bindClassStaticFunction("g_sprites", "load", std::bind(&SpriteManager::load, &g_sprites, _1));
|
|
|
|
g_lua.bindClassStaticFunction("g_sprites", "isLoaded", std::bind(&SpriteManager::isLoaded, &g_sprites));
|
|
|
|
|
2011-12-05 07:44:03 +01:00
|
|
|
g_lua.bindGlobalFunction("exit", std::bind(&Application::exit, g_app));
|
2011-11-16 08:20:14 +01:00
|
|
|
g_lua.bindGlobalFunction("getOufitColor", Outfit::getColor);
|
2011-08-15 16:11:24 +02:00
|
|
|
|
|
|
|
g_lua.registerClass<ProtocolLogin, Protocol>();
|
|
|
|
g_lua.bindClassStaticFunction<ProtocolLogin>("create", &ProtocolLogin::create);
|
2012-01-06 04:29:26 +01:00
|
|
|
g_lua.bindClassMemberFunction<ProtocolLogin>("login", &ProtocolLogin::login);
|
|
|
|
g_lua.bindClassMemberFunction<ProtocolLogin>("cancelLogin", &ProtocolLogin::cancelLogin);
|
2011-08-15 16:11:24 +02:00
|
|
|
|
|
|
|
g_lua.registerClass<ProtocolGame, Protocol>();
|
2011-08-26 20:00:22 +02:00
|
|
|
|
2011-08-29 16:14:21 +02:00
|
|
|
g_lua.registerClass<Thing>();
|
2012-01-03 01:10:39 +01:00
|
|
|
g_lua.bindClassMemberFunction<Thing>("getId", &Thing::getId);
|
2012-01-03 00:08:04 +01:00
|
|
|
g_lua.bindClassMemberFunction<Thing>("getType", &Thing::getType);
|
|
|
|
g_lua.bindClassMemberFunction<Thing>("isContainer", &Thing::isContainer);
|
2012-01-03 23:27:31 +01:00
|
|
|
g_lua.bindClassMemberFunction<Thing>("isMultiUse", &Thing::isMultiUse);
|
|
|
|
g_lua.bindClassMemberFunction<Thing>("isRotateable", &Thing::isRotateable);
|
|
|
|
g_lua.bindClassMemberFunction<Thing>("isNotMoveable", &Thing::isNotMoveable);
|
|
|
|
g_lua.bindClassMemberFunction<Thing>("isPickupable", &Thing::isPickupable);
|
|
|
|
g_lua.bindClassMemberFunction<Thing>("asCreature", &Thing::asCreature);
|
|
|
|
g_lua.bindClassMemberFunction<Thing>("asPlayer", &Thing::asPlayer);
|
2012-01-03 21:41:00 +01:00
|
|
|
g_lua.bindClassMemberFunction<Thing>("asLocalPlayer", &Thing::asLocalPlayer);
|
2011-11-16 18:33:43 +01:00
|
|
|
|
2012-01-03 00:08:04 +01:00
|
|
|
g_lua.registerClass<Creature, Thing>();
|
2012-01-06 04:29:26 +01:00
|
|
|
g_lua.bindClassMemberFunction<Creature>("getName", &Creature::getName);
|
|
|
|
g_lua.bindClassMemberFunction<Creature>("setOutfit", &Creature::setOutfit);
|
|
|
|
g_lua.bindClassMemberFunction<Creature>("getOutfit", &Creature::getOutfit);
|
2011-11-16 18:33:43 +01:00
|
|
|
|
2011-08-29 16:14:21 +02:00
|
|
|
g_lua.registerClass<Player, Creature>();
|
|
|
|
g_lua.registerClass<LocalPlayer, Player>();
|
2012-01-03 00:08:04 +01:00
|
|
|
g_lua.registerClass<Item, Thing>();
|
2011-08-29 16:14:21 +02:00
|
|
|
g_lua.registerClass<Tile>();
|
|
|
|
g_lua.registerClass<Map>();
|
|
|
|
|
2011-08-26 20:00:22 +02:00
|
|
|
g_lua.registerClass<Game>();
|
|
|
|
g_lua.bindClassStaticFunction<Game>("loginWorld", std::bind(&Game::loginWorld, &g_game, _1, _2, _3, _4, _5));
|
2011-08-30 01:20:30 +02:00
|
|
|
g_lua.bindClassStaticFunction<Game>("logout", std::bind(&Game::logout, &g_game, _1));
|
2011-08-29 20:38:01 +02:00
|
|
|
g_lua.bindClassStaticFunction<Game>("cancelLogin", std::bind(&Game::cancelLogin, &g_game));
|
|
|
|
g_lua.bindClassStaticFunction<Game>("isOnline", std::bind(&Game::isOnline, &g_game));
|
2011-11-14 23:32:55 +01:00
|
|
|
g_lua.bindClassStaticFunction<Game>("openOutfitWindow", std::bind(&Game::openOutfitWindow, &g_game));
|
2011-11-16 18:33:43 +01:00
|
|
|
g_lua.bindClassStaticFunction<Game>("setOutfit", std::bind(&Game::setOutfit, &g_game, _1));
|
2012-01-03 21:41:00 +01:00
|
|
|
g_lua.bindClassStaticFunction<Game>("look", std::bind(&Game::look, &g_game, _1));
|
2012-01-03 23:27:31 +01:00
|
|
|
g_lua.bindClassStaticFunction<Game>("use", std::bind(&Game::use, &g_game, _1));
|
2012-01-04 14:02:35 +01:00
|
|
|
g_lua.bindClassStaticFunction<Game>("attack", std::bind(&Game::attack, &g_game, _1));
|
2012-01-05 15:24:38 +01:00
|
|
|
g_lua.bindClassStaticFunction<Game>("cancelAttack", std::bind(&Game::cancelAttack, &g_game));
|
2012-01-04 14:02:35 +01:00
|
|
|
g_lua.bindClassStaticFunction<Game>("follow", std::bind(&Game::follow, &g_game, _1));
|
2012-01-05 15:24:38 +01:00
|
|
|
g_lua.bindClassStaticFunction<Game>("cancelFollow", std::bind(&Game::cancelFollow, &g_game));
|
2012-01-04 14:02:35 +01:00
|
|
|
g_lua.bindClassStaticFunction<Game>("rotate", std::bind(&Game::rotate, &g_game, _1));
|
2012-01-05 13:48:10 +01:00
|
|
|
g_lua.bindClassStaticFunction<Game>("inviteToParty", std::bind(&Game::inviteToParty, &g_game, _1));
|
2012-01-04 15:30:28 +01:00
|
|
|
g_lua.bindClassStaticFunction<Game>("addVip", std::bind(&Game::addVip, &g_game, _1));
|
|
|
|
g_lua.bindClassStaticFunction<Game>("removeVip", std::bind(&Game::removeVip, &g_game, _1));
|
2012-01-05 15:24:38 +01:00
|
|
|
g_lua.bindClassStaticFunction<Game>("getAttackingCreature", std::bind(&Game::getAttackingCreature, &g_game));
|
|
|
|
g_lua.bindClassStaticFunction<Game>("getFollowingCreature", std::bind(&Game::getFollowingCreature, &g_game));
|
2011-08-29 05:04:23 +02:00
|
|
|
|
2011-11-10 06:29:25 +01:00
|
|
|
g_lua.registerClass<UIItem, UIWidget>();
|
2012-01-06 09:48:59 +01:00
|
|
|
g_lua.bindClassStaticFunction<UIItem>("create", []{ return UIItemPtr(new UIItem); } );
|
2011-11-10 06:29:25 +01:00
|
|
|
g_lua.bindClassMemberFunction<UIItem>("getItem", &UIItem::getItem);
|
|
|
|
g_lua.bindClassMemberFunction<UIItem>("setItem", &UIItem::setItem);
|
|
|
|
|
2011-11-14 23:32:55 +01:00
|
|
|
g_lua.registerClass<UICreature, UIWidget>();
|
2012-01-06 09:48:59 +01:00
|
|
|
g_lua.bindClassStaticFunction<UICreature>("create", []{ return UICreaturePtr(new UICreature); } );
|
2011-11-14 23:32:55 +01:00
|
|
|
g_lua.bindClassMemberFunction<UICreature>("getCreature", &UICreature::getCreature);
|
|
|
|
g_lua.bindClassMemberFunction<UICreature>("setCreature", &UICreature::setCreature);
|
|
|
|
|
2011-08-29 05:04:23 +02:00
|
|
|
g_lua.registerClass<UIMap, UIWidget>();
|
2012-01-06 09:48:59 +01:00
|
|
|
g_lua.bindClassStaticFunction<UIMap>("create", []{ return UIMapPtr(new UIMap); } );
|
2011-11-03 21:54:53 +01:00
|
|
|
|
2011-11-20 21:38:35 +01:00
|
|
|
g_lua.registerClass<UIGame, UIWidget>();
|
2012-01-06 09:48:59 +01:00
|
|
|
g_lua.bindClassStaticFunction<UIGame>("create", []{ return UIGamePtr(new UIGame); } );
|
2011-11-20 21:38:35 +01:00
|
|
|
|
2011-11-03 21:54:53 +01:00
|
|
|
#ifdef FORBIDDEN_FUNCTIONS
|
|
|
|
g_lua.bindClassStaticFunction<Game>("talkChannel", std::bind(&Game::talkChannel, &g_game, _1, _2, _3));
|
|
|
|
g_lua.bindClassStaticFunction<Game>("talkPrivate", std::bind(&Game::talkPrivate, &g_game, _1, _2, _3));
|
|
|
|
#endif
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|