mirror of
				https://github.com/DarkflameUniverse/DarkflameServer.git
				synced 2025-10-31 04:32:06 +00:00 
			
		
		
		
	Merge branch 'main' into object-debugger-stuff
This commit is contained in:
		| @@ -5,16 +5,17 @@ | ||||
|  | ||||
| #include "Entity.h" | ||||
| #include "ScriptComponent.h" | ||||
| #include "GameMessages.h" | ||||
| #include "Amf3.h" | ||||
|  | ||||
| ScriptComponent::ScriptComponent(Entity* parent, const int32_t componentID, std::string scriptName, bool serialized, bool client) : Component(parent, componentID) { | ||||
| ScriptComponent::ScriptComponent(Entity* parent, const int32_t componentID, const std::string& scriptName, bool serialized, bool client) : Component(parent, componentID) { | ||||
| 	using namespace GameMessages; | ||||
| 	m_Serialized = serialized; | ||||
| 	m_Client = client; | ||||
| 	m_ScriptName = scriptName; | ||||
|  | ||||
| 	SetScript(scriptName); | ||||
| } | ||||
|  | ||||
| ScriptComponent::~ScriptComponent() { | ||||
|  | ||||
| 	RegisterMsg<GetObjectReportInfo>(this, &ScriptComponent::OnGetObjectReportInfo); | ||||
| } | ||||
|  | ||||
| void ScriptComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) { | ||||
| @@ -50,3 +51,16 @@ void ScriptComponent::SetScript(const std::string& scriptName) { | ||||
| 	// and they may also be used by other script components so DON'T delete them. | ||||
| 	m_Script = CppScripts::GetScript(m_Parent, scriptName); | ||||
| } | ||||
|  | ||||
| bool ScriptComponent::OnGetObjectReportInfo(GameMessages::GameMsg& msg) { | ||||
| 	auto& infoMsg = static_cast<GameMessages::GetObjectReportInfo&>(msg); | ||||
|  | ||||
| 	auto& scriptInfo = infoMsg.info->PushDebug("Script"); | ||||
| 	scriptInfo.PushDebug<AMFStringValue>("Script Name") = m_ScriptName.empty() ? "None" : m_ScriptName; | ||||
| 	auto& networkSettings = scriptInfo.PushDebug("Network Settings"); | ||||
| 	for (const auto* const setting : m_Parent->GetNetworkSettings()) { | ||||
| 		networkSettings.PushDebug<AMFStringValue>(GeneralUtils::UTF16ToWTF8(setting->GetKey())) = setting->GetValueAsString(); | ||||
| 	} | ||||
|  | ||||
| 	return true; | ||||
| } | ||||
|   | ||||
| @@ -21,8 +21,7 @@ class ScriptComponent final : public Component { | ||||
| public: | ||||
| 	static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::SCRIPT; | ||||
|  | ||||
| 	ScriptComponent(Entity* parent, const int32_t componentID, std::string scriptName, bool serialized, bool client); | ||||
| 	~ScriptComponent() override; | ||||
| 	ScriptComponent(Entity* parent, const int32_t componentID, const std::string& scriptName, bool serialized, bool client = false); | ||||
|  | ||||
| 	void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override; | ||||
|  | ||||
| @@ -43,6 +42,8 @@ public: | ||||
| 	 * @param scriptName the name of the script to find | ||||
| 	 */ | ||||
| 	void SetScript(const std::string& scriptName); | ||||
| 	 | ||||
| 	bool OnGetObjectReportInfo(GameMessages::GameMsg& msg); | ||||
|  | ||||
| private: | ||||
|  | ||||
| @@ -60,6 +61,8 @@ private: | ||||
| 	 * Whether or not this script is a client script | ||||
| 	 */ | ||||
| 	bool m_Client; | ||||
|  | ||||
| 	std::string m_ScriptName; | ||||
| }; | ||||
|  | ||||
| #endif // SCRIPTCOMPONENT_H | ||||
|   | ||||
| @@ -7,6 +7,8 @@ | ||||
| #include "CDClientManager.h" | ||||
| #include "CDObjectSkillsTable.h" | ||||
| #include "RenderComponent.h" | ||||
| #include "TeamManager.h" | ||||
| #include "ProximityMonitorComponent.h" | ||||
|  | ||||
| //TODO: this has to be updated so that you only get killed if you're in a certain radius. | ||||
| //And so that all entities in a certain radius are killed, not just the attacker. | ||||
| @@ -17,22 +19,40 @@ void ExplodingAsset::OnStartup(Entity* self) { | ||||
| 	self->SetProximityRadius(10.0f, "crateHitters"); | ||||
| } | ||||
|  | ||||
| void ExplodingAsset::ProgressPlayerMissions(Entity& self, Entity& player) { | ||||
| 	const auto missionID = self.GetVar<int32_t>(u"missionID"); | ||||
| 	auto achievementIDs = self.GetVarAsString(u"achieveID"); | ||||
| 	auto* const missionComponent = player.GetComponent<MissionComponent>(); | ||||
| 	if (missionComponent) { | ||||
| 		if (missionID != 0) { | ||||
| 			missionComponent->ForceProgressValue(missionID, | ||||
| 				static_cast<uint32_t>(eMissionTaskType::SCRIPT), | ||||
| 				self.GetLOT(), false); | ||||
| 		} | ||||
|  | ||||
| 		if (!achievementIDs.empty()) { | ||||
| 			for (const auto& achievementID : GeneralUtils::SplitString(achievementIDs, u'_')) { | ||||
| 				const auto achievementIDInt = GeneralUtils::TryParse<int32_t>(achievementID); | ||||
| 				if (!achievementIDInt) continue; | ||||
| 				missionComponent->ForceProgressValue(achievementIDInt.value(), | ||||
| 					static_cast<uint32_t>(eMissionTaskType::SCRIPT), | ||||
| 					self.GetLOT()); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void ExplodingAsset::OnHit(Entity* self, Entity* attacker) { | ||||
| 	std::vector<Entity*> entities; | ||||
| 	entities.push_back(attacker); | ||||
| 	const auto* const proximityComponent = self->GetComponent<ProximityMonitorComponent>(); | ||||
| 	if (!proximityComponent) return; | ||||
|  | ||||
| 	if (!self->GetBoolean(u"bIsHit")) { | ||||
| 		for (Entity* en : entities) { | ||||
| 			if (en->GetObjectID() == attacker->GetObjectID()) { | ||||
| 				if (Vector3::DistanceSquared(en->GetPosition(), self->GetPosition()) > 10 * 10) continue; | ||||
| 		for (const auto objID : proximityComponent->GetProximityObjects("crateHitters")) { | ||||
| 			auto* const entity = Game::entityManager->GetEntity(objID); | ||||
| 			if (!entity) continue; | ||||
|  | ||||
| 				auto* destroyable = en->GetComponent<DestroyableComponent>(); | ||||
| 				if (destroyable == nullptr) { | ||||
| 					continue; | ||||
| 				} | ||||
|  | ||||
| 				destroyable->Smash(attacker->GetObjectID()); | ||||
| 			} | ||||
| 			auto* const destroyable = entity->GetComponent<DestroyableComponent>(); | ||||
| 			if (destroyable) destroyable->Smash(attacker->GetObjectID()); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| @@ -48,26 +68,17 @@ void ExplodingAsset::OnHit(Entity* self, Entity* attacker) { | ||||
| 		// Technically supposed to get first skill in the skill component but only 1 object in the live game used this. | ||||
| 		skillComponent->CalculateBehavior(147, 4721, LWOOBJID_EMPTY, true); | ||||
| 	} | ||||
|  | ||||
| 	const auto missionID = self->GetVar<int32_t>(u"missionID"); | ||||
| 	auto achievementIDs = self->GetVar<std::u16string>(u"achieveID"); | ||||
|  | ||||
| 	const auto* const team = TeamManager::Instance()->GetTeam(attacker->GetObjectID()); | ||||
| 	// Progress all scripted missions related to this asset | ||||
| 	auto* missionComponent = attacker->GetComponent<MissionComponent>(); | ||||
| 	if (missionComponent != nullptr) { | ||||
| 		if (missionID != 0) { | ||||
| 			missionComponent->ForceProgressValue(missionID, | ||||
| 				static_cast<uint32_t>(eMissionTaskType::SCRIPT), | ||||
| 				self->GetLOT(), false); | ||||
| 		} | ||||
|  | ||||
| 		if (!achievementIDs.empty()) { | ||||
| 			for (const auto& achievementID : GeneralUtils::SplitString(achievementIDs, u'_')) { | ||||
| 				missionComponent->ForceProgressValue(std::stoi(GeneralUtils::UTF16ToWTF8(achievementID)), | ||||
| 					static_cast<uint32_t>(eMissionTaskType::SCRIPT), | ||||
| 					self->GetLOT()); | ||||
| 	if (team) { | ||||
| 		for (const auto& member : team->members) { | ||||
| 			auto* const memberEntity = Game::entityManager->GetEntity(member); | ||||
| 			if (memberEntity) { | ||||
| 				ProgressPlayerMissions(*self, *memberEntity); | ||||
| 			} | ||||
| 		} | ||||
| 	} else { | ||||
| 		ProgressPlayerMissions(*self, *attacker); | ||||
| 	} | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -4,7 +4,8 @@ | ||||
| class ExplodingAsset : public CppScripts::Script | ||||
| { | ||||
| public: | ||||
| 	void OnStartup(Entity* self); | ||||
| 	void OnHit(Entity* self, Entity* attacker); | ||||
| 	void OnProximityUpdate(Entity* self, Entity* entering, std::string name, std::string status); | ||||
| 	void OnStartup(Entity* self) override; | ||||
| 	void OnHit(Entity* self, Entity* attacker) override; | ||||
| 	void OnProximityUpdate(Entity* self, Entity* entering, std::string name, std::string status) override; | ||||
| 	void ProgressPlayerMissions(Entity& self, Entity& player); | ||||
| }; | ||||
|   | ||||
| @@ -1126,6 +1126,13 @@ void HandlePacket(Packet* packet) { | ||||
| 				// Update the characters xml to ensure the update above is not only saved, but so the client picks up on the changes. | ||||
| 				c->SaveXMLToDatabase(); | ||||
|  | ||||
| 				// Fix the destroyable component | ||||
| 				auto* destroyableComponent = player->GetComponent<DestroyableComponent>(); | ||||
|  | ||||
| 				if (destroyableComponent != nullptr) { | ||||
| 					destroyableComponent->FixStats(); | ||||
| 				} | ||||
|  | ||||
| 				WorldPackets::SendCreateCharacter(packet->systemAddress, characterComponent->GetReputation(), player->GetObjectID(), c->GetXMLData(), username, c->GetGMLevel(), c->GetPropertyCloneID()); | ||||
| 				WorldPackets::SendServerState(packet->systemAddress); | ||||
|  | ||||
| @@ -1143,13 +1150,6 @@ void HandlePacket(Packet* packet) { | ||||
|  | ||||
| 				player->GetCharacter()->SetTargetScene(""); | ||||
|  | ||||
| 				// Fix the destroyable component | ||||
| 				auto* destroyableComponent = player->GetComponent<DestroyableComponent>(); | ||||
|  | ||||
| 				if (destroyableComponent != nullptr) { | ||||
| 					destroyableComponent->FixStats(); | ||||
| 				} | ||||
|  | ||||
| 				//Tell the player to generate BBB models, if any: | ||||
| 				if (g_CloneID != 0) { | ||||
| 					const auto& worldId = Game::zoneManager->GetZone()->GetZoneID(); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 David Markowitz
					David Markowitz