mirror of
				https://github.com/DarkflameUniverse/DarkflameServer.git
				synced 2025-10-30 20:22:04 +00:00 
			
		
		
		
	buffs
This commit is contained in:
		| @@ -6,7 +6,9 @@ | ||||
|  | ||||
|  | ||||
| void ApplyBuffBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) { | ||||
| 	auto* entity = EntityManager::Instance()->GetEntity(branch.target == LWOOBJID_EMPTY ? context->originator : branch.target); | ||||
| 	branch.target == LWOOBJID_EMPTY ? context->originator : branch.target; | ||||
| 	if (m_TargetCaster) branch.target = context->originator; | ||||
| 	auto* entity = EntityManager::Instance()->GetEntity(branch.target); | ||||
|  | ||||
| 	if (entity == nullptr) return; | ||||
|  | ||||
| @@ -14,11 +16,12 @@ void ApplyBuffBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitS | ||||
|  | ||||
| 	if (buffComponent == nullptr) return; | ||||
|  | ||||
| 	buffComponent->ApplyBuff(m_BuffId, m_Duration, context->originator, addImmunity, cancelOnDamaged, cancelOnDeath, | ||||
| 		cancelOnLogout, cancelonRemoveBuff, cancelOnUi, cancelOnUnequip, cancelOnZone); | ||||
| 	buffComponent->ApplyBuff(m_BuffId, m_Duration, context->originator, m_AddImmunity, m_ApplyOnTeammates m_CancelOnDamaged, m_CancelOnDeath, | ||||
| 		m_CancelOnLogout, m_CancelOnRemoveBuff, m_CancelOnUi, m_CancelOnUnequip, m_CancelOnZone, m_CancelOnDamageAbsDone, m_UseRefCount); | ||||
| } | ||||
|  | ||||
| void ApplyBuffBehavior::UnCast(BehaviorContext* context, BehaviorBranchContext branch) { | ||||
| 	if (m_IgnoreUncast) return; | ||||
| 	auto* entity = EntityManager::Instance()->GetEntity(branch.target); | ||||
|  | ||||
| 	if (entity == nullptr) return; | ||||
| @@ -37,12 +40,17 @@ void ApplyBuffBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* b | ||||
| void ApplyBuffBehavior::Load() { | ||||
| 	m_BuffId = GetInt("buff_id"); | ||||
| 	m_Duration = GetFloat("duration_secs"); | ||||
| 	addImmunity = GetBoolean("add_immunity"); | ||||
| 	cancelOnDamaged = GetBoolean("cancel_on_damaged"); | ||||
| 	cancelOnDeath = GetBoolean("cancel_on_death"); | ||||
| 	cancelOnLogout = GetBoolean("cancel_on_logout"); | ||||
| 	cancelonRemoveBuff = GetBoolean("cancel_on_remove_buff"); | ||||
| 	cancelOnUi = GetBoolean("cancel_on_ui"); | ||||
| 	cancelOnUnequip = GetBoolean("cancel_on_unequip"); | ||||
| 	cancelOnZone = GetBoolean("cancel_on_zone"); | ||||
| 	m_IgnoreUncast = GetBoolean("ignore_uncast", false); | ||||
| 	m_TargetCaster = GetBoolean("target_caster", false); | ||||
| 	m_AddImmunity = GetBoolean("add_immunity", false); | ||||
| 	m_ApplyOnTeammates = GetBoolean("apply_on_teammates", false); | ||||
| 	m_CancelOnDamaged = GetBoolean("cancel_on_damaged", false); | ||||
| 	m_CancelOnDeath = GetBoolean("cancel_on_death", false); | ||||
| 	m_CancelOnLogout = GetBoolean("cancel_on_logout", false); | ||||
| 	m_CancelOnRemoveBuff = GetBoolean("cancel_on_remove_buff", false); | ||||
| 	m_CancelOnUi = GetBoolean("cancel_on_ui", false); | ||||
| 	m_CancelOnUnequip = GetBoolean("cancel_on_unequip", false); | ||||
| 	m_CancelOnZone = GetBoolean("cancel_on_zone", false); | ||||
| 	m_CancelOnDamageAbsDone = GetBoolean("cancel_on_damage_abs_done", false); | ||||
| 	m_UseRefCount =  GetBoolean("use_ref_count", false); | ||||
| } | ||||
|   | ||||
| @@ -7,18 +7,7 @@ | ||||
| class ApplyBuffBehavior final : public Behavior | ||||
| { | ||||
| public: | ||||
| 	int32_t m_BuffId; | ||||
| 	float m_Duration; | ||||
| 	bool addImmunity; | ||||
| 	bool cancelOnDamaged; | ||||
| 	bool cancelOnDeath; | ||||
| 	bool cancelOnLogout; | ||||
| 	bool cancelonRemoveBuff; | ||||
| 	bool cancelOnUi; | ||||
| 	bool cancelOnUnequip; | ||||
| 	bool cancelOnZone; | ||||
|  | ||||
| 	/* | ||||
| 		/* | ||||
| 	 * Inherited | ||||
| 	 */ | ||||
| 	explicit ApplyBuffBehavior(const uint32_t behaviorId) : Behavior(behaviorId) { | ||||
| @@ -31,4 +20,21 @@ public: | ||||
| 	void Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override; | ||||
|  | ||||
| 	void Load() override; | ||||
|  | ||||
| private: | ||||
| 	int32_t m_BuffId; | ||||
| 	float m_Duration; | ||||
| 	bool m_IgnoreUncast; | ||||
| 	bool m_TargetCaster; | ||||
| 	bool m_AddImmunity; | ||||
| 	bool m_ApplyOnTeammates; | ||||
| 	bool m_CancelOnDamaged; | ||||
| 	bool m_CancelOnDeath; | ||||
| 	bool m_CancelOnLogout; | ||||
| 	bool m_CancelOnRemoveBuff; | ||||
| 	bool m_CancelOnUi; | ||||
| 	bool m_CancelOnUnequip; | ||||
| 	bool m_CancelOnZone; | ||||
| 	bool m_CancelOnDamageAbsDone; | ||||
| 	bool m_UseRefCount; | ||||
| }; | ||||
|   | ||||
| @@ -21,6 +21,8 @@ BuffComponent::~BuffComponent() { | ||||
|  | ||||
| void BuffComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) { | ||||
| 	if (!bIsInitialUpdate) return; | ||||
|  | ||||
| 	// if we have buffs | ||||
| 	if (m_Buffs.empty()) { | ||||
| 		outBitStream->Write0(); | ||||
| 	} else { | ||||
| @@ -29,24 +31,25 @@ void BuffComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUp | ||||
|  | ||||
| 		for (const auto& buff : m_Buffs) { | ||||
| 			outBitStream->Write<uint32_t>(buff.first); | ||||
| 			outBitStream->Write0(); | ||||
| 			outBitStream->Write0(); | ||||
| 			outBitStream->Write0(); | ||||
| 			outBitStream->Write0(); | ||||
| 			outBitStream->Write0(); | ||||
| 			outBitStream->Write0(); | ||||
| 			outBitStream->Write0(); | ||||
| 			outBitStream->Write0(); | ||||
| 			outBitStream->Write0(); | ||||
| 			outBitStream->Write(buff.second.time); // time left | ||||
| 			outBitStream->Write(buff.second.cancelOnDeath); // cancel on death | ||||
| 			outBitStream->Write(buff.second.cancelOnZone); // cancel on zone | ||||
| 			outBitStream->Write(buff.second.cancelOnDamaged); // cancel on damage | ||||
| 			outBitStream->Write(buff.second.cancelOnRemoveBuff); // cancel on remove buff | ||||
| 			outBitStream->Write(buff.second.cancelOnUi); // cancel on UI | ||||
| 			outBitStream->Write(buff.second.cancelOnLogout); // cancel on logout | ||||
| 			outBitStream->Write(buff.second.cancelOnUnequip); // cancel on unequip | ||||
| 			outBitStream->Write0(); // cancel on damage asorb ran out | ||||
|  | ||||
| 			outBitStream->Write0(); | ||||
| 			outBitStream->Write0(); | ||||
| 			outBitStream->Write0(); // if added by team mate | ||||
| 									// teammate lwoobjid | ||||
| 			outBitStream->Write0(); //apply on team mate | ||||
|  | ||||
| 			outBitStream->Write<uint32_t>(0); | ||||
| 			outBitStream->Write(buff.second.refcount); // ref_count | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	outBitStream->Write0(); | ||||
| 	outBitStream->Write0(); // buff immunities | ||||
| } | ||||
|  | ||||
| void BuffComponent::Update(float deltaTime) { | ||||
| @@ -82,17 +85,23 @@ void BuffComponent::Update(float deltaTime) { | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void BuffComponent::ApplyBuff(const int32_t id, const float duration, const LWOOBJID source, bool addImmunity, | ||||
| void BuffComponent::ApplyBuff(const int32_t id, const float duration, const LWOOBJID source, | ||||
| 	bool addImmunity, bool applyOnTeammates, | ||||
| 	bool cancelOnDamaged, bool cancelOnDeath, bool cancelOnLogout, bool cancelOnRemoveBuff, | ||||
| 	bool cancelOnUi, bool cancelOnUnequip, bool cancelOnZone) { | ||||
| 	bool cancelOnUi, bool cancelOnUnequip, bool cancelOnZone, bool cancelOnDamageAbsDone, | ||||
| 	bool useRefCount) { | ||||
| 	// Prevent buffs from stacking. | ||||
|  | ||||
| 	if (HasBuff(id)) { | ||||
| 		return; | ||||
| 		if (useRefCount){ | ||||
| 			auto buff = m_Buffs.find(id); | ||||
| 		} else return; | ||||
| 	} | ||||
|  | ||||
| 	GameMessages::SendAddBuff(const_cast<LWOOBJID&>(m_Parent->GetObjectID()), source, (uint32_t)id, | ||||
| 		(uint32_t)duration * 1000, addImmunity, cancelOnDamaged, cancelOnDeath, | ||||
| 		cancelOnLogout, cancelOnRemoveBuff, cancelOnUi, cancelOnUnequip, cancelOnZone); | ||||
| 		(uint32_t)duration * 1000, addImmunity, applyOnTeammates, cancelOnDamaged, cancelOnDeath, | ||||
| 		cancelOnLogout, cancelOnRemoveBuff, cancelOnUi, cancelOnUnequip, cancelOnZone, cancelOnDamageAbsDone, | ||||
| 		useRefCount); | ||||
|  | ||||
| 	float tick = 0; | ||||
| 	float stacks = 0; | ||||
| @@ -120,7 +129,16 @@ void BuffComponent::ApplyBuff(const int32_t id, const float duration, const LWOO | ||||
| 	buff.stacks = stacks; | ||||
| 	buff.source = source; | ||||
| 	buff.behaviorID = behaviorID; | ||||
|  | ||||
| 	buff.addImmunity = addImmunity; | ||||
| 	buff.cancelOnDamaged = cancelOnDamaged; | ||||
| 	buff.cancelOnDeath = cancelOnDeath; | ||||
| 	buff.cancelOnLogout = cancelOnLogout; | ||||
| 	buff.cancelOnRemoveBuff = cancelOnRemoveBuff; | ||||
| 	buff.cancelOnUi = cancelOnUi; | ||||
| 	buff.cancelOnUnequip = cancelOnUnequip; | ||||
| 	buff.cancelOnZone = cancelOnZone; | ||||
| 	buff.useRefCount = useRefCount; | ||||
| 	buff.refcount = 1; | ||||
| 	m_Buffs.emplace(id, buff); | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -34,6 +34,19 @@ struct Buff | ||||
| 	int32_t stacks = 0; | ||||
| 	LWOOBJID source = 0; | ||||
| 	int32_t behaviorID = 0; | ||||
| 	bool addImmunity = false; | ||||
| 	bool cancelOnDamaged = false; | ||||
| 	bool cancelOnDeath = false; | ||||
| 	bool cancelOnLogout = false; | ||||
| 	bool cancelOnRemoveBuff = false; | ||||
| 	bool cancelOnDamageAbsDone = false; | ||||
| 	bool cancelOnUi = false; | ||||
| 	bool cancelOnUnequip = false; | ||||
| 	bool cancelOnZone = false; | ||||
| 	bool useRefCount = false; | ||||
|  | ||||
| 	uint32_t refcount = 1 | ||||
|  | ||||
| }; | ||||
|  | ||||
| /** | ||||
| @@ -63,6 +76,7 @@ public: | ||||
| 	 * @param duration the duration of the buff in seconds | ||||
| 	 * @param source an optional source entity that cast the buff | ||||
| 	 * @param addImmunity client flag | ||||
| 	 * @param applyOnTeammates should the buff apply on teammates | ||||
| 	 * @param cancelOnDamaged client flag to indicate that the buff should disappear when damaged | ||||
| 	 * @param cancelOnDeath client flag to indicate that the buff should disappear when dying | ||||
| 	 * @param cancelOnLogout client flag to indicate that the buff should disappear when logging out | ||||
| @@ -70,10 +84,13 @@ public: | ||||
| 	 * @param cancelOnUi client flag to indicate that the buff should disappear when interacting with UI | ||||
| 	 * @param cancelOnUnequip client flag to indicate that the buff should disappear when the triggering item is unequipped | ||||
| 	 * @param cancelOnZone client flag to indicate that the buff should disappear when changing zones | ||||
| 	 * @param cancelOnDamageAbsDone cancel if we have done damage absorbtion | ||||
| 	 * @param useRefCount client flag to indicate that the stacks | ||||
| 	 */ | ||||
| 	void ApplyBuff(int32_t id, float duration, LWOOBJID source, bool addImmunity = false, bool cancelOnDamaged = false, | ||||
| 		bool cancelOnDeath = true, bool cancelOnLogout = false, bool cancelOnRemoveBuff = true, | ||||
| 		bool cancelOnUi = false, bool cancelOnUnequip = false, bool cancelOnZone = false); | ||||
| 	void ApplyBuff(int32_t id, float duration, LWOOBJID source, bool addImmunity = false, bool applyOnTeammates = false, | ||||
| 		bool cancelOnDamaged = false, bool cancelOnDeath = true, bool cancelOnLogout = false, bool cancelOnRemoveBuff = true, | ||||
| 		bool cancelOnUi = false, bool cancelOnUnequip = false, bool cancelOnZone = false, bool cancelOnDamageAbsDone = false, | ||||
| 		bool useRefCount = false); | ||||
|  | ||||
| 	/** | ||||
| 	 * Removes a buff from the parent entity, reversing its effects | ||||
|   | ||||
| @@ -4438,8 +4438,10 @@ void GameMessages::SendVehicleNotifyFinishedRace(LWOOBJID objectId, const System | ||||
| } | ||||
|  | ||||
| void GameMessages::SendAddBuff(LWOOBJID& objectID, const LWOOBJID& casterID, uint32_t buffID, uint32_t msDuration, | ||||
| 	bool addImmunity, bool cancelOnDamaged, bool cancelOnDeath, bool cancelOnLogout, | ||||
| 	bool cancelOnRemoveBuff, bool cancelOnUi, bool cancelOnUnequip, bool cancelOnZone, | ||||
| 	bool addImmunity, bool applyOnTeammates, | ||||
| 	bool cancelOnDamaged, bool cancelOnDeath, bool cancelOnLogout, bool cancelOnRemoveBuff, | ||||
| 	bool cancelOnUi, bool cancelOnUnequip, bool cancelOnZone, bool cancelOnDamageAbsDone, | ||||
| 	bool useRefCount, | ||||
| 	const SystemAddress& sysAddr) { | ||||
| 	CBITSTREAM; | ||||
| 	CMSGHEADER; | ||||
| @@ -4448,8 +4450,8 @@ void GameMessages::SendAddBuff(LWOOBJID& objectID, const LWOOBJID& casterID, uin | ||||
| 	bitStream.Write(GAME_MSG::GAME_MSG_ADD_BUFF); | ||||
|  | ||||
| 	bitStream.Write(false); // Added by teammate | ||||
| 	bitStream.Write(false); // Apply on teammates | ||||
| 	bitStream.Write(false); // Cancel on damage absorb ran out | ||||
| 	bitStream.Write(applyOnTeammates); | ||||
| 	bitStream.Write(cancelOnDamageAbsDone); | ||||
| 	bitStream.Write(cancelOnDamaged); | ||||
| 	bitStream.Write(cancelOnDeath); | ||||
| 	bitStream.Write(cancelOnLogout); | ||||
| @@ -4461,7 +4463,7 @@ void GameMessages::SendAddBuff(LWOOBJID& objectID, const LWOOBJID& casterID, uin | ||||
| 	bitStream.Write(cancelOnZone); | ||||
| 	bitStream.Write(false); // Ignore immunities | ||||
| 	bitStream.Write(addImmunity); | ||||
| 	bitStream.Write(false); // Use ref count | ||||
| 	bitStream.Write(useRefCount); | ||||
|  | ||||
| 	bitStream.Write(buffID); | ||||
| 	bitStream.Write(msDuration); | ||||
|   | ||||
| @@ -184,9 +184,11 @@ namespace GameMessages { | ||||
| 	void SendBBBSaveResponse(const LWOOBJID& objectId, const LWOOBJID& localID, unsigned char* buffer, uint32_t bufferSize, const SystemAddress& sysAddr); | ||||
|  | ||||
| 	void SendAddBuff(LWOOBJID& objectID, const LWOOBJID& casterID, uint32_t buffID, uint32_t msDuration, | ||||
| 		bool addImmunity = false, bool cancelOnDamaged = false, bool cancelOnDeath = true, | ||||
| 		bool cancelOnLogout = false, bool cancelOnRemoveBuff = true, bool cancelOnUi = false, | ||||
| 		bool cancelOnUnequip = false, bool cancelOnZone = false, const SystemAddress& sysAddr = UNASSIGNED_SYSTEM_ADDRESS); | ||||
| 		bool addImmunity = false, bool applyOnTeammates = false, | ||||
| 		bool cancelOnDamaged = false, bool cancelOnDeath = true,bool cancelOnLogout = false, bool cancelOnRemoveBuff = true, | ||||
| 		bool cancelOnUi = false, bool cancelOnUnequip = false, bool cancelOnZone = false, bool cancelOnDamageAbsDone = false, | ||||
| 		bool useRefCount = false, | ||||
| 		const SystemAddress& sysAddr = UNASSIGNED_SYSTEM_ADDRESS); | ||||
|  | ||||
| 	void SendToggleGMInvis(LWOOBJID objectId, bool enabled, const SystemAddress& sysAddr); | ||||
|  | ||||
|   | ||||
| @@ -194,7 +194,7 @@ void AuthPackets::SendLoginResponse(dServer* server, const SystemAddress& sysAdd | ||||
| 	PacketUtils::WritePacketString("Talk_Like_A_Pirate", 33, &packet); | ||||
|  | ||||
| 	// 7 unknown strings - perhaps other IP addresses? | ||||
| 	PacketUtils::WritePacketString("", 33, &packet); | ||||
| 	PacketUtils::WritePacketString("ninjago2", 33, &packet); | ||||
| 	PacketUtils::WritePacketString("", 33, &packet); | ||||
| 	PacketUtils::WritePacketString("", 33, &packet); | ||||
| 	PacketUtils::WritePacketString("", 33, &packet); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Aaron Kimbre
					Aaron Kimbre