Compare commits

...

7 Commits

Author SHA1 Message Date
6bf45cad39 simplify passing data around 2022-12-24 14:25:31 -06:00
3f3c5d9215 buff immunities 2022-12-24 11:44:14 -06:00
b7ec08a8e2 fix the serilization 2022-12-24 11:02:02 -06:00
4fee6d1bba 0 2022-12-24 09:40:16 -06:00
8f9df9178a fix 2022-12-24 09:08:41 -06:00
9e530b91d6 comment 2022-12-24 08:25:10 -06:00
9b3c2f094f buffs 2022-12-24 08:08:51 -06:00
8 changed files with 178 additions and 110 deletions

View File

@@ -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,27 @@ 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);
Buff buff;
buff.id = m_BuffId;
buff.duration = m_Duration;
buff.source = context->originator;
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) {
if (m_IgnoreUncast) return;
auto* entity = EntityManager::Instance()->GetEntity(branch.target);
if (entity == nullptr) return;
@@ -37,12 +55,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);
}

View File

@@ -7,17 +7,6 @@
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
*/
@@ -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;
};

View File

@@ -20,33 +20,58 @@ BuffComponent::~BuffComponent() {
}
void BuffComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
if (!bIsInitialUpdate) return;
// apply buffs from previous sessions that are stored in the charxml
if (bIsInitialUpdate) {
// buffs
if (m_Buffs.empty()) {
outBitStream->Write0();
outBitStream->Write0(); // no buffs
} else {
outBitStream->Write1();
outBitStream->Write1(); // we have some
outBitStream->Write<uint32_t>(m_Buffs.size());
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->Write0();
outBitStream->Write0();
outBitStream->Write<uint32_t>(0);
outBitStream->Write(buff.second.time);
outBitStream->Write(buff.second.cancelOnDeath);
outBitStream->Write(buff.second.cancelOnZone);
outBitStream->Write(buff.second.cancelOnDamaged);
outBitStream->Write(buff.second.cancelOnRemoveBuff);
outBitStream->Write(buff.second.cancelOnUi);
outBitStream->Write(buff.second.cancelOnLogout);
outBitStream->Write(buff.second.cancelOnUnequip);
outBitStream->Write(buff.second.cancelOnDamageAbsDone);
outBitStream->Write(buff.second.source != m_Parent->GetObjectID());
outBitStream->Write(buff.second.applyOnTeammates);
if (buff.second.source != m_Parent->GetObjectID()) outBitStream->Write(buff.second.source);
outBitStream->Write(buff.second.refcount);
}
}
outBitStream->Write0();
// buff imunities
if (m_BuffImmunities.empty()) {
outBitStream->Write0(); // no buff immunities
} else {
outBitStream->Write1(); // we have some
outBitStream->Write<uint32_t>(m_BuffImmunities.size());
for (const auto& buffImmunity : m_BuffImmunities) {
outBitStream->Write<uint32_t>(buffImmunity.first);
outBitStream->Write(buffImmunity.second.time);
outBitStream->Write(buffImmunity.second.cancelOnDeath);
outBitStream->Write(buffImmunity.second.cancelOnZone);
outBitStream->Write(buffImmunity.second.cancelOnDamaged);
outBitStream->Write(buffImmunity.second.cancelOnRemoveBuff);
outBitStream->Write(buffImmunity.second.cancelOnUi);
outBitStream->Write(buffImmunity.second.cancelOnLogout);
outBitStream->Write(buffImmunity.second.cancelOnUnequip);
outBitStream->Write(buffImmunity.second.cancelOnDamageAbsDone);
outBitStream->Write(buffImmunity.second.source != m_Parent->GetObjectID());
outBitStream->Write(buffImmunity.second.applyOnTeammates);
if (buffImmunity.second.source != m_Parent->GetObjectID()) outBitStream->Write(buffImmunity.second.source);
outBitStream->Write(buffImmunity.second.refcount);
}
}
} // there is no update serilization, only on initialization
}
void BuffComponent::Update(float deltaTime) {
@@ -82,23 +107,17 @@ void BuffComponent::Update(float deltaTime) {
}
}
void BuffComponent::ApplyBuff(const int32_t id, const float duration, const LWOOBJID source, bool addImmunity,
bool cancelOnDamaged, bool cancelOnDeath, bool cancelOnLogout, bool cancelOnRemoveBuff,
bool cancelOnUi, bool cancelOnUnequip, bool cancelOnZone) {
// Prevent buffs from stacking.
if (HasBuff(id)) {
return;
}
void BuffComponent::ApplyBuff(Buff buff) {
GameMessages::SendAddBuff(const_cast<LWOOBJID&>(m_Parent->GetObjectID()), source, (uint32_t)id,
(uint32_t)duration * 1000, addImmunity, cancelOnDamaged, cancelOnDeath,
cancelOnLogout, cancelOnRemoveBuff, cancelOnUi, cancelOnUnequip, cancelOnZone);
if (HasBuff(buff.id) && HasBuffImmunity(buff.id)) return;
GameMessages::SendAddBuff(const_cast<LWOOBJID&>(m_Parent->GetObjectID()), buff);
float tick = 0;
float stacks = 0;
int32_t behaviorID = 0;
const auto& parameters = GetBuffParameters(id);
const auto& parameters = GetBuffParameters(buff.id);
for (const auto& parameter : parameters) {
if (parameter.name == "overtime") {
auto* behaviorTemplateTable = CDClientManager::Instance()->GetTable<CDSkillBehaviorTable>("SkillBehavior");
@@ -106,22 +125,20 @@ void BuffComponent::ApplyBuff(const int32_t id, const float duration, const LWOO
behaviorID = behaviorTemplateTable->GetSkillByID(parameter.values[0]).behaviorID;
stacks = static_cast<int32_t>(parameter.values[1]);
tick = parameter.values[2];
const auto unknown2 = parameter.values[3]; // Always 0
const auto unknown2 = parameter.values[3]; // TODO: figure this out it changed to all 1 in FT
}
}
ApplyBuffEffect(id);
Buff buff;
buff.id = id;
buff.time = duration;
ApplyBuffEffect(buff.id);
buff.tick = tick;
buff.tickTime = tick;
buff.stacks = stacks;
buff.source = source;
buff.behaviorID = behaviorID;
m_Buffs.emplace(id, buff);
buff.refcount = 0;
if (buff.addImmunity) {
m_BuffImmunities.emplace(buff.id, buff);
} else m_Buffs.emplace(buff.id, buff);
}
void BuffComponent::RemoveBuff(int32_t id, bool fromUnEquip, bool removeImmunity) {
@@ -142,6 +159,10 @@ bool BuffComponent::HasBuff(int32_t id) {
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) {
const auto& parameters = GetBuffParameters(id);
for (const auto& parameter : parameters) {
@@ -288,6 +309,7 @@ void BuffComponent::UpdateXml(tinyxml2::XMLDocument* doc) {
}
for (const auto& buff : m_Buffs) {
if (buff.second.cancelOnLogout || buff.second.cancelOnZone) continue;
auto* buffEntry = doc->NewElement("b");
buffEntry->SetAttribute("id", buff.first);

View File

@@ -28,12 +28,27 @@ struct BuffParameter
struct Buff
{
int32_t id = 0;
float duration = 0;
float time = 0;
float tick = 0;
float tickTime = 0;
int32_t stacks = 0;
LWOOBJID source = 0;
int32_t behaviorID = 0;
bool addImmunity = false;
bool applyOnTeammates = 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 = 0;
};
/**
@@ -59,21 +74,9 @@ public:
/**
* Applies a buff to the parent entity
* @param id the id of 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 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 buff the Buff to apply
*/
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(Buff buff);
/**
* Removes a buff from the parent entity, reversing its effects
@@ -89,6 +92,14 @@ public:
*/
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.
* @param id the id of the buff effects to apply
@@ -129,6 +140,11 @@ private:
*/
std::map<int32_t, Buff> m_Buffs;
/**
* The currently active buff immunities
*/
std::map<int32_t, Buff> m_BuffImmunities;
/**
* Parameters (=effects) for each buff
*/

View File

@@ -61,6 +61,7 @@
#include "RacingControlComponent.h"
#include "RailActivatorComponent.h"
#include "LevelProgressionComponent.h"
#include "BuffComponent.h"
// Message includes:
#include "dZoneManager.h"
@@ -4437,37 +4438,34 @@ void GameMessages::SendVehicleNotifyFinishedRace(LWOOBJID objectId, const System
SEND_PACKET;
}
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,
const SystemAddress& sysAddr) {
void GameMessages::SendAddBuff(LWOOBJID& target, Buff buff, const SystemAddress& sysAddr) {
CBITSTREAM;
CMSGHEADER;
bitStream.Write(objectID);
bitStream.Write(target);
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(cancelOnDamaged);
bitStream.Write(cancelOnDeath);
bitStream.Write(cancelOnLogout);
bitStream.Write(buff.source != target); // If we were added by a teammate/someone else
bitStream.Write(buff.applyOnTeammates);
bitStream.Write(buff.cancelOnDamageAbsDone);
bitStream.Write(buff.cancelOnDamaged);
bitStream.Write(buff.cancelOnDeath);
bitStream.Write(buff.cancelOnLogout);
bitStream.Write(false); // Cancel on move
bitStream.Write(cancelOnRemoveBuff);
bitStream.Write(buff.cancelOnRemoveBuff);
bitStream.Write(cancelOnUi);
bitStream.Write(cancelOnUnequip);
bitStream.Write(cancelOnZone);
bitStream.Write(buff.cancelOnUi);
bitStream.Write(buff.cancelOnUnequip);
bitStream.Write(buff.cancelOnZone);
bitStream.Write(false); // Ignore immunities
bitStream.Write(addImmunity);
bitStream.Write(false); // Use ref count
bitStream.Write(buff.addImmunity);
bitStream.Write(buff.useRefCount);
bitStream.Write(buffID);
bitStream.Write(msDuration);
bitStream.Write(buff.id);
bitStream.Write(buff.duration * 1000); // needs to be in MS
bitStream.Write(casterID);
bitStream.Write(casterID);
bitStream.Write(buff.source);
bitStream.Write(buff.source);
if (sysAddr == UNASSIGNED_SYSTEM_ADDRESS) SEND_PACKET_BROADCAST;
SEND_PACKET;

View File

@@ -22,6 +22,7 @@ class NiPoint3;
enum class eUnequippableActiveType;
enum eInventoryType : uint32_t;
class Item;
struct Buff;
namespace GameMessages {
class PropertyDataMessage;
@@ -183,10 +184,7 @@ namespace GameMessages {
// 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 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);
void SendAddBuff(LWOOBJID& target, Buff buff, const SystemAddress& sysAddr = UNASSIGNED_SYSTEM_ADDRESS);
void SendToggleGMInvis(LWOOBJID objectId, bool enabled, const SystemAddress& sysAddr);

View File

@@ -1463,6 +1463,10 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
if (chatCommand == "buff" && args.size() >= 2 && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) {
auto* buffComponent = entity->GetComponent<BuffComponent>();
if (!buffComponent) {
ChatPackets::SendSystemMessage(sysAddr, u"Error, no buff component.");
return;
}
int32_t id = 0;
int32_t duration = 0;
@@ -1477,9 +1481,10 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
return;
}
if (buffComponent != nullptr) {
buffComponent->ApplyBuff(id, duration, entity->GetObjectID());
}
Buff buff;
buff.id = id;
buff.duration = duration;
buffComponent->ApplyBuff(buff);
return;
}

View File

@@ -193,8 +193,8 @@ 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);
// gating strings
PacketUtils::WritePacketString("ninjago2", 33, &packet);
PacketUtils::WritePacketString("", 33, &packet);
PacketUtils::WritePacketString("", 33, &packet);
PacketUtils::WritePacketString("", 33, &packet);