PhantomPhysics: Fix gravity

Fix gravity not being adjusted when colliding with a phantom physics object

Tested that while on moonbase, the players gravity is no longer reset to 1 when they change their cheat info.
This commit is contained in:
David Markowitz 2023-10-15 18:37:43 -07:00
parent c6087ce77a
commit ff75e6f0f7
3 changed files with 64 additions and 22 deletions

View File

@ -336,11 +336,37 @@ void PhantomPhysicsComponent::Serialize(RakNet::BitStream* outBitStream, bool bI
}
}
// Even if we were to implement Friction server side,
// it also defaults to 1.0f in the last argument, so we dont need two functions to do the same thing.
void ApplyCollisionEffect(const LWOOBJID& target, const ePhysicsEffectType effectType, const float effectScale) {
switch (effectType) {
case ePhysicsEffectType::GRAVITY_SCALE: {
auto* targetEntity = Game::entityManager->GetEntity(target);
if (targetEntity) {
auto* controllablePhysicsComponent = targetEntity->GetComponent<ControllablePhysicsComponent>();
// dont want to apply an effect to nothing.
if (!controllablePhysicsComponent) return;
controllablePhysicsComponent->SetGravityScale(effectScale);
GameMessages::SendSetGravityScale(target, effectScale, targetEntity->GetSystemAddress());
}
}
// The other types are not handled by the server
case ePhysicsEffectType::ATTRACT:
case ePhysicsEffectType::FRICTION:
case ePhysicsEffectType::PUSH:
case ePhysicsEffectType::REPULSE:
default:
break;
}
}
void PhantomPhysicsComponent::Update(float deltaTime) {
if (!m_dpEntity) return;
//Process enter events
for (auto en : m_dpEntity->GetNewObjects()) {
if (!en) continue;
ApplyCollisionEffect(en->GetObjectID(), m_EffectType, m_DirectionalMultiplier);
m_Parent->OnCollisionPhantom(en->GetObjectID());
//If we are a respawn volume, inform the client:
@ -357,6 +383,8 @@ void PhantomPhysicsComponent::Update(float deltaTime) {
//Process exit events
for (auto en : m_dpEntity->GetRemovedObjects()) {
if (!en) continue;
ApplyCollisionEffect(en->GetObjectID(), m_EffectType, 1.0f);
m_Parent->OnCollisionLeavePhantom(en->GetObjectID());
}
}

View File

@ -5473,6 +5473,18 @@ void GameMessages::HandleRemoveItemFromInventory(RakNet::BitStream* inStream, En
}
}
void GameMessages::SendSetGravityScale(const LWOOBJID& target, const float effectScale, const SystemAddress& sysAddr) {
CBITSTREAM;
CMSGHEADER;
bitStream.Write(target);
bitStream.Write(eGameMessageType::SET_GRAVITY_SCALE);
bitStream.Write(effectScale);
SEND_PACKET;
}
void GameMessages::HandleMoveItemInInventory(RakNet::BitStream* inStream, Entity* entity) {
bool destInvTypeIsDefault = false;
int32_t destInvType = eInventoryType::INVALID;

View File

@ -109,6 +109,8 @@ namespace GameMessages {
void SendSetInventorySize(Entity* entity, int invType, int size);
void SendSetGravityScale(const LWOOBJID& target, const float effectScale, const SystemAddress& sysAddr);
void SendSetEmoteLockState(Entity* entity, bool bLock, int emoteID);
void SendSetJetPackMode(Entity* entity, bool use, bool bypassChecks = false, bool doHover = false, int effectID = -1, float airspeed = 10, float maxAirspeed = 15, float verticalVelocity = 1, int warningEffectID = -1);
void SendResurrect(Entity* entity);