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:
David Markowitz
2024-01-12 09:39:51 -08:00
committed by GitHub
parent 66cc582a9a
commit 929d029f12
15 changed files with 200 additions and 305 deletions

View File

@@ -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);
}
}

View File

@@ -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());
}
}