70 - Fire Effects in Multiplayer

This commit is contained in:
Kingsmedia 2022-05-04 22:57:45 +02:00
parent cd21cd9366
commit 85c074d97e
3 changed files with 29 additions and 9 deletions

Binary file not shown.

View File

@ -17,6 +17,14 @@ UCombatComponent::UCombatComponent()
AimWalkSpeed = 350.f; AimWalkSpeed = 350.f;
} }
void UCombatComponent::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
DOREPLIFETIME(UCombatComponent, EquippedWeapon);
DOREPLIFETIME(UCombatComponent, bAiming);
}
void UCombatComponent::BeginPlay() void UCombatComponent::BeginPlay()
{ {
Super::BeginPlay(); Super::BeginPlay();
@ -58,8 +66,22 @@ void UCombatComponent::OnRep_EquippedWeapon()
void UCombatComponent::FireButtonPressed(bool bPressed) void UCombatComponent::FireButtonPressed(bool bPressed)
{ {
bFireButtonPressed = bPressed; bFireButtonPressed = bPressed;
if (bFireButtonPressed)
{
ServerFire();
}
}
void UCombatComponent::ServerFire_Implementation()
{
MulticastFire();
}
void UCombatComponent::MulticastFire_Implementation()
{
if (EquippedWeapon == nullptr) return; if (EquippedWeapon == nullptr) return;
if (Character && bFireButtonPressed) if (Character)
{ {
Character->PlayFireMontage(bAiming); Character->PlayFireMontage(bAiming);
EquippedWeapon->Fire(); EquippedWeapon->Fire();
@ -72,14 +94,6 @@ void UCombatComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActo
} }
void UCombatComponent::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
DOREPLIFETIME(UCombatComponent, EquippedWeapon);
DOREPLIFETIME(UCombatComponent, bAiming);
}
void UCombatComponent::EquipWeapon(AWeapon* WeaponToEquip) void UCombatComponent::EquipWeapon(AWeapon* WeaponToEquip)
{ {
if (Character == nullptr || WeaponToEquip == nullptr) return; if (Character == nullptr || WeaponToEquip == nullptr) return;

View File

@ -33,6 +33,12 @@ protected:
void FireButtonPressed(bool bPressed); void FireButtonPressed(bool bPressed);
UFUNCTION(Server, Reliable)
void ServerFire();
UFUNCTION(NetMulticast, Reliable)
void MulticastFire();
private: private:
class ABlasterCharacter* Character; class ABlasterCharacter* Character;