blaster/Source/Blaster/Components/CombatComponent.cpp

59 lines
1.5 KiB
C++
Raw Normal View History

2022-04-30 11:09:28 +00:00
// Fill out your copyright notice in the Description page of Project Settings.
#include "CombatComponent.h"
#include "Blaster/Character/BlasterCharacter.h"
#include "Blaster/Weapon/Weapon.h"
#include "Engine/SkeletalMeshSocket.h"
2022-04-30 14:48:34 +00:00
#include "Net/UnrealNetwork.h"
2022-04-30 11:09:28 +00:00
UCombatComponent::UCombatComponent()
{
PrimaryComponentTick.bCanEverTick = false;
}
void UCombatComponent::BeginPlay()
{
Super::BeginPlay();
}
2022-04-30 15:38:03 +00:00
void UCombatComponent::SetAiming(bool bIsAiming)
{
bAiming = bIsAiming;
ServerSetAiming(bIsAiming);
}
void UCombatComponent::ServerSetAiming_Implementation(bool bIsAiming)
{
bAiming = bIsAiming;
}
2022-04-30 11:09:28 +00:00
void UCombatComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
}
2022-04-30 14:48:34 +00:00
void UCombatComponent::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
DOREPLIFETIME(UCombatComponent, EquippedWeapon);
2022-04-30 15:38:03 +00:00
DOREPLIFETIME(UCombatComponent, bAiming);
2022-04-30 14:48:34 +00:00
}
2022-04-30 11:09:28 +00:00
void UCombatComponent::EquipWeapon(AWeapon* WeaponToEquip)
{
if (Character == nullptr || WeaponToEquip == nullptr) return;
EquippedWeapon = WeaponToEquip;
EquippedWeapon->SetWeaponState(EWeaponState::EWS_Equipped);
const USkeletalMeshSocket* HandSocket = Character->GetMesh()->GetSocketByName(FName("RightHandSocket"));
if (HandSocket)
{
HandSocket->AttachActor(EquippedWeapon, Character->GetMesh());
}
EquippedWeapon->SetOwner(Character);
}