Tweaked scripts, added ForEachMonster()
(cherry picked from commit 0cf6a3dceb56a85969e8248e19f9143364b75c68)
This commit is contained in:
@@ -41,6 +41,10 @@ roomManagerAPI.SetOnCreate(function(room, index)
|
|||||||
roomAPI.ForEachCharacter(room, function(character)
|
roomAPI.ForEachCharacter(room, function(character)
|
||||||
--
|
--
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
roomAPI.ForEachMonster(room, function(monster)
|
||||||
|
--
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -51,6 +55,7 @@ end)
|
|||||||
--NOTE: room 0 is the first that the client asks for, therefore it must exist
|
--NOTE: room 0 is the first that the client asks for, therefore it must exist
|
||||||
local overworld, uidOne = roomManagerAPI.CreateRoom("overworld", "overworld.bmp")
|
local overworld, uidOne = roomManagerAPI.CreateRoom("overworld", "overworld.bmp")
|
||||||
roomAPI.Initialize(overworld, mapSaver.Load, mapSaver.Save, mapMaker.DebugIsland, mapSaver.Save)
|
roomAPI.Initialize(overworld, mapSaver.Load, mapSaver.Save, mapMaker.DebugIsland, mapSaver.Save)
|
||||||
|
|
||||||
local underworld, uidTwo = roomManagerAPI.CreateRoom("underworld", "overworld.bmp")
|
local underworld, uidTwo = roomManagerAPI.CreateRoom("underworld", "overworld.bmp")
|
||||||
roomAPI.Initialize(underworld, mapSaver.Load, mapSaver.Save, mapMaker.DebugGrassland, mapSaver.Save)
|
roomAPI.Initialize(underworld, mapSaver.Load, mapSaver.Save, mapMaker.DebugGrassland, mapSaver.Save)
|
||||||
|
|
||||||
|
|||||||
@@ -20,8 +20,6 @@
|
|||||||
* distribution.
|
* distribution.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
--TODO: (3) An archive table of all dead characters
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS UserAccounts (
|
CREATE TABLE IF NOT EXISTS UserAccounts (
|
||||||
uid INTEGER PRIMARY KEY AUTOINCREMENT,
|
uid INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
username varchar(100) UNIQUE, --TODO: (3) Swap username for email address
|
username varchar(100) UNIQUE, --TODO: (3) Swap username for email address
|
||||||
@@ -54,27 +52,44 @@ CREATE TABLE IF NOT EXISTS LiveCharacters (
|
|||||||
boundsY INTEGER DEFAULT 0,
|
boundsY INTEGER DEFAULT 0,
|
||||||
boundsW INTEGER DEFAULT 0,
|
boundsW INTEGER DEFAULT 0,
|
||||||
boundsH INTEGER DEFAULT 0
|
boundsH INTEGER DEFAULT 0
|
||||||
|
|
||||||
--TODO: statistics
|
|
||||||
-- baseStats INTEGER REFERENCES StatisticSets(uid)
|
|
||||||
|
|
||||||
--TODO: equipment
|
|
||||||
-- weapon INTEGER REFERENCES WornEquipment(uid)
|
|
||||||
-- helmet INTEGER REFERENCES WornEquipment(uid)
|
|
||||||
-- armour INTEGER REFERENCES WornEquipment(uid)
|
|
||||||
--etc.
|
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DeadCharacters (
|
CREATE TABLE IF NOT EXISTS DeadCharacters (
|
||||||
uid INTEGER PRIMARY KEY AUTOINCREMENT
|
uid INTEGER PRIMARY KEY,
|
||||||
|
|
||||||
|
--metadata
|
||||||
|
owner INTEGER REFERENCES Accounts(uid),
|
||||||
|
handle varchar(100),
|
||||||
|
avatar varchar(100),
|
||||||
|
birth timestamp NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS LiveMonsters (
|
CREATE TABLE IF NOT EXISTS LiveMonsters (
|
||||||
uid INTEGER PRIMARY KEY AUTOINCREMENT
|
uid INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
|
||||||
|
--metadata
|
||||||
|
handle varchar(100) UNIQUE,
|
||||||
|
avatar varchar(100),
|
||||||
|
|
||||||
|
--actions
|
||||||
|
-- script
|
||||||
|
|
||||||
|
--physically exists in the world
|
||||||
|
roomIndex INTEGER DEFAULT 0,
|
||||||
|
originX INTEGER DEFAULT 0,
|
||||||
|
originY INTEGER DEFAULT 0,
|
||||||
|
boundsX INTEGER DEFAULT 0,
|
||||||
|
boundsY INTEGER DEFAULT 0,
|
||||||
|
boundsW INTEGER DEFAULT 0,
|
||||||
|
boundsH INTEGER DEFAULT 0
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DeadMonsters (
|
CREATE TABLE IF NOT EXISTS DeadMonsters (
|
||||||
uid INTEGER PRIMARY KEY AUTOINCREMENT
|
uid INTEGER PRIMARY KEY,
|
||||||
|
|
||||||
|
--metadata
|
||||||
|
handle varchar(100) UNIQUE,
|
||||||
|
avatar varchar(100)
|
||||||
);
|
);
|
||||||
|
|
||||||
-------------------------
|
-------------------------
|
||||||
|
|||||||
@@ -68,8 +68,6 @@ static int getTriggerMgr(lua_State* L) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: character list
|
|
||||||
|
|
||||||
static int forEachCharacter(lua_State* L) {
|
static int forEachCharacter(lua_State* L) {
|
||||||
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
||||||
//pass each character to the given function
|
//pass each character to the given function
|
||||||
@@ -87,6 +85,24 @@ static int forEachCharacter(lua_State* L) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int forEachMonster(lua_State* L) {
|
||||||
|
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
||||||
|
MonsterManager* monsterMgr = room->GetMonsterMgr();
|
||||||
|
//pass each monster to the given function
|
||||||
|
for (auto& it : *monsterMgr->GetContainer()) {
|
||||||
|
lua_pushvalue(L, -1);
|
||||||
|
lua_pushlightuserdata(L, static_cast<void*>(&it.second));
|
||||||
|
//call each iteration, throwing an exception if something happened
|
||||||
|
if (lua_pcall(L, 1, 0, 0) != LUA_OK) {
|
||||||
|
std::ostringstream os;
|
||||||
|
os << "Lua error: ";
|
||||||
|
os << lua_tostring(L, -1);
|
||||||
|
throw(std::runtime_error(os.str()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int setOnTick(lua_State* L) {
|
static int setOnTick(lua_State* L) {
|
||||||
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
||||||
luaL_unref(L, LUA_REGISTRYINDEX, room->GetTickReference());
|
luaL_unref(L, LUA_REGISTRYINDEX, room->GetTickReference());
|
||||||
@@ -124,6 +140,7 @@ static const luaL_Reg roomLib[] = {
|
|||||||
{"GetTriggerMgr",getTriggerMgr},
|
{"GetTriggerMgr",getTriggerMgr},
|
||||||
|
|
||||||
{"ForEachCharacter", forEachCharacter},
|
{"ForEachCharacter", forEachCharacter},
|
||||||
|
{"ForEachMonster", forEachMonster},
|
||||||
|
|
||||||
{"SetOnTick", setOnTick},
|
{"SetOnTick", setOnTick},
|
||||||
{"GetOnTick", getOnTick},
|
{"GetOnTick", getOnTick},
|
||||||
|
|||||||
Reference in New Issue
Block a user