2022-08-06 03:01:59 +00:00
|
|
|
#include "Player.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
#include <ctime>
|
|
|
|
|
|
|
|
#include "Character.h"
|
|
|
|
#include "UserManager.h"
|
|
|
|
#include "EntityManager.h"
|
2024-01-12 17:39:51 +00:00
|
|
|
#include "Game.h"
|
2023-10-21 23:31:55 +00:00
|
|
|
#include "Logger.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
#include "dZoneManager.h"
|
2023-01-07 05:17:05 +00:00
|
|
|
#include "User.h"
|
2022-06-19 07:14:33 +00:00
|
|
|
#include "CppScripts.h"
|
2023-01-07 05:17:05 +00:00
|
|
|
#include "Loot.h"
|
2023-03-04 07:16:37 +00:00
|
|
|
#include "eReplicaComponentType.h"
|
2024-01-13 09:40:56 +00:00
|
|
|
#include "PlayerManager.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-01-12 17:39:51 +00:00
|
|
|
void Player::SetRespawnPos(const NiPoint3& position) {
|
2023-12-22 04:12:52 +00:00
|
|
|
if (!m_Character) return;
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
m_respawnPos = position;
|
|
|
|
|
2023-07-17 22:55:33 +00:00
|
|
|
m_Character->SetRespawnPoint(Game::zoneManager->GetZone()->GetWorldID(), position);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-01-12 17:39:51 +00:00
|
|
|
void Player::SetRespawnRot(const NiQuaternion& rotation) {
|
|
|
|
m_respawnRot = rotation;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2024-01-12 17:39:51 +00:00
|
|
|
void Player::SetSystemAddress(const SystemAddress& value) {
|
|
|
|
m_SystemAddress = value;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2024-01-12 17:39:51 +00:00
|
|
|
Player::Player(const LWOOBJID& objectID, const EntityInfo info, User* user, Entity* parentEntity) : Entity(objectID, info, parentEntity) {
|
|
|
|
m_ParentUser = user;
|
|
|
|
m_Character = m_ParentUser->GetLastUsedChar();
|
|
|
|
m_ParentUser->SetLoggedInChar(objectID);
|
|
|
|
m_GMLevel = m_Character->GetGMLevel();
|
|
|
|
m_SystemAddress = m_ParentUser->GetSystemAddress();
|
|
|
|
m_DroppedCoins = 0;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-01-12 17:39:51 +00:00
|
|
|
m_Character->SetEntity(this);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-01-13 09:40:56 +00:00
|
|
|
PlayerManager::AddPlayer(this);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
Player::~Player() {
|
2023-10-21 23:31:55 +00:00
|
|
|
LOG("Deleted player");
|
2024-01-13 09:40:56 +00:00
|
|
|
|
|
|
|
// Make sure the player exists first. Remove afterwards to prevent the OnPlayerExist functions from not being able to find the player.
|
2024-01-14 19:10:13 +00:00
|
|
|
if (!PlayerManager::RemovePlayer(this)) {
|
2024-01-13 09:40:56 +00:00
|
|
|
LOG("Unable to find player to remove from manager.");
|
2021-12-05 17:54:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-06-19 07:14:33 +00:00
|
|
|
if (IsPlayer()) {
|
2023-07-15 20:56:33 +00:00
|
|
|
Entity* zoneControl = Game::entityManager->GetZoneControlEntity();
|
2022-07-28 13:39:57 +00:00
|
|
|
for (CppScripts::Script* script : CppScripts::GetEntityScripts(zoneControl)) {
|
|
|
|
script->OnPlayerExit(zoneControl, this);
|
|
|
|
}
|
|
|
|
|
2023-07-15 20:56:33 +00:00
|
|
|
std::vector<Entity*> scriptedActs = Game::entityManager->GetEntitiesByComponent(eReplicaComponentType::SCRIPTED_ACTIVITY);
|
2022-07-28 13:39:57 +00:00
|
|
|
for (Entity* scriptEntity : scriptedActs) {
|
|
|
|
if (scriptEntity->GetObjectID() != zoneControl->GetObjectID()) { // Don't want to trigger twice on instance worlds
|
|
|
|
for (CppScripts::Script* script : CppScripts::GetEntityScripts(scriptEntity)) {
|
|
|
|
script->OnPlayerExit(scriptEntity, this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-06-19 07:14:33 +00:00
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|