Characters moving via scripts are pushed & popped from the rooms
The delete & create messages still need to be implemented.
This commit is contained in:
@@ -25,6 +25,18 @@
|
||||
|
||||
#include "entity_api.hpp"
|
||||
|
||||
#include "room_manager.hpp"
|
||||
|
||||
static int setRoomIndex(lua_State* L) {
|
||||
//NOTE: type-dependant calls to various API functions, see bug #43
|
||||
CharacterData* character = static_cast<CharacterData*>(lua_touserdata(L, 1));
|
||||
RoomManager::GetSingleton().PopCharacter(character);
|
||||
character->SetRoomIndex(lua_tointeger(L, 2));
|
||||
RoomManager::GetSingleton().PushCharacter(character);
|
||||
//TODO: (0) send character room change messages
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int getOwner(lua_State* L) {
|
||||
CharacterData* character = static_cast<CharacterData*>(lua_touserdata(L, 1));
|
||||
lua_pushinteger(L, character->GetOwner());
|
||||
@@ -45,33 +57,34 @@ static int getAvatar(lua_State* L) {
|
||||
|
||||
static const luaL_Reg characterLib[] = {
|
||||
// {"GetOwner", getOwner}, //unusable without account API
|
||||
{"SetRoomIndex", setRoomIndex},
|
||||
{"GetHandle", getHandle},
|
||||
{"GetAvatar", getAvatar},
|
||||
{nullptr, nullptr}
|
||||
};
|
||||
|
||||
LUAMOD_API int openCharacterAPI(lua_State* L) {
|
||||
//the local table
|
||||
luaL_newlib(L, characterLib);
|
||||
|
||||
//get the parent table
|
||||
luaL_requiref(L, TORTUGA_ENTITY_API, openEntityAPI, false);
|
||||
|
||||
//clone the parent table into the local table
|
||||
//the local table
|
||||
luaL_newlib(L, characterLib);
|
||||
|
||||
//merge the local table into the parent table
|
||||
lua_pushnil(L); //first key
|
||||
while(lua_next(L, -2)) {
|
||||
//copy the key-value pair
|
||||
lua_pushvalue(L, -2);
|
||||
lua_pushvalue(L, -2);
|
||||
|
||||
//push the copy to the local table
|
||||
//push the copy to the parent table
|
||||
lua_settable(L, -6);
|
||||
|
||||
//pop the original value before continuing
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
//remove the parent table, leaving the expanded child table
|
||||
//remove the local table, leaving the expanded parent table
|
||||
lua_pop(L, 1);
|
||||
|
||||
return 1;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#config
|
||||
INCLUDES+=. ../entities ../server_utilities ../../common/gameplay ../../common/utilities
|
||||
INCLUDES+=. ../entities ../monsters ../rooms ../server_utilities ../triggers ../../common/gameplay ../../common/map ../../common/utilities
|
||||
LIBS+=
|
||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user