mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-05-24 15:52:32 +00:00
base speed stuff
looping fixes proper stopping
This commit is contained in:
parent
8ecfdb6256
commit
e70e2025a8
@ -36,6 +36,7 @@ ControllablePhysicsComponent::ControllablePhysicsComponent(Entity* entity) : Com
|
|||||||
m_AttachedPath = entity->GetVarAsString(u"attached_path");
|
m_AttachedPath = entity->GetVarAsString(u"attached_path");
|
||||||
m_PathWaypoint = entity->GetVarAs<int>(u"attached_path_start");
|
m_PathWaypoint = entity->GetVarAs<int>(u"attached_path_start");
|
||||||
m_PathSpeed = 2.5f;
|
m_PathSpeed = 2.5f;
|
||||||
|
m_BaseSpeed = GetBaseSpeed(m_Parent->GetLOT());
|
||||||
|
|
||||||
|
|
||||||
if (entity->GetLOT() != 1) // Other physics entities we care about will be added by BaseCombatAI
|
if (entity->GetLOT() != 1) // Other physics entities we care about will be added by BaseCombatAI
|
||||||
@ -60,14 +61,22 @@ ControllablePhysicsComponent::~ControllablePhysicsComponent() {
|
|||||||
void ControllablePhysicsComponent::Update(float deltaTime) {
|
void ControllablePhysicsComponent::Update(float deltaTime) {
|
||||||
if (m_AttachedPath != ""){
|
if (m_AttachedPath != ""){
|
||||||
const auto* path = dZoneManager::Instance()->GetZone()->GetPath(m_AttachedPath);
|
const auto* path = dZoneManager::Instance()->GetZone()->GetPath(m_AttachedPath);
|
||||||
// Game::logger->Log("ControllablePhysicsComponent", "path type %i", path->pathType);
|
|
||||||
if (!m_Paused){
|
if (!m_Paused){
|
||||||
if (path->pathWaypoints.size() > m_PathWaypoint) {
|
if (path->pathWaypoints.size() > m_PathWaypoint) {
|
||||||
// TODO: Get proper speed
|
auto mod_speed = m_BaseSpeed;
|
||||||
auto speed = deltaTime * m_PathSpeed;
|
if (m_PathSpeed < 1.0) {
|
||||||
|
mod_speed = m_BaseSpeed * m_PathSpeed;
|
||||||
|
} else {
|
||||||
|
mod_speed = m_PathSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto speed = deltaTime * mod_speed;
|
||||||
auto source = GetPosition();
|
auto source = GetPosition();
|
||||||
auto dest = path->pathWaypoints.at(m_PathWaypoint).position;
|
auto dest = path->pathWaypoints.at(m_PathWaypoint).position;
|
||||||
dest.y = source.y;
|
dest.y = source.y; // hacky way to not glitch with weird heights
|
||||||
|
|
||||||
|
// if we are close enough to the destination waypoint
|
||||||
if (Vector3::DistanceSquared(source, dest) < 2 * 2) {
|
if (Vector3::DistanceSquared(source, dest) < 2 * 2) {
|
||||||
if (path->pathBehavior == PathBehavior::Loop) {
|
if (path->pathBehavior == PathBehavior::Loop) {
|
||||||
if (path->waypointCount < m_PathWaypoint + 1) {
|
if (path->waypointCount < m_PathWaypoint + 1) {
|
||||||
@ -79,7 +88,9 @@ void ControllablePhysicsComponent::Update(float deltaTime) {
|
|||||||
} else m_PathWaypoint++;
|
} else m_PathWaypoint++;
|
||||||
}
|
}
|
||||||
m_Paused = true;
|
m_Paused = true;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto delta = dest - source;
|
const auto delta = dest - source;
|
||||||
const auto length = sqrtf(delta.x * delta.x + delta.y * delta.y + delta.z * delta.z);
|
const auto length = sqrtf(delta.x * delta.x + delta.y * delta.y + delta.z * delta.z);
|
||||||
NiPoint3 velocity;
|
NiPoint3 velocity;
|
||||||
@ -99,14 +110,15 @@ void ControllablePhysicsComponent::Update(float deltaTime) {
|
|||||||
SetVelocity(velocity);
|
SetVelocity(velocity);
|
||||||
SetPosition(source + velocity_pos);
|
SetPosition(source + velocity_pos);
|
||||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||||
} else m_PathWaypoint = 0;
|
} else if (path->pathBehavior == PathBehavior::Loop) m_PathWaypoint = 0;
|
||||||
|
|
||||||
} else { // paused, meaing we are at a waypoint, and we want to do something
|
} else { // paused, meaing we are at a waypoint, and we want to do something
|
||||||
if (m_PausedTime > 0) {
|
if (m_PausedTime > 0) {
|
||||||
m_PausedTime = m_PausedTime - deltaTime;
|
m_PausedTime = m_PausedTime - deltaTime;
|
||||||
} else if (m_PausedTime < 0){
|
} else if (m_PausedTime < 0){
|
||||||
m_Paused = false;
|
m_Paused = false;
|
||||||
m_PausedTime = 0;
|
m_PausedTime = 0;
|
||||||
} else if (path->pathWaypoints.size() - 1 > m_PathWaypoint) {
|
} else if (path->pathWaypoints.size() > m_PathWaypoint) {
|
||||||
PathWaypoint waypoint = path->pathWaypoints.at(m_PathWaypoint);
|
PathWaypoint waypoint = path->pathWaypoints.at(m_PathWaypoint);
|
||||||
if (waypoint.config.size() > 0) {
|
if (waypoint.config.size() > 0) {
|
||||||
for (LDFBaseData* action : waypoint.config) {
|
for (LDFBaseData* action : waypoint.config) {
|
||||||
@ -114,8 +126,12 @@ void ControllablePhysicsComponent::Update(float deltaTime) {
|
|||||||
if (action->GetKey() == u"delay"){
|
if (action->GetKey() == u"delay"){
|
||||||
m_PausedTime = std::stof(action->GetValueAsString());
|
m_PausedTime = std::stof(action->GetValueAsString());
|
||||||
SetVelocity(NiPoint3::ZERO);
|
SetVelocity(NiPoint3::ZERO);
|
||||||
|
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||||
} else if (action->GetKey() == u"emote"){
|
} else if (action->GetKey() == u"emote"){
|
||||||
GameMessages::SendPlayAnimation(m_Parent, GeneralUtils::UTF8ToUTF16(action->GetValueAsString()));
|
GameMessages::SendPlayAnimation(m_Parent, GeneralUtils::UTF8ToUTF16(action->GetValueAsString()));
|
||||||
|
m_PausedTime += 10;
|
||||||
|
SetVelocity(NiPoint3::ZERO);
|
||||||
|
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||||
} else if (action->GetKey() == u"pathspeed") {
|
} else if (action->GetKey() == u"pathspeed") {
|
||||||
m_PathSpeed = std::stof(action->GetValueAsString());
|
m_PathSpeed = std::stof(action->GetValueAsString());
|
||||||
if (m_PathSpeed < 2.5f) m_PathSpeed = 2.5f;
|
if (m_PathSpeed < 2.5f) m_PathSpeed = 2.5f;
|
||||||
@ -130,7 +146,7 @@ void ControllablePhysicsComponent::Update(float deltaTime) {
|
|||||||
if (m_PausedTime == 0) {
|
if (m_PausedTime == 0) {
|
||||||
m_Paused = false;
|
m_Paused = false;
|
||||||
}
|
}
|
||||||
}
|
} else if (path->pathBehavior == PathBehavior::Loop) m_PathWaypoint = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -366,4 +382,24 @@ void ControllablePhysicsComponent::RemovePickupRadiusScale(float value) {
|
|||||||
// m_PathWaypoint = newPathStart;
|
// m_PathWaypoint = newPathStart;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
float ControllablePhysicsComponent::GetBaseSpeed(LOT lot) {
|
||||||
|
|
||||||
|
CDComponentsRegistryTable* componentRegistryTable = CDClientManager::Instance()->GetTable<CDComponentsRegistryTable>("ComponentsRegistry");
|
||||||
|
CDPhysicsComponentTable* physicsComponentTable = CDClientManager::Instance()->GetTable<CDPhysicsComponentTable>("PhysicsComponent");
|
||||||
|
|
||||||
|
int32_t componentID;
|
||||||
|
CDPhysicsComponent* physicsComponent = nullptr;
|
||||||
|
|
||||||
|
componentID = componentRegistryTable->GetByIDAndType(lot, COMPONENT_TYPE_CONTROLLABLE_PHYSICS, -1);
|
||||||
|
|
||||||
|
if (componentID != -1) physicsComponent = physicsComponentTable->GetByID(componentID);
|
||||||
|
|
||||||
|
float speed;
|
||||||
|
if (physicsComponent == nullptr) {
|
||||||
|
speed = 8;
|
||||||
|
} else {
|
||||||
|
speed = physicsComponent->speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
return speed;
|
||||||
|
}
|
||||||
|
@ -287,6 +287,13 @@ public:
|
|||||||
*/
|
*/
|
||||||
void FollowWaypoints(){m_Paused = false;};
|
void FollowWaypoints(){m_Paused = false;};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the base speed from the DB for a given LOT
|
||||||
|
* @param lot the lot to check for
|
||||||
|
* @return the base speed of the lot
|
||||||
|
*/
|
||||||
|
static float GetBaseSpeed(LOT lot);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* The entity that owns this component
|
* The entity that owns this component
|
||||||
@ -428,6 +435,11 @@ private:
|
|||||||
*/
|
*/
|
||||||
float m_PausedTime = 0.0;
|
float m_PausedTime = 0.0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The laden speed of an object
|
||||||
|
*/
|
||||||
|
float m_BaseSpeed;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CONTROLLABLEPHYSICSCOMPONENT_H
|
#endif // CONTROLLABLEPHYSICSCOMPONENT_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user