DarkflameServer/dGame/dBehaviors/CarBoostBehavior.cpp

49 lines
1.3 KiB
C++
Raw Normal View History

#include "CarBoostBehavior.h"
#include "BehaviorBranchContext.h"
#include "GameMessages.h"
#include "EntityManager.h"
#include "BehaviorContext.h"
#include "CharacterComponent.h"
#include "Game.h"
#include "Logger.h"
#include "PossessableComponent.h"
void CarBoostBehavior::Handle(BehaviorContext* context, RakNet::BitStream& bitStream, BehaviorBranchContext branch) {
2022-07-28 13:39:57 +00:00
GameMessages::SendVehicleAddPassiveBoostAction(branch.target, UNASSIGNED_SYSTEM_ADDRESS);
auto* entity = Game::entityManager->GetEntity(context->originator);
2022-07-28 13:39:57 +00:00
if (entity == nullptr) {
return;
}
LOG("Activating car boost!");
2022-07-28 13:39:57 +00:00
auto* possessableComponent = entity->GetComponent<PossessableComponent>();
if (possessableComponent != nullptr) {
auto* possessor = Game::entityManager->GetEntity(possessableComponent->GetPossessor());
2022-07-28 13:39:57 +00:00
if (possessor != nullptr) {
2022-07-28 13:39:57 +00:00
auto* characterComponent = possessor->GetComponent<CharacterComponent>();
if (characterComponent != nullptr) {
LOG("Tracking car boost!");
2022-07-28 13:39:57 +00:00
characterComponent->UpdatePlayerStatistic(RacingCarBoostsActivated);
}
}
}
2022-07-28 13:39:57 +00:00
m_Action->Handle(context, bitStream, branch);
2022-07-28 13:39:57 +00:00
entity->AddCallbackTimer(m_Time, [entity]() {
GameMessages::SendVehicleRemovePassiveBoostAction(entity->GetObjectID(), UNASSIGNED_SYSTEM_ADDRESS);
});
}
2022-07-28 13:39:57 +00:00
void CarBoostBehavior::Load() {
m_Action = GetAction("action");
2022-07-28 13:39:57 +00:00
m_Time = GetFloat("time");
}