Merge pull request #177 from DarkflameUniverse/implement-buccanneer-valiant

Fix #164: Implement Buccaneer Valiant special ability
This commit is contained in:
Mick 2021-12-13 14:31:36 +01:00 committed by GitHub
commit ff3e10d076
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 114 additions and 32 deletions

View File

@ -74,7 +74,7 @@ void AreaOfEffectBehavior::Calculate(BehaviorContext* context, RakNet::BitStream
includeFaction = 1; includeFaction = 1;
} }
for (auto validTarget : context->GetValidTargets(m_ignoreFaction , includeFaction)) for (auto validTarget : context->GetValidTargets(m_ignoreFaction , includeFaction, m_TargetSelf == 1))
{ {
auto* entity = EntityManager::Instance()->GetEntity(validTarget); auto* entity = EntityManager::Instance()->GetEntity(validTarget);
@ -155,4 +155,6 @@ void AreaOfEffectBehavior::Load()
this->m_ignoreFaction = GetInt("ignore_faction"); this->m_ignoreFaction = GetInt("ignore_faction");
this->m_includeFaction = GetInt("include_faction"); this->m_includeFaction = GetInt("include_faction");
this->m_TargetSelf = GetInt("target_self");
} }

View File

@ -14,6 +14,8 @@ public:
int32_t m_includeFaction; int32_t m_includeFaction;
int32_t m_TargetSelf;
/* /*
* Inherited * Inherited
*/ */

View File

