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 "Database.h"
|
|
|
|
#include "MissionComponent.h"
|
|
|
|
#include "UserManager.h"
|
|
|
|
#include "EntityManager.h"
|
|
|
|
#include "dLogger.h"
|
|
|
|
#include "ZoneInstanceManager.h"
|
|
|
|
#include "WorldPackets.h"
|
|
|
|
#include "dZoneManager.h"
|
|
|
|
#include "CharacterComponent.h"
|
|
|
|
#include "Mail.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"
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
std::vector<Player*> Player::m_Players = {};
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
Player::Player(const LWOOBJID& objectID, const EntityInfo info, User* user, Entity* parentEntity) : Entity(objectID, info, parentEntity) {
|
2021-12-05 17:54:36 +00:00
|
|
|
m_ParentUser = user;
|
|
|
|
m_Character = m_ParentUser->GetLastUsedChar();
|
|
|
|
m_ParentUser->SetLoggedInChar(objectID);
|
|
|
|
m_GMLevel = m_Character->GetGMLevel();
|
|
|
|
m_SystemAddress = m_ParentUser->GetSystemAddress();
|
|
|
|
m_DroppedLoot = {};
|
2021-12-11 13:21:00 +00:00
|
|
|
m_DroppedCoins = 0;
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
m_GhostReferencePoint = NiPoint3::ZERO;
|
|
|
|
m_GhostOverridePoint = NiPoint3::ZERO;
|
|
|
|
m_GhostOverride = false;
|
|
|
|
m_ObservedEntitiesLength = 256;
|
|
|
|
m_ObservedEntitiesUsed = 0;
|
|
|
|
m_ObservedEntities.resize(m_ObservedEntitiesLength);
|
|
|
|
|
|
|
|
m_Character->SetEntity(this);
|
|
|
|
|
|
|
|
const auto& iter = std::find(m_Players.begin(), m_Players.end(), this);
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (iter != m_Players.end()) {
|
2021-12-05 17:54:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Players.push_back(this);
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
User* Player::GetParentUser() const {
|
2021-12-05 17:54:36 +00:00
|
|
|
return m_ParentUser;
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
SystemAddress Player::GetSystemAddress() const {
|
2021-12-05 17:54:36 +00:00
|
|
|
return m_SystemAddress;
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void Player::SetSystemAddress(const SystemAddress& value) {
|
2021-12-05 17:54:36 +00:00
|
|
|
m_SystemAddress = value;
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void Player::SetRespawnPos(const NiPoint3 position) {
|
2021-12-05 17:54:36 +00:00
|
|
|
m_respawnPos = position;
|
|
|
|
|
|
|
|
m_Character->SetRespawnPoint(dZoneManager::Instance()->GetZone()->GetWorldID(), position);
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void Player::SetRespawnRot(const NiQuaternion rotation) {
|
2021-12-05 17:54:36 +00:00
|
|
|
m_respawnRot = rotation;
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
NiPoint3 Player::GetRespawnPosition() const {
|
2021-12-05 17:54:36 +00:00
|
|
|
return m_respawnPos;
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
NiQuaternion Player::GetRespawnRotation() const {
|
2021-12-05 17:54:36 +00:00
|
|
|
return m_respawnRot;
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void Player::SendMail(const LWOOBJID sender, const std::string& senderName, const std::string& subject, const std::string& body, LOT attachment, uint16_t attachmentCount) const {
|
2021-12-05 17:54:36 +00:00
|
|
|
Mail::SendMail(sender, senderName, this, subject, body, attachment, attachmentCount);
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void Player::SendToZone(LWOMAPID zoneId, LWOCLONEID cloneId) {
|
2021-12-05 17:54:36 +00:00
|
|
|
const auto objid = GetObjectID();
|
|
|
|
|
|
|
|
ZoneInstanceManager::Instance()->RequestZoneTransfer(Game::server, zoneId, cloneId, false, [objid](bool mythranShift, uint32_t zoneID, uint32_t zoneInstance, uint32_t zoneClone, std::string serverIP, uint16_t serverPort) {
|
|
|
|
auto* entity = EntityManager::Instance()->GetEntity(objid);
|
|
|
|
|
|
|
|
if (entity == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto sysAddr = entity->GetSystemAddress();
|
|
|
|
|
|
|
|
auto* character = entity->GetCharacter();
|
|
|
|
auto* characterComponent = entity->GetComponent<CharacterComponent>();
|
|
|
|
|
|
|
|
if (character != nullptr && characterComponent != nullptr) {
|
|
|
|
character->SetZoneID(zoneID);
|
|
|
|
character->SetZoneInstance(zoneInstance);
|
|
|
|
character->SetZoneClone(zoneClone);
|
|
|
|
|
|
|
|
characterComponent->SetLastRocketConfig(u"");
|
|
|
|
|
|
|
|
character->SaveXMLToDatabase();
|
|
|
|
}
|
|
|
|
|
|
|
|
WorldPackets::SendTransferToWorld(sysAddr, serverIP, serverPort, mythranShift);
|
|
|
|
|
|
|
|
EntityManager::Instance()->DestructEntity(entity);
|
|
|
|
return;
|
2023-07-15 08:54:41 +00:00
|
|
|
});
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void Player::AddLimboConstruction(LWOOBJID objectId) {
|
2021-12-05 17:54:36 +00:00
|
|
|
const auto& iter = std::find(m_LimboConstructions.begin(), m_LimboConstructions.end(), objectId);
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (iter != m_LimboConstructions.end()) {
|
2021-12-05 17:54:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_LimboConstructions.push_back(objectId);
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void Player::RemoveLimboConstruction(LWOOBJID objectId) {
|
2021-12-05 17:54:36 +00:00
|
|
|
const auto& iter = std::find(m_LimboConstructions.begin(), m_LimboConstructions.end(), objectId);
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (iter == m_LimboConstructions.end()) {
|
2021-12-05 17:54:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_LimboConstructions.erase(iter);
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void Player::ConstructLimboEntities() {
|
|
|
|
for (const auto objectId : m_LimboConstructions) {
|
2021-12-05 17:54:36 +00:00
|
|
|
auto* entity = EntityManager::Instance()->GetEntity(objectId);
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (entity == nullptr) {
|
2021-12-05 17:54:36 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
EntityManager::Instance()->ConstructEntity(entity, m_SystemAddress);
|
|
|
|
}
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
m_LimboConstructions.clear();
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
std::map<LWOOBJID, Loot::Info>& Player::GetDroppedLoot() {
|
2021-12-05 17:54:36 +00:00
|
|
|
return m_DroppedLoot;
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
const NiPoint3& Player::GetGhostReferencePoint() const {
|
2021-12-05 17:54:36 +00:00
|
|
|
return m_GhostOverride ? m_GhostOverridePoint : m_GhostReferencePoint;
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
const NiPoint3& Player::GetOriginGhostReferencePoint() const {
|
2021-12-05 17:54:36 +00:00
|
|
|
return m_GhostReferencePoint;
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void Player::SetGhostReferencePoint(const NiPoint3& value) {
|
2021-12-05 17:54:36 +00:00
|
|
|
m_GhostReferencePoint = value;
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void Player::SetGhostOverridePoint(const NiPoint3& value) {
|
2021-12-05 17:54:36 +00:00
|
|
|
m_GhostOverridePoint = value;
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
const NiPoint3& Player::GetGhostOverridePoint() const {
|
2021-12-05 17:54:36 +00:00
|
|
|
return m_GhostOverridePoint;
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void Player::SetGhostOverride(bool value) {
|
2021-12-05 17:54:36 +00:00
|
|
|
m_GhostOverride = value;
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
bool Player::GetGhostOverride() const {
|
2021-12-05 17:54:36 +00:00
|
|
|
return m_GhostOverride;
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void Player::ObserveEntity(int32_t id) {
|
|
|
|
for (int32_t i = 0; i < m_ObservedEntitiesUsed; i++) {
|
|
|
|
if (m_ObservedEntities[i] == 0 || m_ObservedEntities[i] == id) {
|
2021-12-05 17:54:36 +00:00
|
|
|
m_ObservedEntities[i] = id;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto index = m_ObservedEntitiesUsed++;
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (m_ObservedEntitiesUsed > m_ObservedEntitiesLength) {
|
2021-12-05 17:54:36 +00:00
|
|
|
m_ObservedEntities.resize(m_ObservedEntitiesLength + m_ObservedEntitiesLength);
|
|
|
|
|
|
|
|
m_ObservedEntitiesLength = m_ObservedEntitiesLength + m_ObservedEntitiesLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_ObservedEntities[index] = id;
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
bool Player::IsObserved(int32_t id) {
|
|
|
|
for (int32_t i = 0; i < m_ObservedEntitiesUsed; i++) {
|
|
|
|
if (m_ObservedEntities[i] == id) {
|
2021-12-05 17:54:36 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void Player::GhostEntity(int32_t id) {
|
|
|
|
for (int32_t i = 0; i < m_ObservedEntitiesUsed; i++) {
|
|
|
|
if (m_ObservedEntities[i] == id) {
|
2021-12-05 17:54:36 +00:00
|
|
|
m_ObservedEntities[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
Player* Player::GetPlayer(const SystemAddress& sysAddr) {
|
2021-12-05 17:54:36 +00:00
|
|
|
auto* entity = UserManager::Instance()->GetUser(sysAddr)->GetLastUsedChar()->GetEntity();
|
|
|
|
|
|
|
|
return static_cast<Player*>(entity);
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
Player* Player::GetPlayer(const std::string& name) {
|
2023-03-04 07:16:37 +00:00
|
|
|
const auto characters = EntityManager::Instance()->GetEntitiesByComponent(eReplicaComponentType::CHARACTER);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
for (auto* character : characters) {
|
2021-12-05 17:54:36 +00:00
|
|
|
if (!character->IsPlayer()) continue;
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (character->GetCharacter()->GetName() == name) {
|
2021-12-05 17:54:36 +00:00
|
|
|
return static_cast<Player*>(character);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
Player* Player::GetPlayer(LWOOBJID playerID) {
|
|
|
|
for (auto* player : m_Players) {
|
|
|
|
if (player->GetObjectID() == playerID) {
|
2021-12-05 17:54:36 +00:00
|
|
|
return player;
|
|
|
|
}
|
|
|
|
}
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
const std::vector<Player*>& Player::GetAllPlayers() {
|
2021-12-05 17:54:36 +00:00
|
|
|
return m_Players;
|
|
|
|
}
|
|
|
|
|
2021-12-11 13:21:00 +00:00
|
|
|
uint64_t Player::GetDroppedCoins() {
|
|
|
|
return m_DroppedCoins;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Player::SetDroppedCoins(uint64_t value) {
|
|
|
|
m_DroppedCoins = value;
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
Player::~Player() {
|
2022-07-25 02:26:51 +00:00
|
|
|
Game::logger->Log("Player", "Deleted player");
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
for (int32_t i = 0; i < m_ObservedEntitiesUsed; i++) {
|
2021-12-05 17:54:36 +00:00
|
|
|
const auto id = m_ObservedEntities[i];
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (id == 0) {
|
2021-12-05 17:54:36 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto* entity = EntityManager::Instance()->GetGhostCandidate(id);
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (entity != nullptr) {
|
2021-12-05 17:54:36 +00:00
|
|
|
entity->SetObservers(entity->GetObservers() - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_LimboConstructions.clear();
|
|
|
|
|
|
|
|
const auto& iter = std::find(m_Players.begin(), m_Players.end(), this);
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (iter == m_Players.end()) {
|
2021-12-05 17:54:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-06-19 07:14:33 +00:00
|
|
|
if (IsPlayer()) {
|
2022-07-28 13:39:57 +00:00
|
|
|
Entity* zoneControl = EntityManager::Instance()->GetZoneControlEntity();
|
|
|
|
for (CppScripts::Script* script : CppScripts::GetEntityScripts(zoneControl)) {
|
|
|
|
script->OnPlayerExit(zoneControl, this);
|
|
|
|
}
|
|
|
|
|
2023-03-04 07:16:37 +00:00
|
|
|
std::vector<Entity*> scriptedActs = EntityManager::Instance()->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
|
|
|
m_Players.erase(iter);
|
|
|
|
}
|