This commit is contained in:
Aaron Kimbre
2022-12-24 08:08:51 -06:00
parent 1470af99c3
commit 9b3c2f094f
7 changed files with 107 additions and 54 deletions

View File

@@ -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);
}

View File

@@ -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