From cd36a269fd1ccfd40ec09aca25285c6f9a875c43 Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Fri, 18 Aug 2023 21:48:09 +1000 Subject: [PATCH] Account for latency predicting item drop pickup --- source/game/StarItemDrop.cpp | 4 ++-- source/game/StarItemDrop.hpp | 2 +- source/game/StarWorldClient.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source/game/StarItemDrop.cpp b/source/game/StarItemDrop.cpp index 8114de4..3ff0d37 100644 --- a/source/game/StarItemDrop.cpp +++ b/source/game/StarItemDrop.cpp @@ -300,10 +300,10 @@ bool ItemDrop::canTake() const { return m_mode.get() == Mode::Available && m_owningEntity.get() == NullEntityId && !m_item->empty(); } -ItemPtr ItemDrop::takeBy(EntityId entityId) { +ItemPtr ItemDrop::takeBy(EntityId entityId, float timeOffset) { if (canTake()) { m_owningEntity.set(entityId); - m_dropAge.setElapsedTime(0.0); + m_dropAge.setElapsedTime(timeOffset); m_mode.set(Mode::Taken); setPersistent(false); diff --git a/source/game/StarItemDrop.hpp b/source/game/StarItemDrop.hpp index e72878c..54114fb 100644 --- a/source/game/StarItemDrop.hpp +++ b/source/game/StarItemDrop.hpp @@ -70,7 +70,7 @@ public: // Mark this drop as taken by the given entity. The drop will animate // towards them for a while and then disappear. - ItemPtr takeBy(EntityId entityId); + ItemPtr takeBy(EntityId entityId, float timeOffset = 0.0f); // Mark this drop as taken, but do not animate it towards a player simply // disappear next step. diff --git a/source/game/StarWorldClient.cpp b/source/game/StarWorldClient.cpp index de324ad..17a1996 100644 --- a/source/game/StarWorldClient.cpp +++ b/source/game/StarWorldClient.cpp @@ -1126,7 +1126,7 @@ void WorldClient::update(float dt) { if (itemDrop->canTake() && !m_requestedDrops.contains(itemDrop->entityId()) && distSquared < square(DropDist)) { m_requestedDrops.add(itemDrop->entityId()); if (m_mainPlayer->itemsCanHold(itemDrop->item()) != 0) { - itemDrop->takeBy(m_mainPlayer->entityId()); + itemDrop->takeBy(m_mainPlayer->entityId(), (float)m_latency / 1000); m_outgoingPackets.append(make_shared(itemDrop->entityId())); } }