mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-02 02:43: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
|
// Client does the same check, so we're doing it too
|
||||||
auto* const modelComponent = m_Parent->GetComponent<ModelComponent>();
|
auto* const modelComponent = m_Parent->GetComponent<ModelComponent>();
|
||||||
if (modelComponent) {
|
if (modelComponent) {
|
||||||
modelComponent->OnHit();
|
modelComponent->OnHit(source);
|
||||||
// Don't actually deal the damage so the model doesn't die
|
// Don't actually deal the damage so the model doesn't die
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
#include "SimplePhysicsComponent.h"
|
#include "SimplePhysicsComponent.h"
|
||||||
#include "eMissionTaskType.h"
|
#include "eMissionTaskType.h"
|
||||||
#include "eObjectBits.h"
|
#include "eObjectBits.h"
|
||||||
|
#include "DestroyableComponent.h"
|
||||||
|
|
||||||
#include "Database.h"
|
#include "Database.h"
|
||||||
#include "DluAssert.h"
|
#include "DluAssert.h"
|
||||||
@@ -77,6 +78,7 @@ bool ModelComponent::OnRequestUse(GameMessages::RequestUse& requestUse) {
|
|||||||
|
|
||||||
void ModelComponent::Update(float deltaTime) {
|
void ModelComponent::Update(float deltaTime) {
|
||||||
if (m_IsPaused) return;
|
if (m_IsPaused) return;
|
||||||
|
m_DamageCooldown -= deltaTime;
|
||||||
|
|
||||||
// Arrived once this frame's movement reached or passed the target
|
// 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) {
|
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();
|
SyncAngularVelocity();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelComponent::OnChatMessageReceived(const std::string& sMessage) {
|
void ModelComponent::OnChatMessageReceived(const std::string& sMessage, const LWOOBJID sender) {
|
||||||
for (auto& behavior : m_Behaviors) behavior.OnChatMessageReceived(sMessage);
|
for (auto& behavior : m_Behaviors) behavior.OnChatMessageReceived(sMessage, sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelComponent::OnHit() {
|
void ModelComponent::OnHit(const LWOOBJID attacker) {
|
||||||
for (auto& behavior : m_Behaviors) {
|
for (auto& behavior : m_Behaviors) {
|
||||||
behavior.OnHit();
|
behavior.OnHit(attacker);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -438,3 +440,14 @@ bool ModelComponent::OnGetObjectReportInfo(GameMessages::GetObjectReportInfo& re
|
|||||||
|
|
||||||
return true;
|
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.
|
// Degrees per second of the active rotation on axis.
|
||||||
float GetAngularSpeed(const int axis) const noexcept { return std::abs(m_Rotation.velocity[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
|
// Whether or not to restart at the end of the frame
|
||||||
void RestartAtEndOfFrame() { m_RestartAtEndOfFrame = true; }
|
void RestartAtEndOfFrame() { m_RestartAtEndOfFrame = true; }
|
||||||
@@ -187,6 +187,7 @@ public:
|
|||||||
// Decrements the number of strips listening for an attack.
|
// 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.
|
// If this is the last strip removing an attack, it will reset the factions to the default of -1.
|
||||||
void RemoveAttack();
|
void RemoveAttack();
|
||||||
|
void DoDamage(const LWOOBJID target);
|
||||||
private:
|
private:
|
||||||
// Degrees per second per unit of behavior speed
|
// Degrees per second per unit of behavior speed
|
||||||
static constexpr float BASE_ANGULAR_SPEED = 15.0f;
|
static constexpr float BASE_ANGULAR_SPEED = 15.0f;
|
||||||
@@ -285,4 +286,6 @@ private:
|
|||||||
RotationState m_Rotation;
|
RotationState m_Rotation;
|
||||||
|
|
||||||
MoveState m_Move;
|
MoveState m_Move;
|
||||||
|
|
||||||
|
float m_DamageCooldown { 0.0f };
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -802,13 +802,13 @@ const std::map<LWOOBJID, LWOOBJID>& PropertyManagementComponent::GetModels() con
|
|||||||
return models;
|
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) {
|
for (const auto& modelID : models | std::views::keys) {
|
||||||
auto* const model = Game::entityManager->GetEntity(modelID);
|
auto* const model = Game::entityManager->GetEntity(modelID);
|
||||||
if (!model) continue;
|
if (!model) continue;
|
||||||
auto* const modelComponent = model->GetComponent<ModelComponent>();
|
auto* const modelComponent = model->GetComponent<ModelComponent>();
|
||||||
if (!modelComponent) continue;
|
if (!modelComponent) continue;
|
||||||
|
|
||||||
modelComponent->OnChatMessageReceived(sMessage);
|
modelComponent->OnChatMessageReceived(sMessage, sender);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -165,7 +165,7 @@ public:
|
|||||||
LWOOBJID GetId() const noexcept { return propertyId; }
|
LWOOBJID GetId() const noexcept { return propertyId; }
|
||||||
|
|
||||||
|
|
||||||
void OnChatMessageReceived(const std::string& sMessage) const;
|
void OnChatMessageReceived(const std::string& sMessage, const LWOOBJID sender) const;
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* This
|
* This
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ void GameMessageHandler::HandleMessage(RakNet::BitStream& inStream, const System
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
msg->target = objectID;
|
||||||
msg->Deserialize(inStream);
|
msg->Deserialize(inStream);
|
||||||
msg->Handle(*entity, sysAddr);
|
msg->Handle(*entity, sysAddr);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -211,14 +211,14 @@ void PropertyBehavior::Update(float deltaTime, ModelComponent& modelComponent) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PropertyBehavior::OnChatMessageReceived(const std::string& sMessage) {
|
void PropertyBehavior::OnChatMessageReceived(const std::string& sMessage, const LWOOBJID sender) {
|
||||||
auto& activeState = GetActiveState();
|
auto& activeState = GetActiveState();
|
||||||
activeState.OnChatMessageReceived(sMessage);
|
activeState.OnChatMessageReceived(sMessage, sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PropertyBehavior::OnHit() {
|
void PropertyBehavior::OnHit(const LWOOBJID attacker) {
|
||||||
auto& activeState = GetActiveState();
|
auto& activeState = GetActiveState();
|
||||||
activeState.OnHit();
|
activeState.OnHit(attacker);
|
||||||
}
|
}
|
||||||
|
|
||||||
State& PropertyBehavior::GetActiveState() {
|
State& PropertyBehavior::GetActiveState() {
|
||||||
|
|||||||
@@ -46,8 +46,8 @@ public:
|
|||||||
void Deserialize(const tinyxml2::XMLElement& behavior);
|
void Deserialize(const tinyxml2::XMLElement& behavior);
|
||||||
|
|
||||||
void Update(float deltaTime, ModelComponent& modelComponent);
|
void Update(float deltaTime, ModelComponent& modelComponent);
|
||||||
void OnChatMessageReceived(const std::string& sMessage);
|
void OnChatMessageReceived(const std::string& sMessage, const LWOOBJID sender);
|
||||||
void OnHit();
|
void OnHit(const LWOOBJID attacker);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
State& GetActiveState();
|
State& GetActiveState();
|
||||||
|
|||||||
@@ -167,10 +167,10 @@ void State::Update(float deltaTime, ModelComponent& modelComponent, UpdateResult
|
|||||||
for (auto& strip : m_Strips) strip.Update(deltaTime, modelComponent, updateResult);
|
for (auto& strip : m_Strips) strip.Update(deltaTime, modelComponent, updateResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
void State::OnChatMessageReceived(const std::string& sMessage) {
|
void State::OnChatMessageReceived(const std::string& sMessage, const LWOOBJID sender) {
|
||||||
for (auto& strip : m_Strips) strip.OnChatMessageReceived(sMessage);
|
for (auto& strip : m_Strips) strip.OnChatMessageReceived(sMessage, sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
void State::OnHit() {
|
void State::OnHit(const LWOOBJID attacker) {
|
||||||
for (auto& strip : m_Strips) strip.OnHit();
|
for (auto& strip : m_Strips) strip.OnHit(attacker);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ public:
|
|||||||
|
|
||||||
void Update(float deltaTime, ModelComponent& modelComponent, UpdateResult& updateResult);
|
void Update(float deltaTime, ModelComponent& modelComponent, UpdateResult& updateResult);
|
||||||
|
|
||||||
void OnChatMessageReceived(const std::string& sMessage);
|
void OnChatMessageReceived(const std::string& sMessage, const LWOOBJID sender);
|
||||||
void OnHit();
|
void OnHit(const LWOOBJID attacker);
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// The strips contained within this state.
|
// The strips contained within this state.
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include "PropertyManagementComponent.h"
|
#include "PropertyManagementComponent.h"
|
||||||
#include "PlayerManager.h"
|
#include "PlayerManager.h"
|
||||||
#include "SimplePhysicsComponent.h"
|
#include "SimplePhysicsComponent.h"
|
||||||
|
#include "DestroyableComponent.h"
|
||||||
|
|
||||||
#include "dChatFilter.h"
|
#include "dChatFilter.h"
|
||||||
|
|
||||||
@@ -97,6 +98,7 @@ void Strip::HandleMsg(GameMessages::RequestUse& msg) {
|
|||||||
if (nextAction.GetType() == "OnInteract") {
|
if (nextAction.GetType() == "OnInteract") {
|
||||||
IncrementAction();
|
IncrementAction();
|
||||||
m_WaitingForAction = false;
|
m_WaitingForAction = false;
|
||||||
|
m_StripInitiatorID = msg.target;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,23 +116,25 @@ void Strip::HandleMsg(GameMessages::ResetModelToDefaults& msg) {
|
|||||||
m_MovingToStart = false;
|
m_MovingToStart = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Strip::OnChatMessageReceived(const std::string& sMessage) {
|
void Strip::OnChatMessageReceived(const std::string& sMessage, const LWOOBJID sender) {
|
||||||
if (m_PausedTime > 0.0f || !HasMinimumActions()) return;
|
if (m_PausedTime > 0.0f || !HasMinimumActions()) return;
|
||||||
|
|
||||||
const auto& nextAction = GetNextAction();
|
const auto& nextAction = GetNextAction();
|
||||||
if (nextAction.GetType() == "OnChat" && nextAction.GetValueParameterString() == sMessage) {
|
if (nextAction.GetType() == "OnChat" && nextAction.GetValueParameterString() == sMessage) {
|
||||||
IncrementAction();
|
IncrementAction();
|
||||||
m_WaitingForAction = false;
|
m_WaitingForAction = false;
|
||||||
|
m_StripInitiatorID = sender;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Strip::OnHit() {
|
void Strip::OnHit(const LWOOBJID attacker) {
|
||||||
if (m_PausedTime > 0.0f || !HasMinimumActions()) return;
|
if (m_PausedTime > 0.0f || !HasMinimumActions()) return;
|
||||||
|
|
||||||
const auto& nextAction = GetNextAction();
|
const auto& nextAction = GetNextAction();
|
||||||
if (nextAction.GetType() == "OnAttack") {
|
if (nextAction.GetType() == "OnAttack") {
|
||||||
IncrementAction();
|
IncrementAction();
|
||||||
m_WaitingForAction = false;
|
m_WaitingForAction = false;
|
||||||
|
m_StripInitiatorID = attacker;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,9 +267,9 @@ void Strip::ProcNormalAction(float deltaTime, ModelComponent& modelComponent, Up
|
|||||||
// In case a word is removed from the whitelist after it was approved
|
// In case a word is removed from the whitelist after it was approved
|
||||||
const auto modelName = "%[Objects_" + std::to_string(entity.GetLOT()) + "_name]";
|
const auto modelName = "%[Objects_" + std::to_string(entity.GetLOT()) + "_name]";
|
||||||
if (isOk) ChatPackets::SendChatMessage(UNASSIGNED_SYSTEM_ADDRESS, 12, modelName, entity.GetObjectID(), false, GeneralUtils::ASCIIToUTF16(valueStr));
|
if (isOk) ChatPackets::SendChatMessage(UNASSIGNED_SYSTEM_ADDRESS, 12, modelName, entity.GetObjectID(), false, GeneralUtils::ASCIIToUTF16(valueStr));
|
||||||
PropertyManagementComponent::Instance()->OnChatMessageReceived(valueStr.data());
|
PropertyManagementComponent::Instance()->OnChatMessageReceived(valueStr.data(), m_StripInitiatorID);
|
||||||
} else if (nextActionType == "PrivateMessage") {
|
} else if (nextActionType == "PrivateMessage") {
|
||||||
PropertyManagementComponent::Instance()->OnChatMessageReceived(valueStr.data());
|
PropertyManagementComponent::Instance()->OnChatMessageReceived(valueStr.data(), m_StripInitiatorID);
|
||||||
} else if (nextActionType == "PlaySound") {
|
} else if (nextActionType == "PlaySound") {
|
||||||
GameMessages::PlayBehaviorSound sound;
|
GameMessages::PlayBehaviorSound sound;
|
||||||
sound.target = modelComponent.GetParent()->GetObjectID();
|
sound.target = modelComponent.GetParent()->GetObjectID();
|
||||||
@@ -282,6 +286,8 @@ void Strip::ProcNormalAction(float deltaTime, ModelComponent& modelComponent, Up
|
|||||||
Spawn(10497, entity); // Maelstrom Pirate property
|
Spawn(10497, entity); // Maelstrom Pirate property
|
||||||
} else if (nextActionType == "SpawnRonin") {
|
} else if (nextActionType == "SpawnRonin") {
|
||||||
Spawn(10498, entity); // Dark Ronin property
|
Spawn(10498, entity); // Dark Ronin property
|
||||||
|
} else if (nextActionType == "DoDamage") {
|
||||||
|
modelComponent.DoDamage(m_StripInitiatorID);
|
||||||
} else if (nextActionType == "DropImagination") {
|
} else if (nextActionType == "DropImagination") {
|
||||||
for (; numberAsInt > 0; numberAsInt--) SpawnDrop(935, entity); // 1 Imagination powerup
|
for (; numberAsInt > 0; numberAsInt--) SpawnDrop(935, entity); // 1 Imagination powerup
|
||||||
} else if (nextActionType == "DropHealth") {
|
} else if (nextActionType == "DropHealth") {
|
||||||
@@ -411,6 +417,7 @@ void Strip::Update(float deltaTime, ModelComponent& modelComponent, UpdateResult
|
|||||||
|
|
||||||
// Check for trigger blocks and if not a trigger block proc this blocks action
|
// Check for trigger blocks and if not a trigger block proc this blocks action
|
||||||
if (m_NextActionIndex == 0) {
|
if (m_NextActionIndex == 0) {
|
||||||
|
m_StripInitiatorID = LWOOBJID_EMPTY;
|
||||||
LOG("Behavior strip started %s", nextAction.GetType().data());
|
LOG("Behavior strip started %s", nextAction.GetType().data());
|
||||||
m_Speed = DEFAULT_SPEED;
|
m_Speed = DEFAULT_SPEED;
|
||||||
if (nextAction.GetType() == "OnInteract") {
|
if (nextAction.GetType() == "OnInteract") {
|
||||||
@@ -431,6 +438,11 @@ void Strip::Update(float deltaTime, ModelComponent& modelComponent, UpdateResult
|
|||||||
IncrementAction();
|
IncrementAction();
|
||||||
m_PausedFromOnTimer = false;
|
m_PausedFromOnTimer = false;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// in case we run into an unimplemented action or one that isnt a start node
|
||||||
|
// mark as waiting for action so we dont waste time re-starting the same logic and serializing
|
||||||
|
// every frame
|
||||||
|
m_WaitingForAction = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Game::entityManager->SerializeEntity(entity);
|
Game::entityManager->SerializeEntity(entity);
|
||||||
|
|||||||
@@ -46,8 +46,8 @@ public:
|
|||||||
// 2 actions are required for strips to work
|
// 2 actions are required for strips to work
|
||||||
bool HasMinimumActions() const { return m_Actions.size() >= 2; }
|
bool HasMinimumActions() const { return m_Actions.size() >= 2; }
|
||||||
|
|
||||||
void OnChatMessageReceived(const std::string& sMessage);
|
void OnChatMessageReceived(const std::string& sMessage, const LWOOBJID sender);
|
||||||
void OnHit();
|
void OnHit(const LWOOBJID attacker);
|
||||||
private:
|
private:
|
||||||
// Indicates this Strip is waiting for an action to be taken upon it to progress to its actions
|
// Indicates this Strip is waiting for an action to be taken upon it to progress to its actions
|
||||||
bool m_WaitingForAction{ false };
|
bool m_WaitingForAction{ false };
|
||||||
@@ -90,6 +90,8 @@ private:
|
|||||||
|
|
||||||
// Speed applied to moves and rotations started by this strip
|
// Speed applied to moves and rotations started by this strip
|
||||||
float m_Speed{ DEFAULT_SPEED };
|
float m_Speed{ DEFAULT_SPEED };
|
||||||
|
|
||||||
|
LWOOBJID m_StripInitiatorID{ LWOOBJID_EMPTY };
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //!__STRIP__H__
|
#endif //!__STRIP__H__
|
||||||
|
|||||||
@@ -1417,7 +1417,7 @@ void HandlePacket(Packet* packet) {
|
|||||||
std::string sMessage = GeneralUtils::UTF16ToWTF8(chatMessage.message);
|
std::string sMessage = GeneralUtils::UTF16ToWTF8(chatMessage.message);
|
||||||
LOG("%s: %s", playerName.c_str(), sMessage.c_str());
|
LOG("%s: %s", playerName.c_str(), sMessage.c_str());
|
||||||
ChatPackets::SendChatMessage(packet->systemAddress, chatMessage.chatChannel, playerName, user->GetLoggedInChar(), isMythran, chatMessage.message);
|
ChatPackets::SendChatMessage(packet->systemAddress, chatMessage.chatChannel, playerName, user->GetLoggedInChar(), isMythran, chatMessage.message);
|
||||||
if (PropertyManagementComponent::Instance()) PropertyManagementComponent::Instance()->OnChatMessageReceived(sMessage);
|
if (PropertyManagementComponent::Instance()) PropertyManagementComponent::Instance()->OnChatMessageReceived(sMessage, lastChar->GetObjectID());
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user