Adding crazy behavior interface.

This commit is contained in:
KimLS 2016-01-09 01:39:23 -08:00
parent 3a7d7c727f
commit 2ed348f23d
7 changed files with 197 additions and 5 deletions

View File

@ -33,6 +33,7 @@ SET(zone_sources
horse.cpp
inventory.cpp
loottables.cpp
lua_behavior_interface.cpp
lua_bit.cpp
lua_corpse.cpp
lua_client.cpp
@ -150,6 +151,7 @@ SET(zone_headers
guild_mgr.h
hate_list.h
horse.h
lua_behavior_interface.h
lua_bit.h
lua_client.h
lua_corpse.h

View File

@ -236,8 +236,8 @@ bool Client::Process() {
CheckMercSuspendTimer();
}
if(IsAIControlled())
AI_Process();
//if(IsAIControlled())
//AI_Process();
// Don't reset the bindwound timer so we can check it in BindWound as well.
if (bindwound_timer.Check(false) && bindwound_target != 0) {

View File

@ -0,0 +1,166 @@
#ifdef LUA_EQEMU
#include "lua_behavior_interface.h"
#include <lua.hpp>
#include <luabind/luabind.hpp>
#include <luabind/object.hpp>
#include "masterentity.h"
#include "../common/spdat.h"
#include "lua_bit.h"
#include "lua_entity.h"
#include "lua_item.h"
#include "lua_iteminst.h"
#include "lua_mob.h"
#include "lua_hate_list.h"
#include "lua_client.h"
#include "lua_inventory.h"
#include "lua_npc.h"
#include "lua_spell.h"
#include "lua_entity_list.h"
#include "lua_group.h"
#include "lua_raid.h"
#include "lua_corpse.h"
#include "lua_object.h"
#include "lua_door.h"
#include "lua_spawn.h"
#include "lua_packet.h"
#include "lua_general.h"
LuaBehaviorInterface::LuaBehaviorInterface()
{
L = nullptr;
}
LuaBehaviorInterface::~LuaBehaviorInterface()
{
if (L) {
lua_close(L);
}
}
bool LuaBehaviorInterface::Init()
{
if (L) {
return false;
}
L = luaL_newstate();
luaL_openlibs(L);
if (luaopen_bit(L) != 1) {
return false;
}
if (luaL_dostring(L, "math.randomseed(os.time())")) {
return false;
}
#ifdef SANITIZE_LUA_LIBS
lua_pushnil(L);
lua_setglobal(L, "io");
lua_getglobal(L, "os");
lua_pushnil(L);
lua_setfield(L, -2, "exit");
lua_pushnil(L);
lua_setfield(L, -2, "execute");
lua_pushnil(L);
lua_setfield(L, -2, "getenv");
lua_pushnil(L);
lua_setfield(L, -2, "remove");
lua_pushnil(L);
lua_setfield(L, -2, "rename");
lua_pushnil(L);
lua_setfield(L, -2, "setlocale");
lua_pushnil(L);
lua_setfield(L, -2, "tmpname");
lua_pop(L, 1);
lua_pushnil(L);
lua_setglobal(L, "collectgarbage");
lua_pushnil(L);
lua_setglobal(L, "loadfile");
#endif
lua_getglobal(L, "package");
lua_getfield(L, -1, "path");
std::string module_path = lua_tostring(L, -1);
module_path += ";./lua_modules/?.lua";
lua_pop(L, 1);
lua_pushstring(L, module_path.c_str());
lua_setfield(L, -2, "path");
lua_pop(L, 1);
if (!MapFunctions()) {
return false;
}
std::string path = "ai/script_init.lua";
FILE *f = fopen(path.c_str(), "r");
if (f) {
fclose(f);
if (luaL_dofile(L, path.c_str())) {
return false;
}
}
return true;
}
bool LuaBehaviorInterface::MapFunctions()
{
try {
luabind::open(L);
luabind::module(L)
[
lua_register_general(),
lua_register_events(),
lua_register_faction(),
lua_register_slot(),
lua_register_material(),
lua_register_client_version(),
lua_register_appearance(),
lua_register_entity(),
lua_register_mob(),
lua_register_special_abilities(),
lua_register_npc(),
lua_register_client(),
lua_register_inventory(),
lua_register_inventory_where(),
lua_register_iteminst(),
lua_register_item(),
lua_register_spell(),
lua_register_spawn(),
lua_register_hate_entry(),
lua_register_hate_list(),
lua_register_entity_list(),
lua_register_mob_list(),
lua_register_client_list(),
lua_register_npc_list(),
lua_register_corpse_list(),
lua_register_object_list(),
lua_register_door_list(),
lua_register_spawn_list(),
lua_register_group(),
lua_register_raid(),
lua_register_corpse(),
lua_register_door(),
lua_register_object(),
lua_register_packet(),
lua_register_packet_opcodes()
];
}
catch (std::exception &ex) {
return false;
}
return true;
}
#endif

View File

@ -0,0 +1,25 @@
#ifndef EQEMU_LUA_BEHAVIOR_INTERFACE_H
#define EQEMU_LUA_BEHAVIOR_INTERFACE_H
#ifdef LUA_EQEMU
namespace luabind {
namespace adl {
class object;
}
}
struct lua_State;
class LuaBehaviorInterface
{
public:
LuaBehaviorInterface();
~LuaBehaviorInterface();
bool Init();
private:
bool MapFunctions();
lua_State *L;
};
#endif
#endif

View File

@ -87,7 +87,6 @@ private:
void LoadScript(std::string filename, std::string package_name);
bool HasFunction(std::string function, std::string package_name);
void ClearStates();
void MapFunctions(lua_State *L);
QuestEventID ConvertLuaEvent(QuestEventID evt);

View File

@ -1304,7 +1304,7 @@ bool Merc::Process()
return true;
// Merc AI
AI_Process();
//AI_Process();
return true;
}

View File

@ -734,7 +734,7 @@ bool NPC::Process()
}
}
AI_Process();
//AI_Process();
return true;
}