Characters moving via scripts are pushed & popped from the rooms
The delete & create messages still need to be implemented.
This commit is contained in:
@@ -7,9 +7,19 @@ roomAPI = require("room")
|
||||
mapMaker = require("map_maker")
|
||||
mapSaver = require("map_saver")
|
||||
|
||||
characterAPI = require("character")
|
||||
entityAPI = require("entity")
|
||||
networkAPI = require("network")
|
||||
|
||||
--test the room hooks
|
||||
roomManagerAPI.SetOnCreate(function(room, index)
|
||||
print("", "Creating room: ", roomAPI.GetName(room), index)
|
||||
|
||||
roomAPI.SetOnTick(room, function(room)
|
||||
roomAPI.ForEachCharacter(room, function(character)
|
||||
characterAPI.SetRoomIndex(character, 0)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
roomManagerAPI.SetOnUnload(function(room, index)
|
||||
@@ -40,10 +50,6 @@ function createTrigger(handle, room, x, y, script)
|
||||
)
|
||||
end
|
||||
|
||||
characterAPI = require("character")
|
||||
entityAPI = require("entity")
|
||||
networkAPI = require("network")
|
||||
|
||||
--simple teleporter
|
||||
createTrigger("trigger 1", overworld, 0, 0, function(entity)
|
||||
if entityAPI.GetType(entity) ~= "character" then
|
||||
|
||||
@@ -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))
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
#include "entity.hpp"
|
||||
|
||||
static int setRoomIndex(lua_State* L) {
|
||||
//TODO: (1) if this is a character, push/pop from the room system
|
||||
Entity* entity = static_cast<Entity*>(lua_touserdata(L, 1));
|
||||
entity->SetRoomIndex(lua_tointeger(L, 2));
|
||||
return 0;
|
||||
|
||||
@@ -61,27 +61,27 @@ static const luaL_Reg monsterLib[] = {
|
||||
};
|
||||
|
||||
LUAMOD_API int openMonsterAPI(lua_State* L) {
|
||||
//the local table
|
||||
luaL_newlib(L, monsterLib);
|
||||
|
||||
//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, monsterLib);
|
||||
|
||||
//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;
|
||||
|
||||
Reference in New Issue
Block a user