Item drops inherit player velocity, other stuff

This commit is contained in:
Kae 2023-08-18 20:03:06 +10:00
parent ab03c224dd
commit b51e174bdc
7 changed files with 38 additions and 16 deletions

View File

@ -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.
}

View File

@ -425,6 +425,15 @@ Maybe<String> 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;
}

View File

@ -169,6 +169,7 @@ public:
State state() const;
HumanoidEmote emoteState() const;
Maybe<String> dance() const;
bool danceCyclicOrEnded() const;
Direction facingDirection() const;
bool movingBackwards() const;

View File

@ -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<ItemDrop>(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;

View File

@ -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);

View File

@ -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<LoungeAnchor>(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<bool(ItemPtr)> 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));
});
}

View File

@ -551,9 +551,15 @@ 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
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;
}