Added Weapon Saving
This commit is contained in:
parent
75c1976ec4
commit
8886dda901
@ -274,13 +274,22 @@ void AEndlessVendettaCharacter::ToggleCombat()
|
||||
//When 1 is pressed it calls EquipPrimary
|
||||
void AEndlessVendettaCharacter::EquipPrimary()
|
||||
{
|
||||
FActorSpawnParameters spawnParams;
|
||||
spawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
||||
FAttachmentTransformRules AttachmentRules(EAttachmentRule::SnapToTarget, true);
|
||||
FDetachmentTransformRules DetatchRules(EDetachmentRule::KeepWorld, false);
|
||||
|
||||
if (bIsReloading) return;
|
||||
if (IsValid(PrimaryWeapon))
|
||||
{
|
||||
PrimaryWeapon->Destroy();
|
||||
PrimaryWeapon->DetachFromActor(DetatchRules);
|
||||
PrimaryWeapon->SetActorLocation(FVector(0,0,0), false, nullptr, ETeleportType::None);
|
||||
PrimaryWeapon->SetActorHiddenInGame(true);
|
||||
this->GetFirstPersonCameraComponent()->SetFieldOfView(90);
|
||||
UE_LOG(LogTemp, Warning, TEXT("Primary Weapon Is Hidden: %hhd"), PrimaryWeapon->IsHidden());
|
||||
PrimaryWeapon = nullptr;
|
||||
bHasRifle = false;
|
||||
GLog->Log("Primary Weapon Put Away");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -290,29 +299,49 @@ void AEndlessVendettaCharacter::EquipPrimary()
|
||||
if (GadgetManager->IsValidCombatGadget() && GadgetManager->IsCombatEquipped() && !GadgetManager->TryToUnequipCombat()) return;
|
||||
|
||||
|
||||
FActorSpawnParameters spawnParams;
|
||||
spawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
||||
FAttachmentTransformRules AttachmentRules(EAttachmentRule::SnapToTarget, true);
|
||||
|
||||
bHasRifle = true;
|
||||
//Creating a new actor object called PrimaryWeapon that is based off primaryweaponClass
|
||||
AActor* PrimaryWeaponActor = GetWorld()->SpawnActor<AActor>(PrimaryWeaponClass, spawnParams);
|
||||
PrimaryWeaponActor->AttachToComponent(Mesh1P, AttachmentRules, FName("GripPoint"));
|
||||
|
||||
//Changing PrimaryWeaponActor to ABaseWeaponClass type instead of actor and storing it into PrimaryWeapon which is a ABaseClass Object
|
||||
//We do this because we need to check if PrimaryWeapon is equipped and we want primaryweapon to be ABaseWeapon type and not a generic AActor
|
||||
|
||||
if(!IsValid(PrimaryWeapon))
|
||||
{
|
||||
bHasRifle = true;
|
||||
if(!bIsPrimaryWeaponCreated)
|
||||
{
|
||||
PrimaryWeaponActor = GetWorld()->SpawnActor<AActor>(PrimaryWeaponClass, spawnParams);
|
||||
PrimaryWeaponActor->AttachToComponent(Mesh1P, AttachmentRules, FName("GripPoint"));
|
||||
PrimaryWeapon = Cast<ABaseWeaponClass>(PrimaryWeaponActor);
|
||||
PrimaryWeapon->SetActorHiddenInGame(false);
|
||||
bIsPrimaryWeaponCreated = true;
|
||||
}
|
||||
//UE_LOG(LogTemp, Warning, TEXT("Primary Weapon Is Hidden: %hhd"), PrimaryWeapon->IsHidden());
|
||||
GLog->Log("Primary Weapon Equipped");
|
||||
}
|
||||
PrimaryWeaponActor->AttachToComponent(Mesh1P, AttachmentRules, FName("GripPoint"));
|
||||
PrimaryWeapon = Cast<ABaseWeaponClass>(PrimaryWeaponActor);
|
||||
PrimaryWeapon->SetActorHiddenInGame(false);
|
||||
GetWorldTimerManager().ClearTimer(PrimaryWeapon->reloadTimerHandle);
|
||||
}
|
||||
|
||||
void AEndlessVendettaCharacter::EquipSecondary()
|
||||
{
|
||||
FActorSpawnParameters spawnParams;
|
||||
spawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
||||
FAttachmentTransformRules AttachmentRules(EAttachmentRule::SnapToTarget, true);
|
||||
FDetachmentTransformRules DetatchRules(EDetachmentRule::KeepWorld, false);
|
||||
|
||||
if (bIsReloading) return;
|
||||
if (IsValid(SecondaryWeapon))
|
||||
{
|
||||
SecondaryWeapon->Destroy();
|
||||
SecondaryWeapon->DetachFromActor(DetatchRules);
|
||||
SecondaryWeapon->SetActorLocation(FVector(0,0,0), false, nullptr, ETeleportType::None);
|
||||
SecondaryWeapon->SetActorHiddenInGame(true);
|
||||
this->GetFirstPersonCameraComponent()->SetFieldOfView(90);
|
||||
UE_LOG(LogTemp, Warning, TEXT("Secondary Weapon Is Hidden: %hhd"), SecondaryWeapon->IsHidden());
|
||||
SecondaryWeapon = nullptr;
|
||||
bHasRifle = false;
|
||||
GLog->Log("Secondary Weapon Put Away");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -321,15 +350,23 @@ void AEndlessVendettaCharacter::EquipSecondary()
|
||||
if (GadgetManager->IsValidReconGadget() && GadgetManager->IsReconEquipped() && !GadgetManager->TryToUnequipRecon()) return;
|
||||
if (GadgetManager->IsValidCombatGadget() && GadgetManager->IsCombatEquipped() && !GadgetManager->TryToUnequipCombat()) return;
|
||||
|
||||
|
||||
FActorSpawnParameters spawnParams;
|
||||
spawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
||||
FAttachmentTransformRules AttachmentRules(EAttachmentRule::SnapToTarget, true);
|
||||
|
||||
if(!IsValid(SecondaryWeapon))
|
||||
{
|
||||
bHasRifle = true;
|
||||
AActor* SecondaryWeaponActor = GetWorld()->SpawnActor<AActor>(SecondaryWeaponClass, spawnParams);
|
||||
if(!bIsSecondaryWeaponCreated)
|
||||
{
|
||||
SecondaryWeaponActor = GetWorld()->SpawnActor<AActor>(SecondaryWeaponClass, spawnParams);
|
||||
SecondaryWeaponActor->AttachToComponent(Mesh1P, AttachmentRules, FName("GripPoint"));
|
||||
SecondaryWeapon = Cast<ABaseWeaponClass>(SecondaryWeaponActor);
|
||||
SecondaryWeapon->SetActorHiddenInGame(false);
|
||||
bIsSecondaryWeaponCreated = true;
|
||||
}
|
||||
//UE_LOG(LogTemp, Warning, TEXT("Secondary Weapon Is Hidden: %hhd"), SecondaryWeapon->IsHidden());
|
||||
GLog->Log("Secondary Weapon Equipped");
|
||||
}
|
||||
SecondaryWeaponActor->AttachToComponent(Mesh1P, AttachmentRules, FName("GripPoint"));
|
||||
SecondaryWeapon = Cast<ABaseWeaponClass>(SecondaryWeaponActor);
|
||||
SecondaryWeapon->SetActorHiddenInGame(false);
|
||||
GetWorldTimerManager().ClearTimer(SecondaryWeapon->reloadTimerHandle);
|
||||
}
|
||||
|
||||
|
@ -81,6 +81,11 @@ public:
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Stats")
|
||||
float DefaultHealth = 100.0f;
|
||||
|
||||
AActor* PrimaryWeaponActor;
|
||||
AActor* SecondaryWeaponActor;
|
||||
bool bIsPrimaryWeaponCreated = false;
|
||||
bool bIsSecondaryWeaponCreated = false;
|
||||
|
||||
protected:
|
||||
virtual void BeginPlay() override;
|
||||
virtual void Tick(float DeltaTime) override;
|
||||
|
Loading…
Reference in New Issue
Block a user