mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-10 02:08:20 +00:00
simplify passing data around
This commit is contained in:
parent
3f3c5d9215
commit
6bf45cad39
@ -16,11 +16,23 @@ void ApplyBuffBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitS
|
|||||||
|
|
||||||
if (buffComponent == nullptr) return;
|
if (buffComponent == nullptr) return;
|
||||||
|
|
||||||
buffComponent->ApplyBuff(m_BuffId, m_Duration, context->originator,
|
Buff buff;
|
||||||
m_AddImmunity, m_ApplyOnTeammates,
|
buff.id = m_BuffId;
|
||||||
m_CancelOnDamaged, m_CancelOnDeath, m_CancelOnLogout, m_CancelOnRemoveBuff,
|
buff.duration = m_Duration;
|
||||||
m_CancelOnUi, m_CancelOnUnequip, m_CancelOnZone, m_CancelOnDamageAbsDone,
|
buff.source = context->originator;
|
||||||
m_UseRefCount);
|
buff.addImmunity = m_AddImmunity;
|
||||||
|
buff.applyOnTeammates = m_ApplyOnTeammates;
|
||||||
|
buff.cancelOnDamaged = m_CancelOnDamaged;
|
||||||
|
buff.cancelOnDeath = m_CancelOnDeath;
|
||||||
|
buff.cancelOnLogout = m_CancelOnLogout;
|
||||||
|
buff.cancelOnRemoveBuff = m_CancelOnRemoveBuff;
|
||||||
|
buff.cancelOnUi = m_CancelOnUi;
|
||||||
|
buff.cancelOnUnequip = m_CancelOnUnequip;
|
||||||
|
buff.cancelOnZone = m_CancelOnZone;
|
||||||
|
buff.useRefCount = m_UseRefCount;
|
||||||
|
buff.cancelOnDamageAbsDone = m_CancelOnDamageAbsDone;
|
||||||
|
|
||||||
|
buffComponent->ApplyBuff(buff);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApplyBuffBehavior::UnCast(BehaviorContext* context, BehaviorBranchContext branch) {
|
void ApplyBuffBehavior::UnCast(BehaviorContext* context, BehaviorBranchContext branch) {
|
||||||
|
@ -20,11 +20,13 @@ BuffComponent::~BuffComponent() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void BuffComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
|
void BuffComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
|
||||||
|
// apply buffs from previous sessions that are stored in the charxml
|
||||||
if (bIsInitialUpdate) {
|
if (bIsInitialUpdate) {
|
||||||
|
// buffs
|
||||||
if (m_Buffs.empty()) {
|
if (m_Buffs.empty()) {
|
||||||
outBitStream->Write0();
|
outBitStream->Write0(); // no buffs
|
||||||
} else {
|
} else {
|
||||||
outBitStream->Write1();
|
outBitStream->Write1(); // we have some
|
||||||
outBitStream->Write<uint32_t>(m_Buffs.size());
|
outBitStream->Write<uint32_t>(m_Buffs.size());
|
||||||
|
|
||||||
for (const auto& buff : m_Buffs) {
|
for (const auto& buff : m_Buffs) {
|
||||||
@ -38,17 +40,18 @@ void BuffComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUp
|
|||||||
outBitStream->Write(buff.second.cancelOnLogout);
|
outBitStream->Write(buff.second.cancelOnLogout);
|
||||||
outBitStream->Write(buff.second.cancelOnUnequip);
|
outBitStream->Write(buff.second.cancelOnUnequip);
|
||||||
outBitStream->Write(buff.second.cancelOnDamageAbsDone);
|
outBitStream->Write(buff.second.cancelOnDamageAbsDone);
|
||||||
outBitStream->Write0(); // outBitStream->Write(addedByTeammate)
|
outBitStream->Write(buff.second.source != m_Parent->GetObjectID());
|
||||||
outBitStream->Write(buff.second.applyOnTeammates);
|
outBitStream->Write(buff.second.applyOnTeammates);
|
||||||
// if (addedByTeammate) outBitStream->Write(team mate lwoobjid);
|
if (buff.second.source != m_Parent->GetObjectID()) outBitStream->Write(buff.second.source);
|
||||||
outBitStream->Write(buff.second.refcount);
|
outBitStream->Write(buff.second.refcount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// buff imunities
|
||||||
if (m_BuffImmunities.empty()) {
|
if (m_BuffImmunities.empty()) {
|
||||||
outBitStream->Write0();
|
outBitStream->Write0(); // no buff immunities
|
||||||
} else {
|
} else {
|
||||||
outBitStream->Write1();
|
outBitStream->Write1(); // we have some
|
||||||
outBitStream->Write<uint32_t>(m_BuffImmunities.size());
|
outBitStream->Write<uint32_t>(m_BuffImmunities.size());
|
||||||
|
|
||||||
for (const auto& buffImmunity : m_BuffImmunities) {
|
for (const auto& buffImmunity : m_BuffImmunities) {
|
||||||
@ -62,9 +65,9 @@ void BuffComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUp
|
|||||||
outBitStream->Write(buffImmunity.second.cancelOnLogout);
|
outBitStream->Write(buffImmunity.second.cancelOnLogout);
|
||||||
outBitStream->Write(buffImmunity.second.cancelOnUnequip);
|
outBitStream->Write(buffImmunity.second.cancelOnUnequip);
|
||||||
outBitStream->Write(buffImmunity.second.cancelOnDamageAbsDone);
|
outBitStream->Write(buffImmunity.second.cancelOnDamageAbsDone);
|
||||||
outBitStream->Write0(); // outBitStream->Write(addedByTeammate)
|
outBitStream->Write(buffImmunity.second.source != m_Parent->GetObjectID());
|
||||||
outBitStream->Write(buffImmunity.second.applyOnTeammates);
|
outBitStream->Write(buffImmunity.second.applyOnTeammates);
|
||||||
// if (addedByTeammate) outBitStream->Write(team mate lwoobjid);
|
if (buffImmunity.second.source != m_Parent->GetObjectID()) outBitStream->Write(buffImmunity.second.source);
|
||||||
outBitStream->Write(buffImmunity.second.refcount);
|
outBitStream->Write(buffImmunity.second.refcount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -104,22 +107,17 @@ void BuffComponent::Update(float deltaTime) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BuffComponent::ApplyBuff(const int32_t id, const float duration, const LWOOBJID source,
|
void BuffComponent::ApplyBuff(Buff buff) {
|
||||||
bool addImmunity, bool applyOnTeammates,
|
|
||||||
bool cancelOnDamaged, bool cancelOnDeath, bool cancelOnLogout, bool cancelOnRemoveBuff,
|
|
||||||
bool cancelOnUi, bool cancelOnUnequip, bool cancelOnZone, bool cancelOnDamageAbsDone,
|
|
||||||
bool useRefCount) {
|
|
||||||
|
|
||||||
GameMessages::SendAddBuff(const_cast<LWOOBJID&>(m_Parent->GetObjectID()), source, (uint32_t)id,
|
if (HasBuff(buff.id) && HasBuffImmunity(buff.id)) return;
|
||||||
(uint32_t)duration * 1000, addImmunity, applyOnTeammates, cancelOnDamaged, cancelOnDeath,
|
|
||||||
cancelOnLogout, cancelOnRemoveBuff, cancelOnUi, cancelOnUnequip, cancelOnZone, cancelOnDamageAbsDone,
|
GameMessages::SendAddBuff(const_cast<LWOOBJID&>(m_Parent->GetObjectID()), buff);
|
||||||
useRefCount);
|
|
||||||
|
|
||||||
float tick = 0;
|
float tick = 0;
|
||||||
float stacks = 0;
|
float stacks = 0;
|
||||||
int32_t behaviorID = 0;
|
int32_t behaviorID = 0;
|
||||||
|
|
||||||
const auto& parameters = GetBuffParameters(id);
|
const auto& parameters = GetBuffParameters(buff.id);
|
||||||
for (const auto& parameter : parameters) {
|
for (const auto& parameter : parameters) {
|
||||||
if (parameter.name == "overtime") {
|
if (parameter.name == "overtime") {
|
||||||
auto* behaviorTemplateTable = CDClientManager::Instance()->GetTable<CDSkillBehaviorTable>("SkillBehavior");
|
auto* behaviorTemplateTable = CDClientManager::Instance()->GetTable<CDSkillBehaviorTable>("SkillBehavior");
|
||||||
@ -131,31 +129,16 @@ void BuffComponent::ApplyBuff(const int32_t id, const float duration, const LWOO
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ApplyBuffEffect(id);
|
ApplyBuffEffect(buff.id);
|
||||||
|
|
||||||
Buff buff;
|
|
||||||
buff.id = id;
|
|
||||||
buff.time = duration;
|
|
||||||
buff.tick = tick;
|
buff.tick = tick;
|
||||||
buff.tickTime = tick;
|
buff.tickTime = tick;
|
||||||
buff.stacks = stacks;
|
buff.stacks = stacks;
|
||||||
buff.source = source;
|
|
||||||
buff.behaviorID = behaviorID;
|
buff.behaviorID = behaviorID;
|
||||||
buff.addImmunity = addImmunity;
|
|
||||||
buff.applyOnTeammates = applyOnTeammates;
|
|
||||||
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.cancelOnDamageAbsDone = cancelOnDamageAbsDone;
|
|
||||||
|
|
||||||
buff.refcount = 0;
|
buff.refcount = 0;
|
||||||
|
if (buff.addImmunity) {
|
||||||
m_Buffs.emplace(id, buff);
|
m_BuffImmunities.emplace(buff.id, buff);
|
||||||
|
} else m_Buffs.emplace(buff.id, buff);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BuffComponent::RemoveBuff(int32_t id, bool fromUnEquip, bool removeImmunity) {
|
void BuffComponent::RemoveBuff(int32_t id, bool fromUnEquip, bool removeImmunity) {
|
||||||
@ -176,6 +159,10 @@ bool BuffComponent::HasBuff(int32_t id) {
|
|||||||
return m_Buffs.find(id) != m_Buffs.end();
|
return m_Buffs.find(id) != m_Buffs.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BuffComponent::HasBuffImmunity(int32_t id) {
|
||||||
|
return m_BuffImmunities.find(id) != m_BuffImmunities.end();
|
||||||
|
}
|
||||||
|
|
||||||
void BuffComponent::ApplyBuffEffect(int32_t id) {
|
void BuffComponent::ApplyBuffEffect(int32_t id) {
|
||||||
const auto& parameters = GetBuffParameters(id);
|
const auto& parameters = GetBuffParameters(id);
|
||||||
for (const auto& parameter : parameters) {
|
for (const auto& parameter : parameters) {
|
||||||
|
@ -28,6 +28,7 @@ struct BuffParameter
|
|||||||
struct Buff
|
struct Buff
|
||||||
{
|
{
|
||||||
int32_t id = 0;
|
int32_t id = 0;
|
||||||
|
float duration = 0;
|
||||||
float time = 0;
|
float time = 0;
|
||||||
float tick = 0;
|
float tick = 0;
|
||||||
float tickTime = 0;
|
float tickTime = 0;
|
||||||
@ -73,25 +74,9 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Applies a buff to the parent entity
|
* Applies a buff to the parent entity
|
||||||
* @param id the id of the buff to apply
|
* @param buff the Buff to apply
|
||||||
* @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
|
|
||||||
* @param cancelOnRemoveBuff client flag to indicate that the buff should disappear when a concrete GM to do so comes around
|
|
||||||
* @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 applyOnTeammates = false,
|
void ApplyBuff(Buff buff);
|
||||||
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
|
* Removes a buff from the parent entity, reversing its effects
|
||||||
@ -107,6 +92,14 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool HasBuff(int32_t id);
|
bool HasBuff(int32_t id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether or not the entity has a buff immunity identified by `id`
|
||||||
|
* @param id the id of the buff immunity to find
|
||||||
|
* @return whether or not the entity has a buff with the specified id active
|
||||||
|
*/
|
||||||
|
bool HasBuffImmunity(int32_t id);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Applies the effects of the buffs on the entity, e.g.: changing armor, health, imag, etc.
|
* Applies the effects of the buffs on the entity, e.g.: changing armor, health, imag, etc.
|
||||||
* @param id the id of the buff effects to apply
|
* @param id the id of the buff effects to apply
|
||||||
|
@ -61,6 +61,7 @@
|
|||||||
#include "RacingControlComponent.h"
|
#include "RacingControlComponent.h"
|
||||||
#include "RailActivatorComponent.h"
|
#include "RailActivatorComponent.h"
|
||||||
#include "LevelProgressionComponent.h"
|
#include "LevelProgressionComponent.h"
|
||||||
|
#include "BuffComponent.h"
|
||||||
|
|
||||||
// Message includes:
|
// Message includes:
|
||||||
#include "dZoneManager.h"
|
#include "dZoneManager.h"
|
||||||
@ -4437,39 +4438,34 @@ void GameMessages::SendVehicleNotifyFinishedRace(LWOOBJID objectId, const System
|
|||||||
SEND_PACKET;
|
SEND_PACKET;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameMessages::SendAddBuff(LWOOBJID& objectID, const LWOOBJID& casterID, uint32_t buffID, uint32_t msDuration,
|
void GameMessages::SendAddBuff(LWOOBJID& target, Buff buff, const SystemAddress& sysAddr) {
|
||||||
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;
|
CBITSTREAM;
|
||||||
CMSGHEADER;
|
CMSGHEADER;
|
||||||
|
|
||||||
bitStream.Write(objectID);
|
bitStream.Write(target);
|
||||||
bitStream.Write(GAME_MSG::GAME_MSG_ADD_BUFF);
|
bitStream.Write(GAME_MSG::GAME_MSG_ADD_BUFF);
|
||||||
|
|
||||||
bitStream.Write(false); // Added by teammate
|
bitStream.Write(buff.source != target); // If we were added by a teammate/someone else
|
||||||
bitStream.Write(applyOnTeammates);
|
bitStream.Write(buff.applyOnTeammates);
|
||||||
bitStream.Write(cancelOnDamageAbsDone);
|
bitStream.Write(buff.cancelOnDamageAbsDone);
|
||||||
bitStream.Write(cancelOnDamaged);
|
bitStream.Write(buff.cancelOnDamaged);
|
||||||
bitStream.Write(cancelOnDeath);
|
bitStream.Write(buff.cancelOnDeath);
|
||||||
bitStream.Write(cancelOnLogout);
|
bitStream.Write(buff.cancelOnLogout);
|
||||||
bitStream.Write(false); // Cancel on move
|
bitStream.Write(false); // Cancel on move
|
||||||
bitStream.Write(cancelOnRemoveBuff);
|
bitStream.Write(buff.cancelOnRemoveBuff);
|
||||||
|
|
||||||
bitStream.Write(cancelOnUi);
|
bitStream.Write(buff.cancelOnUi);
|
||||||
bitStream.Write(cancelOnUnequip);
|
bitStream.Write(buff.cancelOnUnequip);
|
||||||
bitStream.Write(cancelOnZone);
|
bitStream.Write(buff.cancelOnZone);
|
||||||
bitStream.Write(false); // Ignore immunities
|
bitStream.Write(false); // Ignore immunities
|
||||||
bitStream.Write(addImmunity);
|
bitStream.Write(buff.addImmunity);
|
||||||
bitStream.Write(useRefCount);
|
bitStream.Write(buff.useRefCount);
|
||||||
|
|
||||||
bitStream.Write(buffID);
|
bitStream.Write(buff.id);
|
||||||
bitStream.Write(msDuration);
|
bitStream.Write(buff.duration * 1000); // needs to be in MS
|
||||||
|
|
||||||
bitStream.Write(casterID);
|
bitStream.Write(buff.source);
|
||||||
bitStream.Write(casterID);
|
bitStream.Write(buff.source);
|
||||||
|
|
||||||
if (sysAddr == UNASSIGNED_SYSTEM_ADDRESS) SEND_PACKET_BROADCAST;
|
if (sysAddr == UNASSIGNED_SYSTEM_ADDRESS) SEND_PACKET_BROADCAST;
|
||||||
SEND_PACKET;
|
SEND_PACKET;
|
||||||
|
@ -22,6 +22,7 @@ class NiPoint3;
|
|||||||
enum class eUnequippableActiveType;
|
enum class eUnequippableActiveType;
|
||||||
enum eInventoryType : uint32_t;
|
enum eInventoryType : uint32_t;
|
||||||
class Item;
|
class Item;
|
||||||
|
struct Buff;
|
||||||
|
|
||||||
namespace GameMessages {
|
namespace GameMessages {
|
||||||
class PropertyDataMessage;
|
class PropertyDataMessage;
|
||||||
@ -183,12 +184,7 @@ namespace GameMessages {
|
|||||||
// The success or failure response sent back to the client will preserve the same value for localID.
|
// The success or failure response sent back to the client will preserve the same value for localID.
|
||||||
void SendBBBSaveResponse(const LWOOBJID& objectId, const LWOOBJID& localID, unsigned char* buffer, uint32_t bufferSize, const SystemAddress& sysAddr);
|
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,
|
void SendAddBuff(LWOOBJID& target, Buff buff, 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);
|
void SendToggleGMInvis(LWOOBJID objectId, bool enabled, const SystemAddress& sysAddr);
|
||||||
|
|
||||||
|
@ -1463,6 +1463,10 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
|
|||||||
|
|
||||||
if (chatCommand == "buff" && args.size() >= 2 && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) {
|
if (chatCommand == "buff" && args.size() >= 2 && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) {
|
||||||
auto* buffComponent = entity->GetComponent<BuffComponent>();
|
auto* buffComponent = entity->GetComponent<BuffComponent>();
|
||||||
|
if (!buffComponent) {
|
||||||
|
ChatPackets::SendSystemMessage(sysAddr, u"Error, no buff component.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t id = 0;
|
int32_t id = 0;
|
||||||
int32_t duration = 0;
|
int32_t duration = 0;
|
||||||
@ -1477,9 +1481,10 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buffComponent != nullptr) {
|
Buff buff;
|
||||||
buffComponent->ApplyBuff(id, duration, entity->GetObjectID());
|
buff.id = id;
|
||||||
}
|
buff.duration = duration;
|
||||||
|
buffComponent->ApplyBuff(buff);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user