KLingo Project Documentation 1.0.0
Unreal Engine 5.6 C++ Project Documentation
로딩중...
검색중...
일치하는것 없음
AContactTrigger.cpp
이 파일의 문서화 페이지로 가기
1// Copyright (c) 2025 Doppleddiggong. All rights reserved. Unauthorized copying, modification, or distribution of this file, via any medium is strictly prohibited. Proprietary and confidential.
2
3#include "AContactTrigger.h"
4#include "Components/BoxComponent.h"
5#include "DrawDebugHelpers.h"
6#include "APlayerActor.h"
7#include "GameFramework/PlayerController.h"
9#include "NetworkData.h"
10#include "ALingoGameMode.h"
11#include "FoodCourtManager.h"
12#include "LuggageManager.h"
13#include "ULingoGameHelper.h"
15#include "Kismet/GameplayStatics.h"
16
18{
19 PrimaryActorTick.bCanEverTick = true;
20 bReplicates = true;
21
22 // 루트 컴포넌트로 BoxComponent 생성
23 TriggerBox = CreateDefaultSubobject<UBoxComponent>(TEXT("TriggerBox"));
24 RootComponent = TriggerBox;
25
26 // 박스 크기 기본값 설정
27 TriggerBox->SetBoxExtent(FVector(100.0f, 100.0f, 100.0f));
28
29 // Overlap 이벤트 활성화
30 TriggerBox->SetGenerateOverlapEvents(true);
31 TriggerBox->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
32 TriggerBox->SetCollisionResponseToAllChannels(ECR_Ignore);
33 TriggerBox->SetCollisionResponseToChannel(ECC_Pawn, ECR_Overlap);
34
35 // 초기값 설정
36 bIsTriggered = false;
37 bShowDebugBox = true;
38 DebugBoxColor = FColor::Green;
39
40 VoiceConversationSystem = CreateDefaultSubobject<UVoiceConversationSystem>(TEXT("VoiceConversationSystem"));
41
44}
45
47{
48 Super::BeginPlay();
49
51
52 // Overlap 이벤트 바인딩
53 if (TriggerBox)
54 TriggerBox->OnComponentBeginOverlap.AddDynamic(this, &AContactTrigger::OnTriggerBeginOverlap);
55}
56
57void AContactTrigger::Tick(float DeltaTime)
58{
59 Super::Tick(DeltaTime);
60
62 {
63 FVector BoxCenter = TriggerBox->GetComponentLocation();
64 FVector BoxExtent = TriggerBox->GetScaledBoxExtent();
65 FRotator BoxRotation = TriggerBox->GetComponentRotation();
66
67 // 디버그 박스 표시 (트리거 활성화 상태일 때만)
68 if (!bIsTriggered)
69 {
70 DrawDebugBox(
71 GetWorld(),
72 BoxCenter,
73 BoxExtent,
74 BoxRotation.Quaternion(),
76 false,
77 -1.0f,
78 0,
79 2.0f
80 );
81 }
82
83 // 트리거 정보를 텍스트로 표시
84 FString StatusText = bIsTriggered ? TEXT("[TRIGGERED]") : TEXT("[ACTIVE]");
85 FColor TextColor = bIsTriggered ? FColor::Red : FColor::Green;
86
87 FVector TextLocation = BoxCenter + FVector(0.0f, 0.0f, BoxExtent.Z + 50.0f);
88
89 // 상태 표시
90 DrawDebugString(
91 GetWorld(),
92 TextLocation,
93 StatusText,
94 nullptr,
95 TextColor,
96 0.0f,
97 true,
98 1.2f
99 );
100
101 // 이벤트 메시지 표시
102 FVector MessageLocation = TextLocation + FVector(0.0f, 0.0f, 30.0f);
103 DrawDebugString(
104 GetWorld(),
105 MessageLocation,
106 FString::Printf(TEXT("Message: %s"), *EventMessage),
107 nullptr,
108 FColor::White,
109 0.0f,
110 true,
111 1.0f
112 );
113 }
114}
115
116void AContactTrigger::OnTriggerBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
117 UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
118{
119 // 이미 트리거되었으면 무시
120 if (bIsTriggered)
121 return;
122
123 // PlayerActor인지 확인
124 APlayerActor* PlayerActor = Cast<APlayerActor>(OtherActor);
125 if (PlayerActor)
126 {
127 // 서버 RPC 호출
128 ServerRPC_OnTrigger(PlayerActor);
129 }
130}
131
132void AContactTrigger::ServerRPC_OnTrigger_Implementation(AActor* TriggeringActor)
133{
134 // 이미 트리거되었으면 무시
135 if (bIsTriggered)
136 return;
137
138 // 트리거 비활성화
139 bIsTriggered = true;
140
142}
143
144
146{
147 if (auto KLingoNetwork = UKLingoNetworkSystem::Get(GetWorld()))
148 {
149 switch (InQuestType)
150 {
151 case EQuestType::Read:
152 KLingoNetwork->RequestReadScenario( FResponseReadScenarioDelegate::CreateUObject(this, &AContactTrigger::OnReadResponseScenario));
153 break;
154
155 case EQuestType::Listen: // 듣기
156 KLingoNetwork->RequestListenScenario( FResponseListenScenarioDelegate::CreateUObject(this, &AContactTrigger::OnListenResponseScenario));
157 break;
158 }
159 }
160}
161
163{
164 if (!bWasSuccessful)
165 return;
166
167 // ALingoGameState에 시나리오 데이터 전체 저장
168 if (UWorld* World = GetWorld())
169 {
170 if (auto GM = ULingoGameHelper::GetLingoGameMode(World))
171 GM->BeginReadQuest( ResponseData);
172
173 ALuggageManager* LuggageManager = Cast<ALuggageManager>( UGameplayStatics::GetActorOfClass(World, ALuggageManager::StaticClass()));
174
175 if (LuggageManager)
176 {
177 LuggageManager->StartSpawning();
178 // LuggageManager->InitHolder(ResponseData);
179 }
180 }
181}
182
184{
185 if (!bWasSuccessful)
186 return;
187
188 if (UWorld* World = GetWorld())
189 {
190 if (auto GM = ULingoGameHelper::GetLingoGameMode(World))
191 GM->BeginListenQuest(ResponseData);
192
193 // VoiceConversationSystem->PlayVoiceAudio(ResponseData.voice_data);
194
195 AFoodCourtManager* FCourtManager = Cast<AFoodCourtManager>(UGameplayStatics::GetActorOfClass(
196 World, AFoodCourtManager::StaticClass()));
197 if (FCourtManager)
198 {
199 FCourtManager->SpawnFoodContainer();
200 }
201 }
202}
203
205{
206 MarkerType = InMarkerType;
207}
208
EQuestType
Declares the player-controlled character actor.
ECompassMarkerType
네트워크 요청과 응답에 사용되는 구조체 및 설정을 정의합니다.
KLingo API 요청을 담당하는 서브시스템을 선언합니다.
STT·GPT·TTS 파이프라인을 연결하는 음성 대화 컴포넌트를 선언합니다.
void OnListenResponseScenario(struct FResponseListenScenario &ResponseData, bool bWasSuccessful)
FColor DebugBoxColor
디버그 박스 색상
EQuestType QuestType
void OnTriggerBeginOverlap(UPrimitiveComponent *OverlappedComponent, AActor *OtherActor, UPrimitiveComponent *OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &SweepResult)
트리거 박스 Overlap 시작 이벤트 핸들러
TObjectPtr< class UVoiceConversationSystem > VoiceConversationSystem
virtual void BeginPlay() override
bool bIsTriggered
트리거 활성화 상태 (false = 활성화, true = 비활성화)
virtual void Tick(float DeltaTime) override
void OnReadResponseScenario(struct FResponseReadScenario &ResponseData, bool bWasSuccessful)
virtual void SetCompassMarkerInto(ECompassMarkerType InMarkerType) override
FString EventMessage
플레이어에게 전송할 이벤트 메시지 (Detail 패널에서 설정)
bool bShowDebugBox
디버그 드로우 표시 여부
TObjectPtr< class UBoxComponent > TriggerBox
트리거 영역을 정의하는 박스 컴포넌트
void ServerRPC_OnTrigger(AActor *TriggeringActor)
서버에서 실행되는 트리거 처리 RPC
void OnTriggerScenario(EQuestType InQuestType)
Main character driven directly by the player.
static FString GetStageStartMessage(const EQuestType QuestType)
static class ALingoGameMode * GetLingoGameMode(const UObject *WorldContextObject)