Skip to content

Commit

Permalink
Fixes to Breathing Effects and Stamina in Character Sound Component. …
Browse files Browse the repository at this point in the history
…Synced to ALS 4422789. TODO Fix breathing sound not playing after an Action Sound.
  • Loading branch information
colorindarkness committed Jul 24, 2024
1 parent 272780c commit addb586
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 47 deletions.
Binary file modified Content/ALS/FX/Breath/FX_Breath_01.uasset
Binary file not shown.
Binary file modified Content/ALS/UI/WB_ALS_HUD.uasset
Binary file not shown.
15 changes: 15 additions & 0 deletions Source/ALSXT/Private/ALSXTCharacter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3236,4 +3236,19 @@ void AALSXTCharacter::PlayActionSound_Implementation(bool MovementSound, bool Ac
void AALSXTCharacter::PlayDamageSound_Implementation(bool MovementSound, bool AccentSound, bool WeaponSound, const FGameplayTag& SoundSex, const FGameplayTag& Variant, const FGameplayTag& Overlay, const FGameplayTag& AttackMethod, const FGameplayTag& Strength, const FGameplayTag& AttackForm, const float Damage)
{
CharacterSound->PlayDamageSound(MovementSound, AccentSound, WeaponSound, SoundSex, Variant, Overlay, AttackMethod, Strength, AttackForm, Damage);
}

float AALSXTCharacter::GetCurrentStamina_Implementation() const
{
return CharacterSound->CurrentStamina;
}

FGameplayTag AALSXTCharacter::GetCurrentStaminaTag_Implementation() const
{
return CharacterSound->CurrentStaminaTag;
}

FGameplayTag AALSXTCharacter::GetCurrentBreathType_Implementation() const
{
return CharacterSound->CurrentBreathType;
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ void UALSXTCharacterSoundComponent::UpdateStamina(bool& StaminaTagChanged)
if ((CurrentStamina != NewStamina) && IsValid(VocalizationMixerAudioComponent))
{
CurrentStamina = NewStamina;
FGameplayTag NewStaminaTag{ ConvertStaminaToStaminaTag(IALSXTCharacterInterface::Execute_GetStamina(GetOwner())) };
CurrentStaminaTag = NewStaminaTag;
VocalizationMixerAudioComponent->SetFloatParameter("Stamina", CurrentStamina);
}
else
Expand Down Expand Up @@ -181,58 +183,51 @@ void UALSXTCharacterSoundComponent::PlayCharacterBreathEffectsImplementation(con
UpdateStaminaThresholds();
bool StaminaTagChanged;
UpdateStamina(StaminaTagChanged);
FGameplayTag StaminaToUse{ (StaminaOverride != FGameplayTag::EmptyTag) ? StaminaOverride : CurrentStaminaTag };
FGameplayTag StaminaToUse{ (StaminaOverride != FGameplayTag::EmptyTag || !StaminaOverride.IsValid()) ? StaminaOverride : CurrentStaminaTag };
UpdateVoiceSocketLocation();
FMotionSounds NewMotionSounds;

// If New
if (StaminaTagChanged || StaminaToUse != CurrentStaminaTag || CurrentBreathSounds.IsEmpty())
{
if (IALSXTCharacterSoundComponentInterface::Execute_CanPlayBreathSound(GetOwner()) && ShouldPlayBreathSound())
{
// Get and Set New Sounds
UALSXTCharacterSoundSettings* Settings = IALSXTCharacterSoundComponentInterface::Execute_SelectCharacterSoundSettings(GetOwner());
CurrentBreathSounds = SelectBreathSoundsNew(Settings, IALSXTCharacterInterface::Execute_GetCharacterSex(GetOwner()), ALSXTVoiceVariantTags::Default, ALSXTBreathTypeTags::Regular, StaminaOverride);
TArray<FSound> Sounds;
// Get and Set New Sounds
UALSXTCharacterSoundSettings* Settings = IALSXTCharacterSoundComponentInterface::Execute_SelectCharacterSoundSettings(GetOwner());
CurrentBreathSounds = SelectBreathSoundsNew(Settings, IALSXTCharacterInterface::Execute_GetCharacterSex(GetOwner()), IALSXTCharacterSoundComponentInterface::Execute_GetVoiceParameters(GetOwner()).Variant, IALSXTCharacterInterface::Execute_GetCharacterBreathState(GetOwner()).BreathType, StaminaOverride);
TArray<FSound> Sounds;

for (FALSXTBreathSound BS : CurrentBreathSounds)
{
Sounds.Append(BS.Sounds);
}
for (FALSXTBreathSound BS : CurrentBreathSounds)
{
Sounds.Append(BS.Sounds);
}

if (Sounds.IsValidIndex(0))
{
FSound NewBreathSound;
DetermineNewSound(Sounds, PreviousBreathsAssets, NewBreathSound);
float Pitch = FMath::RandRange(NewBreathSound.PitchRange.X, NewBreathSound.PitchRange.Y);
CurrentBreathSound = NewBreathSound;
SetNewSound(NewBreathSound.Sound, PreviousBreathsAssets, GeneralCharacterSoundSettings.BreathNoRepeats);
}
NewMotionSounds.BreathSounds = Sounds;
if (Sounds.IsValidIndex(0))
{
FSound NewBreathSound;
DetermineNewSound(Sounds, PreviousBreathsAssets, NewBreathSound);
float Pitch = FMath::RandRange(NewBreathSound.PitchRange.X, NewBreathSound.PitchRange.Y);
CurrentBreathSound = NewBreathSound;
SetNewSound(NewBreathSound.Sound, PreviousBreathsAssets, GeneralCharacterSoundSettings.BreathNoRepeats);
}
NewMotionSounds.BreathSounds = Sounds;
}
else // If Same
{
TArray<FSound> Sounds;

if (IALSXTCharacterSoundComponentInterface::Execute_CanPlayBreathSound(GetOwner()) && ShouldPlayBreathSound())
for (FALSXTBreathSound BS : CurrentBreathSounds)
{
TArray<FSound> Sounds;

for (FALSXTBreathSound BS : CurrentBreathSounds)
{
Sounds.Append(BS.Sounds);
}
Sounds.Append(BS.Sounds);
}

if (Sounds.IsValidIndex(0))
{
FSound NewBreathSound;
DetermineNewSound(Sounds, PreviousBreathsAssets, NewBreathSound);
float Pitch = FMath::RandRange(NewBreathSound.PitchRange.X, NewBreathSound.PitchRange.Y);
CurrentBreathSound = NewBreathSound;
SetNewSound(NewBreathSound.Sound, PreviousBreathsAssets, GeneralCharacterSoundSettings.BreathNoRepeats);
}
NewMotionSounds.BreathSounds = Sounds;
if (Sounds.IsValidIndex(0))
{
FSound NewBreathSound;
DetermineNewSound(Sounds, PreviousBreathsAssets, NewBreathSound);
float Pitch = FMath::RandRange(NewBreathSound.PitchRange.X, NewBreathSound.PitchRange.Y);
CurrentBreathSound = NewBreathSound;
SetNewSound(NewBreathSound.Sound, PreviousBreathsAssets, GeneralCharacterSoundSettings.BreathNoRepeats);
}
NewMotionSounds.BreathSounds = Sounds;
}
// V2
if (GetOwner()->GetLocalRole() == ROLE_AutonomousProxy)
Expand Down Expand Up @@ -752,19 +747,23 @@ FGameplayTag UALSXTCharacterSoundComponent::ConvertWeightTagToStrengthTag(const

FGameplayTag UALSXTCharacterSoundComponent::ConvertStaminaToStaminaTag(const float Stamina)
{
if (Stamina >= GeneralCharacterSoundSettings.StaminaOptimalThreshold)
if (Stamina == 1.0)
{
return ALSXTStaminaTags::Full;
}
else if (Stamina < 1.0 && Stamina >= GeneralCharacterSoundSettings.StaminaOptimalThreshold)
{
return ALSXTStaminaTags::Optimal;
}
else if ((Stamina <= GeneralCharacterSoundSettings.StaminaHalfPoint && Stamina > GeneralCharacterSoundSettings.StaminaLowThreshold))
else if (( Stamina >= GeneralCharacterSoundSettings.StaminaHalfPoint && Stamina < GeneralCharacterSoundSettings.StaminaOptimalThreshold))
{
return ALSXTStaminaTags::Half;
}
else if ((Stamina <= GeneralCharacterSoundSettings.StaminaLowThreshold && Stamina > .15))
else if ((Stamina < GeneralCharacterSoundSettings.StaminaHalfPoint && Stamina > GeneralCharacterSoundSettings.StaminaLowThreshold))
{
return ALSXTStaminaTags::Low;
}
else if ((Stamina <= .15))
else if ((Stamina < GeneralCharacterSoundSettings.StaminaLowThreshold))
{
return ALSXTStaminaTags::Empty;
}
Expand Down Expand Up @@ -2150,8 +2149,7 @@ void UALSXTCharacterSoundComponent::PlaySound(FMotionSounds MotionSounds)
if (IALSXTCharacterSoundComponentInterface::Execute_GetBreathEffectsSettings(GetOwner()).VisibleBreathTypes.HasTag(IALSXTCharacterInterface::Execute_GetBreathType(GetOwner())))
{
// UE_LOG(LogTemp, Warning, TEXT("SelectNewBreathParticles"));
FGameplayTag NewStaminaTag{ ConvertStaminaToStaminaTag(IALSXTCharacterInterface::Execute_GetStamina(GetOwner())) };
CurrentBreathParticles = SelectBreathParticles(IALSXTCharacterInterface::Execute_GetBreathType(GetOwner()), NewStaminaTag);
CurrentBreathParticles = SelectBreathParticles(IALSXTCharacterInterface::Execute_GetBreathType(GetOwner()), CurrentStaminaTag);
if (CurrentBreathParticles.IsValidIndex(0))
{
// UpdateVoiceSocketRotation();
Expand All @@ -2160,7 +2158,7 @@ void UALSXTCharacterSoundComponent::PlaySound(FMotionSounds MotionSounds)
ServerPlayBreathParticle(NiagaraSystem);
}
}

return;
}

// VOCAL
Expand Down Expand Up @@ -2199,6 +2197,7 @@ void UALSXTCharacterSoundComponent::PlaySound(FMotionSounds MotionSounds)
// ServerPlayBreathParticle(NiagaraSystem);
}
}
return;
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions Source/ALSXT/Public/ALSXTCharacter.h
Original file line number Diff line number Diff line change
Expand Up @@ -1861,6 +1861,10 @@ class ALSXT_API AALSXTCharacter : public AAlsCharacter, public IALSXTCharacterCu
virtual void PlayActionSound_Implementation(bool MovementSound, bool AccentSound, bool WeaponSound, UPARAM(meta = (Categories = "Als.Character Movement Sound"))const FGameplayTag& Type, UPARAM(meta = (Categories = "Als.Sex"))const FGameplayTag& SoundSex, UPARAM(meta = (Categories = "Als.Voice Variant"))const FGameplayTag& Variant, UPARAM(meta = (Categories = "Als.OverlayMode"))const FGameplayTag& Overlay, UPARAM(meta = (Categories = "Als.Action Strength"))const FGameplayTag& Strength, const float Stamina) override;
virtual void PlayDamageSound_Implementation(bool MovementSound, bool AccentSound, bool WeaponSound, UPARAM(meta = (Categories = "Als.Sex"))const FGameplayTag& SoundSex, UPARAM(meta = (Categories = "Als.Voice Variant"))const FGameplayTag& Variant, UPARAM(meta = (Categories = "Als.OverlayMode"))const FGameplayTag& Overlay, UPARAM(meta = (Categories = "Als.Attack Method"))const FGameplayTag& AttackMethod, UPARAM(meta = (Categories = "Als.Action Strength"))const FGameplayTag& Strength, const FGameplayTag& AttackForm, const float Damage) override;

virtual float GetCurrentStamina_Implementation() const;
virtual FGameplayTag GetCurrentStaminaTag_Implementation() const;
virtual FGameplayTag GetCurrentBreathType_Implementation() const;

// Freelooking Interface Functions
virtual FGameplayTag GetCharacterFreelooking_Implementation() const override;
virtual FALSXTFreelookState GetCharacterFreelookState_Implementation() const override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class ALSXT_API UALSXTCharacterSoundComponent : public UActorComponent
float CurrentStamina {1.0f};

UPROPERTY(Replicated, BlueprintReadOnly, Category = "Settings", Meta = (AllowPrivateAccess))
FGameplayTag CurrentStaminaTag {ALSXTStaminaTags::Optimal};
FGameplayTag CurrentStaminaTag {ALSXTStaminaTags::Full};

UPROPERTY(Replicated, BlueprintReadOnly, Category = "Settings", Meta = (AllowPrivateAccess))
FGameplayTag CurrentBreathType{ ALSXTBreathTypeTags::Regular };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ class ALSXT_API IALSXTCharacterSoundComponentInterface {
UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = "Character Sound Component Interface|Parameters")
FALSXTCharacterVoiceParameters GetVoiceParameters();

UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = "Character Sound Component Interface|Breath Effects")
float GetCurrentStamina() const;

UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = "Character Sound Component Interface|Breath Effects")
FGameplayTag GetCurrentStaminaTag() const;

UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = "Character Sound Component Interface|Breath Effects")
FGameplayTag GetCurrentBreathType() const;

UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = "Character Sound Component Interface|Breath Effects")
bool CanPlayBreathSound();

Expand Down Expand Up @@ -54,9 +63,6 @@ class ALSXT_API IALSXTCharacterSoundComponentInterface {
UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = "Character Breath Effects Interface|Parameters")
FRotator GetVoiceSocketRotation();

UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = "Character Breath Effects Interface|Parameters")
FGameplayTag GetCurrentBreathType();

UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = "Character Breath Effects Interface|Parameters")
FGameplayTag GetHoldingBreath();

Expand Down

0 comments on commit addb586

Please sign in to comment.