mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-12 15:53:44 +00:00
Add DoDamage behavior and dont try and start the same node multiple times
This commit is contained in:
@@ -588,7 +588,7 @@ void DestroyableComponent::Damage(uint32_t damage, const LWOOBJID source, uint32
|
||||
// Client does the same check, so we're doing it too
|
||||
auto* const modelComponent = m_Parent->GetComponent<ModelComponent>();
|
||||
if (modelComponent) {
|
||||
modelComponent->OnHit();
|
||||
modelComponent->OnHit(source);
|
||||
// Don't actually deal the damage so the model doesn't die
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "SimplePhysicsComponent.h"
|
||||
#include "eMissionTaskType.h"
|
||||
#include "eObjectBits.h"
|
||||
#include "DestroyableComponent.h"
|
||||
|
||||
#include "Database.h"
|
||||
#include "DluAssert.h"
|
||||
@@ -77,6 +78,7 @@ bool ModelComponent::OnRequestUse(GameMessages::RequestUse& requestUse) {
|
||||
|
||||
void ModelComponent::Update(float deltaTime) {
|
||||
if (m_IsPaused) return;
|
||||
m_DamageCooldown -= deltaTime;
|
||||
|
||||
// Arrived once this frame's movement reached or passed the target
|
||||
if (m_Move.target && (*m_Move.target - m_Parent->GetPosition()).DotProduct(m_Move.targetDirection) <= 0.0f) {
|
||||
@@ -388,13 +390,13 @@ void ModelComponent::ResetRotationState(const NiQuaternion& newBase) {
|
||||
SyncAngularVelocity();
|
||||
}
|
||||
|
||||
void ModelComponent::OnChatMessageReceived(const std::string& sMessage) {
|
||||
for (auto& behavior : m_Behaviors) behavior.OnChatMessageReceived(sMessage);
|
||||
void ModelComponent::OnChatMessageReceived(const std::string& sMessage, const LWOOBJID sender) {
|
||||
for (auto& behavior : m_Behaviors) behavior.OnChatMessageReceived(sMessage, sender);
|
||||
}
|
||||
|
||||
void ModelComponent::OnHit() {
|
||||
void ModelComponent::OnHit(const LWOOBJID attacker) {
|
||||
for (auto& behavior : m_Behaviors) {
|
||||
behavior.OnHit();
|
||||
behavior.OnHit(attacker);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -438,3 +440,14 @@ bool ModelComponent::OnGetObjectReportInfo(GameMessages::GetObjectReportInfo& re
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ModelComponent::DoDamage(const LWOOBJID target) {
|
||||
// dont do damage if we've done damage recently
|
||||
if (m_DamageCooldown > 0.0f) return;
|
||||
m_DamageCooldown = 1.0f;
|
||||
auto* const initiator = Game::entityManager->GetEntity(target);
|
||||
if (initiator) {
|
||||
auto* const destComp = initiator->GetComponent<DestroyableComponent>();
|
||||
if (destComp) destComp->Damage(1, GetParent()->GetObjectID());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,9 +173,9 @@ public:
|
||||
// Degrees per second of the active rotation on axis.
|
||||
float GetAngularSpeed(const int axis) const noexcept { return std::abs(m_Rotation.velocity[axis]); }
|
||||
|
||||
void OnChatMessageReceived(const std::string& sMessage);
|
||||
void OnChatMessageReceived(const std::string& sMessage, const LWOOBJID sender);
|
||||
|
||||
void OnHit();
|
||||
void OnHit(const LWOOBJID attacker);
|
||||
|
||||
// Whether or not to restart at the end of the frame
|
||||
void RestartAtEndOfFrame() { m_RestartAtEndOfFrame = true; }
|
||||
@@ -187,6 +187,7 @@ public:
|
||||
// Decrements the number of strips listening for an attack.
|
||||
// If this is the last strip removing an attack, it will reset the factions to the default of -1.
|
||||
void RemoveAttack();
|
||||
void DoDamage(const LWOOBJID target);
|
||||
private:
|
||||
// Degrees per second per unit of behavior speed
|
||||
static constexpr float BASE_ANGULAR_SPEED = 15.0f;
|
||||
@@ -285,4 +286,6 @@ private:
|
||||
RotationState m_Rotation;
|
||||
|
||||
MoveState m_Move;
|
||||
|
||||
float m_DamageCooldown { 0.0f };
|
||||
};
|
||||
|
||||
@@ -802,13 +802,13 @@ const std::map<LWOOBJID, LWOOBJID>& PropertyManagementComponent::GetModels() con
|
||||
return models;
|
||||
}
|
||||
|
||||
void PropertyManagementComponent::OnChatMessageReceived(const std::string& sMessage) const {
|
||||
void PropertyManagementComponent::OnChatMessageReceived(const std::string& sMessage, const LWOOBJID sender) const {
|
||||
for (const auto& modelID : models | std::views::keys) {
|
||||
auto* const model = Game::entityManager->GetEntity(modelID);
|
||||
if (!model) continue;
|
||||
auto* const modelComponent = model->GetComponent<ModelComponent>();
|
||||
if (!modelComponent) continue;
|
||||
|
||||
modelComponent->OnChatMessageReceived(sMessage);
|
||||
modelComponent->OnChatMessageReceived(sMessage, sender);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ public:
|
||||
LWOOBJID GetId() const noexcept { return propertyId; }
|
||||
|
||||
|
||||
void OnChatMessageReceived(const std::string& sMessage) const;
|
||||
void OnChatMessageReceived(const std::string& sMessage, const LWOOBJID sender) const;
|
||||
private:
|
||||
/**
|
||||
* This
|
||||
|
||||
Reference in New Issue
Block a user