KLingo Project Documentation 1.0.0
Unreal Engine 5.6 C++ Project Documentation
로딩중...
검색중...
일치하는것 없음
OrderKiosk.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
4#include "OrderKiosk.h"
5
6#include "ATeleportOut.h"
7#include "CityName.h"
8#include "ConveyorBelt.h"
9#include "Food.h"
10#include "ListenAnswer.h"
11#include "Components/BoxComponent.h"
12#include "Kismet/GameplayStatics.h"
13#include "Net/UnrealNetwork.h"
14
15#define TARGET_LOCATION FVector(5604.438473,-5691.762227,-3648.742048)
16
17// Sets default values
19{
20 // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
21 PrimaryActorTick.bCanEverTick = true;
22 bReplicates = true;
23
24 FoodCollision = CreateDefaultSubobject<UBoxComponent>(TEXT("FoodCollision"));
25 SetRootComponent(FoodCollision);
26
27 SubmitCollision = CreateDefaultSubobject<UBoxComponent>(TEXT("SubmitCollision"));
28 SubmitCollision->SetupAttachment(GetRootComponent());
29
31}
32
33// Called when the game starts or when spawned
35{
36 Super::BeginPlay();
37
38 FoodCollision->OnComponentBeginOverlap.AddDynamic(this, &AOrderKiosk::BeginFoodOverlap);
39 SubmitCollision->OnComponentBeginOverlap.AddDynamic(this, &AOrderKiosk::BeginSubmitOverlap);
40
41 TArray<AActor*> CityNames;
42 UGameplayStatics::GetAllActorsOfClass(GetWorld(), ACityName::StaticClass(), CityNames);
43 for (AActor* Actor : CityNames)
44 {
45 if (ACityName* CN = Cast<ACityName>(Actor))
46 {
47 if (CN->Index == 0) FoodDisplay = CN;
48 else if (CN->Index == 1) CityDisplay = CN;
49 }
50 }
51}
52
53// Called every frame
54void AOrderKiosk::Tick(float DeltaTime)
55{
56 Super::Tick(DeltaTime);
57}
58
59void AOrderKiosk::BeginFoodOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
60 UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
61{
62 UE_LOG(LogTemp, Warning, TEXT("[OrderKiosk::BeginFoodOverlap] IsOnceStopped: %d"), IsOnceStopped);
63
64 if (IsOnceStopped) return;
65
66 if (AFood* Temp = Cast<AFood>(OtherActor))
67 {
70
71 UE_LOG(LogTemp, Warning, TEXT("[OrderKiosk::BeginFoodOverlap] Food detected. InAnswerType: %d, City=%s, Food=%s"),
72 InAnswerType, *CurrentData.word1.name, *CurrentData.word2.name);
73
74 // 이미 정답 데이터가 있으면 컨베이어 계속 움직임
75 if (InAnswerType == EAnswerType::Food && CurrentData.word2.name != TEXT("")) return;
76
77 // City가 이미 있는 경우 (부분정답), 바로 3초 후 이동 타이머 설정
78 if (InAnswerType == EAnswerType::City && CurrentData.word1.name != TEXT(""))
79 {
80 UE_LOG(LogTemp, Warning, TEXT("[OrderKiosk::BeginFoodOverlap] City already set - Setting timer for teleport"));
81
82 FTimerHandle TimerHandle;
83 GetWorldTimerManager().SetTimer(TimerHandle, FTimerDelegate::CreateLambda([this]
84 {
85 UE_LOG(LogTemp, Warning, TEXT("[OrderKiosk] Timer triggered - Moving FoodContainer (from BeginFoodOverlap)"));
87 }), 3.f, false);
88
89 return;
90 }
91
92 // 아직 설정 안 됐으면 컨베이어 멈추기
93 if (ConveyorsToControl.Num() <= 0) return;
94
95 UE_LOG(LogTemp, Warning, TEXT("[OrderKiosk::BeginFoodOverlap] Stopping conveyor"));
96
97 for (auto Conveyor : ConveyorsToControl)
98 {
99 if (AConveyorBelt* CB = Cast<AConveyorBelt>(Conveyor))
100 {
101 CB->ChangeConveyorSpeed(0.f);
102 }
103 }
104 }
105}
106
107void AOrderKiosk::BeginSubmitOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
108 UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
109{
110 // 답 제출하면 컨베이어 재개
111 if (AListenAnswer* Answer = Cast<AListenAnswer>(OtherActor))
112 {
113 UE_LOG(LogTemp, Warning, TEXT("[OrderKiosk::BeginSubmitOverlap] ListenAnswer detected. AnswerType: %d, Index: %d"),
114 Answer->AnswerData.AnswerType, InAnswerType);
115
116 if (ConveyorsToControl.Num() <= 0) return;
117
118 for (auto Conveyor : ConveyorsToControl)
119 {
120 if (AConveyorBelt* CB = Cast<AConveyorBelt>(Conveyor))
121 {
122 if (!CurrentFoodContainer) return;
123
124 // 인덱스 번호와 정답 타입이 일치하면 데이터 전달 후 컨베이어 움직이기
125 if (Answer->AnswerData.AnswerType == InAnswerType)
126 {
127 UE_LOG(LogTemp, Warning, TEXT("[OrderKiosk::BeginSubmitOverlap] AnswerType matched. InAnswerType: %d"), InAnswerType);
128
129 switch (InAnswerType)
130 {
132 CurrentFoodContainer->SetFoodMesh(Answer->AnswerData.word1, Answer->Mesh->GetStaticMesh());
135 break;
136
138 {
139 UE_LOG(LogTemp, Warning, TEXT("[OrderKiosk::BeginSubmitOverlap] City case - Setting timer for teleport"));
140
141 CurrentFoodContainer->SetCityName(Answer->AnswerData.word1);
143
144 // 3초 뒤 정답 구간으로 이동
145 FTimerHandle TimerHandle;
146 GetWorldTimerManager().SetTimer(TimerHandle, FTimerDelegate::CreateLambda([this]
147 {
148 UE_LOG(LogTemp, Warning, TEXT("[OrderKiosk] Timer triggered - Moving FoodContainer"));
150
151 }), 3.f, false);
152
153 break;
154 }
155
156 default:
157 break;
158 }
159
160 CB->ChangeConveyorSpeed(200.f);
161
163 //CurrentFoodContainer = nullptr;
164 }
165 }
166 }
167
168 IsOnceStopped = true;
169 }
170 else
171 {
172 UE_LOG(LogTemp, Warning, TEXT("[OrderKiosk::BeginSubmitOverlap] OtherActor is not a ListenAnswer"));
173 }
174}
175
177{
178 MarkerType = InMarkerType;
179}
180
181void AOrderKiosk::Server_MoveFoodContainer_Implementation(AActor* ActorToMove)
182{
183 ActorToMove->SetActorLocation(TeleportOut->GetActorLocation());
184}
185
186void AOrderKiosk::Server_DestroyListenAnswer_Implementation(AActor* ActorToDestroy)
187{
188 ActorToDestroy->Destroy();
189}
190
191
192
ECompassMarkerType
void SetChecked()
Definition CityName.cpp:57
Definition Food.h:37
void UpdateFoodWidget()
Widget에 음식 이름 업데이트
Definition Food.cpp:100
void SetFoodMesh(FWordInfo InWord, UStaticMesh *InMesh)
Definition Food.cpp:167
FFoodCapsuleData CurrentFoodData
Definition Food.h:77
void SetCityName(FWordInfo InWord)
Definition Food.cpp:84
class UBoxComponent * SubmitCollision
Definition OrderKiosk.h:41
class UBoxComponent * FoodCollision
Definition OrderKiosk.h:38
class ACityName * CityDisplay
Definition OrderKiosk.h:77
virtual void Tick(float DeltaTime) override
EAnswerType InAnswerType
Definition OrderKiosk.h:62
class AFood * CurrentFoodContainer
Definition OrderKiosk.h:59
bool IsOnceStopped
Definition OrderKiosk.h:54
class ACityName * FoodDisplay
Definition OrderKiosk.h:76
void BeginFoodOverlap(UPrimitiveComponent *OverlappedComponent, AActor *OtherActor, UPrimitiveComponent *OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &SweepResult)
void Server_DestroyListenAnswer(AActor *ActorToDestroy)
virtual void SetCompassMarkerInto(ECompassMarkerType InMarkerType) override
virtual void BeginPlay() override
void BeginSubmitOverlap(UPrimitiveComponent *OverlappedComponent, AActor *OtherActor, UPrimitiveComponent *OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &SweepResult)
void Server_MoveFoodContainer(AActor *ActorToMove)
TObjectPtr< class ATeleportOut > TeleportOut
Definition OrderKiosk.h:50
TArray< AActor * > ConveyorsToControl
Definition OrderKiosk.h:67
FWordInfo word1
시나리오 단어 정보
Definition Food.h:22
FWordInfo word2
Definition Food.h:25
FString name