Implemented client-side HandleCharacterCreate
This commit is contained in:
@@ -21,6 +21,8 @@
|
|||||||
*/
|
*/
|
||||||
#include "base_character.hpp"
|
#include "base_character.hpp"
|
||||||
|
|
||||||
|
#include "config_utility.hpp"
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//graphics
|
//graphics
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -71,7 +73,9 @@ std::string BaseCharacter::GetHandle() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string BaseCharacter::SetAvatar(std::string s) {
|
std::string BaseCharacter::SetAvatar(std::string s) {
|
||||||
return avatar = s;
|
avatar = s;
|
||||||
|
sprite.LoadSurface(ConfigUtility::GetSingleton()["dir.sprites"] + avatar, CHARACTER_CELLS_X, CHARACTER_CELLS_Y);
|
||||||
|
return avatar;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string BaseCharacter::GetAvatar() const {
|
std::string BaseCharacter::GetAvatar() const {
|
||||||
|
|||||||
@@ -42,10 +42,6 @@ int Entity::SetEntityIndex(int i) {
|
|||||||
return entityIndex = i;
|
return entityIndex = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Entity::SetRoomIndex(int i) {
|
|
||||||
return roomIndex = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector2 Entity::SetOrigin(Vector2 v) {
|
Vector2 Entity::SetOrigin(Vector2 v) {
|
||||||
return origin = v;
|
return origin = v;
|
||||||
}
|
}
|
||||||
@@ -62,10 +58,6 @@ int Entity::GetEntityIndex() {
|
|||||||
return entityIndex;
|
return entityIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Entity::GetRoomIndex() {
|
|
||||||
return roomIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector2 Entity::GetOrigin() {
|
Vector2 Entity::GetOrigin() {
|
||||||
return origin;
|
return origin;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,13 +36,11 @@ public:
|
|||||||
|
|
||||||
//accessors & mutators
|
//accessors & mutators
|
||||||
int SetEntityIndex(int i);
|
int SetEntityIndex(int i);
|
||||||
int SetRoomIndex(int i);
|
|
||||||
Vector2 SetOrigin(Vector2 v);
|
Vector2 SetOrigin(Vector2 v);
|
||||||
Vector2 SetMotion(Vector2 v);
|
Vector2 SetMotion(Vector2 v);
|
||||||
BoundingBox SetBounds(BoundingBox b);
|
BoundingBox SetBounds(BoundingBox b);
|
||||||
|
|
||||||
int GetEntityIndex();
|
int GetEntityIndex();
|
||||||
int GetRoomIndex();
|
|
||||||
Vector2 GetOrigin();
|
Vector2 GetOrigin();
|
||||||
Vector2 GetMotion();
|
Vector2 GetMotion();
|
||||||
BoundingBox GetBounds();
|
BoundingBox GetBounds();
|
||||||
@@ -53,7 +51,6 @@ protected:
|
|||||||
|
|
||||||
SpriteSheet sprite;
|
SpriteSheet sprite;
|
||||||
int entityIndex = -1;
|
int entityIndex = -1;
|
||||||
int roomIndex = -1;
|
|
||||||
Vector2 origin;
|
Vector2 origin;
|
||||||
Vector2 motion;
|
Vector2 motion;
|
||||||
BoundingBox bounds;
|
BoundingBox bounds;
|
||||||
|
|||||||
@@ -96,7 +96,9 @@ InWorld::InWorld(int* const argClientIndex, int* const argAccountIndex):
|
|||||||
}
|
}
|
||||||
|
|
||||||
InWorld::~InWorld() {
|
InWorld::~InWorld() {
|
||||||
//
|
//unload the local data
|
||||||
|
characterMap.clear();
|
||||||
|
monsterMap.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -168,6 +170,16 @@ void InWorld::Render(SDL_Surface* const screen) {
|
|||||||
tileSheet.DrawRegionTo(screen, &(*it), camera.x, camera.y);
|
tileSheet.DrawRegionTo(screen, &(*it), camera.x, camera.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//draw the entities
|
||||||
|
for (auto& it : characterMap) {
|
||||||
|
//TODO: depth ordering
|
||||||
|
it.second.DrawTo(screen, camera.x, camera.y);
|
||||||
|
}
|
||||||
|
for (auto& it : monsterMap) {
|
||||||
|
//TODO: depth ordering
|
||||||
|
it.second.DrawTo(screen, camera.x, camera.y);
|
||||||
|
}
|
||||||
|
|
||||||
//draw UI
|
//draw UI
|
||||||
disconnectButton.DrawTo(screen);
|
disconnectButton.DrawTo(screen);
|
||||||
shutDownButton.DrawTo(screen);
|
shutDownButton.DrawTo(screen);
|
||||||
@@ -328,8 +340,7 @@ void InWorld::SendShutdownRequest() {
|
|||||||
|
|
||||||
void InWorld::HandleLogoutResponse(ClientPacket* const argPacket) {
|
void InWorld::HandleLogoutResponse(ClientPacket* const argPacket) {
|
||||||
accountIndex = -1;
|
accountIndex = -1;
|
||||||
|
characterIndex = -1;
|
||||||
//TODO: unload the character
|
|
||||||
|
|
||||||
SendDisconnectRequest();
|
SendDisconnectRequest();
|
||||||
}
|
}
|
||||||
@@ -340,7 +351,10 @@ void InWorld::HandleDisconnectResponse(ClientPacket* const argPacket) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void InWorld::HandleDisconnectForced(ClientPacket* const argPacket) {
|
void InWorld::HandleDisconnectForced(ClientPacket* const argPacket) {
|
||||||
//TODO: More needed in the disconnection
|
//clear the local data
|
||||||
|
accountIndex = -1;
|
||||||
|
characterIndex = -1;
|
||||||
|
|
||||||
SetNextScene(SceneList::DISCONNECTEDSCREEN);
|
SetNextScene(SceneList::DISCONNECTEDSCREEN);
|
||||||
ConfigUtility::GetSingleton()["client.disconnectMessage"] = "You have been forcibly disconnected by the server";
|
ConfigUtility::GetSingleton()["client.disconnectMessage"] = "You have been forcibly disconnected by the server";
|
||||||
}
|
}
|
||||||
@@ -394,9 +408,36 @@ void InWorld::UpdateMap() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//entity management
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
//NOTE: preexisting characters will result in query responses
|
||||||
|
//NOTE: new characters will result in create messages
|
||||||
|
//NOTE: this client's character will exist in both
|
||||||
|
|
||||||
void InWorld::HandleCharacterCreate(CharacterPacket* const argPacket) {
|
void InWorld::HandleCharacterCreate(CharacterPacket* const argPacket) {
|
||||||
//TODO: HandleCharacterCreate()
|
//prevent double message
|
||||||
std::cout << "HandleCharacterCreate" << std::endl;
|
if (characterMap.find(argPacket->characterIndex) != characterMap.end()) {
|
||||||
|
std::ostringstream msg;
|
||||||
|
msg << "Double character creation event; ";
|
||||||
|
msg << "Index: " << argPacket->characterIndex << "; ";
|
||||||
|
msg << "Handle: " << argPacket->handle;
|
||||||
|
throw(std::runtime_error(msg.str()));
|
||||||
|
}
|
||||||
|
|
||||||
|
//implicity create and retrieve the entity
|
||||||
|
BaseCharacter& character = characterMap[argPacket->characterIndex];
|
||||||
|
|
||||||
|
//fill the character's info
|
||||||
|
character.SetOrigin({0, 0});
|
||||||
|
character.SetMotion({0, 0});
|
||||||
|
character.SetBounds({CHARACTER_BOUNDS_X, CHARACTER_BOUNDS_Y, CHARACTER_BOUNDS_WIDTH, CHARACTER_BOUNDS_HEIGHT});
|
||||||
|
character.SetHandle(argPacket->handle);
|
||||||
|
character.SetAvatar(argPacket->avatar);
|
||||||
|
|
||||||
|
//debug
|
||||||
|
std::cout << "Create, total: " << characterMap.size() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) {
|
void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) {
|
||||||
@@ -407,7 +448,4 @@ void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) {
|
|||||||
void InWorld::HandleCharacterQueryExists(CharacterPacket* const argPacket) {
|
void InWorld::HandleCharacterQueryExists(CharacterPacket* const argPacket) {
|
||||||
//TODO: HandleCharacterQueryExists()
|
//TODO: HandleCharacterQueryExists()
|
||||||
std::cout << "HandleCharacterQueryExists" << std::endl;
|
std::cout << "HandleCharacterQueryExists" << std::endl;
|
||||||
//NOTE: preexisting characters will result in query responses
|
|
||||||
//NOTE: new characters will result in create messages
|
|
||||||
//NOTE: this client's character will exist in both
|
|
||||||
}
|
}
|
||||||
@@ -44,6 +44,8 @@
|
|||||||
|
|
||||||
//client
|
//client
|
||||||
#include "base_scene.hpp"
|
#include "base_scene.hpp"
|
||||||
|
#include "base_character.hpp"
|
||||||
|
#include "base_monster.hpp"
|
||||||
|
|
||||||
//STL
|
//STL
|
||||||
#include <map>
|
#include <map>
|
||||||
@@ -99,6 +101,7 @@ protected:
|
|||||||
//indexes
|
//indexes
|
||||||
int& clientIndex;
|
int& clientIndex;
|
||||||
int& accountIndex;
|
int& accountIndex;
|
||||||
|
int characterIndex = -1;
|
||||||
|
|
||||||
//graphics
|
//graphics
|
||||||
Image buttonImage;
|
Image buttonImage;
|
||||||
@@ -120,6 +123,9 @@ protected:
|
|||||||
int marginX = 0, marginY = 0;
|
int marginX = 0, marginY = 0;
|
||||||
} camera;
|
} camera;
|
||||||
|
|
||||||
|
//entities
|
||||||
|
std::map<int, BaseCharacter> characterMap;
|
||||||
|
std::map<int, BaseMonster> monsterMap;
|
||||||
|
|
||||||
//heartbeat
|
//heartbeat
|
||||||
//TODO: Heartbeat needs it's own utility
|
//TODO: Heartbeat needs it's own utility
|
||||||
|
|||||||
@@ -35,4 +35,8 @@ constexpr int CHARACTER_BOUNDS_Y = 16;
|
|||||||
constexpr int CHARACTER_BOUNDS_WIDTH = 32;
|
constexpr int CHARACTER_BOUNDS_WIDTH = 32;
|
||||||
constexpr int CHARACTER_BOUNDS_HEIGHT = 32;
|
constexpr int CHARACTER_BOUNDS_HEIGHT = 32;
|
||||||
|
|
||||||
|
//the character's sprite format
|
||||||
|
constexpr int CHARACTER_CELLS_X = 4;
|
||||||
|
constexpr int CHARACTER_CELLS_Y = 4;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user