mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-25 23:17:28 +00:00
Make wrapper for casting skills (#987)
* Make wrapper for casting skills this is to reduce magic numbers in the code base Only updated one use of this to demo that this works. Will be do more in a sepearate PR. Also, inadvertantly fix damage stacking and self-damage in the teslapack * add skill<->behavior caching * explicit by reference * address emo's feedback
This commit is contained in:
parent
91c0c1fcfb
commit
3cd0d1ec3d
@ -22,10 +22,13 @@
|
|||||||
#include "EchoStartSkill.h"
|
#include "EchoStartSkill.h"
|
||||||
#include "dMessageIdentifiers.h"
|
#include "dMessageIdentifiers.h"
|
||||||
#include "DoClientProjectileImpact.h"
|
#include "DoClientProjectileImpact.h"
|
||||||
|
#include "CDClientManager.h"
|
||||||
|
|
||||||
ProjectileSyncEntry::ProjectileSyncEntry() {
|
ProjectileSyncEntry::ProjectileSyncEntry() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unordered_map<uint32_t, uint32_t> SkillComponent::m_skillBehaviorCache = {};
|
||||||
|
|
||||||
bool SkillComponent::CastPlayerSkill(const uint32_t behaviorId, const uint32_t skillUid, RakNet::BitStream* bitStream, const LWOOBJID target, uint32_t skillID) {
|
bool SkillComponent::CastPlayerSkill(const uint32_t behaviorId, const uint32_t skillUid, RakNet::BitStream* bitStream, const LWOOBJID target, uint32_t skillID) {
|
||||||
auto* context = new BehaviorContext(this->m_Parent->GetObjectID());
|
auto* context = new BehaviorContext(this->m_Parent->GetObjectID());
|
||||||
|
|
||||||
@ -210,6 +213,29 @@ void SkillComponent::RegisterCalculatedProjectile(const LWOOBJID projectileId, B
|
|||||||
this->m_managedProjectiles.push_back(entry);
|
this->m_managedProjectiles.push_back(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SkillComponent::CastSkill(const uint32_t skillId, LWOOBJID target, const LWOOBJID optionalOriginatorID){
|
||||||
|
uint32_t behaviorId = -1;
|
||||||
|
// try to find it via the cache
|
||||||
|
const auto& pair = m_skillBehaviorCache.find(skillId);
|
||||||
|
|
||||||
|
// if it's not in the cache look it up and cache it
|
||||||
|
if (pair == m_skillBehaviorCache.end()) {
|
||||||
|
auto skillTable = CDClientManager::Instance()->GetTable<CDSkillBehaviorTable>("SkillBehavior");
|
||||||
|
behaviorId = skillTable->GetSkillByID(skillId).behaviorID;
|
||||||
|
m_skillBehaviorCache.insert_or_assign(skillId, behaviorId);
|
||||||
|
} else {
|
||||||
|
behaviorId = pair->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check to see if we got back a valid behavior
|
||||||
|
if (behaviorId == -1) {
|
||||||
|
Game::logger->LogDebug("SkillComponent", "Tried to cast skill %i but found no behavior", skillId);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return CalculateBehavior(skillId, behaviorId, target, false, false, optionalOriginatorID).success;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
SkillExecutionResult SkillComponent::CalculateBehavior(const uint32_t skillId, const uint32_t behaviorId, const LWOOBJID target, const bool ignoreTarget, const bool clientInitalized, const LWOOBJID originatorOverride) {
|
SkillExecutionResult SkillComponent::CalculateBehavior(const uint32_t skillId, const uint32_t behaviorId, const LWOOBJID target, const bool ignoreTarget, const bool clientInitalized, const LWOOBJID originatorOverride) {
|
||||||
auto* bitStream = new RakNet::BitStream();
|
auto* bitStream = new RakNet::BitStream();
|
||||||
|
@ -119,6 +119,15 @@ public:
|
|||||||
*/
|
*/
|
||||||
void RegisterPlayerProjectile(LWOOBJID projectileId, BehaviorContext* context, const BehaviorBranchContext& branch, LOT lot);
|
void RegisterPlayerProjectile(LWOOBJID projectileId, BehaviorContext* context, const BehaviorBranchContext& branch, LOT lot);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper for CalculateBehavior that mimics the call structure in scripts and helps reduce magic numbers
|
||||||
|
* @param skillId the skill to cast
|
||||||
|
* @param target the target of the skill
|
||||||
|
* @param optionalOriginatorID change the originator of the skill
|
||||||
|
* @return if the case succeeded
|
||||||
|
*/
|
||||||
|
bool CastSkill(const uint32_t skillId, LWOOBJID target = LWOOBJID_EMPTY, const LWOOBJID optionalOriginatorID = LWOOBJID_EMPTY);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes a server-side skill calculation.
|
* Initializes a server-side skill calculation.
|
||||||
* @param skillId the skill ID
|
* @param skillId the skill ID
|
||||||
@ -190,6 +199,11 @@ private:
|
|||||||
*/
|
*/
|
||||||
uint32_t m_skillUid;
|
uint32_t m_skillUid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cache for looking up a behavior id via a skill ID
|
||||||
|
*/
|
||||||
|
static std::unordered_map<uint32_t, uint32_t> m_skillBehaviorCache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sync a server-side projectile calculation.
|
* Sync a server-side projectile calculation.
|
||||||
* @param entry the projectile information
|
* @param entry the projectile information
|
||||||
|
@ -14,7 +14,7 @@ void CoilBackpackBase::NotifyHitOrHealResult(Entity* self, Entity* attacker, int
|
|||||||
if (self->GetVar<uint8_t>(u"coilCount") > 4) {
|
if (self->GetVar<uint8_t>(u"coilCount") > 4) {
|
||||||
auto* skillComponent = self->GetComponent<SkillComponent>();
|
auto* skillComponent = self->GetComponent<SkillComponent>();
|
||||||
if (!skillComponent) return;
|
if (!skillComponent) return;
|
||||||
skillComponent->CalculateBehavior(m_SkillId, m_BehaviorId, self->GetObjectID());
|
skillComponent->CastSkill(m_SkillId);
|
||||||
self->SetVar<uint8_t>(u"coilCount", 0);
|
self->SetVar<uint8_t>(u"coilCount", 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,8 @@
|
|||||||
|
|
||||||
class CoilBackpackBase: public CppScripts::Script {
|
class CoilBackpackBase: public CppScripts::Script {
|
||||||
public:
|
public:
|
||||||
CoilBackpackBase(uint32_t skillId, uint32_t behaviorId) {
|
CoilBackpackBase(uint32_t skillId) {
|
||||||
m_SkillId = skillId;
|
m_SkillId = skillId;
|
||||||
m_BehaviorId = behaviorId;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void OnFactionTriggerItemEquipped(Entity* itemOwner, LWOOBJID itemObjId) override;
|
void OnFactionTriggerItemEquipped(Entity* itemOwner, LWOOBJID itemObjId) override;
|
||||||
@ -15,7 +14,6 @@ public:
|
|||||||
void OnFactionTriggerItemUnequipped(Entity* itemOwner, LWOOBJID itemObjId) override;
|
void OnFactionTriggerItemUnequipped(Entity* itemOwner, LWOOBJID itemObjId) override;
|
||||||
private:
|
private:
|
||||||
uint32_t m_SkillId = 0;
|
uint32_t m_SkillId = 0;
|
||||||
uint32_t m_BehaviorId = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //!__GemPackBase__H__
|
#endif //!__GemPackBase__H__
|
||||||
|
@ -5,10 +5,9 @@
|
|||||||
|
|
||||||
class GemPack : public CoilBackpackBase {
|
class GemPack : public CoilBackpackBase {
|
||||||
public:
|
public:
|
||||||
GemPack() : CoilBackpackBase(skillId, behaviorId) {};
|
GemPack() : CoilBackpackBase(skillId) {};
|
||||||
private:
|
private:
|
||||||
static const uint32_t skillId = 1488;
|
static const uint32_t skillId = 1488;
|
||||||
static const uint32_t behaviorId = 36779;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //!__GEMPACK__H__
|
#endif //!__GEMPACK__H__
|
||||||
|
@ -5,10 +5,9 @@
|
|||||||
|
|
||||||
class ShardArmor : public CoilBackpackBase {
|
class ShardArmor : public CoilBackpackBase {
|
||||||
public:
|
public:
|
||||||
ShardArmor() : CoilBackpackBase(skillId, behaviorId) {};
|
ShardArmor() : CoilBackpackBase(skillId) {};
|
||||||
private:
|
private:
|
||||||
static const uint32_t skillId = 1249;
|
static const uint32_t skillId = 1249;
|
||||||
static const uint32_t behaviorId = 29086;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //!__SHARDARMOR__H__
|
#endif //!__SHARDARMOR__H__
|
||||||
|
@ -5,10 +5,9 @@
|
|||||||
|
|
||||||
class TeslaPack : public CoilBackpackBase {
|
class TeslaPack : public CoilBackpackBase {
|
||||||
public:
|
public:
|
||||||
TeslaPack() : CoilBackpackBase(skillId, behaviorId) {};
|
TeslaPack() : CoilBackpackBase(skillId) {};
|
||||||
private:
|
private:
|
||||||
static const uint32_t skillId = 1001;
|
static const uint32_t skillId = 1001;
|
||||||
static const uint32_t behaviorId = 20917;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //!__TESLAPACK__H__
|
#endif //!__TESLAPACK__H__
|
||||||
|
Loading…
Reference in New Issue
Block a user