-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUFO_Part.cpp
93 lines (72 loc) · 2.61 KB
/
UFO_Part.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Fill out your copyright notice in the Description page of Project Settings.
#include "UFO_Part.h"
//Added
#include "Components/StaticMeshComponent.h"
#include "UFO_Part.h"
#include "Kismet/GameplayStatics.h"
#include "../UFO/UFO.h"
#include "../../Game_Rules/Hivemind_GameState.h"
#include "Sound/SoundCue.h"
// Sets default values
AUFO_Part::AUFO_Part()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = false;
PrimaryActorTick.bStartWithTickEnabled = false;
//No damage
bCanBeDamaged = false;
//The trigger zone of the power source will automatically collect this
//Make sure that it can actually respond to ECC_GameTraceChannel1 though
Mesh->SetCollisionObjectType(ECC_GameTraceChannel1);
Mesh->SetCollisionResponseToAllChannels(ECR_Ignore);
Mesh->SetCollisionResponseToChannel(ECC_GameTraceChannel2, ECR_Overlap);
Mesh->SetCollisionResponseToChannel(ECC_Visibility, ECR_Block);
//Player can't walk through it
Mesh->SetCollisionResponseToChannel(ECC_Pawn, ECR_Block);
Mesh->CanCharacterStepUpOn = ECB_No;
//Setup variables
HealthBonus = 25.f;
//Set root
SetRootComponent(Mesh);
//Is an autoaim target
Tags.Add("AutoAimTarget");
}
void AUFO_Part::Collect()
{
//Call super
Super::Collect();
//Specific stuff for UFO part
UWorld* const World = GetWorld();
if (World)
{
//Physics
Mesh->SetSimulatePhysics(true);
Mesh->SetCollisionEnabled(ECollisionEnabled::PhysicsOnly);
//Also change collision types when beaming
Mesh->SetCollisionResponseToAllChannels(ECR_Ignore);
Mesh->SetCollisionResponseToChannel(ECC_WorldDynamic, ECR_Block);
Mesh->SetCollisionResponseToChannel(ECC_WorldStatic, ECR_Block);
Mesh->SetCollisionResponseToChannel(ECC_GameTraceChannel1, ECR_Block);
//Mesh->SetCollisionResponseToChannel(ECC_Pawn, ECR_Block);
//Notify we got a part
AHivemind_GameState* const GameState = World->GetGameState<AHivemind_GameState>();
if (GameState)
{
GameState->NotifyPartCollected(HealthBonus);
}
}
//Not autoaim target anymore
Tags.Remove("AutoAimTarget");
//Play sound
UGameplayStatics::SpawnSoundAtLocation(this, Sound_Collect, GetActorLocation());
//Teleport (beam particles are played by power source)
SetActorLocation(BeamTarget);
}
// Called when the game starts or when spawned
void AUFO_Part::BeginPlay()
{
Super::BeginPlay();
//Retrieve beam target
AUFO* const UFO = Cast<AUFO>(UGameplayStatics::GetActorOfClass(this, AUFO::StaticClass()));
BeamTarget = UFO->GetBeamLocation();
}