DarkflameServer/dScripts/EquipmentTriggers/CoilBackpackBase.cpp
Aaron Kimbrell 3cd0d1ec3d
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
2023-02-10 02:30:17 -06:00

26 lines
866 B
C++

#include "CoilBackpackBase.h"
#include "Entity.h"
#include "SkillComponent.h"
void CoilBackpackBase::OnFactionTriggerItemEquipped(Entity* itemOwner, LWOOBJID itemObjId) {
itemOwner->Subscribe(itemObjId, this, "HitOrHealResult");
itemOwner->SetVar<uint8_t>(u"coilCount", 0);
}
void CoilBackpackBase::NotifyHitOrHealResult(Entity* self, Entity* attacker, int32_t damage) {
if (damage > 0) {
self->SetVar<uint8_t>(u"coilCount", self->GetVar<uint8_t>(u"coilCount") + 1);
if (self->GetVar<uint8_t>(u"coilCount") > 4) {
auto* skillComponent = self->GetComponent<SkillComponent>();
if (!skillComponent) return;
skillComponent->CastSkill(m_SkillId);
self->SetVar<uint8_t>(u"coilCount", 0);
}
}
}
void CoilBackpackBase::OnFactionTriggerItemUnequipped(Entity* itemOwner, LWOOBJID itemObjId) {
itemOwner->Unsubscribe(itemObjId, "HitOrHealResult");
}