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