Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/game
diff options
context:
space:
mode:
Diffstat (limited to 'source/game')
-rw-r--r--source/game/StarNpc.cpp2
-rw-r--r--source/game/StarNpc.hpp2
-rw-r--r--source/game/StarPlayer.cpp9
-rw-r--r--source/game/StarPlayer.hpp4
-rw-r--r--source/game/StarWorldClient.cpp1
-rw-r--r--source/game/interfaces/StarToolUserEntity.hpp2
-rw-r--r--source/game/items/StarMaterialItem.cpp28
-rw-r--r--source/game/items/StarMaterialItem.hpp1
8 files changed, 37 insertions, 12 deletions
diff --git a/source/game/StarNpc.cpp b/source/game/StarNpc.cpp
index 9e97417..af0bedb 100644
--- a/source/game/StarNpc.cpp
+++ b/source/game/StarNpc.cpp
@@ -1024,7 +1024,7 @@ float Npc::beamGunRadius() const {
void Npc::addParticles(List<Particle> const&) {}
-void Npc::addSound(String const&, float) {}
+void Npc::addSound(String const&, float, float) {}
bool Npc::inToolRange() const {
return true;
diff --git a/source/game/StarNpc.hpp b/source/game/StarNpc.hpp
index 02a6ae1..481dd9e 100644
--- a/source/game/StarNpc.hpp
+++ b/source/game/StarNpc.hpp
@@ -147,7 +147,7 @@ public:
Vec4B favoriteColor() const override;
float beamGunRadius() const override;
void addParticles(List<Particle> const& particles) override;
- void addSound(String const& sound, float volume = 1.0f) override;
+ void addSound(String const& sound, float volume = 1.0f, float pitch = 1.0f) override;
bool inToolRange() const override;
bool inToolRange(Vec2F const& position) const override;
void addEphemeralStatusEffects(List<EphemeralStatusEffect> const& statusEffects) override;
diff --git a/source/game/StarPlayer.cpp b/source/game/StarPlayer.cpp
index a711f4d..2a60d2b 100644
--- a/source/game/StarPlayer.cpp
+++ b/source/game/StarPlayer.cpp
@@ -412,8 +412,8 @@ void Player::addParticles(List<Particle> const& particles) {
m_callbackParticles.appendAll(particles);
}
-void Player::addSound(String const& sound, float volume) {
- m_callbackSounds.append({sound, volume});
+void Player::addSound(String const& sound, float volume, float pitch) {
+ m_callbackSounds.emplaceAppend(sound, volume, pitch);
}
void Player::addEphemeralStatusEffects(List<EphemeralStatusEffect> const& statusEffects) {
@@ -1100,8 +1100,9 @@ void Player::render(RenderCallback* renderCallback) {
renderCallback->addAudios(m_statusController->pullNewAudios());
for (auto const& p : take(m_callbackSounds)) {
- auto audio = make_shared<AudioInstance>(*Root::singleton().assets()->audio(p.first));
- audio->setVolume(p.second);
+ auto audio = make_shared<AudioInstance>(*Root::singleton().assets()->audio(get<0>(p)));
+ audio->setVolume(get<1>(p));
+ audio->setPitchMultiplier(get<2>(p));
audio->setPosition(position());
renderCallback->addAudio(move(audio));
}
diff --git a/source/game/StarPlayer.hpp b/source/game/StarPlayer.hpp
index c70c21e..1773d23 100644
--- a/source/game/StarPlayer.hpp
+++ b/source/game/StarPlayer.hpp
@@ -342,7 +342,7 @@ public:
bool inInteractionRange(Vec2F aimPos) const;
void addParticles(List<Particle> const& particles) override;
- void addSound(String const& sound, float volume = 1.0f) override;
+ void addSound(String const& sound, float volume = 1.0f, float pitch = 1.0f) override;
bool wireToolInUse() const;
void setWireConnector(WireConnector* wireConnector) const;
@@ -611,7 +611,7 @@ private:
List<RpcPromise<InteractAction>> m_pendingInteractActions;
List<Particle> m_callbackParticles;
- List<pair<String, float>> m_callbackSounds;
+ List<tuple<String, float, float>> m_callbackSounds;
List<String> m_queuedMessages;
List<ItemPtr> m_queuedItemPickups;
diff --git a/source/game/StarWorldClient.cpp b/source/game/StarWorldClient.cpp
index 17a1996..d3fbdce 100644
--- a/source/game/StarWorldClient.cpp
+++ b/source/game/StarWorldClient.cpp
@@ -1126,6 +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) {
+ m_startupHiddenEntities.erase(itemDrop->entityId());
itemDrop->takeBy(m_mainPlayer->entityId(), (float)m_latency / 1000);
m_outgoingPackets.append(make_shared<RequestDropPacket>(itemDrop->entityId()));
}
diff --git a/source/game/interfaces/StarToolUserEntity.hpp b/source/game/interfaces/StarToolUserEntity.hpp
index 60134ef..a83d5ff 100644
--- a/source/game/interfaces/StarToolUserEntity.hpp
+++ b/source/game/interfaces/StarToolUserEntity.hpp
@@ -94,7 +94,7 @@ public:
// FIXME: This is a dumb way of getting limited animation support
virtual void addEffectEmitters(StringSet const& emitters) = 0;
virtual void addParticles(List<Particle> const& particles) = 0;
- virtual void addSound(String const& sound, float volume = 1.0f) = 0;
+ virtual void addSound(String const& sound, float volume = 1.0f, float pitch = 1.0f) = 0;
virtual void setCameraFocusEntity(Maybe<EntityId> const& cameraFocusEntity) = 0;
};
diff --git a/source/game/items/StarMaterialItem.cpp b/source/game/items/StarMaterialItem.cpp
index c3e21f0..0d3c9a5 100644
--- a/source/game/items/StarMaterialItem.cpp
+++ b/source/game/items/StarMaterialItem.cpp
@@ -1,5 +1,6 @@
#include "StarMaterialItem.hpp"
#include "StarJson.hpp"
+#include "StarJsonExtra.hpp"
#include "StarMaterialDatabase.hpp"
#include "StarRoot.hpp"
#include "StarAssets.hpp"
@@ -31,8 +32,20 @@ MaterialItem::MaterialItem(Json const& config, String const& directory, Json con
setCooldownTime(config.queryFloat("materialItems.cooldown", defaultParameters.queryFloat("materialItems.cooldown")));
m_blockRadius = config.getFloat("blockRadius", defaultParameters.getFloat("blockRadius"));
m_altBlockRadius = config.getFloat("altBlockRadius", defaultParameters.getFloat("altBlockRadius"));
- m_multiplace = config.getBool("allowMultiplace", BlockCollisionSet.contains(Root::singleton().materialDatabase()->materialCollisionKind(m_material)));
+ auto materialDatabase = Root::singleton().materialDatabase();
+ m_multiplace = config.getBool("allowMultiplace", BlockCollisionSet.contains(materialDatabase->materialCollisionKind(m_material)));
+ m_placeSounds = jsonToStringList(config.get("placeSounds", JsonArray()));
+ if (m_placeSounds.empty()) {
+ auto miningSound = materialDatabase->miningSound(m_material);
+ if (!miningSound.empty())
+ m_placeSounds.append(move(miningSound));
+ auto stepSound = materialDatabase->footstepSound(m_material);
+ if (!stepSound.empty())
+ m_placeSounds.append(move(stepSound));
+ else if (m_placeSounds.empty())
+ m_placeSounds.append(materialDatabase->defaultFootstepSound());
+ }
m_shifting = false;
}
@@ -98,6 +111,7 @@ void MaterialItem::fire(FireMode mode, bool shifting, bool edgeTriggered) {
steps = (int)ceil(magnitude);
}
+ unsigned total = 0;
bool fail = true;
for (int i = 0; i != steps; ++i) {
auto placementOrigin = aimPosition + diff * ((float)i / steps);
@@ -110,12 +124,20 @@ void MaterialItem::fire(FireMode mode, bool shifting, bool edgeTriggered) {
size_t failed = world()->applyTileModifications(modifications, false).size();
if (failed < modifications.size()) {
fail = false;
- consume(modifications.size() - failed);
+ unsigned placed = modifications.size() - failed;
+ consume(placed);
+ total += placed;
}
}
- if (!fail)
+ if (!fail) {
+ auto sound = Random::randValueFrom(m_placeSounds, "");
+ if (total && !sound.empty()) {
+ float intensity = clamp((float)total / 20, 0.0f, 1.0f);
+ owner()->addSound(sound, 1.0f + intensity, (1.25f - intensity * 0.75f) * Random::randf(0.9f, 1.1f));
+ }
FireableItem::fire(mode, shifting, edgeTriggered);
+ }
m_lastAimPosition = aimPosition;
}
diff --git a/source/game/items/StarMaterialItem.hpp b/source/game/items/StarMaterialItem.hpp
index 50da0fd..ca345eb 100644
--- a/source/game/items/StarMaterialItem.hpp
+++ b/source/game/items/StarMaterialItem.hpp
@@ -45,6 +45,7 @@ private:
float m_altBlockRadius;
bool m_shifting;
bool m_multiplace;
+ StringList m_placeSounds;
Maybe<Vec2F> m_lastAimPosition;
};