DarkflameServer/dGame/PlayerManager.cpp
David Markowitz f0b6ad89d9
chore: Player class removal (#1445)
* SystemAddress and destructor

* move respawn logic to character comp

Tested that respawn pos and rot can be set as per previously by crossing a respawn point and smashing to see if I would respawn at the new place.

* Move loot cheat checking

* Remove GetParentUser overload

Tested completing missions
control behaviors
collecting life crate
completing a bunch of missions using macros
loading into worlds
brick-by-brick
placing models
digging the x spot in gnarled forest
can still ban and mute players
cheat detection is still doing its thing
flags are still set (checked with flag 45)
claim codes still work (created new char, checked the lego club mail was there)

* Move player constructor logic

Its now at the bottom of Entity constructor.  Time to remove Player

* Remove Player class

Removes the Player class.  Tested that I can still login and see another player in Venture Explorer and logging out a few times still works as well as smashing enemies

* store ptr

* Update SlashCommandHandler.cpp
2024-02-04 06:29:05 -08:00

68 lines
1.5 KiB
C++

#include "PlayerManager.h"
#include "Character.h"
#include "User.h"
#include "UserManager.h"
#include "eReplicaComponentType.h"
namespace {
std::vector<Entity*> m_Players;
};
const std::vector<Entity*>& PlayerManager::GetAllPlayers() {
return m_Players;
}
void PlayerManager::AddPlayer(Entity* player) {
const auto& iter = std::find(m_Players.begin(), m_Players.end(), player);
if (iter == m_Players.end()) {
m_Players.push_back(player);
}
}
bool PlayerManager::RemovePlayer(Entity* player) {
const auto iter = std::find(m_Players.begin(), m_Players.end(), player);
const bool toReturn = iter != m_Players.end();
if (toReturn) {
m_Players.erase(iter);
}
return toReturn;
}
Entity* PlayerManager::GetPlayer(const SystemAddress& sysAddr) {
auto* entity = UserManager::Instance()->GetUser(sysAddr)->GetLastUsedChar()->GetEntity();
return entity;
}
Entity* PlayerManager::GetPlayer(const std::string& name) {
const auto characters = Game::entityManager->GetEntitiesByComponent(eReplicaComponentType::CHARACTER);
Entity* player = nullptr;
for (auto* character : characters) {
if (!character->IsPlayer()) continue;
if (GeneralUtils::CaseInsensitiveStringCompare(name, character->GetCharacter()->GetName())) {
player = character;
break;
}
}
return player;
}
Entity* PlayerManager::GetPlayer(LWOOBJID playerID) {
Entity* playerToReturn = nullptr;
for (auto* player : m_Players) {
if (player->GetObjectID() == playerID) {
playerToReturn = player;
break;
}
}
return playerToReturn;
}