-
Notifications
You must be signed in to change notification settings - Fork 0
/
crime_events_minigame.verse
395 lines (336 loc) · 13.7 KB
/
crime_events_minigame.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /Verse.org/Random }
# 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
crime_events_minigame := class(creative_device):
# Notifies players when crime alert minigame has started
@editable
messageDevice : hud_message_device = hud_message_device{}
# Tracks the amount of time players have to complete crime alert minigame
@editable
crimeTimer : timer_device = timer_device{}
# Grants XP Award for completed crime alert minigames
@editable
xpGranter : accolades_device = accolades_device{}
# Grants 50 gold as reward for completed crime alert minigames
@editable
goldGranter : item_granter_device = item_granter_device{}
# Grants 1 gold for each guard eliminated
@editable
goldGranterForGuardElim : item_granter_device = item_granter_device{}
# Granters that hold items to be rewarded for completed crime alert minigames
@editable
granter1 : item_granter_device = item_granter_device{}
@editable
granter2 : item_granter_device = item_granter_device{}
@editable
granter3 : item_granter_device = item_granter_device{}
# Guards are spawned at crime spots to be defeated for crime alert minigame
@editable
crimeSpot1 : guard_spawner_device = guard_spawner_device{}
@editable
crimeSpot2 : guard_spawner_device = guard_spawner_device{}
@editable
crimeSpot3 : guard_spawner_device = guard_spawner_device{}
@editable
crimeSpot4 : guard_spawner_device = guard_spawner_device{}
@editable
crimeSpot5 : guard_spawner_device = guard_spawner_device{}
@editable
crimeSpot6 : guard_spawner_device = guard_spawner_device{}
@editable
crimeSpotBank : guard_spawner_device = guard_spawner_device{}
@editable
ctbl1 : collectible_object_device = collectible_object_device{}
@editable
ctbl2 : collectible_object_device = collectible_object_device{}
@editable
ctbl3 : collectible_object_device = collectible_object_device{}
@editable
ctbl4 : collectible_object_device = collectible_object_device{}
@editable
ctbl5 : collectible_object_device = collectible_object_device{}
@editable
ctbl6 : collectible_object_device = collectible_object_device{}
@editable
ctbl7 : collectible_object_device = collectible_object_device{}
var IsBankCrime : logic = false
# Number of crime spots
var NCrimeSpots : int = 6
# Max number of guards
var MaxGuards : int = 8
# Number of remaining guards
var NGuardsRemaining : int = -1
# Index of active crime spot
var RandomCrimeIndex : int = -1
# Amount of time between crime alert minigames in minutes (5 minutes / 1 minute for testing)
var StandByMinutes : float = 5.0
# Amount of time to display messages
var CrimeAlertMessageDuration : float = 0.0
var CrimeEndedMessageDuration : float = 5.0
# Crime alert messages
CrimeAlertType1Message<localizes>: message = "Crime reported near a landing zone"
CrimeAlertType2Message<localizes>: message = "Crime reported from a residence"
CrimeAlertType3Message<localizes>: message = "Crime reported in the city"
CrimeAlertType4Message<localizes>: message = "Crime reported at the bank"
# Crime alert minigame completed messages
CrimeAlertSuccessMessage<localizes>: message = "Mission Completed"
CrimeAlertFailedMessage<localizes>: message = "Mission Failed"
CrimeAlertEndedMessage<localizes>: message = "Mission Ended"
# Runs when the device is started in a running game
OnBegin<override>()<suspends>:void=
InitGuards()
InitCollectibles()
crimeTimer.SuccessEvent.Subscribe(OnTimerCompleted)
spawn:
StartCrimeAlertRound()
InitNPCBattleSimulation()
# Init all guard spawners to listen for when guards are eliminated
InitGuards() : void=
set NGuardsRemaining = MaxGuards
crimeSpot1.EliminatedEvent.Subscribe(OnGuardEliminated)
crimeSpot2.EliminatedEvent.Subscribe(OnGuardEliminated)
crimeSpot3.EliminatedEvent.Subscribe(OnGuardEliminated)
crimeSpot4.EliminatedEvent.Subscribe(OnGuardEliminated)
crimeSpot5.EliminatedEvent.Subscribe(OnGuardEliminated)
crimeSpot6.EliminatedEvent.Subscribe(OnGuardEliminated)
crimeSpotBank.EliminatedEvent.Subscribe(OnBankGuardEliminated)
InitCollectibles() : void=
ctbl1.CollectedEvent.Subscribe(OnCollected)
ctbl2.CollectedEvent.Subscribe(OnCollected)
ctbl3.CollectedEvent.Subscribe(OnCollected)
ctbl4.CollectedEvent.Subscribe(OnCollected)
ctbl5.CollectedEvent.Subscribe(OnCollected)
ctbl6.CollectedEvent.Subscribe(OnCollected)
ctbl7.CollectedEvent.Subscribe(OnCollected)
OnCollected(Agent : agent) : void=
goldGranter.GrantItem(Agent)
goldGranter.GrantItem(Agent)
# Tracks when all guards have been eliminated
OnGuardEliminated(Result : device_ai_interaction_result) : void=
set NGuardsRemaining -= 1
if(Agent := Result.Source?):
if(NGuardsRemaining > 0):
goldGranterForGuardElim.GrantItem(Agent)
if(NGuardsRemaining = 0):
crimeTimer.Complete()
if(Agent := Result.Source?):
RewardPlayer(Agent)
OnBankGuardEliminated(Result : device_ai_interaction_result) : void=
set NGuardsRemaining -= 1
if(Agent := Result.Source?):
if(NGuardsRemaining > 0):
goldGranterForGuardElim.GrantItem(Agent)
if(NGuardsRemaining = 0):
if(Agent := Result.Source?):
goldGranter.GrantItem(Agent)
xpGranter.Award(Agent)
# Reward players with xp, gold, & appropriate item
RewardPlayer(Agent : agent) : void=
if(RandomCrimeIndex < 3):
granter1.GrantItem(Agent)
else if(RandomCrimeIndex < 5):
granter2.GrantItem(Agent)
else if(RandomCrimeIndex < 7):
granter3.GrantItem(Agent)
else:
granter2.GrantItem(Agent)
goldGranter.GrantItem(Agent)
xpGranter.Award(Agent)
# Init timer to reset crime alert round when completed
OnTimerCompleted(Agent : ?agent) : void=
DisplayCrimeEndedMessage()
ResetCrimeAlertRound()
# Notifies player whether mission was completed or failed
DisplayCrimeEndedMessage() : void=
if(IsBankCrime = true):
messageDevice.SetText(CrimeAlertSuccessMessage)
else if(NGuardsRemaining = 0):
messageDevice.SetText(CrimeAlertSuccessMessage)
else:
messageDevice.SetText(CrimeAlertFailedMessage)
messageDevice.SetDisplayTime(CrimeEndedMessageDuration)
messageDevice.Show()
# Converts minutes to seconds
MinutesToSeconds(Minutes : float) : float=
return 60 * Minutes
# Delays crime alert minigame for a number of minutes
StandBy()<suspends> : void=
Sleep(MinutesToSeconds(StandByMinutes))
# Each crime alert minigame starts after a delay
StartCrimeAlertRound()<suspends> : void=
StandBy()
BankCrimeChanceIndex : int = GetRandomInt(1, 4)
if(BankCrimeChanceIndex = 1):
set IsBankCrime = true
StartBankCrimeAlert()
else:
set IsBankCrime = false
StartCrimeAlert()
SpawnCollectibles() : void=
RespawnCollectibles()
ShowThreeRandomCollectibles()
RespawnCollectibles() : void=
ctbl1.RespawnForAll()
ctbl2.RespawnForAll()
ctbl3.RespawnForAll()
ctbl4.RespawnForAll()
ctbl5.RespawnForAll()
ctbl6.RespawnForAll()
ctbl7.RespawnForAll()
ShowThreeRandomCollectibles() : void=
Collectibles : []collectible_object_device = array{ctbl1, ctbl2, ctbl3, ctbl4, ctbl5, ctbl6, ctbl7}
RandomLocations : []collectible_object_device = Shuffle(Collectibles)
if(RndmCtbl := RandomLocations[1]):
RndmCtbl.Show()
if(RndmCtbl := RandomLocations[2]):
RndmCtbl.Show()
if(RndmCtbl := RandomLocations[3]):
RndmCtbl.Show()
StartBankCrimeAlert() : void=
DisplayBankCrimeAlertMessage()
SpawnCollectibles()
crimeSpotBank.Enable()
crimeTimer.Start()
# Crime event of some bots starts at random crime spot
StartCrimeAlert() : void=
set RandomCrimeIndex = GetRandomInt(1, NCrimeSpots)
DisplayCrimeAlertMessage()
SpawnGuards()
crimeTimer.Start()
DisplayBankCrimeAlertMessage() : void=
messageDevice.SetText(CrimeAlertType4Message)
messageDevice.SetDisplayTime(CrimeAlertMessageDuration)
messageDevice.Show()
# Notifies player of crime alert minigame & type of crime
DisplayCrimeAlertMessage() : void=
if(RandomCrimeIndex < 3):
messageDevice.SetText(CrimeAlertType1Message)
else if(RandomCrimeIndex < 5):
messageDevice.SetText(CrimeAlertType2Message)
else if(RandomCrimeIndex < 7):
messageDevice.SetText(CrimeAlertType3Message)
else:
messageDevice.SetText(CrimeAlertType2Message)
messageDevice.SetDisplayTime(CrimeAlertMessageDuration)
messageDevice.Show()
# Spawns guards at one of the crime spots for players to defeat
SpawnGuards() : void=
if(RandomCrimeIndex = 1):
crimeSpot1.Enable()
else if(RandomCrimeIndex = 2):
crimeSpot2.Enable()
else if(RandomCrimeIndex = 3):
crimeSpot3.Enable()
else if(RandomCrimeIndex = 4):
crimeSpot4.Enable()
else if(RandomCrimeIndex = 5):
crimeSpot5.Enable()
else if(RandomCrimeIndex = 6):
crimeSpot6.Enable()
# Resets all devices and starts over crime alert round
ResetCrimeAlertRound() : void=
crimeTimer.Reset()
ResetGuards()
spawn:
StartCrimeAlertRound()
ResetCollectibles() : void=
ctbl1.Hide()
ctbl2.Hide()
ctbl3.Hide()
ctbl4.Hide()
ctbl5.Hide()
ctbl6.Hide()
ctbl7.Hide()
# Despawns guards & resets the appropriate guard spawner
ResetGuards() : void=
set NGuardsRemaining = MaxGuards
if(IsBankCrime = true):
crimeSpotBank.Disable()
crimeSpotBank.Reset()
ResetCollectibles()
else if(RandomCrimeIndex = 1):
crimeSpot1.Disable()
crimeSpot1.Reset()
else if(RandomCrimeIndex = 2):
crimeSpot2.Disable()
crimeSpot2.Reset()
else if(RandomCrimeIndex = 3):
crimeSpot3.Disable()
crimeSpot3.Reset()
else if(RandomCrimeIndex = 4):
crimeSpot4.Disable()
crimeSpot4.Reset()
else if(RandomCrimeIndex = 5):
crimeSpot5.Disable()
crimeSpot5.Reset()
else if(RandomCrimeIndex = 6):
crimeSpot6.Disable()
crimeSpot6.Reset()
# NPC Battle Simulation Script
# guard spawners
@editable
battleNPCs1 : guard_spawner_device = guard_spawner_device{}
@editable
battleNPCs2 : guard_spawner_device = guard_spawner_device{}
# start battle button
@editable
startBattleButton : button_device = button_device{}
# npcs remaining
var Team1NPCsRemaining : int = -1
var Team2NPCsRemaining : int = -1
# max npcs
MaxNPCs : int = 50
# simulation messages
battleStartedMessage<localizes>: message = "NPC Battle Simulation has started"
npcTeam1WinsMessage<localizes>: message = "Team 1 NPCs have won the battle"
npcTeam2WinsMessage<localizes>: message = "Team 2 NPCs have won the battle"
InitNPCBattleSimulation() : void=
InitBattleNPCs()
startBattleButton.InteractedWithEvent.Subscribe(startBattleButtonPressed)
InitBattleNPCs() : void=
set Team1NPCsRemaining = MaxNPCs
set Team2NPCsRemaining = MaxNPCs
battleNPCs1.EliminatedEvent.Subscribe(OnTeam1NPCEliminated)
battleNPCs2.EliminatedEvent.Subscribe(OnTeam2NPCEliminated)
startBattleButtonPressed(Agent : agent) : void=
DisplayBattleStartedMessage()
startBattleButton.Disable()
spawnBattleNPCs()
DisplayBattleStartedMessage() : void=
messageDevice.SetText(battleStartedMessage)
messageDevice.SetDisplayTime(CrimeAlertMessageDuration)
messageDevice.Show()
spawnBattleNPCs() : void=
battleNPCs1.Enable()
battleNPCs2.Enable()
OnTeam1NPCEliminated(Result : device_ai_interaction_result) : void=
set Team1NPCsRemaining -= 1
if(Agent := Result.Source?):
goldGranterForGuardElim.GrantItem(Agent)
if(Team1NPCsRemaining = 0):
EndSimulation()
OnTeam2NPCEliminated(Result : device_ai_interaction_result) : void=
set Team2NPCsRemaining -= 1
if(Agent := Result.Source?):
goldGranterForGuardElim.GrantItem(Agent)
if(Team2NPCsRemaining = 0):
EndSimulation()
EndSimulation() : void=
DisplaySimulationEndedMessage()
set Team1NPCsRemaining = MaxNPCs
set Team2NPCsRemaining = MaxNPCs
battleNPCs1.Disable()
battleNPCs2.Disable()
battleNPCs1.Reset()
battleNPCs2.Reset()
startBattleButton.Enable()
DisplaySimulationEndedMessage() : void=
if(Team1NPCsRemaining > 0):
messageDevice.SetText(npcTeam1WinsMessage)
else:
messageDevice.SetText(npcTeam2WinsMessage)
messageDevice.SetDisplayTime(CrimeEndedMessageDuration)
messageDevice.Show()