From 1676ed71353f252fe7a67c01bcd10cd75033c37f Mon Sep 17 00:00:00 2001 From: Caleb Buhungiro Date: Sat, 13 Sep 2025 16:30:18 +0800 Subject: [PATCH] prevent player from damaging team member --- Content/Maps/GameLevel.umap | 2 +- Source/Crunch/Private/Character/CCharacter.cpp | 9 +++++++++ Source/Crunch/Private/GAS/CGameplayAbility.cpp | 13 +++++++++++-- Source/Crunch/Private/GAS/GA_Combo.cpp | 4 +--- Source/Crunch/Private/Game/CGameMode.cpp | 5 ++--- Source/Crunch/Public/GAS/CGameplayAbility.h | 8 ++++---- 6 files changed, 28 insertions(+), 13 deletions(-) diff --git a/Content/Maps/GameLevel.umap b/Content/Maps/GameLevel.umap index fe4b131..2881c56 100644 --- a/Content/Maps/GameLevel.umap +++ b/Content/Maps/GameLevel.umap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:1d5b946910f74e69d6a7a519630591c27f05269541d3062346cded272a51f344 +oid sha256:eb90937d6ed7be34b8830e08f4554ee8b97639c7a19fa0cdc8f3ab21fea9c9d7 size 15354151 diff --git a/Source/Crunch/Private/Character/CCharacter.cpp b/Source/Crunch/Private/Character/CCharacter.cpp index cabcad0..15dc44e 100644 --- a/Source/Crunch/Private/Character/CCharacter.cpp +++ b/Source/Crunch/Private/Character/CCharacter.cpp @@ -205,6 +205,15 @@ void ACCharacter::ReSpawn() GetCharacterMovement()->SetMovementMode(MOVE_Walking); GetMesh()->GetAnimInstance()->StopAllMontages(0.f); SetStatusGaugeEnabled(true); + + if (HasAuthority() && GetController()) + { + if (const auto StartSpot { GetController()->StartSpot }; StartSpot.IsValid()) + { + SetActorTransform(StartSpot->GetActorTransform()); + } + } + if (CAbilitySystemComponent) { CAbilitySystemComponent->ApplyFullStatEffect(); diff --git a/Source/Crunch/Private/GAS/CGameplayAbility.cpp b/Source/Crunch/Private/GAS/CGameplayAbility.cpp index db798b2..e7e9dd5 100644 --- a/Source/Crunch/Private/GAS/CGameplayAbility.cpp +++ b/Source/Crunch/Private/GAS/CGameplayAbility.cpp @@ -15,11 +15,14 @@ UAnimInstance* UCGameplayAbility::GetOwnerAnimInstance() const } TArray UCGameplayAbility::GetHitResultFromSweepLocationTargetData( - const FGameplayAbilityTargetDataHandle& TargetDataHandle, float SphereSweepRadius, bool bDrawDebug, - bool bIgnoreSelf) const + const FGameplayAbilityTargetDataHandle& TargetDataHandle, float SphereSweepRadius, ETeamAttitude::Type TargetTeam, + bool bDrawDebug, bool bIgnoreSelf) const { TArray OutResults; TSet HitActors; + + const auto OwnerTeamInterface{Cast(GetAvatarActorFromActorInfo())}; + for (const auto TargetData : TargetDataHandle.Data) { const FVector StartLoc{TargetData->GetOrigin().GetTranslation()}; @@ -49,6 +52,12 @@ TArray UCGameplayAbility::GetHitResultFromSweepLocationTargetData( for (const auto Result : Results) { if (HitActors.Contains(Result.GetActor())) continue; + + if (OwnerTeamInterface) + { + const auto OtherActorTeamAttitude{OwnerTeamInterface->GetTeamAttitudeTowards(*Result.GetActor())}; + if (OtherActorTeamAttitude != TargetTeam) continue; + } HitActors.Add(Result.GetActor()); OutResults.Add(Result); } diff --git a/Source/Crunch/Private/GAS/GA_Combo.cpp b/Source/Crunch/Private/GAS/GA_Combo.cpp index 19a4bcb..d2d4599 100644 --- a/Source/Crunch/Private/GAS/GA_Combo.cpp +++ b/Source/Crunch/Private/GAS/GA_Combo.cpp @@ -152,9 +152,7 @@ void UGA_Combo::DoDamage(FGameplayEventData Data) auto HitResults{ GetHitResultFromSweepLocationTargetData( Data.TargetData, - TargetSweepSphereRadius, - false, - true + TargetSweepSphereRadius ) }; diff --git a/Source/Crunch/Private/Game/CGameMode.cpp b/Source/Crunch/Private/Game/CGameMode.cpp index c090103..87c97ec 100644 --- a/Source/Crunch/Private/Game/CGameMode.cpp +++ b/Source/Crunch/Private/Game/CGameMode.cpp @@ -16,7 +16,7 @@ APlayerController* ACGameMode::SpawnPlayerController(ENetRole InRemoteRole, cons NewPlayerControllerTeamInterface->SetGenericTeamId(TeamId); } NewPlayerController->StartSpot = FindNextStartSpotForTeam(TeamId); - + return NewPlayerController; } @@ -34,8 +34,7 @@ AActor* ACGameMode::FindNextStartSpotForTeam(const FGenericTeamId& TeamId) const { return nullptr; } - auto World{GetWorld()}; - for (TActorIterator It(World); It; ++It) + for (TActorIterator It{GetWorld()}; It; ++It) { if (It->PlayerStartTag == *StartSpotTag) { diff --git a/Source/Crunch/Public/GAS/CGameplayAbility.h b/Source/Crunch/Public/GAS/CGameplayAbility.h index 13adc5f..1f977be 100644 --- a/Source/Crunch/Public/GAS/CGameplayAbility.h +++ b/Source/Crunch/Public/GAS/CGameplayAbility.h @@ -3,12 +3,10 @@ #pragma once #include "CoreMinimal.h" +#include "GenericTeamAgentInterface.h" #include "Abilities/GameplayAbility.h" #include "CGameplayAbility.generated.h" -/** - * - */ UCLASS() class CRUNCH_API UCGameplayAbility : public UGameplayAbility { @@ -17,6 +15,8 @@ class CRUNCH_API UCGameplayAbility : public UGameplayAbility protected: UAnimInstance* GetOwnerAnimInstance() const; TArray GetHitResultFromSweepLocationTargetData(const FGameplayAbilityTargetDataHandle& TargetDataHandle, - float SphereSweepRadius = 30.f, bool bDrawDebug = false, + float SphereSweepRadius = 30.f, + ETeamAttitude::Type TargetTeam = ETeamAttitude::Hostile, + bool bDrawDebug = false, bool bIgnoreSelf = true) const; };