mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-21 21:17:25 +00:00
update switch behavior (#1503)
was using very old code from pre-foss that has not been updated with the new behavior knowledge. The code has been updated accordingly to what the client expects. Tested that ice shurikens can now destroy the legs of the skeleton towers in crux prime. Tested that the following weapons can still do damage to enemies and objects in the world: surikens of ice serratorizer Super Morning Star Super Dagger elite long barrel blaster (charge and normal) Mosaic Wand
This commit is contained in:
parent
35ce8771e5
commit
3a4e554da9
@ -7,9 +7,9 @@
|
|||||||
#include "BuffComponent.h"
|
#include "BuffComponent.h"
|
||||||
|
|
||||||
void SwitchBehavior::Handle(BehaviorContext* context, RakNet::BitStream& bitStream, const BehaviorBranchContext branch) {
|
void SwitchBehavior::Handle(BehaviorContext* context, RakNet::BitStream& bitStream, const BehaviorBranchContext branch) {
|
||||||
auto state = true;
|
bool state = true;
|
||||||
|
|
||||||
if (this->m_imagination > 0 || !this->m_isEnemyFaction) {
|
if (m_imagination > 0 || m_targetHasBuff > 0 || m_Distance > -1.0f) {
|
||||||
if (!bitStream.Read(state)) {
|
if (!bitStream.Read(state)) {
|
||||||
LOG("Unable to read state from bitStream, aborting Handle! %i", bitStream.GetNumberOfUnreadBits());
|
LOG("Unable to read state from bitStream, aborting Handle! %i", bitStream.GetNumberOfUnreadBits());
|
||||||
return;
|
return;
|
||||||
@ -18,49 +18,59 @@ void SwitchBehavior::Handle(BehaviorContext* context, RakNet::BitStream& bitStre
|
|||||||
|
|
||||||
auto* entity = Game::entityManager->GetEntity(context->originator);
|
auto* entity = Game::entityManager->GetEntity(context->originator);
|
||||||
|
|
||||||
if (entity == nullptr) {
|
if (!entity) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto* destroyableComponent = entity->GetComponent<DestroyableComponent>();
|
auto* destroyableComponent = entity->GetComponent<DestroyableComponent>();
|
||||||
|
|
||||||
if (destroyableComponent == nullptr) {
|
if (destroyableComponent) {
|
||||||
return;
|
if (m_isEnemyFaction) {
|
||||||
|
auto* target = Game::entityManager->GetEntity(branch.target);
|
||||||
|
if (target) state = destroyableComponent->IsEnemy(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_DEBUG("[%i] State: (%d), imagination: (%i) / (%f)", entity->GetLOT(), state, destroyableComponent->GetImagination(), destroyableComponent->GetMaxImagination());
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_DEBUG("[%i] State: (%d), imagination: (%i) / (%f)", entity->GetLOT(), state, destroyableComponent->GetImagination(), destroyableComponent->GetMaxImagination());
|
auto* behaviorToCall = state ? m_actionTrue : m_actionFalse;
|
||||||
|
behaviorToCall->Handle(context, bitStream, branch);
|
||||||
if (state) {
|
|
||||||
this->m_actionTrue->Handle(context, bitStream, branch);
|
|
||||||
} else {
|
|
||||||
this->m_actionFalse->Handle(context, bitStream, branch);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SwitchBehavior::Calculate(BehaviorContext* context, RakNet::BitStream& bitStream, BehaviorBranchContext branch) {
|
void SwitchBehavior::Calculate(BehaviorContext* context, RakNet::BitStream& bitStream, BehaviorBranchContext branch) {
|
||||||
auto state = true;
|
bool state = true;
|
||||||
|
if (m_imagination > 0 || m_targetHasBuff > 0 || m_Distance > -1.0f) {
|
||||||
if (this->m_imagination > 0 || !this->m_isEnemyFaction) {
|
|
||||||
auto* entity = Game::entityManager->GetEntity(branch.target);
|
auto* entity = Game::entityManager->GetEntity(branch.target);
|
||||||
|
|
||||||
state = entity != nullptr;
|
state = entity != nullptr;
|
||||||
|
|
||||||
if (state && m_targetHasBuff != 0) {
|
if (state) {
|
||||||
auto* buffComponent = entity->GetComponent<BuffComponent>();
|
if (m_targetHasBuff != 0) {
|
||||||
|
auto* buffComponent = entity->GetComponent<BuffComponent>();
|
||||||
|
|
||||||
if (buffComponent != nullptr && !buffComponent->HasBuff(m_targetHasBuff)) {
|
if (buffComponent != nullptr && !buffComponent->HasBuff(m_targetHasBuff)) {
|
||||||
state = false;
|
state = false;
|
||||||
|
}
|
||||||
|
} else if (m_imagination > 0) {
|
||||||
|
auto* destroyableComponent = entity->GetComponent<DestroyableComponent>();
|
||||||
|
|
||||||
|
if (destroyableComponent && destroyableComponent->GetImagination() < m_imagination) {
|
||||||
|
state = false;
|
||||||
|
}
|
||||||
|
} else if (m_Distance > -1.0f) {
|
||||||
|
auto* originator = Game::entityManager->GetEntity(context->originator);
|
||||||
|
|
||||||
|
if (originator) {
|
||||||
|
const auto distance = (originator->GetPosition() - entity->GetPosition()).Length();
|
||||||
|
|
||||||
|
state = distance <= m_Distance;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bitStream.Write(state);
|
bitStream.Write(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state) {
|
auto* behaviorToCall = state ? m_actionTrue : m_actionFalse;
|
||||||
this->m_actionTrue->Calculate(context, bitStream, branch);
|
behaviorToCall->Calculate(context, bitStream, branch);
|
||||||
} else {
|
|
||||||
this->m_actionFalse->Calculate(context, bitStream, branch);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SwitchBehavior::Load() {
|
void SwitchBehavior::Load() {
|
||||||
@ -72,5 +82,7 @@ void SwitchBehavior::Load() {
|
|||||||
|
|
||||||
this->m_isEnemyFaction = GetBoolean("isEnemyFaction");
|
this->m_isEnemyFaction = GetBoolean("isEnemyFaction");
|
||||||
|
|
||||||
this->m_targetHasBuff = GetInt("target_has_buff");
|
this->m_targetHasBuff = GetInt("target_has_buff", -1);
|
||||||
|
|
||||||
|
this->m_Distance = GetFloat("distance", -1.0f);
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,8 @@ public:
|
|||||||
|
|
||||||
int32_t m_targetHasBuff;
|
int32_t m_targetHasBuff;
|
||||||
|
|
||||||
|
float m_Distance;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Inherited
|
* Inherited
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user