Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: PhantomPhysics gravity #1221

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion dGame/dComponents/PhantomPhysicsComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ PhantomPhysicsComponent::PhantomPhysicsComponent(Entity* parent) : PhysicsCompon
m_dpEntity->SetRotation(m_Rotation);
m_dpEntity->SetPosition(m_Position);
dpWorld::Instance().AddEntity(m_dpEntity);
} else if (info->physicsAsset == "env\\env_won_fv_gas-blocking-volume.hkx"){
} else if (info->physicsAsset == "env\\env_won_fv_gas-blocking-volume.hkx") {
m_dpEntity = new dpEntity(m_Parent->GetObjectID(), 390.496826f, 111.467964f, 600.821534f, true);
m_dpEntity->SetScale(m_Scale);
m_dpEntity->SetRotation(m_Rotation);
Expand Down Expand Up @@ -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:
Expand All @@ -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());
}
}
Expand Down
54 changes: 33 additions & 21 deletions dGame/dGameMessages/GameMessages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ void GameMessages::SendResurrect(Entity* entity) {
destroyableComponent->SetImagination(imaginationToRestore);
}
}
});
});


auto cont = static_cast<ControllablePhysicsComponent*>(entity->GetComponent(eReplicaComponentType::CONTROLLABLE_PHYSICS));
Expand Down Expand Up @@ -2964,14 +2964,14 @@ void GameMessages::SendSetStunned(LWOOBJID objectId, eStateChangeType stateChang
}

void GameMessages::SendSetStunImmunity(LWOOBJID target, eStateChangeType state, const SystemAddress& sysAddr,
LWOOBJID originator,
bool bImmuneToStunAttack,
bool bImmuneToStunEquip,
bool bImmuneToStunInteract,
bool bImmuneToStunJump,
bool bImmuneToStunMove,
bool bImmuneToStunTurn,
bool bImmuneToStunUseItem) {
LWOOBJID originator,
bool bImmuneToStunAttack,
bool bImmuneToStunEquip,
bool bImmuneToStunInteract,
bool bImmuneToStunJump,
bool bImmuneToStunMove,
bool bImmuneToStunTurn,
bool bImmuneToStunUseItem) {
CBITSTREAM;
CMSGHEADER;

Expand All @@ -2996,15 +2996,15 @@ void GameMessages::SendSetStunImmunity(LWOOBJID target, eStateChangeType state,
}

void GameMessages::SendSetStatusImmunity(LWOOBJID objectId, eStateChangeType state, const SystemAddress& sysAddr,
bool bImmuneToBasicAttack,
bool bImmuneToDamageOverTime,
bool bImmuneToKnockback,
bool bImmuneToInterrupt,
bool bImmuneToSpeed,
bool bImmuneToImaginationGain,
bool bImmuneToImaginationLoss,
bool bImmuneToQuickbuildInterrupt,
bool bImmuneToPullToPoint) {
bool bImmuneToBasicAttack,
bool bImmuneToDamageOverTime,
bool bImmuneToKnockback,
bool bImmuneToInterrupt,
bool bImmuneToSpeed,
bool bImmuneToImaginationGain,
bool bImmuneToImaginationLoss,
bool bImmuneToQuickbuildInterrupt,
bool bImmuneToPullToPoint) {
CBITSTREAM;
CMSGHEADER;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -6269,7 +6281,7 @@ void GameMessages::HandleConfirmDonationOnPlayer(RakNet::BitStream* inStream, En
auto* donationEntity = Game::entityManager->GetEntity(characterComponent->GetCurrentInteracting());
if (!donationEntity) return;
auto* donationVendorComponent = donationEntity->GetComponent<DonationVendorComponent>();
if(!donationVendorComponent) return;
if (!donationVendorComponent) return;
if (donationVendorComponent->GetActivityID() == 0) {
Game::logger->Log("GameMessages", "WARNING: Trying to dontate to a vendor with no activity");
return;
Expand All @@ -6279,7 +6291,7 @@ void GameMessages::HandleConfirmDonationOnPlayer(RakNet::BitStream* inStream, En
auto items = inventory->GetItems();
if (!items.empty()) {
uint32_t count = 0;
for (auto& [itemID, item] : items){
for (auto& [itemID, item] : items) {
count += item->GetCount();
item->RemoveFromInventory();
}
Expand All @@ -6297,7 +6309,7 @@ void GameMessages::HandleCancelDonationOnPlayer(RakNet::BitStream* inStream, Ent
auto* inventory = inventoryComponent->GetInventory(eInventoryType::DONATION);
if (!inventory) return;
auto items = inventory->GetItems();
for (auto& [itemID, item] : items){
for (auto& [itemID, item] : items) {
inventoryComponent->MoveItemToInventory(item, eInventoryType::BRICKS, item->GetCount(), false, false, true);
}
auto* characterComponent = entity->GetComponent<CharacterComponent>();
Expand Down
2 changes: 2 additions & 0 deletions dGame/dGameMessages/GameMessages.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading