DarkflameServer/dGame/dBehaviors/CarBoostBehavior.cpp

49 lines
1.4 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 "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);
2022-07-28 13:39:57 +00:00
auto* entity = EntityManager::Instance()->GetEntity(context->originator);
2022-07-28 13:39:57 +00:00
if (entity == nullptr) {
return;
}
2022-07-28 13:39:57 +00:00
Game::logger->Log("Car boost", "Activating car boost!");
2022-07-28 13:39:57 +00:00
auto* possessableComponent = entity->GetComponent<PossessableComponent>();
if (possessableComponent != nullptr) {
2022-07-28 13:39:57 +00:00
auto* possessor = EntityManager::Instance()->GetEntity(possessableComponent->GetPossessor());
if (possessor != nullptr) {
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);
}
}
}
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");
}