2021-12-05 17:54:36 +00:00
|
|
|
#include "CarBoostBehavior.h"
|
|
|
|
#include "BehaviorBranchContext.h"
|
|
|
|
#include "GameMessages.h"
|
|
|
|
#include "EntityManager.h"
|
|
|
|
#include "BehaviorContext.h"
|
|
|
|
#include "CharacterComponent.h"
|
|
|
|
#include "Game.h"
|
|
|
|
#include "dLogger.h"
|
|
|
|
#include "PossessableComponent.h"
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void CarBoostBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
|
|
|
GameMessages::SendVehicleAddPassiveBoostAction(branch.target, UNASSIGNED_SYSTEM_ADDRESS);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
auto* entity = EntityManager::Instance()->GetEntity(context->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
|
|
|
Game::logger->Log("Car boost", "Activating car boost!");
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
auto* possessableComponent = entity->GetComponent<PossessableComponent>();
|
|
|
|
if (possessableComponent != nullptr) {
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
auto* possessor = EntityManager::Instance()->GetEntity(possessableComponent->GetPossessor());
|
|
|
|
if (possessor != nullptr) {
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
auto* characterComponent = possessor->GetComponent<CharacterComponent>();
|
|
|
|
if (characterComponent != nullptr) {
|
|
|
|
Game::logger->Log("Car boost", "Tracking car boost!");
|
|
|
|
characterComponent->UpdatePlayerStatistic(RacingCarBoostsActivated);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
m_Action->Handle(context, bitStream, branch);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
entity->AddCallbackTimer(m_Time, [entity]() {
|
|
|
|
GameMessages::SendVehicleRemovePassiveBoostAction(entity->GetObjectID(), UNASSIGNED_SYSTEM_ADDRESS);
|
|
|
|
});
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void CarBoostBehavior::Load() {
|
|
|
|
m_Action = GetAction("action");
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
m_Time = GetFloat("time");
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|