2021-12-05 17:54:36 +00:00
|
|
|
#include "OverTimeBehavior.h"
|
|
|
|
#include "BehaviorBranchContext.h"
|
|
|
|
#include "BehaviorContext.h"
|
|
|
|
#include "Game.h"
|
2023-10-21 23:31:55 +00:00
|
|
|
#include "Logger.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
#include "EntityManager.h"
|
|
|
|
#include "SkillComponent.h"
|
|
|
|
#include "DestroyableComponent.h"
|
2022-12-18 15:46:04 +00:00
|
|
|
#include "CDClientDatabase.h"
|
|
|
|
#include "CDClientManager.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-03-17 14:36:21 +00:00
|
|
|
#include "CDSkillBehaviorTable.h"
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void OverTimeBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
|
|
|
const auto originator = context->originator;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-07-15 20:56:33 +00:00
|
|
|
auto* entity = Game::entityManager->GetEntity(originator);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (entity == nullptr) return;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
for (size_t i = 0; i < m_NumIntervals; i++) {
|
|
|
|
entity->AddCallbackTimer((i + 1) * m_Delay, [originator, branch, this]() {
|
2023-07-15 20:56:33 +00:00
|
|
|
auto* entity = Game::entityManager->GetEntity(originator);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (entity == nullptr) return;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
auto* skillComponent = entity->GetComponent<SkillComponent>();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (skillComponent == nullptr) return;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
skillComponent->CalculateBehavior(m_Action, m_ActionBehaviorId, branch.target, true, true);
|
|
|
|
});
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void OverTimeBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void OverTimeBehavior::Load() {
|
|
|
|
m_Action = GetInt("action");
|
|
|
|
// Since m_Action is a skillID and not a behavior, get is correlated behaviorID.
|
2022-04-25 23:56:40 +00:00
|
|
|
|
2024-02-09 05:40:43 +00:00
|
|
|
CDSkillBehaviorTable* skillTable = CDClientManager::GetTable<CDSkillBehaviorTable>();
|
2022-07-28 13:39:57 +00:00
|
|
|
m_ActionBehaviorId = skillTable->GetSkillByID(m_Action).behaviorID;
|
2022-04-25 23:56:40 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
m_Delay = GetFloat("delay");
|
|
|
|
m_NumIntervals = GetInt("num_intervals");
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|