diff --git a/Content/Blueprints/Character/BP_BlasterCharacter.uasset b/Content/Blueprints/Character/BP_BlasterCharacter.uasset index 799a318..38af9f6 100644 Binary files a/Content/Blueprints/Character/BP_BlasterCharacter.uasset and b/Content/Blueprints/Character/BP_BlasterCharacter.uasset differ diff --git a/Content/Blueprints/GameModes/BP_TeamsGameMode.uasset b/Content/Blueprints/GameModes/BP_TeamsGameMode.uasset index 753c46e..a13b8d8 100644 Binary files a/Content/Blueprints/GameModes/BP_TeamsGameMode.uasset and b/Content/Blueprints/GameModes/BP_TeamsGameMode.uasset differ diff --git a/Content/Maps/BlasterMap.umap b/Content/Maps/BlasterMap.umap index ecc8b4b..05be7bc 100644 Binary files a/Content/Maps/BlasterMap.umap and b/Content/Maps/BlasterMap.umap differ diff --git a/Source/Blaster/Character/BlasterCharacter.cpp b/Source/Blaster/Character/BlasterCharacter.cpp index 14237cd..2c0b859 100644 --- a/Source/Blaster/Character/BlasterCharacter.cpp +++ b/Source/Blaster/Character/BlasterCharacter.cpp @@ -316,6 +316,29 @@ void ABlasterCharacter::MulticastLostTheLead_Implementation() } } +void ABlasterCharacter::SetTeamColor(ETeam Team) +{ + if (GetMesh() == nullptr) return; + switch (Team) + { + case ETeam::ET_RedTeam: + if (RedMaterial == nullptr) return; + GetMesh()->SetMaterial(0, RedMaterial); + DissolveMaterialInstance = RedDissolveMatInst; + break; + case ETeam::ET_BlueTeam: + if (BlueMaterial == nullptr) return; + GetMesh()->SetMaterial(0, BlueMaterial); + DissolveMaterialInstance = BlueDissolveMatInst; + break; + case ETeam::ET_NoTeam: + if (OriginalMaterial == nullptr) return; + GetMesh()->SetMaterial(0, OriginalMaterial); + DissolveMaterialInstance = BlueDissolveMatInst; + break; + } +} + void ABlasterCharacter::BeginPlay() { Super::BeginPlay(); @@ -903,7 +926,8 @@ void ABlasterCharacter::PollInit() // Initialize Score now we have the PlayerState BlasterPlayerState->IncreaseScore(0.f); BlasterPlayerState->IncreaseDefeats(0); - + SetTeamColor(BlasterPlayerState->GetTeam()); + const ABlasterGameState* BlasterGameState = Cast(UGameplayStatics::GetGameState(this)); if (BlasterGameState && BlasterGameState->TopScoringPlayers.Contains(BlasterPlayerState)) { diff --git a/Source/Blaster/Character/BlasterCharacter.h b/Source/Blaster/Character/BlasterCharacter.h index 18d31f0..c1d5b4b 100644 --- a/Source/Blaster/Character/BlasterCharacter.h +++ b/Source/Blaster/Character/BlasterCharacter.h @@ -5,6 +5,7 @@ #include "CoreMinimal.h" #include "Blaster/Interfaces/InteractWithCrosshairInterface.h" #include "Blaster/Types/CombatState.h" +#include "Blaster/Types/Team.h" #include "Blaster/Types/TurningInPlace.h" #include "Components/TimelineComponent.h" #include "GameFramework/Character.h" @@ -66,6 +67,8 @@ public: UFUNCTION(NetMulticast, Reliable) void MulticastLostTheLead(); + + void SetTeamColor(ETeam Team); protected: virtual void BeginPlay() override; @@ -277,9 +280,25 @@ private: UMaterialInstanceDynamic* DynamicDissolveMaterialInstance; // Material instance set on the Blueprint, used with the dynamic material instance - UPROPERTY(EditAnywhere, Category = Elimination) + UPROPERTY(VisibleAnywhere, Category = Elimination) UMaterialInstance* DissolveMaterialInstance; + // Team colors + UPROPERTY(EditAnywhere, Category = Elimination) + UMaterialInstance* RedDissolveMatInst; + + UPROPERTY(EditAnywhere, Category = Elimination) + UMaterialInstance* RedMaterial; + + UPROPERTY(EditAnywhere, Category = Elimination) + UMaterialInstance* BlueDissolveMatInst; + + UPROPERTY(EditAnywhere, Category = Elimination) + UMaterialInstance* BlueMaterial; + + UPROPERTY(EditAnywhere, Category = Elimination) + UMaterialInstance* OriginalMaterial; + // Elimination effects UPROPERTY(EditAnywhere) UParticleSystem* EliminationBotEffect; diff --git a/Source/Blaster/PlayerState/BlasterPlayerState.cpp b/Source/Blaster/PlayerState/BlasterPlayerState.cpp index b3e0d24..857c716 100644 --- a/Source/Blaster/PlayerState/BlasterPlayerState.cpp +++ b/Source/Blaster/PlayerState/BlasterPlayerState.cpp @@ -70,3 +70,22 @@ void ABlasterPlayerState::OnRep_Defeats() } } } + +void ABlasterPlayerState::SetTeam(ETeam TeamToSet) +{ + Team = TeamToSet; + ABlasterCharacter* BCharacter = Cast(GetPawn()); + if (BCharacter) + { + BCharacter->SetTeamColor(Team); + } +} + +void ABlasterPlayerState::OnRep_Team() +{ + ABlasterCharacter* BCharacter = Cast(GetPawn()); + if (BCharacter) + { + BCharacter->SetTeamColor(Team); + } +} diff --git a/Source/Blaster/PlayerState/BlasterPlayerState.h b/Source/Blaster/PlayerState/BlasterPlayerState.h index e6c7f56..6bde265 100644 --- a/Source/Blaster/PlayerState/BlasterPlayerState.h +++ b/Source/Blaster/PlayerState/BlasterPlayerState.h @@ -33,11 +33,13 @@ private: UPROPERTY(ReplicatedUsing = OnRep_Defeats) int32 Defeats; - UPROPERTY(Replicated) + UPROPERTY(ReplicatedUsing = OnRep_Team) ETeam Team = ETeam::ET_NoTeam; + UFUNCTION() + void OnRep_Team(); public: FORCEINLINE ETeam GetTeam() const { return Team; } - FORCEINLINE void SetTeam(ETeam TeamToSet) { Team = TeamToSet; } + void SetTeam(ETeam TeamToSet); };