mirror of
				https://github.com/DarkflameUniverse/DarkflameServer.git
				synced 2025-10-30 20:22:04 +00:00 
			
		
		
		
	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*.
This commit is contained in:
		| @@ -1879,7 +1879,7 @@ const NiQuaternion& Entity::GetRotation() const { | ||||
| 	return NiQuaternion::IDENTITY; | ||||
| } | ||||
|  | ||||
| void Entity::SetPosition(NiPoint3 position) { | ||||
| void Entity::SetPosition(const NiPoint3& position) { | ||||
| 	auto* controllable = GetComponent<ControllablePhysicsComponent>(); | ||||
|  | ||||
| 	if (controllable != nullptr) { | ||||
| @@ -1907,7 +1907,7 @@ void Entity::SetPosition(NiPoint3 position) { | ||||
| 	Game::entityManager->SerializeEntity(this); | ||||
| } | ||||
|  | ||||
| void Entity::SetRotation(NiQuaternion rotation) { | ||||
| void Entity::SetRotation(const NiQuaternion& rotation) { | ||||
| 	auto* controllable = GetComponent<ControllablePhysicsComponent>(); | ||||
|  | ||||
| 	if (controllable != nullptr) { | ||||
|   | ||||
| @@ -106,7 +106,7 @@ public: | ||||
|  | ||||
| 	virtual User* GetParentUser() const; | ||||
|  | ||||
| 	virtual SystemAddress GetSystemAddress() const { return UNASSIGNED_SYSTEM_ADDRESS; }; | ||||
| 	virtual const SystemAddress& GetSystemAddress() const { return UNASSIGNED_SYSTEM_ADDRESS; }; | ||||
|  | ||||
| 	/** | ||||
| 	 * Setters | ||||
| @@ -124,13 +124,13 @@ public: | ||||
|  | ||||
| 	void SetNetworkId(uint16_t id); | ||||
|  | ||||
| 	void SetPosition(NiPoint3 position); | ||||
| 	void SetPosition(const NiPoint3& position); | ||||
|  | ||||
| 	void SetRotation(NiQuaternion rotation); | ||||
| 	void SetRotation(const NiQuaternion& rotation); | ||||
|  | ||||
| 	virtual void SetRespawnPos(NiPoint3 position) {} | ||||
| 	virtual void SetRespawnPos(const NiPoint3& position) {} | ||||
|  | ||||
| 	virtual void SetRespawnRot(NiQuaternion rotation) {} | ||||
| 	virtual void SetRespawnRot(const NiQuaternion& rotation) {} | ||||
|  | ||||
| 	virtual void SetSystemAddress(const SystemAddress& value) {}; | ||||
|  | ||||
| @@ -229,8 +229,8 @@ public: | ||||
| 	void TriggerEvent(eTriggerEventType event, Entity* optionalTarget = nullptr); | ||||
| 	void ScheduleDestructionAfterUpdate() { m_ShouldDestroyAfterUpdate = true; } | ||||
|  | ||||
| 	virtual NiPoint3 GetRespawnPosition() const { return NiPoint3::ZERO; } | ||||
| 	virtual NiQuaternion GetRespawnRotation() const { return NiQuaternion::IDENTITY; } | ||||
| 	virtual const NiPoint3& GetRespawnPosition() const { return NiPoint3::ZERO; } | ||||
| 	virtual const NiQuaternion& GetRespawnRotation() const { return NiQuaternion::IDENTITY; } | ||||
|  | ||||
| 	void Sleep(); | ||||
| 	void Wake(); | ||||
|   | ||||
							
								
								
									
										243
									
								
								dGame/Player.cpp
									
									
									
									
									
								
							
							
						
						
									
										243
									
								
								dGame/Player.cpp
									
									
									
									
									
								
							| @@ -18,7 +18,38 @@ | ||||
| #include "Loot.h" | ||||
| #include "eReplicaComponentType.h" | ||||
|  | ||||
| std::vector<Player*> Player::m_Players = {}; | ||||
| namespace { | ||||
| 	std::vector<Player*> m_Players; | ||||
| }; | ||||
|  | ||||
| const std::vector<Player*>& Player::GetAllPlayers() { | ||||
| 	return m_Players; | ||||
| } | ||||
|  | ||||
| void Player::SetGhostReferencePoint(const NiPoint3& value) { | ||||
| 	m_GhostReferencePoint = value; | ||||
| } | ||||
|  | ||||
| void Player::SetGhostOverridePoint(const NiPoint3& value) { | ||||
| 	m_GhostOverridePoint = value; | ||||
| } | ||||
|  | ||||
| void Player::SetRespawnPos(const NiPoint3& position) { | ||||
| 	if (!m_Character) return; | ||||
|  | ||||
| 	m_respawnPos = position; | ||||
|  | ||||
| 	m_Character->SetRespawnPoint(Game::zoneManager->GetZone()->GetWorldID(), position); | ||||
|  | ||||
| } | ||||
|  | ||||
| void Player::SetRespawnRot(const NiQuaternion& rotation) { | ||||
| 	m_respawnRot = rotation; | ||||
| } | ||||
|  | ||||
| void Player::SetSystemAddress(const SystemAddress& value) { | ||||
| 	m_SystemAddress = value; | ||||
| } | ||||
|  | ||||
| Player::Player(const LWOOBJID& objectID, const EntityInfo info, User* user, Entity* parentEntity) : Entity(objectID, info, parentEntity) { | ||||
| 	m_ParentUser = user; | ||||
| @@ -32,116 +63,37 @@ Player::Player(const LWOOBJID& objectID, const EntityInfo info, User* user, Enti | ||||
| 	m_GhostReferencePoint = NiPoint3::ZERO; | ||||
| 	m_GhostOverridePoint = NiPoint3::ZERO; | ||||
| 	m_GhostOverride = false; | ||||
| 	m_ObservedEntitiesLength = 256; | ||||
| 	m_ObservedEntitiesUsed = 0; | ||||
| 	m_ObservedEntities.resize(m_ObservedEntitiesLength); | ||||
|  | ||||
| 	int32_t initialObservedEntitiesCapacity = 256; | ||||
| 	m_ObservedEntities.resize(initialObservedEntitiesCapacity); | ||||
|  | ||||
| 	m_Character->SetEntity(this); | ||||
|  | ||||
| 	const auto& iter = std::find(m_Players.begin(), m_Players.end(), this); | ||||
|  | ||||
| 	if (iter != m_Players.end()) { | ||||
| 		return; | ||||
| 	if (iter == m_Players.end()) { | ||||
| 		m_Players.push_back(this); | ||||
| 	} | ||||
|  | ||||
| 	m_Players.push_back(this); | ||||
| } | ||||
|  | ||||
| User* Player::GetParentUser() const { | ||||
| 	return m_ParentUser; | ||||
| } | ||||
|  | ||||
| SystemAddress Player::GetSystemAddress() const { | ||||
| 	return m_SystemAddress; | ||||
| } | ||||
|  | ||||
| void Player::SetSystemAddress(const SystemAddress& value) { | ||||
| 	m_SystemAddress = value; | ||||
| } | ||||
|  | ||||
| void Player::SetRespawnPos(const NiPoint3 position) { | ||||
| 	if (!m_Character) return; | ||||
|  | ||||
| 	m_respawnPos = position; | ||||
|  | ||||
| 	m_Character->SetRespawnPoint(Game::zoneManager->GetZone()->GetWorldID(), position); | ||||
| } | ||||
|  | ||||
| void Player::SetRespawnRot(const NiQuaternion rotation) { | ||||
| 	m_respawnRot = rotation; | ||||
| } | ||||
|  | ||||
| NiPoint3 Player::GetRespawnPosition() const { | ||||
| 	return m_respawnPos; | ||||
| } | ||||
|  | ||||
| NiQuaternion Player::GetRespawnRotation() const { | ||||
| 	return m_respawnRot; | ||||
| } | ||||
|  | ||||
| void Player::SendMail(const LWOOBJID sender, const std::string& senderName, const std::string& subject, const std::string& body, LOT attachment, uint16_t attachmentCount) const { | ||||
| 	Mail::SendMail(sender, senderName, this, subject, body, attachment, attachmentCount); | ||||
| } | ||||
|  | ||||
| void Player::SendToZone(LWOMAPID zoneId, LWOCLONEID cloneId) { | ||||
| 	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 = Game::entityManager->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); | ||||
|  | ||||
| 		Game::entityManager->DestructEntity(entity); | ||||
| 		return; | ||||
| 		}); | ||||
| } | ||||
|  | ||||
| void Player::AddLimboConstruction(LWOOBJID objectId) { | ||||
| 	const auto& iter = std::find(m_LimboConstructions.begin(), m_LimboConstructions.end(), objectId); | ||||
|  | ||||
| 	if (iter != m_LimboConstructions.end()) { | ||||
| 		return; | ||||
| 	const auto iter = std::find(m_LimboConstructions.begin(), m_LimboConstructions.end(), objectId); | ||||
| 	if (iter == m_LimboConstructions.end()) { | ||||
| 		m_LimboConstructions.push_back(objectId); | ||||
| 	} | ||||
|  | ||||
| 	m_LimboConstructions.push_back(objectId); | ||||
| } | ||||
|  | ||||
| void Player::RemoveLimboConstruction(LWOOBJID objectId) { | ||||
| 	const auto& iter = std::find(m_LimboConstructions.begin(), m_LimboConstructions.end(), objectId); | ||||
|  | ||||
| 	if (iter == m_LimboConstructions.end()) { | ||||
| 		return; | ||||
| 	} | ||||
|  | ||||
| 	m_LimboConstructions.erase(iter); | ||||
| 	const auto iter = std::find(m_LimboConstructions.begin(), m_LimboConstructions.end(), objectId); | ||||
| 	if (iter != m_LimboConstructions.end()) { | ||||
| 		m_LimboConstructions.erase(iter); | ||||
| 	}	 | ||||
| } | ||||
|  | ||||
| void Player::ConstructLimboEntities() { | ||||
| 	for (const auto objectId : m_LimboConstructions) { | ||||
| 	for (const auto& objectId : m_LimboConstructions) { | ||||
| 		auto* entity = Game::entityManager->GetEntity(objectId); | ||||
|  | ||||
| 		if (entity == nullptr) { | ||||
| 			continue; | ||||
| 		} | ||||
| 		if (!entity) continue; | ||||
|  | ||||
| 		Game::entityManager->ConstructEntity(entity, m_SystemAddress); | ||||
| 	} | ||||
| @@ -149,72 +101,28 @@ void Player::ConstructLimboEntities() { | ||||
| 	m_LimboConstructions.clear(); | ||||
| } | ||||
|  | ||||
| std::map<LWOOBJID, Loot::Info>& Player::GetDroppedLoot() { | ||||
| 	return m_DroppedLoot; | ||||
| } | ||||
|  | ||||
| const NiPoint3& Player::GetGhostReferencePoint() const { | ||||
| 	return m_GhostOverride ? m_GhostOverridePoint : m_GhostReferencePoint; | ||||
| } | ||||
|  | ||||
| const NiPoint3& Player::GetOriginGhostReferencePoint() const { | ||||
| 	return m_GhostReferencePoint; | ||||
| } | ||||
|  | ||||
| void Player::SetGhostReferencePoint(const NiPoint3& value) { | ||||
| 	m_GhostReferencePoint = value; | ||||
| } | ||||
|  | ||||
| void Player::SetGhostOverridePoint(const NiPoint3& value) { | ||||
| 	m_GhostOverridePoint = value; | ||||
| } | ||||
|  | ||||
| const NiPoint3& Player::GetGhostOverridePoint() const { | ||||
| 	return m_GhostOverridePoint; | ||||
| } | ||||
|  | ||||
| void Player::SetGhostOverride(bool value) { | ||||
| 	m_GhostOverride = value; | ||||
| } | ||||
|  | ||||
| bool Player::GetGhostOverride() const { | ||||
| 	return m_GhostOverride; | ||||
| } | ||||
|  | ||||
| void Player::ObserveEntity(int32_t id) { | ||||
| 	for (int32_t i = 0; i < m_ObservedEntitiesUsed; i++) { | ||||
| 		if (m_ObservedEntities[i] == 0 || m_ObservedEntities[i] == id) { | ||||
| 			m_ObservedEntities[i] = id; | ||||
| 	for (auto& observedEntity : m_ObservedEntities) { | ||||
| 		if (observedEntity == 0 || observedEntity == id) { | ||||
| 			observedEntity = id; | ||||
|  | ||||
| 			return; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	const auto index = m_ObservedEntitiesUsed++; | ||||
| 	m_ObservedEntities.reserve(m_ObservedEntities.size() + 1); | ||||
|  | ||||
| 	if (m_ObservedEntitiesUsed > m_ObservedEntitiesLength) { | ||||
| 		m_ObservedEntities.resize(m_ObservedEntitiesLength + m_ObservedEntitiesLength); | ||||
|  | ||||
| 		m_ObservedEntitiesLength = m_ObservedEntitiesLength + m_ObservedEntitiesLength; | ||||
| 	} | ||||
|  | ||||
| 	m_ObservedEntities[index] = id; | ||||
| 	m_ObservedEntities.push_back(id); | ||||
| } | ||||
|  | ||||
| bool Player::IsObserved(int32_t id) { | ||||
| 	for (int32_t i = 0; i < m_ObservedEntitiesUsed; i++) { | ||||
| 		if (m_ObservedEntities[i] == id) { | ||||
| 			return true; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return false; | ||||
| 	return std::find(m_ObservedEntities.begin(), m_ObservedEntities.end(), id) != m_ObservedEntities.end(); | ||||
| } | ||||
|  | ||||
| void Player::GhostEntity(int32_t id) { | ||||
| 	for (int32_t i = 0; i < m_ObservedEntitiesUsed; i++) { | ||||
| 		if (m_ObservedEntities[i] == id) { | ||||
| 			m_ObservedEntities[i] = 0; | ||||
| 	for (auto& observedEntity : m_ObservedEntities) { | ||||
| 		if (observedEntity == id) { | ||||
| 			observedEntity = 0; | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| @@ -228,59 +136,44 @@ Player* Player::GetPlayer(const SystemAddress& sysAddr) { | ||||
| Player* Player::GetPlayer(const std::string& name) { | ||||
| 	const auto characters = Game::entityManager->GetEntitiesByComponent(eReplicaComponentType::CHARACTER); | ||||
|  | ||||
| 	Player* player = nullptr; | ||||
| 	for (auto* character : characters) { | ||||
| 		if (!character->IsPlayer()) continue; | ||||
| 		 | ||||
| 		if (GeneralUtils::CaseInsensitiveStringCompare(name, character->GetCharacter()->GetName())) { | ||||
| 			return dynamic_cast<Player*>(character); | ||||
| 			player = dynamic_cast<Player*>(character); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return nullptr; | ||||
| 	return player; | ||||
| } | ||||
|  | ||||
| Player* Player::GetPlayer(LWOOBJID playerID) { | ||||
| 	Player* playerToReturn = nullptr; | ||||
| 	for (auto* player : m_Players) { | ||||
| 		if (player->GetObjectID() == playerID) { | ||||
| 			return player; | ||||
| 			playerToReturn = player; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return nullptr; | ||||
| } | ||||
|  | ||||
| const std::vector<Player*>& Player::GetAllPlayers() { | ||||
| 	return m_Players; | ||||
| } | ||||
|  | ||||
| uint64_t Player::GetDroppedCoins() { | ||||
| 	return m_DroppedCoins; | ||||
| } | ||||
|  | ||||
| void Player::SetDroppedCoins(uint64_t value) { | ||||
| 	m_DroppedCoins = value; | ||||
| 	return playerToReturn; | ||||
| } | ||||
|  | ||||
| Player::~Player() { | ||||
| 	LOG("Deleted player"); | ||||
|  | ||||
| 	for (int32_t i = 0; i < m_ObservedEntitiesUsed; i++) { | ||||
| 		const auto id = m_ObservedEntities[i]; | ||||
| 	for (auto& observedEntity : m_ObservedEntities) { | ||||
| 		if (observedEntity == 0) continue; | ||||
|  | ||||
| 		if (id == 0) { | ||||
| 			continue; | ||||
| 		} | ||||
|  | ||||
| 		auto* entity = Game::entityManager->GetGhostCandidate(id); | ||||
|  | ||||
| 		if (entity != nullptr) { | ||||
| 			entity->SetObservers(entity->GetObservers() - 1); | ||||
| 		} | ||||
| 		auto* entity = Game::entityManager->GetGhostCandidate(observedEntity); | ||||
| 		if (!entity) continue; | ||||
| 		 | ||||
| 		entity->SetObservers(entity->GetObservers() - 1); | ||||
| 	} | ||||
|  | ||||
| 	m_LimboConstructions.clear(); | ||||
|  | ||||
| 	const auto& iter = std::find(m_Players.begin(), m_Players.end(), this); | ||||
| 	const auto iter = std::find(m_Players.begin(), m_Players.end(), this); | ||||
|  | ||||
| 	if (iter == m_Players.end()) { | ||||
| 		return; | ||||
|   | ||||
| @@ -18,64 +18,44 @@ public: | ||||
| 	 * Getters | ||||
| 	 */ | ||||
|  | ||||
| 	User* GetParentUser() const override; | ||||
| 	User* GetParentUser() const override { return m_ParentUser; }; | ||||
|  | ||||
| 	SystemAddress GetSystemAddress() const override; | ||||
| 	const SystemAddress& GetSystemAddress() const override { return m_SystemAddress; }; | ||||
|  | ||||
| 	NiPoint3 GetRespawnPosition() const override; | ||||
| 	const NiPoint3& GetRespawnPosition() const override { return m_respawnPos; }; | ||||
|  | ||||
| 	NiQuaternion GetRespawnRotation() const override; | ||||
| 	const NiQuaternion& GetRespawnRotation() const override { return m_respawnRot; }; | ||||
|  | ||||
| 	const NiPoint3& GetGhostReferencePoint() const; | ||||
| 	const NiPoint3& GetGhostReferencePoint() const { return m_GhostOverride ? m_GhostOverridePoint : m_GhostReferencePoint; }; | ||||
|  | ||||
| 	const NiPoint3& GetOriginGhostReferencePoint() const; | ||||
| 	const NiPoint3& GetOriginGhostReferencePoint() const { return m_GhostReferencePoint; }; | ||||
|  | ||||
| 	const NiPoint3& GetGhostOverridePoint() const; | ||||
| 	const NiPoint3& GetGhostOverridePoint() const { return m_GhostOverridePoint; }; | ||||
|  | ||||
| 	bool GetGhostOverride() const; | ||||
| 	bool GetGhostOverride() const { return m_GhostOverride; }; | ||||
|  | ||||
| 	std::map<LWOOBJID, Loot::Info>& GetDroppedLoot(); | ||||
| 	std::map<LWOOBJID, Loot::Info>& GetDroppedLoot() { return m_DroppedLoot; }; | ||||
|  | ||||
| 	uint64_t GetDroppedCoins(); | ||||
| 	uint64_t GetDroppedCoins() const { return m_DroppedCoins; }; | ||||
|  | ||||
| 	/** | ||||
| 	 * Setters | ||||
| 	 */ | ||||
|  | ||||
| 	void SetGhostOverride(bool value) { m_GhostOverride = value; }; | ||||
|  | ||||
| 	void SetDroppedCoins(const uint64_t value) { m_DroppedCoins = value; }; | ||||
|  | ||||
| 	void SetSystemAddress(const SystemAddress& value) override; | ||||
|  | ||||
| 	void SetRespawnPos(NiPoint3 position) override; | ||||
| 	void SetRespawnPos(const NiPoint3& position) override; | ||||
|  | ||||
| 	void SetRespawnRot(NiQuaternion rotation) override; | ||||
| 	void SetRespawnRot(const NiQuaternion& rotation) override; | ||||
|  | ||||
| 	void SetGhostReferencePoint(const NiPoint3& value); | ||||
|  | ||||
| 	void SetGhostOverridePoint(const NiPoint3& value); | ||||
|  | ||||
| 	void SetGhostOverride(bool value); | ||||
|  | ||||
| 	void SetDroppedCoins(uint64_t value); | ||||
|  | ||||
| 	/** | ||||
| 	 * Wrapper for sending an in-game mail. | ||||
| 	 * | ||||
| 	 * @param sender id of the sender. LWOOBJID_EMPTY for system mail | ||||
| 	 * @param senderName name of the sender. Max 32 characters. | ||||
| 	 * @param subject mail subject. Max 50 characters. | ||||
| 	 * @param body mail body. Max 400 characters. | ||||
| 	 * @param attachment LOT of the attached item. LOT_NULL if no attachment. | ||||
| 	 * @param attachmentCount stack size for attachment. | ||||
| 	 */ | ||||
| 	void SendMail(LWOOBJID sender, const std::string& senderName, const std::string& subject, const std::string& body, LOT attachment, uint16_t attachmentCount) const; | ||||
|  | ||||
| 	/** | ||||
| 	 * Wrapper for transfering the player to another instance. | ||||
| 	 * | ||||
| 	 * @param zoneId zoneID for the new instance. | ||||
| 	 * @param cloneId cloneID for the new instance. | ||||
| 	 */ | ||||
| 	void SendToZone(LWOMAPID zoneId, LWOCLONEID cloneId = 0); | ||||
|  | ||||
| 	/** | ||||
| 	 * Ghosting | ||||
| 	 */ | ||||
| @@ -86,11 +66,11 @@ public: | ||||
|  | ||||
| 	void ConstructLimboEntities(); | ||||
|  | ||||
| 	void ObserveEntity(int32_t id); | ||||
| 	void ObserveEntity(const int32_t id); | ||||
|  | ||||
| 	bool IsObserved(int32_t id); | ||||
| 	bool IsObserved(const int32_t id); | ||||
|  | ||||
| 	void GhostEntity(int32_t id); | ||||
| 	void GhostEntity(const int32_t id); | ||||
|  | ||||
| 	/** | ||||
| 	 * Static methods | ||||
| @@ -122,15 +102,9 @@ private: | ||||
|  | ||||
| 	std::vector<int32_t> m_ObservedEntities; | ||||
|  | ||||
| 	int32_t m_ObservedEntitiesLength; | ||||
|  | ||||
| 	int32_t m_ObservedEntitiesUsed; | ||||
|  | ||||
| 	std::vector<LWOOBJID> m_LimboConstructions; | ||||
|  | ||||
| 	std::map<LWOOBJID, Loot::Info> m_DroppedLoot; | ||||
|  | ||||
| 	uint64_t m_DroppedCoins; | ||||
|  | ||||
| 	static std::vector<Player*> m_Players; | ||||
| }; | ||||
|   | ||||
| @@ -20,6 +20,8 @@ | ||||
| #include "Database.h" | ||||
| #include "CDRewardCodesTable.h" | ||||
| #include "Mail.h" | ||||
| #include "ZoneInstanceManager.h" | ||||
| #include "WorldPackets.h" | ||||
| #include <ctime> | ||||
|  | ||||
| CharacterComponent::CharacterComponent(Entity* parent, Character* character) : Component(parent) { | ||||
| @@ -763,12 +765,12 @@ void CharacterComponent::AwardClaimCodes() { | ||||
| 	if (!m_Parent) return; | ||||
| 	auto* user = m_Parent->GetParentUser(); | ||||
| 	if (!user) return; | ||||
| 	 | ||||
|  | ||||
| 	auto rewardCodes = Database::Get()->GetRewardCodesByAccountID(user->GetAccountID()); | ||||
| 	if (rewardCodes.empty()) return; | ||||
|  | ||||
| 	auto* cdrewardCodes = CDClientManager::Instance().GetTable<CDRewardCodesTable>(); | ||||
| 	for (auto const rewardCode: rewardCodes){ | ||||
| 	for (auto const rewardCode : rewardCodes) { | ||||
| 		LOG_DEBUG("Processing RewardCode %i", rewardCode); | ||||
| 		const uint32_t rewardCodeIndex = rewardCode >> 6; | ||||
| 		const uint32_t bitIndex = rewardCode % 64; | ||||
| @@ -786,3 +788,32 @@ void CharacterComponent::AwardClaimCodes() { | ||||
| 		Mail::SendMail(LWOOBJID_EMPTY, "%[MAIL_SYSTEM_NOTIFICATION]", m_Parent, subject.str(), body.str(), attachmentLOT, 1); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void CharacterComponent::SendToZone(LWOMAPID zoneId, LWOCLONEID cloneId) const { | ||||
| 	const auto objid = m_Parent->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 = Game::entityManager->GetEntity(objid); | ||||
|  | ||||
| 		if (!entity) return; | ||||
|  | ||||
| 		const auto sysAddr = entity->GetSystemAddress(); | ||||
|  | ||||
| 		auto* character = entity->GetCharacter(); | ||||
| 		auto* characterComponent = entity->GetComponent<CharacterComponent>(); | ||||
|  | ||||
| 		if (character && characterComponent) { | ||||
| 			character->SetZoneID(zoneID); | ||||
| 			character->SetZoneInstance(zoneInstance); | ||||
| 			character->SetZoneClone(zoneClone); | ||||
|  | ||||
| 			characterComponent->SetLastRocketConfig(u""); | ||||
|  | ||||
| 			character->SaveXMLToDatabase(); | ||||
| 		} | ||||
|  | ||||
| 		WorldPackets::SendTransferToWorld(sysAddr, serverIP, serverPort, mythranShift); | ||||
|  | ||||
| 		Game::entityManager->DestructEntity(entity); | ||||
| 		}); | ||||
| } | ||||
|   | ||||
| @@ -281,6 +281,14 @@ public: | ||||
|  | ||||
| 	LWOOBJID GetCurrentInteracting() {return m_CurrentInteracting;}; | ||||
|  | ||||
| 	/** | ||||
| 	 * Sends a player to another zone with an optional clone ID | ||||
| 	 * | ||||
| 	 * @param zoneId zoneID for the new instance. | ||||
| 	 * @param cloneId cloneID for the new instance. | ||||
| 	 */ | ||||
| 	void SendToZone(LWOMAPID zoneId, LWOCLONEID cloneId = 0) const; | ||||
|  | ||||
| 	/** | ||||
| 	 * Character info regarding this character, including clothing styles, etc. | ||||
| 	 */ | ||||
|   | ||||
| @@ -31,6 +31,7 @@ | ||||
| #include "eMissionTaskType.h" | ||||
| #include "eStateChangeType.h" | ||||
| #include "eUseItemResponse.h" | ||||
| #include "Mail.h" | ||||
|  | ||||
| #include "CDComponentsRegistryTable.h" | ||||
| #include "CDInventoryComponentTable.h" | ||||
| @@ -264,17 +265,11 @@ void InventoryComponent::AddItem( | ||||
| 		} | ||||
|  | ||||
| 		if (slot == -1) { | ||||
| 			auto* player = dynamic_cast<Player*>(GetParent()); | ||||
|  | ||||
| 			if (player == nullptr) { | ||||
| 				return; | ||||
| 			} | ||||
|  | ||||
| 			outOfSpace += size; | ||||
|  | ||||
| 			switch (sourceType) { | ||||
| 			case 0: | ||||
| 				player->SendMail(LWOOBJID_EMPTY, "Darkflame Universe", "Lost Reward", "You received an item and didn't have room for it.", lot, size); | ||||
| 				Mail::SendMail(LWOOBJID_EMPTY, "Darkflame Universe", m_Parent, "Lost Reward", "You received an item and didn't have room for it.", lot, size); | ||||
| 				break; | ||||
|  | ||||
| 			case 1: | ||||
|   | ||||
| @@ -20,6 +20,7 @@ | ||||
| #include "InventoryComponent.h" | ||||
| #include "eMissionTaskType.h" | ||||
| #include "eObjectBits.h" | ||||
| #include "CharacterComponent.h" | ||||
|  | ||||
| #include <vector> | ||||
| #include "CppScripts.h" | ||||
| @@ -247,7 +248,8 @@ void PropertyManagementComponent::OnStartBuilding() { | ||||
| 	for (auto* player : players) { | ||||
| 		if (player == ownerEntity) continue; | ||||
|  | ||||
| 		player->SendToZone(zoneId); | ||||
| 		auto* characterComponent = player->GetComponent<CharacterComponent>(); | ||||
| 		if (characterComponent) characterComponent->SendToZone(zoneId); | ||||
| 	} | ||||
| 	auto inventoryComponent = ownerEntity->GetComponent<InventoryComponent>(); | ||||
|  | ||||
|   | ||||
| @@ -71,10 +71,8 @@ void RacingControlComponent::OnPlayerLoaded(Entity* player) { | ||||
|  | ||||
| 	// If the race has already started, send the player back to the main world. | ||||
| 	if (m_Loaded || !vehicle) { | ||||
| 		auto* playerInstance = dynamic_cast<Player*>(player); | ||||
| 		if (playerInstance) { | ||||
| 			playerInstance->SendToZone(m_MainWorld); | ||||
| 		} | ||||
| 		auto* characterComponent = player->GetComponent<CharacterComponent>(); | ||||
| 		if (characterComponent) characterComponent->SendToZone(m_MainWorld); | ||||
| 		return; | ||||
| 	} | ||||
|  | ||||
| @@ -105,10 +103,11 @@ void RacingControlComponent::LoadPlayerVehicle(Entity* player, | ||||
|  | ||||
| 	if (item == nullptr) { | ||||
| 		LOG("Failed to find item"); | ||||
| 		auto* playerInstance = dynamic_cast<Player*>(player); | ||||
| 		if (playerInstance) { | ||||
| 		auto* characterComponent = player->GetComponent<CharacterComponent>(); | ||||
|  | ||||
| 		if (characterComponent) { | ||||
| 			m_LoadedPlayers--; | ||||
| 			playerInstance->SendToZone(m_MainWorld); | ||||
| 			characterComponent->SendToZone(m_MainWorld); | ||||
| 		} | ||||
| 		return; | ||||
|  | ||||
| @@ -427,9 +426,9 @@ void RacingControlComponent::HandleMessageBoxResponse(Entity* player, int32_t bu | ||||
| 			m_Parent->GetObjectID(), 3, 0, LWOOBJID_EMPTY, u"", | ||||
| 			player->GetObjectID(), UNASSIGNED_SYSTEM_ADDRESS); | ||||
|  | ||||
| 		auto* playerInstance = dynamic_cast<Player*>(player); | ||||
| 		auto* characterComponent = player->GetComponent<CharacterComponent>(); | ||||
|  | ||||
| 		playerInstance->SendToZone(m_MainWorld); | ||||
| 		if (characterComponent) characterComponent->SendToZone(m_MainWorld); | ||||
|  | ||||
| 		vehicle->Kill(); | ||||
| 	} | ||||
| @@ -561,9 +560,9 @@ void RacingControlComponent::Update(float deltaTime) { | ||||
| 					continue; | ||||
| 				} | ||||
|  | ||||
| 				auto* playerInstance = dynamic_cast<Player*>(playerEntity); | ||||
| 				auto* characterComponent = playerEntity->GetComponent<CharacterComponent>(); | ||||
|  | ||||
| 				playerInstance->SendToZone(m_MainWorld); | ||||
| 				if (characterComponent) characterComponent->SendToZone(m_MainWorld); | ||||
| 			} | ||||
|  | ||||
| 			m_LobbyPlayers.clear(); | ||||
| @@ -623,9 +622,9 @@ void RacingControlComponent::Update(float deltaTime) { | ||||
| 					continue; | ||||
| 				} | ||||
|  | ||||
| 				auto* playerInstance = dynamic_cast<Player*>(playerEntity); | ||||
| 				auto* characterComponent = playerEntity->GetComponent<CharacterComponent>(); | ||||
|  | ||||
| 				playerInstance->SendToZone(m_MainWorld); | ||||
| 				if (characterComponent) characterComponent->SendToZone(m_MainWorld); | ||||
| 			} | ||||
|  | ||||
| 			return; | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
| #include "BaseConsoleTeleportServer.h" | ||||
| #include "GameMessages.h" | ||||
| #include "Player.h" | ||||
| #include "CharacterComponent.h" | ||||
| #include "RenderComponent.h" | ||||
| #include "EntityManager.h" | ||||
| #include "eTerminateType.h" | ||||
| @@ -94,7 +94,9 @@ void BaseConsoleTeleportServer::TransferPlayer(Entity* self, Entity* player, int | ||||
|  | ||||
| 	const auto& teleportZone = self->GetVar<std::u16string>(u"transferZoneID"); | ||||
|  | ||||
| 	static_cast<Player*>(player)->SendToZone(std::stoi(GeneralUtils::UTF16ToWTF8(teleportZone))); | ||||
| 	auto* characterComponent = player->GetComponent<CharacterComponent>(); | ||||
|  | ||||
| 	if (characterComponent) characterComponent->SendToZone(std::stoi(GeneralUtils::UTF16ToWTF8(teleportZone))); | ||||
|  | ||||
| 	UpdatePlayerTable(self, player, false); | ||||
| } | ||||
|   | ||||
| @@ -3,7 +3,7 @@ | ||||
| #include "DestroyableComponent.h" | ||||
| #include "EntityManager.h" | ||||
| #include "dZoneManager.h" | ||||
| #include "Player.h" | ||||
| #include "CharacterComponent.h" | ||||
| #include "eMissionTaskType.h" | ||||
| #include "eMissionState.h" | ||||
| #include "MissionComponent.h" | ||||
| @@ -23,7 +23,8 @@ void BaseSurvivalServer::BasePlayerLoaded(Entity* self, Entity* player) { | ||||
| 	const auto& playersIter = std::find(state.players.begin(), state.players.end(), player->GetObjectID()); | ||||
|  | ||||
| 	if (waitingIter != state.waitingPlayers.end() || playersIter != state.players.end()) { | ||||
| 		static_cast<Player*>(player)->SendToZone(player->GetCharacter()->GetLastNonInstanceZoneID()); | ||||
| 		auto* characterComponent = player->GetComponent<CharacterComponent>(); | ||||
| 		if (characterComponent) characterComponent->SendToZone(player->GetCharacter()->GetLastNonInstanceZoneID()); | ||||
|  | ||||
| 		return; | ||||
| 	} | ||||
| @@ -161,8 +162,8 @@ void BaseSurvivalServer::BaseMessageBoxResponse(Entity* self, Entity* sender, in | ||||
| 		if (sender->IsPlayer()) { | ||||
| 			auto* character = sender->GetCharacter(); | ||||
| 			if (character != nullptr) { | ||||
| 				auto* player = dynamic_cast<Player*>(sender); | ||||
| 				player->SendToZone(character->GetLastNonInstanceZoneID()); | ||||
| 				auto* characterComponent = sender->GetComponent<CharacterComponent>(); | ||||
| 				if (characterComponent) characterComponent->SendToZone(character->GetLastNonInstanceZoneID()); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|   | ||||
| @@ -3,7 +3,7 @@ | ||||
| #include "DestroyableComponent.h" | ||||
| #include "EntityManager.h" | ||||
| #include "dZoneManager.h" | ||||
| #include "Player.h" | ||||
| #include "CharacterComponent.h" | ||||
| #include "eMissionTaskType.h" | ||||
| #include "eMissionState.h" | ||||
| #include "MissionComponent.h" | ||||
| @@ -162,8 +162,8 @@ void BaseWavesServer::BaseMessageBoxResponse(Entity* self, Entity* sender, int32 | ||||
| 		if (sender->IsPlayer()) { | ||||
| 			auto* character = sender->GetCharacter(); | ||||
| 			if (character != nullptr) { | ||||
| 				auto* player = dynamic_cast<Player*>(sender); | ||||
| 				player->SendToZone(character->GetLastNonInstanceZoneID()); | ||||
| 				auto* characterComponent = sender->GetComponent<CharacterComponent>(); | ||||
| 				if (characterComponent) characterComponent->SendToZone(character->GetLastNonInstanceZoneID()); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|   | ||||
| @@ -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); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
|   | ||||
| @@ -461,8 +461,9 @@ void SGCannon::RemovePlayer(LWOOBJID playerID) { | ||||
| 		return; | ||||
|  | ||||
| 	auto* character = playerObject->GetCharacter(); | ||||
| 	if (character != nullptr) { | ||||
| 		playerObject->SendToZone(character->GetLastNonInstanceZoneID()); | ||||
| 	auto* characterComponent = playerObject->GetComponent<CharacterComponent>(); | ||||
| 	if (characterComponent && character) { | ||||
| 		characterComponent->SendToZone(character->GetLastNonInstanceZoneID()); | ||||
| 	} | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -1,10 +1,11 @@ | ||||
| #include "WblGenericZone.h" | ||||
| #include "Player.h" | ||||
| #include "CharacterComponent.h" | ||||
|  | ||||
| void WblGenericZone::OnFireEventServerSide(Entity* self, Entity* sender, std::string args, int32_t param1, int32_t param2, int32_t param3) { | ||||
| 	if (args == m_WblAbortMsg) { | ||||
| 		if (!sender) return; | ||||
| 		auto player = dynamic_cast<Player*>(sender); | ||||
| 		if (player) player->SendToZone(m_WblMainZone); | ||||
|  | ||||
| 		auto* characterComponent = sender->GetComponent<CharacterComponent>(); | ||||
| 		if (characterComponent) characterComponent->SendToZone(m_WblMainZone); | ||||
| 	} | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 David Markowitz
					David Markowitz