mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-18 17:55:27 +00:00
Merge origin/main into experimental: behaviors, raw terrain scene lookups, property model fixes, player count
Main's model behaviors (every rotation, DoDamage, OnTimer, OnStartup, MoveBackToStart, moves along the model's local axes), raw terrain reading with scene lookups and scene tools, property model and brick by brick fixes and the chat server's player count fix, merged onto this branch's structures: - game messages stay structs; the angular velocity messages join them and the handler sets a message's target - strips own their speed again and the block names, moves and rotations stay in the shared action table (PropertyBehaviorActions, which the dashboard's behavior player reads; it now lists rotations too) - the zone keeps reading its file through ZoneFile and takes the boundaries from it, then loads the raw terrain as main does; the old dNavigation terrain reader is gone - the show all response stays a struct and logs a player count mismatch as main does - the property management component tells models who sent a chat message Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
#include "Strip.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include "CombatMessages.h"
|
||||
|
||||
#include "Amf3.h"
|
||||
@@ -10,6 +12,7 @@
|
||||
#include "PropertyManagementComponent.h"
|
||||
#include "PlayerManager.h"
|
||||
#include "SimplePhysicsComponent.h"
|
||||
#include "DestroyableComponent.h"
|
||||
|
||||
#include "dChatFilter.h"
|
||||
|
||||
@@ -102,6 +105,7 @@ void Strip::HandleMsg(GameMessages::RequestUse& msg) {
|
||||
if (nextAction.GetType() == PropertyBehaviorActions::ON_INTERACT) {
|
||||
IncrementAction();
|
||||
m_WaitingForAction = false;
|
||||
m_StripInitiatorID = msg.target;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,27 +114,34 @@ void Strip::HandleMsg(GameMessages::ResetModelToDefaults& msg) {
|
||||
m_WaitingForAction = false;
|
||||
m_PausedTime = 0.0f;
|
||||
m_NextActionIndex = 0;
|
||||
m_InActionMove = NiPoint3Constant::ZERO;
|
||||
m_InActionTranslation = NiPoint3Constant::ZERO;
|
||||
m_PreviousFramePosition = NiPoint3Constant::ZERO;
|
||||
m_InActionRotation = NiPoint3Constant::ZERO;
|
||||
m_RotationProgress = 0.0f;
|
||||
m_Speed = DEFAULT_SPEED;
|
||||
m_PausedFromOnTimer = 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;
|
||||
|
||||
const auto& nextAction = GetNextAction();
|
||||
if (nextAction.GetType() == PropertyBehaviorActions::ON_CHAT && nextAction.GetValueParameterString() == sMessage) {
|
||||
IncrementAction();
|
||||
m_WaitingForAction = false;
|
||||
m_StripInitiatorID = sender;
|
||||
}
|
||||
}
|
||||
|
||||
void Strip::OnHit() {
|
||||
void Strip::OnHit(const LWOOBJID attacker) {
|
||||
if (m_PausedTime > 0.0f || !HasMinimumActions()) return;
|
||||
|
||||
const auto& nextAction = GetNextAction();
|
||||
if (nextAction.GetType() == PropertyBehaviorActions::ON_ATTACK) {
|
||||
IncrementAction();
|
||||
m_WaitingForAction = false;
|
||||
m_StripInitiatorID = attacker;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,19 +189,37 @@ void Strip::ProcNormalAction(float deltaTime, ModelComponent& modelComponent, Up
|
||||
namespace Actions = PropertyBehaviorActions;
|
||||
/* BEGIN Move */
|
||||
if (const auto* move = Actions::Find(Actions::MOVES, nextActionType)) {
|
||||
const auto& unit = move->axis == 'x' ? NiPoint3Constant::UNIT_X : move->axis == 'y' ? NiPoint3Constant::UNIT_Y : NiPoint3Constant::UNIT_Z;
|
||||
// Default velocity is 3 units per second.
|
||||
if (modelComponent.TrySetVelocity(unit * move->sign)) {
|
||||
// Local right (x), up (y) and forward (z) axes
|
||||
const int axis = move->axis == 'x' ? 0 : move->axis == 'y' ? 1 : 2;
|
||||
if (modelComponent.TryStartMove(axis, move->sign, m_Speed)) {
|
||||
m_PreviousFramePosition = entity.GetPosition();
|
||||
auto& distance = move->axis == 'x' ? m_InActionMove.x : move->axis == 'y' ? m_InActionMove.y : m_InActionMove.z;
|
||||
m_MoveInterruptCount = modelComponent.GetMoveInterruptCount();
|
||||
auto& distance = move->axis == 'x' ? m_InActionTranslation.x : move->axis == 'y' ? m_InActionTranslation.y : m_InActionTranslation.z;
|
||||
distance = move->sign < 0 ? -number : number;
|
||||
}
|
||||
}
|
||||
/* END Move */
|
||||
|
||||
/* BEGIN Rotate */
|
||||
else if (const auto* rotation = Actions::Find(Actions::ROTATIONS, nextActionType)) {
|
||||
// Local tilt (x), spin (y) and roll (z) axes
|
||||
const int axis = rotation->axis == 'x' ? 0 : rotation->axis == 'y' ? 1 : 2;
|
||||
if (number != 0.0 && modelComponent.TryStartRotation(axis, rotation->sign, m_Speed)) {
|
||||
m_MoveInterruptCount = modelComponent.GetMoveInterruptCount();
|
||||
auto& degrees = rotation->axis == 'x' ? m_InActionRotation.x : rotation->axis == 'y' ? m_InActionRotation.y : m_InActionRotation.z;
|
||||
degrees = rotation->sign * number;
|
||||
m_RotationProgress = 0.0f;
|
||||
}
|
||||
}
|
||||
/* END Rotate */
|
||||
|
||||
/* BEGIN Navigation */
|
||||
else if (nextActionType == Actions::SET_SPEED) {
|
||||
modelComponent.SetSpeed(number);
|
||||
// Floored so a move or rotation can never stall forever
|
||||
m_Speed = std::max(static_cast<float>(number), MIN_SPEED);
|
||||
} else if (nextActionType == Actions::MOVE_BACK_TO_START) {
|
||||
modelComponent.StartMoveTo(modelComponent.GetOriginalPosition(), m_Speed);
|
||||
m_MovingToStart = true;
|
||||
}
|
||||
/* END Navigation */
|
||||
|
||||
@@ -226,9 +255,9 @@ void Strip::ProcNormalAction(float deltaTime, ModelComponent& modelComponent, Up
|
||||
chatMessage.message = GeneralUtils::ASCIIToUTF16(valueStr);
|
||||
chatMessage.Broadcast();
|
||||
}
|
||||
PropertyManagementComponent::Instance()->OnChatMessageReceived(valueStr.data());
|
||||
PropertyManagementComponent::Instance()->OnChatMessageReceived(valueStr.data(), m_StripInitiatorID);
|
||||
} else if (nextActionType == Actions::PRIVATE_MESSAGE) {
|
||||
PropertyManagementComponent::Instance()->OnChatMessageReceived(valueStr.data());
|
||||
PropertyManagementComponent::Instance()->OnChatMessageReceived(valueStr.data(), m_StripInitiatorID);
|
||||
} else if (nextActionType == Actions::PLAY_SOUND) {
|
||||
GameMessages::PlayBehaviorSound sound;
|
||||
sound.target = modelComponent.GetParent()->GetObjectID();
|
||||
@@ -241,6 +270,8 @@ void Strip::ProcNormalAction(float deltaTime, ModelComponent& modelComponent, Up
|
||||
/* BEGIN Gameplay */
|
||||
else if (const auto* spawn = Actions::Find(Actions::SPAWNS, nextActionType)) {
|
||||
Spawn(spawn->lot, entity);
|
||||
} else if (nextActionType == Actions::DO_DAMAGE) {
|
||||
modelComponent.DoDamage(m_StripInitiatorID);
|
||||
} else if (const auto* drop = Actions::Find(Actions::DROPS, nextActionType)) {
|
||||
for (; numberAsInt > 0; numberAsInt--) SpawnDrop(drop->lot, entity);
|
||||
}
|
||||
@@ -277,49 +308,66 @@ void Strip::RemoveStates(ModelComponent& modelComponent) const {
|
||||
}
|
||||
|
||||
bool Strip::CheckMovement(float deltaTime, ModelComponent& modelComponent) {
|
||||
if (m_MovingToStart) {
|
||||
if (modelComponent.IsMovingToTarget()) return false;
|
||||
m_MovingToStart = false;
|
||||
}
|
||||
|
||||
// A MoveBackToStart cancelled our move, so skip to the next action
|
||||
if (m_MoveInterruptCount != modelComponent.GetMoveInterruptCount()) m_InActionTranslation = NiPoint3Constant::ZERO;
|
||||
|
||||
auto& entity = *modelComponent.GetParent();
|
||||
const auto& currentPos = entity.GetPosition();
|
||||
const auto diff = currentPos - m_PreviousFramePosition;
|
||||
const auto [moveX, moveY, moveZ] = m_InActionMove;
|
||||
m_PreviousFramePosition = currentPos;
|
||||
|
||||
// Only want to subtract from the move if one is being performed.
|
||||
// Starts at true because we may not be doing a move at all.
|
||||
// If one is being done, then one of the move_ variables will be non-zero
|
||||
bool moveFinished = true;
|
||||
NiPoint3 finalPositionAdjustment = NiPoint3Constant::ZERO;
|
||||
if (moveX != 0.0f) {
|
||||
m_InActionMove.x -= diff.x;
|
||||
// If the sign bit is different between the two numbers, then we have finished our move.
|
||||
moveFinished = std::signbit(m_InActionMove.x) != std::signbit(moveX);
|
||||
finalPositionAdjustment.x = m_InActionMove.x;
|
||||
} else if (moveY != 0.0f) {
|
||||
m_InActionMove.y -= diff.y;
|
||||
// If the sign bit is different between the two numbers, then we have finished our move.
|
||||
moveFinished = std::signbit(m_InActionMove.y) != std::signbit(moveY);
|
||||
finalPositionAdjustment.y = m_InActionMove.y;
|
||||
} else if (moveZ != 0.0f) {
|
||||
m_InActionMove.z -= diff.z;
|
||||
// If the sign bit is different between the two numbers, then we have finished our move.
|
||||
moveFinished = std::signbit(m_InActionMove.z) != std::signbit(moveZ);
|
||||
finalPositionAdjustment.z = m_InActionMove.z;
|
||||
}
|
||||
for (int axis = 0; axis < 3; axis++) {
|
||||
const float target = m_InActionTranslation[axis];
|
||||
if (target == 0.0f) continue;
|
||||
|
||||
// Once done, set the in action move & velocity to zero
|
||||
if (moveFinished && m_InActionMove != NiPoint3Constant::ZERO) {
|
||||
auto entityVelocity = entity.GetVelocity();
|
||||
// Zero out only the velocity that was acted on
|
||||
if (moveX != 0.0f) entityVelocity.x = 0.0f;
|
||||
else if (moveY != 0.0f) entityVelocity.y = 0.0f;
|
||||
else if (moveZ != 0.0f) entityVelocity.z = 0.0f;
|
||||
modelComponent.SetVelocity(entityVelocity);
|
||||
// The local axes are orthonormal so this isolates our axis from any other active moves
|
||||
const auto& axisVector = modelComponent.GetMoveAxis(axis);
|
||||
m_InActionTranslation[axis] -= diff.DotProduct(axisVector);
|
||||
|
||||
// If the sign bit is different between the two numbers, then we have finished our move.
|
||||
if (std::signbit(m_InActionTranslation[axis]) == std::signbit(target)) return false;
|
||||
|
||||
// Do the final adjustment so we will have moved exactly the requested units
|
||||
entity.SetPosition(entity.GetPosition() + finalPositionAdjustment);
|
||||
m_InActionMove = NiPoint3Constant::ZERO;
|
||||
entity.SetPosition(entity.GetPosition() + axisVector * m_InActionTranslation[axis]);
|
||||
modelComponent.StopMove(axis);
|
||||
m_InActionTranslation = NiPoint3Constant::ZERO;
|
||||
}
|
||||
|
||||
return moveFinished;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Strip::CheckRotation(float deltaTime, ModelComponent& modelComponent) {
|
||||
if (m_MoveInterruptCount != modelComponent.GetMoveInterruptCount()) {
|
||||
for (int axis = 0; axis < 3; axis++) {
|
||||
if (m_InActionRotation[axis] != 0.0f) modelComponent.StopRotation(axis);
|
||||
}
|
||||
m_InActionRotation = NiPoint3Constant::ZERO;
|
||||
m_RotationProgress = 0.0f;
|
||||
}
|
||||
|
||||
for (int axis = 0; axis < 3; axis++) {
|
||||
const float target = m_InActionRotation[axis];
|
||||
if (target == 0.0f) continue;
|
||||
|
||||
// Snapping to the target keeps the final angle exact regardless of speed or frame time
|
||||
const float step = modelComponent.GetAngularSpeed(axis) * deltaTime;
|
||||
if (std::abs(target - m_RotationProgress) <= step) m_RotationProgress = target;
|
||||
else m_RotationProgress += std::copysign(step, target);
|
||||
|
||||
modelComponent.SetRotationProgress(axis, m_RotationProgress);
|
||||
if (m_RotationProgress != target) return false;
|
||||
|
||||
modelComponent.StopRotation(axis);
|
||||
m_InActionRotation = NiPoint3Constant::ZERO;
|
||||
m_RotationProgress = 0.0f;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Strip::Update(float deltaTime, ModelComponent& modelComponent, UpdateResult& updateResult) {
|
||||
@@ -327,8 +375,9 @@ void Strip::Update(float deltaTime, ModelComponent& modelComponent, UpdateResult
|
||||
// Strips are also designed to have 2 actions or more to run.
|
||||
if (!HasMinimumActions()) return;
|
||||
|
||||
// Return if this strip has an active movement action
|
||||
// Return if this strip has an active movement or rotation action
|
||||
if (!CheckMovement(deltaTime, modelComponent)) return;
|
||||
if (!CheckRotation(deltaTime, modelComponent)) return;
|
||||
|
||||
// Don't run this strip if we're paused.
|
||||
m_PausedTime -= deltaTime;
|
||||
@@ -346,16 +395,35 @@ void Strip::Update(float deltaTime, ModelComponent& modelComponent, UpdateResult
|
||||
|
||||
// Check for trigger blocks and if not a trigger block proc this blocks action
|
||||
if (m_NextActionIndex == 0) {
|
||||
m_StripInitiatorID = LWOOBJID_EMPTY;
|
||||
LOG("Behavior strip started %s", nextAction.GetType().data());
|
||||
m_Speed = DEFAULT_SPEED;
|
||||
if (nextAction.GetType() == PropertyBehaviorActions::ON_INTERACT) {
|
||||
modelComponent.AddInteract();
|
||||
m_WaitingForAction = true;
|
||||
} else if (nextAction.GetType() == PropertyBehaviorActions::ON_CHAT) {
|
||||
// logic here if needed
|
||||
m_WaitingForAction = true;
|
||||
} else if (nextAction.GetType() == PropertyBehaviorActions::ON_ATTACK) {
|
||||
modelComponent.AddAttack();
|
||||
m_WaitingForAction = true;
|
||||
} else if (nextAction.GetType() == PropertyBehaviorActions::ON_STARTUP) {
|
||||
IncrementAction();
|
||||
} else if (nextAction.GetType() == PropertyBehaviorActions::ON_TIMER) {
|
||||
if (!m_PausedFromOnTimer) {
|
||||
m_PausedTime = nextAction.GetValueParameterDouble();
|
||||
m_PausedFromOnTimer = true;
|
||||
} else {
|
||||
IncrementAction();
|
||||
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);
|
||||
m_WaitingForAction = true;
|
||||
} else { // should be a normal block
|
||||
ProcNormalAction(deltaTime, modelComponent, updateResult);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user