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