mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-05 18:24:12 +00:00
Public release of the DLU server code!
Have fun!
This commit is contained in:
85
dGame/dBehaviors/BlockBehavior.cpp
Normal file
85
dGame/dBehaviors/BlockBehavior.cpp
Normal file
@@ -0,0 +1,85 @@
|
||||
#include "BlockBehavior.h"
|
||||
|
||||
#include "BehaviorContext.h"
|
||||
#include "BehaviorBranchContext.h"
|
||||
#include "EntityManager.h"
|
||||
#include "Game.h"
|
||||
#include "dLogger.h"
|
||||
#include "DestroyableComponent.h"
|
||||
|
||||
void BlockBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
const auto target = context->originator;
|
||||
|
||||
auto* entity = EntityManager::Instance()->GetEntity(target);
|
||||
|
||||
if (entity == nullptr)
|
||||
{
|
||||
Game::logger->Log("DamageAbsorptionBehavior", "Failed to find target (%llu)!\n", branch.target);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
auto* destroyableComponent = entity->GetComponent<DestroyableComponent>();
|
||||
|
||||
if (destroyableComponent == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
destroyableComponent->SetAttacksToBlock(this->m_numAttacksCanBlock);
|
||||
|
||||
if (branch.start > 0)
|
||||
{
|
||||
context->RegisterEndBehavior(this, branch);
|
||||
}
|
||||
else if (branch.duration > 0)
|
||||
{
|
||||
context->RegisterTimerBehavior(this, branch);
|
||||
}
|
||||
}
|
||||
|
||||
void BlockBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
Handle(context, bitStream, branch);
|
||||
}
|
||||
|
||||
void BlockBehavior::UnCast(BehaviorContext* context, BehaviorBranchContext branch)
|
||||
{
|
||||
const auto target = context->originator;
|
||||
|
||||
auto* entity = EntityManager::Instance()->GetEntity(target);
|
||||
|
||||
if (entity == nullptr)
|
||||
{
|
||||
Game::logger->Log("DamageAbsorptionBehavior", "Failed to find target (%llu)!\n", branch.target);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
auto* destroyableComponent = entity->GetComponent<DestroyableComponent>();
|
||||
|
||||
destroyableComponent->SetAttacksToBlock(this->m_numAttacksCanBlock);
|
||||
|
||||
if (destroyableComponent == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
destroyableComponent->SetAttacksToBlock(0);
|
||||
}
|
||||
|
||||
void BlockBehavior::Timer(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second)
|
||||
{
|
||||
UnCast(context, branch);
|
||||
}
|
||||
|
||||
void BlockBehavior::End(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second)
|
||||
{
|
||||
UnCast(context, branch);
|
||||
}
|
||||
|
||||
void BlockBehavior::Load()
|
||||
{
|
||||
this->m_numAttacksCanBlock = GetInt("num_attacks_can_block");
|
||||
}
|
Reference in New Issue
Block a user