DarkflameServer/dGame/dBehaviors/ChangeIdleFlagsBehavior.cpp
Aaron Kimbrell 631365b7f7
Add change idle flags behavior and GM (#871)
* update naming for animation flag enum value 0

* Add change idle flags behaviors and GM

* default to 0 when none is given
2022-12-16 15:24:13 -06:00

38 lines
1.4 KiB
C++

#include "ChangeIdleFlagsBehavior.h"
#include "BehaviorContext.h"
#include "BehaviorBranchContext.h"
void ChangeIdleFlagsBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
const auto target = branch.target != LWOOBJID_EMPTY ? branch.target : context->originator;
if (!target) return;
GameMessages::SendChangeIdleFlags(target, m_FlagsOn, m_FlagsOff, UNASSIGNED_SYSTEM_ADDRESS);
if (branch.duration > 0.0f) {
context->RegisterTimerBehavior(this, branch);
} else if (branch.start > 0) {
context->RegisterEndBehavior(this, branch);
}
}
void ChangeIdleFlagsBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
Handle(context, bitStream, branch);
}
void ChangeIdleFlagsBehavior::End(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) {
const auto target = branch.target != LWOOBJID_EMPTY ? branch.target : context->originator;
if (!target) return;
// flip on and off to end behavior
GameMessages::SendChangeIdleFlags(target, m_FlagsOff, m_FlagsOn, UNASSIGNED_SYSTEM_ADDRESS);
}
void ChangeIdleFlagsBehavior::Timer(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) {
End(context, branch, second);
}
void ChangeIdleFlagsBehavior::Load() {
m_FlagsOff = static_cast<eAnimationFlags>(GetInt("flags_off", 0));
m_FlagsOn = static_cast<eAnimationFlags>(GetInt("flags_on", 0));
}