The server is updating the barrier display
This commit is contained in:
+15
-1
@@ -837,6 +837,11 @@ void World::hCharacterMovement(CharacterPacket* const argPacket) {
|
|||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
void World::hCreatureUpdate(CreaturePacket* const argPacket) {
|
void World::hCreatureUpdate(CreaturePacket* const argPacket) {
|
||||||
|
//BUGFIX: Sometimes crash on exit
|
||||||
|
if (!localCharacter) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//Cull creatures that are too far away
|
//Cull creatures that are too far away
|
||||||
if ( (localCharacter->GetOrigin() - argPacket->origin).Length() > INFLUENCE_RADIUS) {
|
if ( (localCharacter->GetOrigin() - argPacket->origin).Length() > INFLUENCE_RADIUS) {
|
||||||
//ignore beyond 1000 units
|
//ignore beyond 1000 units
|
||||||
@@ -947,7 +952,11 @@ void World::hCreatureMovement(CreaturePacket* const argPacket) {
|
|||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
void World::hBarrierUpdate(BarrierPacket* const argPacket) {
|
void World::hBarrierUpdate(BarrierPacket* const argPacket) {
|
||||||
std::cout << "Barrier Update" << std::endl;
|
//BUGFIX: Sometimes crash on exit
|
||||||
|
if (!localCharacter) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//Cull barriers that are too far away
|
//Cull barriers that are too far away
|
||||||
if ( (localCharacter->GetOrigin() - argPacket->origin).Length() > INFLUENCE_RADIUS) {
|
if ( (localCharacter->GetOrigin() - argPacket->origin).Length() > INFLUENCE_RADIUS) {
|
||||||
//ignore beyond 1000 units
|
//ignore beyond 1000 units
|
||||||
@@ -1057,6 +1066,11 @@ void World::hTextWhisper(TextPacket* const argPacket) {
|
|||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
void World::SendLocalCharacterMovement() {
|
void World::SendLocalCharacterMovement() {
|
||||||
|
//BUGFIX: Sometimes crash on exit
|
||||||
|
if (!localCharacter) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
CharacterPacket newPacket;
|
CharacterPacket newPacket;
|
||||||
newPacket.type = SerialPacketType::CHARACTER_MOVEMENT;
|
newPacket.type = SerialPacketType::CHARACTER_MOVEMENT;
|
||||||
|
|
||||||
|
|||||||
@@ -64,8 +64,6 @@ local function bunnySquare(creature)
|
|||||||
|
|
||||||
--is it time to change direction?
|
--is it time to change direction?
|
||||||
if os.time() - tonumber(timestamp) >= 4 then
|
if os.time() - tonumber(timestamp) >= 4 then
|
||||||
-- print("changing directions")
|
|
||||||
|
|
||||||
if string.match("south", direction) then
|
if string.match("south", direction) then
|
||||||
direction = "east"
|
direction = "east"
|
||||||
creatureAPI.SetMotion(creature, 1, 0)
|
creatureAPI.SetMotion(creature, 1, 0)
|
||||||
@@ -91,45 +89,49 @@ local function bunnySquare(creature)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function barrierTick(barrier)
|
local function barrierTick(barrier)
|
||||||
--load from the object
|
local timestamp = barrierAPI.GetTag(barrier, "timestamp")
|
||||||
local statusTable = {}
|
|
||||||
for i = 1, 8 do
|
--initialize the timestamp
|
||||||
statusTable[i] = barrierAPI.GetStatus(barrier, i)
|
if string.len(timestamp) == 0 then
|
||||||
|
timestamp = tostring(os.time())
|
||||||
|
barrierAPI.SetTag(barrier, "timestamp", timestamp)
|
||||||
|
end
|
||||||
|
|
||||||
|
--is it time to change the display?
|
||||||
|
if os.time() - tonumber(timestamp) < 1 then
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
timestamp = tostring(os.time())
|
||||||
|
barrierAPI.SetTag(barrier, "timestamp", timestamp)
|
||||||
end
|
end
|
||||||
|
|
||||||
--binary tick
|
--binary tick
|
||||||
for i = 1, 8, 0 do
|
for i = 1, 8 do
|
||||||
if status[i] == 0 then
|
if barrierAPI.GetStatus(barrier, i) == 0 then
|
||||||
status[i] = 1
|
barrierAPI.SetStatus(barrier, i, 1)
|
||||||
break
|
return 1
|
||||||
else
|
else
|
||||||
status[i] = 0
|
barrierAPI.SetStatus(barrier, i, 0)
|
||||||
i = i + 1
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return 0
|
||||||
--save to the object
|
|
||||||
for i = 1, 8 do
|
|
||||||
barrierAPI.GetStatus(barrier, i, statusTable[i])
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--test the room hooks
|
--test the room hooks
|
||||||
roomManagerAPI.SetOnCreate(function(room, index)
|
roomManagerAPI.SetOnCreate(function(room, index)
|
||||||
print("", "Creating room: ", roomAPI.GetName(room), index)
|
print("", "Creating room: ", roomAPI.GetName(room), index)
|
||||||
|
|
||||||
--TODO: (0) creatureManager with SetOnCreate
|
--TODO:creatureManager with SetOnCreate, SetOnUnload & create
|
||||||
creatureManagerAPI.SetOnCreate(roomAPI.GetCreatureMgr(room), function(creature, index)
|
creatureManagerAPI.SetOnCreate(roomAPI.GetCreatureMgr(room), function(creature, index)
|
||||||
print ("making creature: ", index)
|
--
|
||||||
end)
|
end)
|
||||||
print("Here it comes...")
|
|
||||||
|
|
||||||
creatureManagerAPI.Create(roomAPI.GetCreatureMgr(room), "anibunny.png", bunnySquare)
|
|
||||||
|
|
||||||
creatureManagerAPI.SetOnUnload(roomAPI.GetCreatureMgr(room), function(creature)
|
creatureManagerAPI.SetOnUnload(roomAPI.GetCreatureMgr(room), function(creature)
|
||||||
print("unloading creature...")
|
--
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
creatureManagerAPI.Create(roomAPI.GetCreatureMgr(room), "anibunny.png", bunnySquare)
|
||||||
|
|
||||||
--TODO: (0) barrierManager with Create
|
--TODO: (0) barrierManager with Create
|
||||||
barrierManagerAPI.SetOnCreate(roomAPI.GetBarrierMgr(room), function(barrier)
|
barrierManagerAPI.SetOnCreate(roomAPI.GetBarrierMgr(room), function(barrier)
|
||||||
barrierAPI.SetScript(barrier, barrierTick)
|
barrierAPI.SetScript(barrier, barrierTick)
|
||||||
@@ -143,6 +145,8 @@ roomManagerAPI.SetOnCreate(function(room, index)
|
|||||||
roomAPI.ForEachCreature(room, function(creature)
|
roomAPI.ForEachCreature(room, function(creature)
|
||||||
--
|
--
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
--TODO: for each barrier
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|||||||
@@ -66,13 +66,13 @@ static int getInstance(lua_State* L) {
|
|||||||
|
|
||||||
static int setStatus(lua_State* L) {
|
static int setStatus(lua_State* L) {
|
||||||
BarrierData* barrier = static_cast<BarrierData*>(lua_touserdata(L, 1));
|
BarrierData* barrier = static_cast<BarrierData*>(lua_touserdata(L, 1));
|
||||||
barrier->SetStatus(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
barrier->SetStatus(lua_tointeger(L, 2) - 1, lua_tointeger(L, 3));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int getStatus(lua_State* L) {
|
static int getStatus(lua_State* L) {
|
||||||
BarrierData* barrier = static_cast<BarrierData*>(lua_touserdata(L, 1));
|
BarrierData* barrier = static_cast<BarrierData*>(lua_touserdata(L, 1));
|
||||||
lua_pushinteger(L, barrier->GetStatus(lua_tointeger(L, 2)) );
|
lua_pushinteger(L, barrier->GetStatus(lua_tointeger(L, 2) - 1));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
BarrierData::BarrierData(int i):
|
BarrierData::BarrierData(int i):
|
||||||
Entity::Entity("barrier")
|
Entity::Entity("barrier")
|
||||||
@@ -47,7 +48,7 @@ int BarrierData::Update(lua_State* L) {
|
|||||||
//check for errors
|
//check for errors
|
||||||
if(lua_pcall(L, 1, 1, 0) != LUA_OK) {
|
if(lua_pcall(L, 1, 1, 0) != LUA_OK) {
|
||||||
std::ostringstream msg;
|
std::ostringstream msg;
|
||||||
msg << "Error running creature script: " << lua_tostring(L, -1);
|
msg << "Error running barrier script: " << lua_tostring(L, -1);
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
throw(std::runtime_error(msg.str()));
|
throw(std::runtime_error(msg.str()));
|
||||||
}
|
}
|
||||||
@@ -86,14 +87,14 @@ int BarrierData::GetInstanceIndex() const {
|
|||||||
|
|
||||||
int BarrierData::SetStatus(int k, int v) {
|
int BarrierData::SetStatus(int k, int v) {
|
||||||
if (k < 0 || k >= 8) {
|
if (k < 0 || k >= 8) {
|
||||||
return -1;
|
throw(std::runtime_error("Failed to set status"));
|
||||||
}
|
}
|
||||||
return status[k] = v;
|
return status[k] = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BarrierData::GetStatus(int k) {
|
int BarrierData::GetStatus(int k) {
|
||||||
if (k < 0 || k >= 8) {
|
if (k < 0 || k >= 8) {
|
||||||
return -1;
|
throw(std::runtime_error("Failed to get status"));
|
||||||
}
|
}
|
||||||
return status[k];
|
return status[k];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user