From b51e174bdc158187fc110dc4a947946d3dc329c1 Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Fri, 18 Aug 2023 20:03:06 +1000 Subject: [PATCH] Item drops inherit player velocity, other stuff --- assets/opensb/player.config.patch | 4 +++- source/game/StarHumanoid.cpp | 9 +++++++++ source/game/StarHumanoid.hpp | 1 + source/game/StarItemDrop.cpp | 8 ++++---- source/game/StarItemDrop.hpp | 4 ++-- source/game/StarPlayer.cpp | 14 +++++++++----- source/game/StarUniverseClient.cpp | 14 ++++++++++---- 7 files changed, 38 insertions(+), 16 deletions(-) diff --git a/assets/opensb/player.config.patch b/assets/opensb/player.config.patch index 3daa696..5960507 100644 --- a/assets/opensb/player.config.patch +++ b/assets/opensb/player.config.patch @@ -10,5 +10,7 @@ "minWireJitter" : 0.0, "minWireTrans" : 0.1, "maxWireTrans" : 0.4 - } + }, + + "swapDance" : null // Set this to a valid dance to trigger on character swap. } \ No newline at end of file diff --git a/source/game/StarHumanoid.cpp b/source/game/StarHumanoid.cpp index 106dd9f..64c5f46 100644 --- a/source/game/StarHumanoid.cpp +++ b/source/game/StarHumanoid.cpp @@ -425,6 +425,15 @@ Maybe Humanoid::dance() const { return m_dance; } +bool Humanoid::danceCyclicOrEnded() const { + if (!m_dance) + return false; + + auto danceDatabase = Root::singleton().danceDatabase(); + auto dance = danceDatabase->getDance(*m_dance); + return dance->cyclic || m_danceTimer > dance->duration; +} + Direction Humanoid::facingDirection() const { return m_facingDirection; } diff --git a/source/game/StarHumanoid.hpp b/source/game/StarHumanoid.hpp index 6ee5cfd..e296b32 100644 --- a/source/game/StarHumanoid.hpp +++ b/source/game/StarHumanoid.hpp @@ -169,6 +169,7 @@ public: State state() const; HumanoidEmote emoteState() const; Maybe dance() const; + bool danceCyclicOrEnded() const; Direction facingDirection() const; bool movingBackwards() const; diff --git a/source/game/StarItemDrop.cpp b/source/game/StarItemDrop.cpp index 895e4bb..8114de4 100644 --- a/source/game/StarItemDrop.cpp +++ b/source/game/StarItemDrop.cpp @@ -38,7 +38,7 @@ ItemDropPtr ItemDrop::createRandomizedDrop(ItemDescriptor const& descriptor, Vec return itemDrop; } -ItemDropPtr ItemDrop::throwDrop(ItemPtr const& item, Vec2F const& position, Vec2F const& direction, bool eternal) { +ItemDropPtr ItemDrop::throwDrop(ItemPtr const& item, Vec2F const& position, Vec2F const& velocity, Vec2F const& direction, bool eternal) { if (!item) return {}; @@ -47,7 +47,7 @@ ItemDropPtr ItemDrop::throwDrop(ItemPtr const& item, Vec2F const& position, Vec2 ItemDropPtr itemDrop = make_shared(item); itemDrop->setPosition(position); if (direction != Vec2F()) - itemDrop->setVelocity(vnorm(direction) * idconfig.getFloat("throwSpeed")); + itemDrop->setVelocity(velocity + vnorm(direction) * idconfig.getFloat("throwSpeed")); itemDrop->setEternal(eternal); itemDrop->setIntangibleTime(idconfig.getFloat("throwIntangibleTime")); @@ -55,12 +55,12 @@ ItemDropPtr ItemDrop::throwDrop(ItemPtr const& item, Vec2F const& position, Vec2 return itemDrop; } -ItemDropPtr ItemDrop::throwDrop(ItemDescriptor const& itemDescriptor, Vec2F const& position, Vec2F const& direction, bool eternal) { +ItemDropPtr ItemDrop::throwDrop(ItemDescriptor const& itemDescriptor, Vec2F const& position, Vec2F const& velocity, Vec2F const& direction, bool eternal) { if (!itemDescriptor || itemDescriptor.isEmpty()) return {}; auto itemDatabase = Root::singleton().itemDatabase(); - auto itemDrop = throwDrop(itemDatabase->item(itemDescriptor), position, direction); + auto itemDrop = throwDrop(itemDatabase->item(itemDescriptor), position, velocity, direction); itemDrop->setEternal(eternal); return itemDrop; diff --git a/source/game/StarItemDrop.hpp b/source/game/StarItemDrop.hpp index d88da73..e72878c 100644 --- a/source/game/StarItemDrop.hpp +++ b/source/game/StarItemDrop.hpp @@ -23,8 +23,8 @@ public: // Create a drop and throw in the given direction with a hard-coded initial // throw velocity (unrelated to magnitude of direction, direction is // normalized first). Initially intangible for 1 second. - static ItemDropPtr throwDrop(ItemPtr const& item, Vec2F const& position, Vec2F const& direction, bool eternal = false); - static ItemDropPtr throwDrop(ItemDescriptor const& itemDescriptor, Vec2F const& position, Vec2F const& direction, bool eternal = false); + static ItemDropPtr throwDrop(ItemPtr const& item, Vec2F const& position, Vec2F const& velocity, Vec2F const& direction, bool eternal = false); + static ItemDropPtr throwDrop(ItemDescriptor const& itemDescriptor, Vec2F const& position, Vec2F const& velocity, Vec2F const& direction, bool eternal = false); ItemDrop(ItemPtr item); ItemDrop(Json const& diskStore); diff --git a/source/game/StarPlayer.cpp b/source/game/StarPlayer.cpp index a78d300..a711f4d 100644 --- a/source/game/StarPlayer.cpp +++ b/source/game/StarPlayer.cpp @@ -717,10 +717,11 @@ void Player::dropItem() { if (!canUseTool()) return; - for (auto throwSlot : {m_inventory->primaryHeldSlot(), m_inventory->secondaryHeldSlot()}) { + Vec2F throwDirection = world()->geometry().diff(aimPosition(), position()); + for (auto& throwSlot : {m_inventory->primaryHeldSlot(), m_inventory->secondaryHeldSlot()}) { if (throwSlot) { if (auto drop = m_inventory->takeSlot(*throwSlot)) { - world()->addEntity(ItemDrop::throwDrop(drop, position(), world()->geometry().diff(aimPosition(), position()))); + world()->addEntity(ItemDrop::throwDrop(drop, position(), velocity(), throwDirection)); break; } } @@ -979,17 +980,20 @@ void Player::update(float dt, uint64_t) { m_humanoid->setMovingBackwards(false); m_humanoid->setRotation(m_movementController->rotation()); + bool suppressedItems = !canUseTool(); + auto loungeAnchor = as(m_movementController->entityAnchor()); if (loungeAnchor && loungeAnchor->dance) m_humanoid->setDance(*loungeAnchor->dance); - else + else if ((!suppressedItems && (m_tools->primaryHandItem() || m_tools->altHandItem())) + || m_humanoid->danceCyclicOrEnded() || m_movementController->running()) m_humanoid->setDance({}); bool isClient = world()->isClient(); if (isClient) m_armor->setupHumanoidClothingDrawables(*m_humanoid, forceNude()); - m_tools->suppressItems(!canUseTool()); + m_tools->suppressItems(suppressedItems); m_tools->tick(dt, m_shifting, m_pendingMoves); if (auto overrideFacingDirection = m_tools->setupHumanoidHandItems(*m_humanoid, position(), aimPosition())) @@ -2348,7 +2352,7 @@ void Player::dropSelectedItems(function filter) { m_inventory->forEveryItem([&](InventorySlot const&, ItemPtr& item) { if (item && (!filter || filter(item))) - world()->addEntity(ItemDrop::throwDrop(take(item), position(), Vec2F::withAngle(Random::randf(-Constants::pi, Constants::pi)), true)); + world()->addEntity(ItemDrop::throwDrop(take(item), position(), velocity(), Vec2F::withAngle(Random::randf(-Constants::pi, Constants::pi)), true)); }); } diff --git a/source/game/StarUniverseClient.cpp b/source/game/StarUniverseClient.cpp index 7d5adbb..3423f2d 100644 --- a/source/game/StarUniverseClient.cpp +++ b/source/game/StarUniverseClient.cpp @@ -551,10 +551,16 @@ bool UniverseClient::reloadPlayer(Json const& data, Uuid const& uuid, bool reset bool UniverseClient::switchPlayer(Uuid const& uuid) { if (uuid == mainPlayer()->uuid()) return false; - else if (auto data = m_playerStorage->maybeGetPlayerData(uuid)) - return reloadPlayer(*data, uuid, true, true); - else - return false; + else if (auto data = m_playerStorage->maybeGetPlayerData(uuid)) { + if (reloadPlayer(*data, uuid, true, true)) { + auto dance = Root::singleton().assets()->json("/player.config:swapDance"); + if (dance.isType(Json::Type::String)) + m_mainPlayer->humanoid()->setDance(dance.toString()); + return true; + } + } + + return false; } bool UniverseClient::switchPlayer(size_t index) {