mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-06 10:44:08 +00:00
chore: Simplify and move Player functionality to relevant component (#1408)
* Moving and organizing Player code - Move code to CharacterComponent - Remove extraneous interfaces - Simplify some code greatly - Change some types to return and take in const ref (only structs larger than 8 bytes benefit from this change.) - Update code to use CharacterComponent for sending to zone instead of Player*. * Moving and organizing Player code - Move code to CharacterComponent - Remove extraneous interfaces - Simplify some code greatly - Change some types to return and take in const ref (only structs larger than 8 bytes benefit from this change.) - Update code to use CharacterComponent for sending to zone instead of Player*. - Remove static storage container (static containers can be destroyed before exit/terminate handler executes) * remove player cast * Remove extra includes
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#include "BaseConsoleTeleportServer.h"
|
||||
#include "GameMessages.h"
|
||||
#include "Player.h"
|
||||
#include "CharacterComponent.h"
|
||||
#include "RenderComponent.h"
|
||||
#include "EntityManager.h"
|
||||
#include "eTerminateType.h"
|
||||
@@ -94,7 +94,9 @@ void BaseConsoleTeleportServer::TransferPlayer(Entity* self, Entity* player, int
|
||||
|
||||
const auto& teleportZone = self->GetVar<std::u16string>(u"transferZoneID");
|
||||
|
||||
static_cast<Player*>(player)->SendToZone(std::stoi(GeneralUtils::UTF16ToWTF8(teleportZone)));
|
||||
auto* characterComponent = player->GetComponent<CharacterComponent>();
|
||||
|
||||
if (characterComponent) characterComponent->SendToZone(std::stoi(GeneralUtils::UTF16ToWTF8(teleportZone)));
|
||||
|
||||
UpdatePlayerTable(self, player, false);
|
||||
}
|
||||
|
@@ -3,7 +3,7 @@
|
||||
#include "DestroyableComponent.h"
|
||||
#include "EntityManager.h"
|
||||
#include "dZoneManager.h"
|
||||
#include "Player.h"
|
||||
#include "CharacterComponent.h"
|
||||
#include "eMissionTaskType.h"
|
||||
#include "eMissionState.h"
|
||||
#include "MissionComponent.h"
|
||||
@@ -23,7 +23,8 @@ void BaseSurvivalServer::BasePlayerLoaded(Entity* self, Entity* player) {
|
||||
const auto& playersIter = std::find(state.players.begin(), state.players.end(), player->GetObjectID());
|
||||
|
||||
if (waitingIter != state.waitingPlayers.end() || playersIter != state.players.end()) {
|
||||
static_cast<Player*>(player)->SendToZone(player->GetCharacter()->GetLastNonInstanceZoneID());
|
||||
auto* characterComponent = player->GetComponent<CharacterComponent>();
|
||||
if (characterComponent) characterComponent->SendToZone(player->GetCharacter()->GetLastNonInstanceZoneID());
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -161,8 +162,8 @@ void BaseSurvivalServer::BaseMessageBoxResponse(Entity* self, Entity* sender, in
|
||||
if (sender->IsPlayer()) {
|
||||
auto* character = sender->GetCharacter();
|
||||
if (character != nullptr) {
|
||||
auto* player = dynamic_cast<Player*>(sender);
|
||||
player->SendToZone(character->GetLastNonInstanceZoneID());
|
||||
auto* characterComponent = sender->GetComponent<CharacterComponent>();
|
||||
if (characterComponent) characterComponent->SendToZone(character->GetLastNonInstanceZoneID());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -3,7 +3,7 @@
|
||||
#include "DestroyableComponent.h"
|
||||
#include "EntityManager.h"
|
||||
#include "dZoneManager.h"
|
||||
#include "Player.h"
|
||||
#include "CharacterComponent.h"
|
||||
#include "eMissionTaskType.h"
|
||||
#include "eMissionState.h"
|
||||
#include "MissionComponent.h"
|
||||
@@ -162,8 +162,8 @@ void BaseWavesServer::BaseMessageBoxResponse(Entity* self, Entity* sender, int32
|
||||
if (sender->IsPlayer()) {
|
||||
auto* character = sender->GetCharacter();
|
||||
if (character != nullptr) {
|
||||
auto* player = dynamic_cast<Player*>(sender);
|
||||
player->SendToZone(character->GetLastNonInstanceZoneID());
|
||||
auto* characterComponent = sender->GetComponent<CharacterComponent>();
|
||||
if (characterComponent) characterComponent->SendToZone(character->GetLastNonInstanceZoneID());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
#include "InstanceExitTransferPlayerToLastNonInstance.h"
|
||||
#include "GameMessages.h"
|
||||
#include "Player.h"
|
||||
#include "CharacterComponent.h"
|
||||
#include "Character.h"
|
||||
#include "dServer.h"
|
||||
#include "eTerminateType.h"
|
||||
@@ -23,10 +23,8 @@ void InstanceExitTransferPlayerToLastNonInstance::OnUse(Entity* self, Entity* us
|
||||
}
|
||||
|
||||
void InstanceExitTransferPlayerToLastNonInstance::OnMessageBoxResponse(Entity* self, Entity* sender, int32_t button, const std::u16string& identifier, const std::u16string& userData) {
|
||||
auto* player = dynamic_cast<Player*>(sender);
|
||||
if (player == nullptr)
|
||||
return;
|
||||
|
||||
if (!sender->IsPlayer()) return;
|
||||
|
||||
auto* character = sender->GetCharacter();
|
||||
if (character != nullptr) {
|
||||
if (identifier == u"Instance_Exit" && button == 1) {
|
||||
@@ -47,7 +45,8 @@ void InstanceExitTransferPlayerToLastNonInstance::OnMessageBoxResponse(Entity* s
|
||||
}
|
||||
}
|
||||
|
||||
player->SendToZone(lastInstance);
|
||||
auto* characterComponent = sender->GetComponent<CharacterComponent>();
|
||||
if (characterComponent) characterComponent->SendToZone(lastInstance);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -453,16 +453,12 @@ void SGCannon::SpawnNewModel(Entity* self) {
|
||||
|
||||
void SGCannon::RemovePlayer(LWOOBJID playerID) {
|
||||
auto* player = Game::entityManager->GetEntity(playerID);
|
||||
if (player == nullptr)
|
||||
return;
|
||||
if (!player) return;
|
||||
|
||||
auto* playerObject = dynamic_cast<Player*>(player);
|
||||
if (playerObject == nullptr)
|
||||
return;
|
||||
|
||||
auto* character = playerObject->GetCharacter();
|
||||
if (character != nullptr) {
|
||||
playerObject->SendToZone(character->GetLastNonInstanceZoneID());
|
||||
auto* character = player->GetCharacter();
|
||||
auto* characterComponent = player->GetComponent<CharacterComponent>();
|
||||
if (characterComponent && character) {
|
||||
characterComponent->SendToZone(character->GetLastNonInstanceZoneID());
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,10 +1,11 @@
|
||||
#include "WblGenericZone.h"
|
||||
#include "Player.h"
|
||||
#include "CharacterComponent.h"
|
||||
|
||||
void WblGenericZone::OnFireEventServerSide(Entity* self, Entity* sender, std::string args, int32_t param1, int32_t param2, int32_t param3) {
|
||||
if (args == m_WblAbortMsg) {
|
||||
if (!sender) return;
|
||||
auto player = dynamic_cast<Player*>(sender);
|
||||
if (player) player->SendToZone(m_WblMainZone);
|
||||
|
||||
auto* characterComponent = sender->GetComponent<CharacterComponent>();
|
||||
if (characterComponent) characterComponent->SendToZone(m_WblMainZone);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user