play sound functioning

This commit is contained in:
David Markowitz 2025-04-02 22:15:14 -07:00
parent 480bc49c4f
commit e1913ffc9f
3 changed files with 40 additions and 14 deletions

View File

@ -6456,4 +6456,9 @@ namespace GameMessages {
stream.Write(duration != 3.0f);
if (builderID != 3.0f) stream.Write(duration);
}
void PlayBehaviorSound::Serialize(RakNet::BitStream& stream) const {
stream.Write(soundID != -1);
if (soundID != -1) stream.Write(soundID);
}
}

View File

@ -821,6 +821,14 @@ namespace GameMessages {
LWOOBJID builderID{ LWOOBJID_EMPTY };
float duration{ 3.0f };
};
struct PlayBehaviorSound : public GameMsg {
PlayBehaviorSound() : GameMsg(MessageType::Game::PLAY_BEHAVIOR_SOUND) {}
void Serialize(RakNet::BitStream& stream) const;
int32_t soundID{ -1 };
};
};
#endif // GAMEMESSAGES_H

View File

@ -115,34 +115,44 @@ void Strip::ProcNormalAction(float deltaTime, ModelComponent& modelComponent) {
auto& nextAction = GetNextAction();
auto number = nextAction.GetValueParameterDouble();
auto numberAsInt = static_cast<int32_t>(number);
if (GetNextAction().GetType() == "SpawnStromling") {
auto nextActionType = GetNextAction().GetType();
if (nextActionType == "SpawnStromling") {
Spawn(10495, entity);
} else if (GetNextAction().GetType() == "SpawnPirate") {
} else if (nextActionType == "SpawnPirate") {
Spawn(10497, entity);
} else if (GetNextAction().GetType() == "SpawnRonin") {
} else if (nextActionType == "SpawnRonin") {
Spawn(10498, entity);
} else if (GetNextAction().GetType() == "DropImagination") {
} else if (nextActionType == "DropImagination") {
for (; numberAsInt > 0; numberAsInt--) SpawnDrop(935, entity);
} else if (GetNextAction().GetType() == "DropHealth") {
} else if (nextActionType == "DropHealth") {
for (; numberAsInt > 0; numberAsInt--) SpawnDrop(177, entity);
} else if (GetNextAction().GetType() == "DropArmor") {
} else if (nextActionType == "DropArmor") {
for (; numberAsInt > 0; numberAsInt--) SpawnDrop(6431, entity);
} else if (GetNextAction().GetType() == "Smash") {
} else if (nextActionType == "Smash") {
GameMessages::Smash smash{};
smash.target = entity.GetObjectID();
smash.killerID = entity.GetObjectID();
smash.Send(UNASSIGNED_SYSTEM_ADDRESS);
} else if (GetNextAction().GetType() == "UnSmash") {
} else if (nextActionType == "UnSmash") {
GameMessages::UnSmash unsmash{};
unsmash.target = entity.GetObjectID();
unsmash.duration = number;
unsmash.builderID = LWOOBJID_EMPTY;
unsmash.Send(UNASSIGNED_SYSTEM_ADDRESS);
m_PausedTime = number;
} else if (nextAction.GetType() == "Wait") {
} else if (nextActionType == "Wait") {
m_PausedTime = number;
} else if (nextActionType == "PlaySound") {
GameMessages::PlayBehaviorSound sound;
sound.target = modelComponent.GetParent()->GetObjectID();
sound.soundID = numberAsInt;
sound.Send(UNASSIGNED_SYSTEM_ADDRESS);
} else {
LOG("Tried to play action (%s) which is not supported.", nextAction.GetType().data());
static std::set<std::string> g_PlayedSounds;
if (!g_PlayedSounds.contains(nextActionType.data())) {
LOG("Tried to play action (%s) which is not supported.", nextActionType.data());
g_PlayedSounds.insert(nextActionType.data());
}
return;
}
@ -174,10 +184,13 @@ void Strip::Update(float deltaTime, ModelComponent& modelComponent) {
RemoveStates(modelComponent);
// Check for starting blocks and if not a starting block proc this blocks action
if (m_NextActionIndex == 0) {
if (nextAction.GetType() == "OnInteract") {
modelComponent.AddInteract();
Game::entityManager->SerializeEntity(entity);
m_WaitingForAction = true;
}
} else { // should be a normal block
ProcNormalAction(deltaTime, modelComponent);
}