KLingo Project Documentation 1.0.0
Unreal Engine 5.6 C++ Project Documentation
로딩중...
검색중...
일치하는것 없음
ATeleportTrigger.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 "ATeleportTrigger.h"
5
6#include "ALingoGameState.h"
7#include "Components/BoxComponent.h"
8#include "DrawDebugHelpers.h"
9#include "APlayerActor.h"
10#include "ATeleportOut.h"
12#include "GameFramework/PlayerController.h"
13#include "GameLogging.h"
14
15
17{
18 PrimaryActorTick.bCanEverTick = true;
19 bReplicates = true;
20
21 // 루트 컴포넌트로 BoxComponent 생성
22 TriggerBox = CreateDefaultSubobject<UBoxComponent>(TEXT("TriggerBox"));
23 RootComponent = TriggerBox;
24
25 // 박스 크기 기본값 설정
26 TriggerBox->SetBoxExtent(FVector(100.0f, 100.0f, 100.0f));
27
28 // Overlap 이벤트 활성화
29 TriggerBox->SetGenerateOverlapEvents(true);
30 TriggerBox->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
31 TriggerBox->SetCollisionResponseToAllChannels(ECR_Ignore);
32 TriggerBox->SetCollisionResponseToChannel(ECC_Pawn, ECR_Overlap);
33
34 // 초기값 설정
35 bIsOneShot = true;
36 bIsTriggered = false;
37 bShowDebugBox = true;
38 DebugBoxColor = FColor::Green;
39
41}
42
44{
45 Super::BeginPlay();
46
47 if (TriggerBox)
48 TriggerBox->OnComponentBeginOverlap.AddDynamic(this, &ATeleportTrigger::OnTriggerBeginOverlap);
49}
50
51void ATeleportTrigger::Tick(float DeltaTime)
52{
53 Super::Tick(DeltaTime);
54
56 {
57 FVector BoxCenter = TriggerBox->GetComponentLocation();
58 FVector BoxExtent = TriggerBox->GetScaledBoxExtent();
59 FRotator BoxRotation = TriggerBox->GetComponentRotation();
60
61 // 디버그 박스 표시 (트리거 활성화 상태일 때만)
62 if (!bIsTriggered)
63 {
64 DrawDebugBox(
65 GetWorld(),
66 BoxCenter,
67 BoxExtent,
68 BoxRotation.Quaternion(),
70 false,
71 -1.0f,
72 0,
73 2.0f
74 );
75 }
76
77 // 트리거 정보를 텍스트로 표시
78 FString StatusText = bIsTriggered ? TEXT("[TRIGGERED]") : TEXT("[ACTIVE]");
79 FColor TextColor = bIsTriggered ? FColor::Red : FColor::Green;
80
81 FVector TextLocation = BoxCenter + FVector(0.0f, 0.0f, BoxExtent.Z + 50.0f);
82
83 // 상태 표시
84 DrawDebugString(
85 GetWorld(),
86 TextLocation,
87 StatusText,
88 nullptr,
89 TextColor,
90 0.0f,
91 true,
92 1.2f
93 );
94 }
95}
96
98 UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
99 UPrimitiveComponent* OtherComp, int32 OtherBodyIndex,
100 bool bFromSweep, const FHitResult& SweepResult)
101{
102 // 서버에서만 처리
103 if (!HasAuthority())
104 return;
105
106 // 원샷 모드이고 이미 트리거되었으면 무시
108 return;
109
110 // PlayerActor인지 확인
111 APlayerActor* PlayerActor = Cast<APlayerActor>(OtherActor);
112 if (PlayerActor)
113 {
114 // TeleportOut이 설정되어 있는지 확인
115 if (!TeleportOut)
116 {
117 PRINTLOG(TEXT("ATeleportTrigger: TeleportOut이 설정되지 않았습니다!"));
118 return;
119 }
120
121 // TeleportOut의 위치 가져오기
122 FTransform TargetTransform = TeleportOut->GetActorTransform();
123
124 // NetworkBroadcastActor를 통해 모든 플레이어 텔레포트
125 if (ANetworkBroadcastActor* BroadcastActor = ANetworkBroadcastActor::Get(this))
126 {
127 BroadcastActor->SendTeleportAllPlayers(TargetTransform, this);
128 PRINTLOG( TEXT("텔레포트 요청: %s"), *TargetTransform.ToString());
129
130 // 마커 변경
131 if (ALingoGameState* GS = GetWorld()->GetGameState<ALingoGameState>())
132 {
133 if (ActorHasTag(FName("ReadQuestEnd")))
134 {
135 GS->SetAllCompassVisibility(false);
136 GS->SetCompassVisibilityByTag("ListenQuestStart", true);
137 }
138 else if (ActorHasTag(FName("ListenQuestEnd")))
139 {
140 GS->SetAllCompassVisibility(false);
141 GS->SetCompassVisibilityByTag("Whitney", true);
142 }
143 }
144
145
146 if ( DoorIndex > 0 )
147 {
148 BroadcastActor->SendDoorMessage(DoorIndex, true, this);
149 }
150 }
151 else
152 {
153 PRINTLOG(TEXT("ATeleportTrigger: NetworkBroadcastActor를 찾을 수 없습니다!"));
154 }
155
156
157
158
159 OnActivate();
160
161 // 원샷 모드일 때만 트리거 상태 변경
162 if (bIsOneShot)
163 bIsTriggered = true;
164 }
165}
166
168{
169 MarkerType = InMarkerType;
170}
171
173{
174 PRINT_STRING(TEXT("ABroadcastTrigger Activated"));
175}
176
네트워크 복제를 위한 전역 브로드캐스트 Actor
Declares the player-controlled character actor.
ECompassMarkerType
YiSan 전반에서 사용하는 공용 인터페이스를 선언합니다.
#define PRINTLOG(fmt,...)
Definition GameLogging.h:30
#define PRINT_STRING(fmt,...)
Definition GameLogging.h:45
네트워크 복제를 위한 전역 브로드캐스트 Actor
static ANetworkBroadcastActor * Get(const UObject *WorldContextObject)
싱글톤 인스턴스 가져오기
Main character driven directly by the player.
virtual void Tick(float DeltaTime) override
void OnTriggerBeginOverlap(UPrimitiveComponent *OverlappedComponent, AActor *OtherActor, UPrimitiveComponent *OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &SweepResult)
트리거 박스 Overlap 시작 이벤트 핸들러
TObjectPtr< class ATeleportOut > TeleportOut
텔레포트 목표 위치를 나타내는 TeleportOut Actor
FColor DebugBoxColor
디버그 박스 색상
bool bIsOneShot
원샷 모드 활성화 여부 (true = 한 번만 작동, false = 반복 작동 가능)
bool bShowDebugBox
디버그 드로우 표시 여부
virtual void BeginPlay() override
virtual void OnActivate_Implementation()
TObjectPtr< class UBoxComponent > TriggerBox
트리거 영역을 정의하는 박스 컴포넌트
virtual void SetCompassMarkerInto(ECompassMarkerType InMarkerType) override
bool bIsTriggered
트리거 활성화 상태 (false = 활성화, true = 비활성화)