mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-06-28 15:50:02 +00:00
Move in all directions is functional
This commit is contained in:
parent
891b176b4f
commit
a4a91f1e73
@ -1994,6 +1994,22 @@ void Entity::SetRotation(const NiQuaternion& rotation) {
|
|||||||
Game::entityManager->SerializeEntity(this);
|
Game::entityManager->SerializeEntity(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Entity::SetVelocity(const NiPoint3& velocity) {
|
||||||
|
auto* controllable = GetComponent<ControllablePhysicsComponent>();
|
||||||
|
|
||||||
|
if (controllable != nullptr) {
|
||||||
|
controllable->SetVelocity(velocity);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto* simple = GetComponent<SimplePhysicsComponent>();
|
||||||
|
|
||||||
|
if (simple != nullptr) {
|
||||||
|
simple->SetVelocity(velocity);
|
||||||
|
}
|
||||||
|
|
||||||
|
Game::entityManager->SerializeEntity(this);
|
||||||
|
}
|
||||||
|
|
||||||
bool Entity::GetBoolean(const std::u16string& name) const {
|
bool Entity::GetBoolean(const std::u16string& name) const {
|
||||||
return GetVar<bool>(name);
|
return GetVar<bool>(name);
|
||||||
}
|
}
|
||||||
|
@ -148,6 +148,8 @@ public:
|
|||||||
|
|
||||||
void SetRespawnRot(const NiQuaternion& rotation);
|
void SetRespawnRot(const NiQuaternion& rotation);
|
||||||
|
|
||||||
|
void SetVelocity(const NiPoint3& velocity);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Component management
|
* Component management
|
||||||
*/
|
*/
|
||||||
|
@ -30,10 +30,16 @@ bool ModelComponent::OnResetModelToDefaults(GameMessages::GameMsg& msg) {
|
|||||||
unsmash.target = GetParent()->GetObjectID();
|
unsmash.target = GetParent()->GetObjectID();
|
||||||
unsmash.duration = 0.0f;
|
unsmash.duration = 0.0f;
|
||||||
unsmash.Send(UNASSIGNED_SYSTEM_ADDRESS);
|
unsmash.Send(UNASSIGNED_SYSTEM_ADDRESS);
|
||||||
|
|
||||||
|
m_Parent->SetPosition(m_OriginalPosition);
|
||||||
|
m_Parent->SetRotation(m_OriginalRotation);
|
||||||
|
m_Parent->SetVelocity(NiPoint3Constant::ZERO);
|
||||||
|
|
||||||
m_NumListeningInteract = 0;
|
m_NumListeningInteract = 0;
|
||||||
m_NumActiveUnSmash = 0;
|
m_NumActiveUnSmash = 0;
|
||||||
m_Dirty = true;
|
m_Dirty = true;
|
||||||
Game::entityManager->SerializeEntity(GetParent());
|
Game::entityManager->SerializeEntity(GetParent());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ public:
|
|||||||
* Returns the original position of the model
|
* Returns the original position of the model
|
||||||
* @return the original position of the model
|
* @return the original position of the model
|
||||||
*/
|
*/
|
||||||
const NiPoint3& GetPosition() { return m_OriginalPosition; }
|
const NiPoint3& GetOriginalPosition() { return m_OriginalPosition; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the original position of the model
|
* Sets the original position of the model
|
||||||
@ -53,7 +53,7 @@ public:
|
|||||||
* Returns the original rotation of the model
|
* Returns the original rotation of the model
|
||||||
* @return the original rotation of the model
|
* @return the original rotation of the model
|
||||||
*/
|
*/
|
||||||
const NiQuaternion& GetRotation() { return m_OriginalRotation; }
|
const NiQuaternion& GetOriginalRotation() { return m_OriginalRotation; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the original rotation of the model
|
* Sets the original rotation of the model
|
||||||
|
@ -696,8 +696,9 @@ void PropertyManagementComponent::Save() {
|
|||||||
Database::Get()->AddBehavior(info);
|
Database::Get()->AddBehavior(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto position = entity->GetPosition();
|
// Always save the original position so we can move the model freely
|
||||||
const auto rotation = entity->GetRotation();
|
const auto& position = modelComponent->GetOriginalPosition();
|
||||||
|
const auto& rotation = modelComponent->GetOriginalRotation();
|
||||||
|
|
||||||
if (std::find(present.begin(), present.end(), id) == present.end()) {
|
if (std::find(present.begin(), present.end(), id) == present.end()) {
|
||||||
IPropertyContents::Model model;
|
IPropertyContents::Model model;
|
||||||
|
@ -33,6 +33,13 @@ SimplePhysicsComponent::SimplePhysicsComponent(Entity* parent, int32_t component
|
|||||||
SimplePhysicsComponent::~SimplePhysicsComponent() {
|
SimplePhysicsComponent::~SimplePhysicsComponent() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SimplePhysicsComponent::Update(const float deltaTime) {
|
||||||
|
if (m_Velocity == NiPoint3Constant::ZERO) return;
|
||||||
|
m_Position += m_Velocity * deltaTime;
|
||||||
|
m_DirtyPosition = true;
|
||||||
|
Game::entityManager->SerializeEntity(m_Parent);
|
||||||
|
}
|
||||||
|
|
||||||
void SimplePhysicsComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
|
void SimplePhysicsComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
|
||||||
if (bIsInitialUpdate) {
|
if (bIsInitialUpdate) {
|
||||||
outBitStream.Write(m_ClimbableType != eClimbableType::CLIMBABLE_TYPE_NOT);
|
outBitStream.Write(m_ClimbableType != eClimbableType::CLIMBABLE_TYPE_NOT);
|
||||||
|
@ -33,6 +33,8 @@ public:
|
|||||||
SimplePhysicsComponent(Entity* parent, int32_t componentID);
|
SimplePhysicsComponent(Entity* parent, int32_t componentID);
|
||||||
~SimplePhysicsComponent() override;
|
~SimplePhysicsComponent() override;
|
||||||
|
|
||||||
|
void Update(const float deltaTime) override;
|
||||||
|
|
||||||
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
|
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -97,6 +97,8 @@ void Strip::HandleMsg(GameMessages::ResetModelToDefaults& msg) {
|
|||||||
m_WaitingForAction = false;
|
m_WaitingForAction = false;
|
||||||
m_PausedTime = 0.0f;
|
m_PausedTime = 0.0f;
|
||||||
m_NextActionIndex = 0;
|
m_NextActionIndex = 0;
|
||||||
|
m_InActionMove = NiPoint3Constant::ZERO;
|
||||||
|
m_PreviousFramePosition = NiPoint3Constant::ZERO;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Strip::IncrementAction() {
|
void Strip::IncrementAction() {
|
||||||
@ -127,19 +129,37 @@ void Strip::ProcNormalAction(float deltaTime, ModelComponent& modelComponent) {
|
|||||||
auto number = nextAction.GetValueParameterDouble();
|
auto number = nextAction.GetValueParameterDouble();
|
||||||
auto numberAsInt = static_cast<int32_t>(number);
|
auto numberAsInt = static_cast<int32_t>(number);
|
||||||
auto nextActionType = GetNextAction().GetType();
|
auto nextActionType = GetNextAction().GetType();
|
||||||
if (nextActionType == "SpawnStromling") {
|
|
||||||
Spawn(10495, entity); // Stromling property
|
// TODO replace with switch case and nextActionType with enum
|
||||||
} else if (nextActionType == "SpawnPirate") {
|
/* BEGIN Move */
|
||||||
Spawn(10497, entity); // Maelstrom Pirate property
|
if (nextActionType == "FlyUp" || nextActionType == "FlyDown") {
|
||||||
} else if (nextActionType == "SpawnRonin") {
|
bool isFlyDown = nextActionType == "FlyDown";
|
||||||
Spawn(10498, entity); // Dark Ronin property
|
m_PreviousFramePosition = entity.GetPosition();
|
||||||
} else if (nextActionType == "DropImagination") {
|
m_InActionMove.y = isFlyDown ? -number : number;
|
||||||
for (; numberAsInt > 0; numberAsInt--) SpawnDrop(935, entity); // 1 Imagination powerup
|
|
||||||
} else if (nextActionType == "DropHealth") {
|
// Default velocity is 3 units per second.
|
||||||
for (; numberAsInt > 0; numberAsInt--) SpawnDrop(177, entity); // 1 Life powerup
|
entity.SetVelocity(NiPoint3{0.0f, isFlyDown ? -3.0f : 3.0f, 0.0f});
|
||||||
} else if (nextActionType == "DropArmor") {
|
}
|
||||||
for (; numberAsInt > 0; numberAsInt--) SpawnDrop(6431, entity); // 1 Armor powerup
|
else if (nextActionType == "MoveRight" || nextActionType == "MoveLeft") {
|
||||||
} else if (nextActionType == "Smash") {
|
bool isMoveLeft = nextActionType == "MoveLeft";
|
||||||
|
m_PreviousFramePosition = entity.GetPosition();
|
||||||
|
m_InActionMove.x = isMoveLeft ? -number : number;
|
||||||
|
|
||||||
|
// Default velocity is 3 units per second.
|
||||||
|
entity.SetVelocity(NiPoint3{isMoveLeft ? -3.0f : 3.0f, 0.0f, 0.0f});
|
||||||
|
}
|
||||||
|
else if (nextActionType == "MoveForward" || nextActionType == "MoveBackward") {
|
||||||
|
bool isMoveBackward = nextActionType == "MoveBackward";
|
||||||
|
m_PreviousFramePosition = entity.GetPosition();
|
||||||
|
m_InActionMove.z = isMoveBackward ? -number : number;
|
||||||
|
|
||||||
|
// Default velocity is 3 units per second.
|
||||||
|
entity.SetVelocity(NiPoint3{0.0f, 0.0f, isMoveBackward ? -3.0f : 3.0f});
|
||||||
|
}
|
||||||
|
/* END Move */
|
||||||
|
|
||||||
|
/* BEGIN Action */
|
||||||
|
else if (nextActionType == "Smash") {
|
||||||
if (!modelComponent.IsUnSmashing()) {
|
if (!modelComponent.IsUnSmashing()) {
|
||||||
GameMessages::Smash smash{};
|
GameMessages::Smash smash{};
|
||||||
smash.target = entity.GetObjectID();
|
smash.target = entity.GetObjectID();
|
||||||
@ -162,7 +182,24 @@ void Strip::ProcNormalAction(float deltaTime, ModelComponent& modelComponent) {
|
|||||||
sound.target = modelComponent.GetParent()->GetObjectID();
|
sound.target = modelComponent.GetParent()->GetObjectID();
|
||||||
sound.soundID = numberAsInt;
|
sound.soundID = numberAsInt;
|
||||||
sound.Send(UNASSIGNED_SYSTEM_ADDRESS);
|
sound.Send(UNASSIGNED_SYSTEM_ADDRESS);
|
||||||
} else {
|
}
|
||||||
|
/* END Action */
|
||||||
|
/* BEGIN Gameplay */
|
||||||
|
else if (nextActionType == "SpawnStromling") {
|
||||||
|
Spawn(10495, entity); // Stromling property
|
||||||
|
} else if (nextActionType == "SpawnPirate") {
|
||||||
|
Spawn(10497, entity); // Maelstrom Pirate property
|
||||||
|
} else if (nextActionType == "SpawnRonin") {
|
||||||
|
Spawn(10498, entity); // Dark Ronin property
|
||||||
|
} else if (nextActionType == "DropImagination") {
|
||||||
|
for (; numberAsInt > 0; numberAsInt--) SpawnDrop(935, entity); // 1 Imagination powerup
|
||||||
|
} else if (nextActionType == "DropHealth") {
|
||||||
|
for (; numberAsInt > 0; numberAsInt--) SpawnDrop(177, entity); // 1 Life powerup
|
||||||
|
} else if (nextActionType == "DropArmor") {
|
||||||
|
for (; numberAsInt > 0; numberAsInt--) SpawnDrop(6431, entity); // 1 Armor powerup
|
||||||
|
}
|
||||||
|
/* END Gameplay */
|
||||||
|
else {
|
||||||
static std::set<std::string> g_WarnedActions;
|
static std::set<std::string> g_WarnedActions;
|
||||||
if (!g_WarnedActions.contains(nextActionType.data())) {
|
if (!g_WarnedActions.contains(nextActionType.data())) {
|
||||||
LOG("Tried to play action (%s) which is not supported.", nextActionType.data());
|
LOG("Tried to play action (%s) which is not supported.", nextActionType.data());
|
||||||
@ -187,7 +224,43 @@ void Strip::RemoveStates(ModelComponent& modelComponent) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Strip::CheckMovement(float deltaTime, ModelComponent& modelComponent) {
|
||||||
|
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;
|
||||||
|
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);
|
||||||
|
} 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);
|
||||||
|
} 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
// once done, set the in action move & velocity to zero
|
||||||
|
if (moveFinished) {
|
||||||
|
entity.SetVelocity(NiPoint3Constant::ZERO);
|
||||||
|
m_InActionMove = NiPoint3Constant::ZERO;
|
||||||
|
}
|
||||||
|
|
||||||
|
return moveFinished;
|
||||||
|
}
|
||||||
|
|
||||||
void Strip::Update(float deltaTime, ModelComponent& modelComponent) {
|
void Strip::Update(float deltaTime, ModelComponent& modelComponent) {
|
||||||
|
if (!CheckMovement(deltaTime, modelComponent)) return;
|
||||||
|
|
||||||
m_PausedTime -= deltaTime;
|
m_PausedTime -= deltaTime;
|
||||||
if (m_PausedTime > 0.0f) return;
|
if (m_PausedTime > 0.0f) return;
|
||||||
|
|
||||||
@ -200,7 +273,7 @@ void Strip::Update(float deltaTime, ModelComponent& modelComponent) {
|
|||||||
|
|
||||||
RemoveStates(modelComponent);
|
RemoveStates(modelComponent);
|
||||||
|
|
||||||
// Check for starting blocks and if not a starting 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) {
|
||||||
if (nextAction.GetType() == "OnInteract") {
|
if (nextAction.GetType() == "OnInteract") {
|
||||||
modelComponent.AddInteract();
|
modelComponent.AddInteract();
|
||||||
|
@ -29,6 +29,10 @@ public:
|
|||||||
|
|
||||||
void IncrementAction();
|
void IncrementAction();
|
||||||
void Spawn(LOT object, Entity& entity);
|
void Spawn(LOT object, Entity& entity);
|
||||||
|
|
||||||
|
// Checks the movement logic for whether or not to proceed
|
||||||
|
// Returns true if the movement can continue, false if it needs to wait more.
|
||||||
|
bool CheckMovement(float deltaTime, ModelComponent& modelComponent);
|
||||||
void Update(float deltaTime, ModelComponent& modelComponent);
|
void Update(float deltaTime, ModelComponent& modelComponent);
|
||||||
void SpawnDrop(LOT dropLOT, Entity& entity);
|
void SpawnDrop(LOT dropLOT, Entity& entity);
|
||||||
void ProcNormalAction(float deltaTime, ModelComponent& modelComponent);
|
void ProcNormalAction(float deltaTime, ModelComponent& modelComponent);
|
||||||
@ -37,7 +41,8 @@ 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 };
|
||||||
|
|
||||||
// The amount of time this strip is paused for. Any interactions with this strip should be bounced if this is greater than 0.
|
// The amount of time this strip is paused for. Any interactions with this strip should be bounced if this is greater than 0.
|
||||||
|
// Actions that do not use time do not use this (ex. positions).
|
||||||
float m_PausedTime{ 0.0f };
|
float m_PausedTime{ 0.0f };
|
||||||
|
|
||||||
// The index of the next action to be played. This should always be within range of [0, m_Actions.size()).
|
// The index of the next action to be played. This should always be within range of [0, m_Actions.size()).
|
||||||
@ -48,6 +53,13 @@ private:
|
|||||||
|
|
||||||
// The location of this strip on the UGBehaviorEditor UI
|
// The location of this strip on the UGBehaviorEditor UI
|
||||||
StripUiPosition m_Position;
|
StripUiPosition m_Position;
|
||||||
|
|
||||||
|
// The current actions remaining distance to the target
|
||||||
|
// Only 1 of these vertexs' will be active at once for any given strip.
|
||||||
|
NiPoint3 m_InActionMove{};
|
||||||
|
|
||||||
|
// The position of the parent model on the previous frame
|
||||||
|
NiPoint3 m_PreviousFramePosition{};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //!__STRIP__H__
|
#endif //!__STRIP__H__
|
||||||
|
Loading…
x
Reference in New Issue
Block a user