@ -325,7 +325,7 @@ void BehaviorContext::Reset()
this->scheduledUpdates.clear(); this->scheduledUpdates.clear();
} }
std::vector<LWOOBJID> BehaviorContext::GetValidTargets(int32_t ignoreFaction, int32_t includeFaction) const std::vector<LWOOBJID> BehaviorContext::GetValidTargets(int32_t ignoreFaction, int32_t includeFaction, bool targetSelf) const
{ {
auto* entity = EntityManager::Instance()->GetEntity(this->caster); auto* entity = EntityManager::Instance()->GetEntity(this->caster);
@ -353,7 +353,7 @@ std::vector<LWOOBJID> BehaviorContext::GetValidTargets(int32_t ignoreFaction, in
} }
} }
if (ignoreFaction || includeFaction || (!entity->HasComponent(COMPONENT_TYPE_PHANTOM_PHYSICS) && !entity->HasComponent(COMPONENT_TYPE_CONTROLLABLE_PHYSICS) && targets.empty())) if (ignoreFaction || includeFaction || (!entity->HasComponent(COMPONENT_TYPE_PHANTOM_PHYSICS) && targets.empty()))
{ {
DestroyableComponent* destroyableComponent; DestroyableComponent* destroyableComponent;
if (!entity->TryGetComponent(COMPONENT_TYPE_DESTROYABLE, destroyableComponent)) if (!entity->TryGetComponent(COMPONENT_TYPE_DESTROYABLE, destroyableComponent))
@ -362,12 +362,11 @@ std::vector<LWOOBJID> BehaviorContext::GetValidTargets(int32_t ignoreFaction, in
} }
auto entities = EntityManager::Instance()->GetEntitiesByComponent(COMPONENT_TYPE_CONTROLLABLE_PHYSICS); auto entities = EntityManager::Instance()->GetEntitiesByComponent(COMPONENT_TYPE_CONTROLLABLE_PHYSICS);
for (auto* candidate : entities) for (auto* candidate : entities)
{ {
const auto id = candidate->GetObjectID(); const auto id = candidate->GetObjectID();
if (destroyableComponent->CheckValidity(id, ignoreFaction || includeFaction)) if ((id != entity->GetObjectID() || targetSelf) && destroyableComponent->CheckValidity(id, ignoreFaction || includeFaction))
{ {
targets.push_back(id); targets.push_back(id);
} }

View File

@ -102,7 +102,7 @@ struct BehaviorContext
void Reset(); void Reset();
std::vector<LWOOBJID> GetValidTargets(int32_t ignoreFaction = 0, int32_t includeFaction = 0) const; std::vector<LWOOBJID> GetValidTargets(int32_t ignoreFaction = 0, int32_t includeFaction = 0, const bool targetSelf = false) const;
explicit BehaviorContext(LWOOBJID originator, bool calculation = false); explicit BehaviorContext(LWOOBJID originator, bool calculation = false);

View File

@ -1,44 +1,81 @@
#include "ForceMovementBehavior.h" #include "ForceMovementBehavior.h"
#include "BehaviorBranchContext.h" #include "BehaviorBranchContext.h"
#include "BehaviorContext.h" #include "BehaviorContext.h"
#include "ControllablePhysicsComponent.h"
#include "EntityManager.h"
void ForceMovementBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch) void ForceMovementBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch) {
{ if (this->m_hitAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY && this->m_hitEnemyAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY && this->m_hitFactionAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY) {
if (this->m_hitAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY && this->m_hitEnemyAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY && this->m_hitFactionAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY)
{
return; return;
} }
uint32_t handle; uint32_t handle;
bitStream->Read(handle); bitStream->Read(handle);
context->RegisterSyncBehavior(handle, this, branch); context->RegisterSyncBehavior(handle, this, branch);
} }
void ForceMovementBehavior::Sync(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) void ForceMovementBehavior::Sync(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
{ {
uint32_t next; uint32_t next;
bitStream->Read(next); bitStream->Read(next);
LWOOBJID target; LWOOBJID target;
bitStream->Read(target); bitStream->Read(target);
auto* behavior = CreateBehavior(next);
branch.target = target; branch.target = target;
auto* behavior = CreateBehavior(next);
behavior->Handle(context, bitStream, branch); behavior->Handle(context, bitStream, branch);
} }
void ForceMovementBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
if (this->m_hitAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY && this->m_hitEnemyAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY && this->m_hitFactionAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY) {
return;
}
auto* casterEntity = EntityManager::Instance()->GetEntity(context->caster);
if (casterEntity != nullptr) {
auto* controllablePhysicsComponent = casterEntity->GetComponent<ControllablePhysicsComponent>();
if (controllablePhysicsComponent != nullptr) {
if (m_Forward == 1) {
controllablePhysicsComponent->SetVelocity(controllablePhysicsComponent->GetRotation().GetForwardVector() * 25);
}
EntityManager::Instance()->SerializeEntity(casterEntity);
}
}
const auto skillHandle = context->GetUniqueSkillId();
bitStream->Write(skillHandle);
context->SyncCalculation(skillHandle, this->m_Duration, this, branch);
}
void ForceMovementBehavior::Load() void ForceMovementBehavior::Load()
{ {
this->m_hitAction = GetAction("hit_action"); this->m_hitAction = GetAction("hit_action");
this->m_hitEnemyAction = GetAction("hit_action_enemy"); this->m_hitEnemyAction = GetAction("hit_action_enemy");
this->m_hitFactionAction = GetAction("hit_action_faction"); this->m_hitFactionAction = GetAction("hit_action_faction");
this->m_Duration = GetFloat("duration");
this->m_Forward = GetFloat("forward");
this->m_Left = GetFloat("left");
this->m_Yaw = GetFloat("yaw");
}
void ForceMovementBehavior::SyncCalculation(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
auto* casterEntity = EntityManager::Instance()->GetEntity(context->caster);
if (casterEntity != nullptr) {
auto* controllablePhysicsComponent = casterEntity->GetComponent<ControllablePhysicsComponent>();
if (controllablePhysicsComponent != nullptr) {
controllablePhysicsComponent->SetPosition(controllablePhysicsComponent->GetPosition() + controllablePhysicsComponent->GetVelocity() * m_Duration);
controllablePhysicsComponent->SetVelocity({});
EntityManager::Instance()->SerializeEntity(casterEntity);
}
}
this->m_hitAction->Calculate(context, bitStream, branch);
this->m_hitEnemyAction->Calculate(context, bitStream, branch);
this->m_hitEnemyAction->Calculate(context, bitStream, branch);
} }

View File

@ -10,6 +10,11 @@ public:
Behavior* m_hitFactionAction; Behavior* m_hitFactionAction;
float_t m_Duration;
float_t m_Forward;
float_t m_Left;
float_t m_Yaw;
/* /*
* Inherited * Inherited
*/ */
@ -18,8 +23,12 @@ public:
{ {
} }
void Calculate(BehaviorContext *context, RakNet::BitStream *bitStream, BehaviorBranchContext branch) override;
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override; void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
void SyncCalculation(BehaviorContext *context, RakNet::BitStream *bitStream, BehaviorBranchContext branch) override;
void Sync(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override; void Sync(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
void Load() override; void Load() override;

View File

@ -0,0 +1,24 @@
#include "BuccaneerValiantShip.h"
#include "SkillComponent.h"
#include "dLogger.h"
void BuccaneerValiantShip::OnStartup(Entity* self) {
const auto skill = 982;
const auto behavior = 20577;
const auto skillCastTimer = 1.0F;
self->AddCallbackTimer(skillCastTimer, [self]() {
auto* skillComponent = self->GetComponent<SkillComponent>();
auto* owner = self->GetOwner();
if (skillComponent != nullptr && owner != nullptr) {
skillComponent->CalculateBehavior(skill, behavior, LWOOBJID_EMPTY, true, false, owner->GetObjectID());
// Kill self if missed
const auto selfSmashTimer = 1.1F;
self->AddCallbackTimer(selfSmashTimer, [self]() {
self->Kill();
});
}
});
}

View File

@ -0,0 +1,6 @@
#pragma once
#include "CppScripts.h"
class BuccaneerValiantShip : public CppScripts::Script {
void OnStartup(Entity *self) override;
};

View File

@ -261,6 +261,7 @@
#include "PersonalFortress.h" #include "PersonalFortress.h"
#include "PropertyDevice.h" #include "PropertyDevice.h"
#include "ImaginationBackpackHealServer.h" #include "ImaginationBackpackHealServer.h"
#include "BuccaneerValiantShip.h"
// Survival scripts // Survival scripts
#include "AgSurvivalStromling.h" #include "AgSurvivalStromling.h"
@ -774,6 +775,8 @@ CppScripts::Script* CppScripts::GetScript(Entity* parent, const std::string& scr
script = new PropertyDevice(); script = new PropertyDevice();
else if (scriptName == "scripts\\02_server\\Map\\General\\L_IMAG_BACKPACK_HEALS_SERVER.lua") else if (scriptName == "scripts\\02_server\\Map\\General\\L_IMAG_BACKPACK_HEALS_SERVER.lua")
script = new ImaginationBackpackHealServer(); script = new ImaginationBackpackHealServer();
else if (scriptName == "scripts\\EquipmentScripts\\BuccaneerValiantShip.lua")
script = new BuccaneerValiantShip();
//Ignore these scripts: //Ignore these scripts:
else if (scriptName == "scripts\\02_server\\Enemy\\General\\L_SUSPEND_LUA_AI.lua") else if (scriptName == "scripts\\02_server\\Enemy\\General\\L_SUSPEND_LUA_AI.lua")