-
Notifications
You must be signed in to change notification settings - Fork 0
/
VoiceLineSystem.as
105 lines (95 loc) · 3.06 KB
/
VoiceLineSystem.as
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
94
95
96
97
98
99
100
101
102
103
104
105
import Telegram;
import VoiceInsanety;
import VoiceBox;
import Painting;
import void playVoiceLine(USoundCue voiceLine) from "PlayerCharacter";
class UVoiceLineSystem: UActorComponent
{
UPROPERTY(EditAnywhere)
float delay;
UPROPERTY(EditAnywhere)
Telegram locationBased;
Telegram insanityBased;
UPROPERTY()
VoiceInsanety voiceInsanityComponent;
float deleyTime, isplayingTime;
bool isPlaying;
UPROPERTY()
bool ableToPlay = false;
void messageHandeling(Telegram msg)
{
AActor sender = msg.sender;
APainting painting = Cast<APainting>(sender);
AVoiceBox voiceBox = Cast<AVoiceBox>(sender);
if((msg.sender == painting || msg.sender == voiceBox))
{
// Print("Got to say stuff");
locationBased = msg;
}
else
insanityBased = msg;
}
UFUNCTION(BlueprintOverride)
void Tick(float DeltaSeconds)
{
if(!isPlaying && ableToPlay)
checkVoiceLineToPlay();
else if(isPlaying && isplayingTime <= GetCurrentWorld().GetTimeSeconds())
isPlaying = false;
}
bool checkPlayability(Telegram msg)
{
AActor sender = msg.sender;
APainting painting = Cast<APainting>(sender);
AVoiceBox voiceBox = Cast<AVoiceBox>(sender);
if(painting != nullptr)
{
if(painting.isLookingAtPainting)
{
return true;
}
}
else if (voiceBox != nullptr){
if(voiceBox.playerIsInside)
{
return true;
}
}
return false;
}
UFUNCTION(BlueprintOverride)
void BeginPlay()
{
voiceInsanityComponent = Cast<VoiceInsanety>(Gameplay::GetPlayerPawn(0).GetComponentByClass(VoiceInsanety::StaticClass()));
deleyTime = GetWorld().GetTimeSeconds() + deleyTime;
}
UFUNCTION()
void checkVoiceLineToPlay()
{
if(locationBased.extraSoundque != nullptr && this.checkPlayability(locationBased))
{
playVoiceLine(locationBased.extraSoundque);
deleyTime = GetWorld().GetTimeSeconds() + locationBased.extraSoundque.Duration + delay;
isplayingTime = GetWorld().GetTimeSeconds() + locationBased.extraSoundque.Duration + 1;
locationBased.extraSoundque = nullptr;
isPlaying = true;
AVoiceBox voiceBox = Cast<AVoiceBox>(locationBased.sender);
if(voiceBox != nullptr)
{
voiceBox.destroyItem();
}
}
else if(insanityBased.sender != nullptr && deleyTime <= GetWorld().GetTimeSeconds())
{
USoundCue temp = voiceInsanityComponent.choiceVoiceLine();
if(temp != nullptr)
{
playVoiceLine(temp);
deleyTime = GetWorld().GetTimeSeconds() + temp.Duration + delay;
isplayingTime = GetWorld().GetTimeSeconds() + temp.Duration;
}
insanityBased.sender = nullptr;
isPlaying = true;
}
}
}