Implemented networked room chainging function
This commit is contained in:
@@ -22,18 +22,14 @@
|
|||||||
#include "character_api.hpp"
|
#include "character_api.hpp"
|
||||||
|
|
||||||
#include "character_data.hpp"
|
#include "character_data.hpp"
|
||||||
|
|
||||||
#include "entity_api.hpp"
|
#include "entity_api.hpp"
|
||||||
|
|
||||||
#include "room_manager.hpp"
|
#include "room_manager.hpp"
|
||||||
|
#include "server_utilities.hpp"
|
||||||
|
|
||||||
static int setRoomIndex(lua_State* L) {
|
static int setRoomIndex(lua_State* L) {
|
||||||
//NOTE: type-dependant calls to various API functions, see bug #43
|
//NOTE: type-dependant calls to various API functions, see bug #43
|
||||||
CharacterData* character = static_cast<CharacterData*>(lua_touserdata(L, 1));
|
CharacterData* character = static_cast<CharacterData*>(lua_touserdata(L, 1));
|
||||||
RoomManager::GetSingleton().PopCharacter(character);
|
pumpAndChangeRooms(character, lua_tointeger(L, 2), -1); //TODO: (0) undefined behavior without character index
|
||||||
character->SetRoomIndex(lua_tointeger(L, 2));
|
|
||||||
RoomManager::GetSingleton().PushCharacter(character);
|
|
||||||
//TODO: (0) send character room change messages
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -212,21 +212,7 @@ void ServerApplication::hCharacterMovement(CharacterPacket* const argPacket) {
|
|||||||
|
|
||||||
//check if moving rooms
|
//check if moving rooms
|
||||||
if (characterData->GetRoomIndex() != argPacket->roomIndex) {
|
if (characterData->GetRoomIndex() != argPacket->roomIndex) {
|
||||||
//delete from the old room
|
pumpAndChangeRooms(characterData, argPacket->roomIndex, argPacket->characterIndex);
|
||||||
CharacterPacket newPacket;
|
|
||||||
copyCharacterToPacket(&newPacket, argPacket->characterIndex);
|
|
||||||
newPacket.type = SerialPacketType::CHARACTER_DELETE;
|
|
||||||
pumpPacketProximity(&newPacket, characterData->GetRoomIndex());
|
|
||||||
|
|
||||||
//move the character between rooms
|
|
||||||
roomMgr.PopCharacter(characterData);
|
|
||||||
characterData->SetRoomIndex(argPacket->roomIndex);
|
|
||||||
roomMgr.PushCharacter(characterData);
|
|
||||||
|
|
||||||
//create in the new room
|
|
||||||
copyCharacterToPacket(&newPacket, argPacket->characterIndex);
|
|
||||||
newPacket.type = SerialPacketType::CHARACTER_CREATE;
|
|
||||||
pumpPacketProximity(&newPacket, characterData->GetRoomIndex());
|
|
||||||
}
|
}
|
||||||
//if not moving between rooms
|
//if not moving between rooms
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -140,6 +140,10 @@ void copyCharacterToPacket(CharacterPacket* const packet, int characterIndex) {
|
|||||||
throw(std::runtime_error("Failed to copy a character to a packet"));
|
throw(std::runtime_error("Failed to copy a character to a packet"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
copyCharacterToPacket(packet, characterData, characterIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void copyCharacterToPacket(CharacterPacket* const packet, CharacterData* const characterData, int characterIndex) {
|
||||||
//NOTE: keep this up to date when the character changes
|
//NOTE: keep this up to date when the character changes
|
||||||
packet->characterIndex = characterIndex;
|
packet->characterIndex = characterIndex;
|
||||||
strncpy(packet->handle, characterData->GetHandle().c_str(), PACKET_STRING_SIZE);
|
strncpy(packet->handle, characterData->GetHandle().c_str(), PACKET_STRING_SIZE);
|
||||||
@@ -150,3 +154,31 @@ void copyCharacterToPacket(CharacterPacket* const packet, int characterIndex) {
|
|||||||
packet->motion = characterData->GetMotion();
|
packet->motion = characterData->GetMotion();
|
||||||
packet->bounds = characterData->GetBounds();
|
packet->bounds = characterData->GetBounds();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void pumpAndChangeRooms(int characterIndex, int newRoomIndex) {
|
||||||
|
//BUG: three redundant lookups
|
||||||
|
|
||||||
|
//get the character object
|
||||||
|
CharacterData* character = CharacterManager::GetSingleton().Get(characterIndex);
|
||||||
|
|
||||||
|
//pass ownwards
|
||||||
|
pumpAndChangeRooms(character, newRoomIndex, characterIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void pumpAndChangeRooms(CharacterData* const characterData, int newRoomIndex, int characterIndex) {
|
||||||
|
//delete from the old room
|
||||||
|
CharacterPacket newPacket;
|
||||||
|
copyCharacterToPacket(&newPacket, characterData, characterIndex);
|
||||||
|
newPacket.type = SerialPacketType::CHARACTER_DELETE;
|
||||||
|
pumpPacketProximity(&newPacket, characterData->GetRoomIndex());
|
||||||
|
|
||||||
|
//move the character between rooms
|
||||||
|
RoomManager::GetSingleton().PopCharacter(characterData);
|
||||||
|
characterData->SetRoomIndex(newRoomIndex);
|
||||||
|
RoomManager::GetSingleton().PushCharacter(characterData);
|
||||||
|
|
||||||
|
//create in the new room
|
||||||
|
copyCharacterToPacket(&newPacket, characterData, characterIndex);
|
||||||
|
newPacket.type = SerialPacketType::CHARACTER_CREATE;
|
||||||
|
pumpPacketProximity(&newPacket, characterData->GetRoomIndex());
|
||||||
|
}
|
||||||
@@ -22,14 +22,20 @@
|
|||||||
#ifndef SERVERUTILITIES_HPP_
|
#ifndef SERVERUTILITIES_HPP_
|
||||||
#define SERVERUTILITIES_HPP_
|
#define SERVERUTILITIES_HPP_
|
||||||
|
|
||||||
|
#include "character_data.hpp"
|
||||||
#include "serial_packet.hpp"
|
#include "serial_packet.hpp"
|
||||||
#include "vector2.hpp"
|
#include "vector2.hpp"
|
||||||
|
|
||||||
void fullClientUnload(int index);
|
void fullClientUnload(int index);
|
||||||
void fullAccountUnload(int index);
|
void fullAccountUnload(int index);
|
||||||
void fullCharacterUnload(int index);
|
void fullCharacterUnload(int index);
|
||||||
|
|
||||||
void pumpPacket(SerialPacket* const argPacket);
|
void pumpPacket(SerialPacket* const argPacket);
|
||||||
void pumpPacketProximity(SerialPacket* const argPacket, int roomIndex, Vector2 position = {0, 0}, int distance = -1);
|
void pumpPacketProximity(SerialPacket* const argPacket, int roomIndex, Vector2 position = {0, 0}, int distance = -1);
|
||||||
|
|
||||||
void copyCharacterToPacket(CharacterPacket* const packet, int characterIndex);
|
void copyCharacterToPacket(CharacterPacket* const packet, int characterIndex);
|
||||||
|
void copyCharacterToPacket(CharacterPacket* const packet, CharacterData* const characterData, int characterIndex);
|
||||||
|
void pumpAndChangeRooms(int characterIndex, int newRoomIndex);
|
||||||
|
void pumpAndChangeRooms(CharacterData* const characterData, int newRoomIndex, int characterIndex);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Reference in New Issue
Block a user