Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4cce98dba4 | |||
| b2aecc933a |
@@ -21,31 +21,55 @@
|
|||||||
*/
|
*/
|
||||||
#include "battle_data.hpp"
|
#include "battle_data.hpp"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
BattleData::BattleData() {
|
BattleData::BattleData() {
|
||||||
//
|
for (int i = 0; i < BATTLE_SIZE; i++) {
|
||||||
|
characterArray[i] = nullptr;
|
||||||
|
creatureArray[i] = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BattleData::~BattleData() {
|
BattleData::~BattleData() {
|
||||||
//
|
for (int i = 0; i < BATTLE_SIZE; i++) {
|
||||||
|
if (characterArray[i] != nullptr || creatureArray[i] != nullptr) {
|
||||||
|
//breaking a cardinal sin
|
||||||
|
throw(std::runtime_error("BattleData not empty on destruction"));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BattleData::Update() {
|
void BattleData::Update() {
|
||||||
//
|
//TODO: (0) EMPTY
|
||||||
}
|
}
|
||||||
|
|
||||||
//accessors and mutators
|
//accessors and mutators
|
||||||
void BattleData::PushCharacter(CharacterData* const characterData) {
|
int BattleData::PushCharacter(CharacterData* const characterData) {
|
||||||
//
|
//push the character into the battle object
|
||||||
|
for (int i = 0; i < BATTLE_SIZE; i++) {
|
||||||
|
if (characterArray[i] == nullptr) {
|
||||||
|
characterArray[i] = characterData;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BattleData::PopCharacter(CharacterData* const characterData) {
|
int BattleData::PopCharacter(CharacterData const * const characterData) {
|
||||||
//
|
//pop the character from the battle object
|
||||||
|
for (int i = 0; i < BATTLE_SIZE; i++) {
|
||||||
|
if (characterArray[i] == characterData) {
|
||||||
|
characterArray[i] = nullptr;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BattleData::PushCreature(CreatureData* const creatureData) {
|
int BattleData::PushCreature(CreatureData* const creatureData) {
|
||||||
//
|
//TODO: (0) EMPTY
|
||||||
}
|
}
|
||||||
|
|
||||||
void BattleData::PopCreature(CreatureData* const creatureData) {
|
int BattleData::PopCreature(CreatureData const * const creatureData) {
|
||||||
//
|
//TODO: (0) EMPTY
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,19 +28,21 @@
|
|||||||
|
|
||||||
class BattleData {
|
class BattleData {
|
||||||
public:
|
public:
|
||||||
|
constexpr static int BATTLE_SIZE = 8;
|
||||||
|
|
||||||
BattleData();
|
BattleData();
|
||||||
~BattleData();
|
~BattleData();
|
||||||
|
|
||||||
void Update();
|
void Update();
|
||||||
|
|
||||||
//accessors and mutators
|
//accessors and mutators
|
||||||
void PushCharacter(CharacterData* const characterData);
|
int PushCharacter(CharacterData* const characterData);
|
||||||
void PopCharacter(CharacterData* const characterData);
|
int PopCharacter(CharacterData const * const characterData);
|
||||||
|
|
||||||
void PushCreature(CreatureData* const creatureData);
|
int PushCreature(CreatureData* const creatureData);
|
||||||
void PopCreature(CreatureData* const creatureData);
|
int PopCreature(CreatureData const * const creatureData);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::array<CharacterData*, 8> characterArray;
|
std::array<CharacterData*, BATTLE_SIZE> characterArray;
|
||||||
std::array<CreatureData*, 8> creatureArray;
|
std::array<CreatureData*, BATTLE_SIZE> creatureArray;
|
||||||
};
|
};
|
||||||
@@ -67,6 +67,12 @@ static int setRoom(lua_State* L) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int getIndex(lua_State* L) {
|
||||||
|
CharacterData* character = static_cast<CharacterData*>(lua_touserdata(L, 1));
|
||||||
|
lua_pushinteger(L, character->GetIndex());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static int getOwner(lua_State* L) {
|
static int getOwner(lua_State* L) {
|
||||||
CharacterData* character = static_cast<CharacterData*>(lua_touserdata(L, 1));
|
CharacterData* character = static_cast<CharacterData*>(lua_touserdata(L, 1));
|
||||||
lua_pushinteger(L, character->GetOwner());
|
lua_pushinteger(L, character->GetOwner());
|
||||||
@@ -87,6 +93,7 @@ static int getAvatar(lua_State* L) {
|
|||||||
|
|
||||||
static const luaL_Reg characterLib[] = {
|
static const luaL_Reg characterLib[] = {
|
||||||
{"SetRoom", setRoom},
|
{"SetRoom", setRoom},
|
||||||
|
{"GetIndex", getIndex},
|
||||||
// {"GetOwner", getOwner}, //unusable without account API
|
// {"GetOwner", getOwner}, //unusable without account API
|
||||||
{"GetHandle", getHandle},
|
{"GetHandle", getHandle},
|
||||||
{"GetAvatar", getAvatar},
|
{"GetAvatar", getAvatar},
|
||||||
|
|||||||
@@ -30,6 +30,10 @@ CharacterData::CharacterData(): Entity("character") {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//database stuff
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
int CharacterData::GetIndex() {
|
int CharacterData::GetIndex() {
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
friend class CharacterManager;
|
friend class CharacterManager;
|
||||||
|
|
||||||
|
//database stuff
|
||||||
int index = -1;
|
int index = -1;
|
||||||
int owner = -1;
|
int owner = -1;
|
||||||
std::string handle;
|
std::string handle;
|
||||||
|
|||||||
@@ -205,20 +205,30 @@ void RoomData::RunFrameCharacterBarrierCollisions() {
|
|||||||
//barrier bounds
|
//barrier bounds
|
||||||
BoundingBox barrierBox = barrierIt.second.GetBounds() + barrierIt.second.GetOrigin();
|
BoundingBox barrierBox = barrierIt.second.GetBounds() + barrierIt.second.GetOrigin();
|
||||||
|
|
||||||
|
//move the character to the battle screen
|
||||||
if (characterBox.CheckOverlap(barrierBox)) {
|
if (characterBox.CheckOverlap(barrierBox)) {
|
||||||
//Actually move the character to a battle
|
//TODO: (0) What if the barrier is full?
|
||||||
BattleData* battle = battleMgr.Find(barrierIt.second.GetBattleIndex());
|
//TODO: (0) What if the player logs in on top of a barrier?
|
||||||
// battle->PushCharacter(characterIt.second);
|
//pump character unload
|
||||||
// characterList.
|
CharacterPacket charPacket;
|
||||||
|
charPacket.type = SerialPacketType::CHARACTER_UNLOAD;
|
||||||
|
charPacket.characterIndex = characterIt->GetIndex();
|
||||||
|
pumpPacketProximity(static_cast<SerialPacket*>(&charPacket), characterIt->GetRoomIndex());
|
||||||
|
|
||||||
|
std::cout << "CharacterList size: " << characterList.size() << std::endl;
|
||||||
|
|
||||||
|
//Actually move the character to a battle
|
||||||
|
BattleData* battle = battleMgr.Find(barrierIt.second.GetBattleIndex()); //TODO: barriers should hold the battle's pointer
|
||||||
|
battle->PushCharacter(characterIt);
|
||||||
|
PopCharacter(characterIt);
|
||||||
|
|
||||||
//DEBUG: output barrierIndex, battleIndex
|
//DEBUG: output barrierIndex, battleIndex
|
||||||
std::cout << barrierIt.first << "\t" << barrierIt.second.GetBattleIndex() << std::endl;
|
std::cout << "CharacterList size: " << characterList.size() << std::endl;
|
||||||
|
|
||||||
//Send the entry message to the client
|
//Send the entry message to the client
|
||||||
BarrierPacket newPacket;
|
// BarrierPacket newPacket;
|
||||||
newPacket.type = SerialPacketType::BARRIER_ENTRY;
|
// newPacket.type = SerialPacketType::BARRIER_ENTRY;
|
||||||
newPacket.barrierIndex = barrierIt.first;
|
// newPacket.barrierIndex = barrierIt.first;
|
||||||
|
|
||||||
// udpNetworkUtility.Send();
|
// udpNetworkUtility.Send();
|
||||||
|
|
||||||
@@ -285,6 +295,13 @@ void RoomData::PopCharacter(CharacterData const * const character) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//check the battles to see if the character isn't there
|
||||||
|
for (auto& it : *battleMgr.GetContainer()) {
|
||||||
|
if (it.second.PopCharacter(character)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
throw(std::logic_error("cannot remove a non-existant instance of CharacterData in RoomData"));
|
throw(std::logic_error("cannot remove a non-existant instance of CharacterData in RoomData"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -596,11 +596,36 @@ void ServerApplication::hQueryCharacterExists(CharacterPacket* const argPacket)
|
|||||||
//respond with all character data
|
//respond with all character data
|
||||||
CharacterPacket newPacket;
|
CharacterPacket newPacket;
|
||||||
|
|
||||||
for (auto& it : *characterMgr.GetContainer()) {
|
//retrieve all character data
|
||||||
if (argPacket->roomIndex != -1 && it.second.GetRoomIndex() != argPacket->roomIndex) {
|
if (argPacket->roomIndex == -1) {
|
||||||
continue;
|
for (auto& it : *characterMgr.GetContainer()) {
|
||||||
|
copyCharacterToPacket(&newPacket, &it.second, it.first);
|
||||||
|
newPacket.type = SerialPacketType::QUERY_CHARACTER_EXISTS;
|
||||||
|
network.SendTo(argPacket->srcAddress, static_cast<SerialPacket*>(&newPacket));
|
||||||
}
|
}
|
||||||
copyCharacterToPacket(&newPacket, it.first);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//look for the room
|
||||||
|
RoomData* room = roomMgr.Find(argPacket->roomIndex);
|
||||||
|
|
||||||
|
//room not found
|
||||||
|
if (!room) {
|
||||||
|
//build the error message
|
||||||
|
std::ostringstream msg;
|
||||||
|
msg << "Room not found: " << argPacket->roomIndex;
|
||||||
|
|
||||||
|
//build & send the packet
|
||||||
|
TextPacket newPacket;
|
||||||
|
newPacket.type = SerialPacketType::CHARACTER_REJECTION;
|
||||||
|
strncpy(newPacket.text, msg.str().c_str(), PACKET_STRING_SIZE);
|
||||||
|
network.SendTo(argPacket->srcAddress, static_cast<SerialPacket*>(&newPacket));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto& it : *room->GetCharacterList()) {
|
||||||
|
copyCharacterToPacket(&newPacket, it, it->GetIndex());
|
||||||
newPacket.type = SerialPacketType::QUERY_CHARACTER_EXISTS;
|
newPacket.type = SerialPacketType::QUERY_CHARACTER_EXISTS;
|
||||||
network.SendTo(argPacket->srcAddress, static_cast<SerialPacket*>(&newPacket));
|
network.SendTo(argPacket->srcAddress, static_cast<SerialPacket*>(&newPacket));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user