-
Notifications
You must be signed in to change notification settings - Fork 0
/
enemy_device.verse
129 lines (112 loc) · 5.32 KB
/
enemy_device.verse
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using { /Fortnite.com/Devices }
using { /Fortnite.com/Characters}
using { /Verse.org/Simulation }
using { /Verse.org/Random }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/SpatialMath }
# See https://dev.epicgames.com/documentation/en-us/uefn/create-your-own-device-in-verse for how to create a verse device.
# A Verse-authored creative device that can be placed in a level
enemy_device := class(creative_device):
@editable var Enemy : creative_prop = creative_prop{}
@editable var EnemyZone : mutator_zone_device = mutator_zone_device{}
@editable Button1 :button_device = button_device{}
@editable PlayerSpawner: player_spawner_device = player_spawner_device{}
@editable HealthBarColor: string = "ffffff"
var InitialPosition<private>: vector3 = vector3{X:=0.0, Y:= 0.0, Z:=0.0}
var InitialRotation<private>: rotation = rotation{}
var CurrentAgent<private>: ?agent = false
var IsEmerged<private> : logic = false
MaxX :float = 3580.0
MaxY :float = 5100.0
# Runs when the device is started in a running game
OnBegin<override>()<suspends>:void=
Button1.InteractedWithEvent.Subscribe(OnButton)
PlayerSpawner.SpawnedEvent.Subscribe(OnPlayerSpawned)
EnemyZone.AgentEntersEvent.Subscribe(OnPlayerCaptured)
OnPlayerSpawned(Agent: agent):void=
if (IsEmerged = false):
return
Print("OnPlayerSpawned")
spawn{StartChasing(Agent)}
OnButton(Agent: agent):void =
spawn{Emerge()}
spawn{StartChasing(Agent)}
OnPlayerCaptured(Agent : agent) :void =
if (IsEmerged = false):
return
if (FortniteCharacter : fort_character = Agent.GetFortCharacter[]):
MyCharacterHealth : float = FortniteCharacter.GetHealth()
FortniteCharacter.Damage(MyCharacterHealth)
set CurrentAgent = false
BackToInitialPosition()
Print("OnPlayerCaptured")
BackToInitialPosition():void =
spawn{Enemy.MoveTo(InitialPosition, InitialRotation, 1.0 )}
StartChasing(Agent: agent)<suspends>:void =
Print("StartChasing")
Sleep(3.0) #プレーヤースポーン直後は無敵期間があるようなのでwait
set CurrentAgent = option{Agent}
loop:
race:
RotateTowardPlayer(Agent)
Wait()
if (CurrentAgent = false):
Print("Break loop1") #Wait中に倒した時のため必要
break
Attack(Agent)
if (CurrentAgent = false):
Print("Break loop2") #Attack中に倒した時のため必要
break
Sleep(1.0)
Wait()<suspends>:void =
WaitTime := GetRandomFloat(0.0, 10.0)
#Print("Wait for {WaitTime} seconds")
Sleep(WaitTime)
Emerge()<suspends>:void =
PropLocation := Enemy.GetTransform().Translation
NewLocation := vector3{X := PropLocation.X, Y := PropLocation.Y, Z := PropLocation.Z + 400.0}
Enemy.MoveTo(NewLocation, Enemy.GetTransform().Rotation, 1.5)
set InitialPosition = Enemy.GetTransform().Translation
set InitialRotation = Enemy.GetTransform().Rotation
set IsEmerged = true
BackToGround()<suspends>:void =
Print("BackToGround")
set CurrentAgent = false
set IsEmerged = false
PropLocation := Enemy.GetTransform().Translation
NewLocation := vector3{X := PropLocation.X, Y := PropLocation.Y, Z := PropLocation.Z - 400.0}
Enemy.MoveTo(NewLocation, Enemy.GetTransform().Rotation, 2.0)
Attack(Agent: agent)<suspends>:void =
#Print("Attack")
if (PlayerCharacter := Agent.GetFortCharacter[]):
PlayerLocation := PlayerCharacter.GetTransform().Translation
PropLocation := Enemy.GetTransform().Translation
Xdiff := PlayerLocation.X - PropLocation.X
Ydiff := PlayerLocation.Y - PropLocation.Y
var NewX :float = PropLocation.X + 1.5*Xdiff
var NewY :float = PropLocation.Y + 1.5*Ydiff
if (NewX < 0.0):
set NewX = 0.0
if (NewX > MaxX):
set NewX = MaxX
if (NewY < 0.0):
set NewY = 0.0
if (NewY > MaxY):
set NewY = MaxY
NewLocation := vector3{X := NewX, Y := NewY, Z := PropLocation.Z}
Enemy.MoveTo(NewLocation, Enemy.GetTransform().Rotation, 2.0)
RotateTowardPlayer(Agent : agent)<suspends>:void=
#Print("RotateTowardPlayer")
loop:
if (CurrentAgent = false):
break
if (PlayerCharacter := Agent.GetFortCharacter[]):
PropLocation := Enemy.GetTransform().Translation
PlayerLocation := PlayerCharacter.GetTransform().Translation
if (LookDirection := (PropLocation - PlayerLocation).MakeUnitVector[]):
Yaw := RadiansToDegrees(ArcTan(LookDirection.Y, LookDirection.X)) #+ 140.0
Pitch := 0.0 #RadiansToDegrees(ArcTan(LookDirection.Z, Sqrt((LookDirection.X * LookDirection.X) + (LookDirection.Y * LookDirection.Y))))
Roll := 0.0
NewRotation := MakeRotationFromYawPitchRollDegrees(Yaw, Pitch, Roll)
Enemy.MoveTo(PropLocation, NewRotation, 0.5)
Sleep(0.0)