diff --git a/Content/Maps/BlasterMap.umap b/Content/Maps/BlasterMap.umap index 2ca2a95..7eec221 100644 Binary files a/Content/Maps/BlasterMap.umap and b/Content/Maps/BlasterMap.umap differ diff --git a/Source/Blaster/Components/CombatComponent.cpp b/Source/Blaster/Components/CombatComponent.cpp index ca36c81..a483adf 100644 --- a/Source/Blaster/Components/CombatComponent.cpp +++ b/Source/Blaster/Components/CombatComponent.cpp @@ -17,6 +17,14 @@ UCombatComponent::UCombatComponent() AimWalkSpeed = 350.f; } +void UCombatComponent::GetLifetimeReplicatedProps(TArray& OutLifetimeProps) const +{ + Super::GetLifetimeReplicatedProps(OutLifetimeProps); + + DOREPLIFETIME(UCombatComponent, EquippedWeapon); + DOREPLIFETIME(UCombatComponent, bAiming); +} + void UCombatComponent::BeginPlay() { Super::BeginPlay(); @@ -58,8 +66,22 @@ void UCombatComponent::OnRep_EquippedWeapon() void UCombatComponent::FireButtonPressed(bool bPressed) { bFireButtonPressed = bPressed; + + if (bFireButtonPressed) + { + ServerFire(); + } +} + +void UCombatComponent::ServerFire_Implementation() +{ + MulticastFire(); +} + +void UCombatComponent::MulticastFire_Implementation() +{ if (EquippedWeapon == nullptr) return; - if (Character && bFireButtonPressed) + if (Character) { Character->PlayFireMontage(bAiming); EquippedWeapon->Fire(); @@ -72,14 +94,6 @@ void UCombatComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActo } -void UCombatComponent::GetLifetimeReplicatedProps(TArray& OutLifetimeProps) const -{ - Super::GetLifetimeReplicatedProps(OutLifetimeProps); - - DOREPLIFETIME(UCombatComponent, EquippedWeapon); - DOREPLIFETIME(UCombatComponent, bAiming); -} - void UCombatComponent::EquipWeapon(AWeapon* WeaponToEquip) { if (Character == nullptr || WeaponToEquip == nullptr) return; diff --git a/Source/Blaster/Components/CombatComponent.h b/Source/Blaster/Components/CombatComponent.h index f6bec73..0be7800 100644 --- a/Source/Blaster/Components/CombatComponent.h +++ b/Source/Blaster/Components/CombatComponent.h @@ -33,6 +33,12 @@ protected: void FireButtonPressed(bool bPressed); + UFUNCTION(Server, Reliable) + void ServerFire(); + + UFUNCTION(NetMulticast, Reliable) + void MulticastFire(); + private: class ABlasterCharacter* Character;