16#include "Components/BoxComponent.h"
20 PrimaryActorTick.bCanEverTick =
true;
29 bAlwaysRelevant =
true;
31 RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT(
"Root"));
33 SwitchBody = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT(
"SwitchBody"));
35 SwitchBody->SetRelativeRotation(FRotator(0.f, 0.f, 90.0f));
36 SwitchBody->SetRelativeLocation(FVector::ZeroVector);
38 SwitchBody->SetMobility(EComponentMobility::Movable);
40 SwitchCollision = CreateDefaultSubobject<UBoxComponent>(TEXT(
"SwitchCollision"));
45 SwitchCollision->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Ignore);
47 SwitchCollision->SetCollisionResponseToChannel(ECC_PhysicsBody, ECR_Overlap);
71 PRINTLOG( TEXT(
"SwitchBody is null"));
76 UMaterialInterface* Material =
SwitchBody->GetMaterial(0);
84 UMaterialInstanceDynamic* DynMaterial = UMaterialInstanceDynamic::Create(Material,
this);
87 PRINTLOG( TEXT(
"Failed to create dynamic material"));
100 UAnimInstance* AnimInstance =
SwitchBody->GetAnimInstance();
103 PRINTLOG( TEXT(
"AnimInstance is null"));
115 PRINTLOG( TEXT(
"Failed to cast to UABP_CubeButton"));
123 PRINTLOG( TEXT(
"EmissiveMaterial is null"));
140 PRINTLOG( TEXT(
"AnimBlueprint is null"));
160 Super::Tick(DeltaTime);
170 UBroadcastManager::Get(GetWorld())->SendWeightSwitch(
ButtonIndex,
true);
196 UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
197 UPrimitiveComponent* OtherComp, int32 OtherBodyIndex,
bool bFromSweep,
const FHitResult& SweepResult)
205 PRINTLOG(TEXT(
"OnBeginOverlap: Client detected overlap, skipping (server will handle)"));
212 if (Cast<APlayerActor>(OtherActor))
227 if (
Aluggage* Luggage = Cast<Aluggage>(OtherActor))
230 ALingoGameState* GS = Cast<ALingoGameState>(GetWorld()->GetGameState());
233 PRINTLOG(TEXT(
"OnBeginOverlap: GameState is null! Cannot validate answer."));
242 PRINTLOG(TEXT(
"[WeightSwitch] Server validating: LuggageIdx=%d, CorrectIdx=%d"),
243 Luggage->GetSpawnIdx(), CorrectIdx);
245 if (CorrectIdx == Luggage->GetSpawnIdx())
263 FTimerHandle TimerHandle;
264 GetWorldTimerManager().SetTimer(TimerHandle, [
this, GS, Luggage]
266 int32 LuggageIdx = Luggage->GetSpawnIdx();
272 if (WrongList.Num() == 0)
275 PRINTLOG( TEXT(
"[AWeightSwitch] Wrong luggage :"));
276 for (
auto Wrong : WrongList)
285 FTimerHandle TimerHandle;
286 GetWorldTimerManager().SetTimer(TimerHandle, [
this, GS, Luggage]
288 FString LuggageColor = Luggage->GetColor();
289 FString LuggagePattern = Luggage->GetPattern();
290 int32 LuggageIdx = Luggage->GetSpawnIdx();
312 UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
313 UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
332 UBroadcastManager::Get(GetWorld())->SendWeightSwitch(
ButtonIndex,
false);
355void AWeightSwitch::Multicast_ShowResultPopup_Implementation(int32 CorrectAnswerIndex)
358 if (
ALingoGameState* GS = Cast<ALingoGameState>(GetWorld()->GetGameState()))
360 GS->AddWrongReadAnswer(CorrectAnswerIndex);
362 PRINTLOG(TEXT(
"[Multicast_ShowResultPopup] Added correct answer index %d to local GameState"), CorrectAnswerIndex);
366 if (
auto Popup = UPopupManager::ShowPopupAs<UPopup_Result>(GetWorld(), EPopupType::Result))
387void AWeightSwitch::Multicast_ShowWrongPopup_Implementation(
const FString& LuggageColor,
const FString& LuggagePattern)
390 if (
UPopupManager* PopupMgr = UPopupManager::Get(GetWorld()))
393 FString Message = FString::Printf(TEXT(
"Wrong Answer\nThis is not the correct Answer.\n\nColor: %s\nPattern: %s"),
394 *LuggageColor, *LuggagePattern);
396 if (
auto DM = UBroadcastManager::Get(
this))
397 DM->SendTutorMessage(FText::FromString(Message));
Declares the player-controlled character actor.
YiSan 전반에서 사용하는 공용 인터페이스를 선언합니다.
#define PRINTLOG(fmt,...)
#define PRINT_STRING(fmt,...)
KLingo API 요청을 담당하는 서브시스템을 선언합니다.
UTweenAnimInstance 클래스를 선언합니다.
TArray< int32 > WrongReadAnswerList
FORCEINLINE const FResponseReadScenario & GetReadScenarioData() const
void AddWrongReadAnswer(int32 Value)
TObjectPtr< class UMaterialInstanceDynamic > EmissiveMaterial
virtual void Tick(float DeltaTime) override
void OnWeightSwitch(int InButtonIndex, bool InActive)
TArray< class AActor * > OverlappingActors
void SetActivate(bool State)
void OnEndOverlap(UPrimitiveComponent *OverlappedComponent, AActor *OtherActor, UPrimitiveComponent *OtherComp, int32 OtherBodyIndex)
WeightSwitch Overlap 종료 처리
virtual void OnActivate_Implementation(const bool State)
void OnActivate(const bool State)
void Multicast_ShowResultPopup(int32 CorrectAnswerIndex)
[Multicast RPC] 모든 클라이언트에 정답 결과 팝업 표시
TObjectPtr< class USkeletalMeshComponent > SwitchBody
void Multicast_ShowWrongPopup(const FString &LuggageColor, const FString &LuggagePattern)
[Multicast RPC] 모든 클라이언트에 오답 메시지 표시
TObjectPtr< class UBoxComponent > SwitchCollision
TObjectPtr< class UTweenAnimInstance > AnimBlueprint
FLinearColor DeactivateColor
FLinearColor ActivateColor
void OnBeginOverlap(UPrimitiveComponent *OverlappedComponent, AActor *OtherActor, UPrimitiveComponent *OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &SweepResult)
WeightSwitch Overlap 시작 처리
virtual void BeginPlay() override
블루프린트에서 사용할 수 있는 간단한 트윈 애님 인스턴스.
int32 correct_answer_index