Guest User

Untitled

a guest
Oct 15th, 2024
540
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.97 KB | None | 1 0
  1. using { /Fortnite.com/Devices }
  2. using { /Verse.org/Simulation }
  3. using { /UnrealEngine.com/Temporary/Diagnostics }
  4.  
  5. ################################# SORTING ALGORITHM ###################################################
  6. MergeSort<public>(Array:[]t, Compare(L:t, R:t)<decides><transacts>:t where t:type)<transacts>:[]t=
  7. Length:int = Array.Length
  8. if:
  9. Length > 1
  10. Mid:int = Floor(Length / 2)
  11. Left:[]t = Array.Slice[0, Mid]
  12. Right:[]t = Array.Slice[Mid]
  13. then:
  14. LeftSorted:[]t = MergeSort(Left, Compare)
  15.  
  16. RightSorted:[]t = MergeSort(Right, Compare)
  17.  
  18.  
  19. Merge(LeftSorted, RightSorted, Compare)
  20. else:
  21.  
  22.  
  23. Array
  24.  
  25.  
  26. Merge(Left:[]t, Right:[]t, Compare(L:t, R:t)<decides><transacts>:t where t:type)<transacts>:[]t=
  27. var LeftIndex:int = 0
  28. var RightIndex:int = 0
  29. var MergedArray:[]t = array{}
  30.  
  31.  
  32. loop:
  33. if (LeftElement := Left[LeftIndex], RightElement := Right[RightIndex]):
  34. if (Compare[LeftElement, RightElement]):
  35. set MergedArray += array{LeftElement}
  36. set LeftIndex += 1
  37. else:
  38. set MergedArray += array{RightElement}
  39. set RightIndex += 1
  40. else:
  41. if (LeftIndex >= Left.Length):
  42. option{set MergedArray += Right.Slice[RightIndex]}
  43. else:
  44. option{set MergedArray += Left.Slice[LeftIndex]}
  45.  
  46. break
  47.  
  48.  
  49. MergedArray
  50.  
  51. ################################### VERSE DEVICE #############################################################################################
  52.  
  53. player_leaderboards_example := class(creative_device):
  54. @editable
  55. PlayerReferences:[]player_reference_device = array{}
  56.  
  57. @editable
  58. Leaderboards:[]billboard_device = array{}
  59.  
  60. @editable
  61. RaceManager:race_manager_device = race_manager_device{}
  62.  
  63. @editable
  64. PlacementRequiredForWin:int = 1
  65.  
  66. @editable
  67. PointsPerPlace:[]int = array{5, 3, 1}
  68.  
  69. var CurrentFinishOrder:int = 0
  70.  
  71. OnBegin<override>()<suspends>:void=
  72. Players := GetPlayspace().GetPlayers()
  73. InitializeAllPlayerStats(Players)
  74. UpdateStatsBillboards(Players, Leaderboards)
  75. UpdatePlayerReferences(Players, PlayerReferences)
  76.  
  77. for:
  78. Player:Players
  79. do:
  80. spawn{WaitForPlayerToFinishRace(Player)}
  81.  
  82.  
  83. WaitForPlayerToFinishRace(Player:agent)<suspends>:void=
  84. race:
  85.  
  86. loop:
  87. FinishingPlayer := RaceManager.RaceCompletedEvent.Await()
  88. if:
  89. FinishingPlayer = Player
  90. then:
  91. RecordPlayerFinish(Player)
  92. break
  93.  
  94.  
  95. loop:
  96. LeavingPlayer := GetPlayspace().PlayerRemovedEvent().Await()
  97. if:
  98. LeavingPlayer = Player
  99. then:
  100. break
  101.  
  102. RecordPlayerFinish(Player:agent):void=
  103. PlayerFinishOrder:int = CurrentFinishOrder
  104. set CurrentFinishOrder += 1
  105.  
  106. if:
  107. PointsToAward := PointsPerPlace[PlayerFinishOrder]
  108. then:
  109. AddPoints(Player, PointsToAward)
  110.  
  111. if:
  112. PlayerFinishOrder < PlacementRequiredForWin
  113. then:
  114. AddWin(Player, 1)
  115.  
  116. ################################################# HANDLES THE PLAYER STATS AND DATA #################################################################
  117.  
  118.  
  119. GetPlayerStats<public>(Agent:agent)<decides><transacts>:player_stats_table=
  120. var PlayerStats:player_stats_table = player_stats_table{}
  121. if:
  122. Player := player[Agent]
  123. PlayerStatsTable := PlayerStatsMap[Player]
  124. set PlayerStats = MakePlayerStatsTable(PlayerStatsTable)
  125. PlayerStats
  126.  
  127.  
  128. InitializeAllPlayerStats<public>(Players:[]player):void =
  129. for (Player : Players):
  130. InitializePlayerStat(Player)
  131.  
  132.  
  133. InitializePlayerStat<public>(Player:player):void=
  134. if:
  135. not PlayerStatsMap[Player]
  136. set PlayerStatsMap[Player] = player_stats_table{}
  137. else:
  138. Print("Unable to initialize player stats")
  139.  
  140. AddPoints<public>(Agent:agent, NewPoints:int):void=
  141. if:
  142. Player := player[Agent]
  143. PlayerStatsTable := PlayerStatsMap[Player]
  144. CurrentPoints := PlayerStatsTable.Points
  145. set PlayerStatsMap[Player] = player_stats_table:
  146. MakePlayerStatsTable<constructor>(PlayerStatsTable)
  147. Points := CurrentPoints + NewPoints
  148. else:
  149. Print("Unable to record player points")
  150.  
  151. AddWin<public>(Agent:agent, NewWins:int):void=
  152. if:
  153. Player := player[Agent]
  154. PlayerStatsTable := PlayerStatsMap[Player]
  155. CurrentWins := PlayerStatsTable.Wins
  156. set PlayerStatsMap[Player] = player_stats_table:
  157. MakePlayerStatsTable<constructor>(PlayerStatsTable)
  158. Wins := CurrentWins + NewWins
  159. else:
  160. Print("Unable to record player Wins")
  161.  
  162.  
  163. ######################################## HANDLES UPDATES AND DATA DISPLAY ########################################################################################
  164.  
  165.  
  166. StatsMessage<localizes>(CurrentPlayer:message, Points:message, Wins:message):message=
  167. "{CurrentPlayer}:\n{Points}\n{Wins}"
  168. PlayerText<localizes>(CurrentPlayer:agent):message = "Player {CurrentPlayer}"
  169. PointsText<localizes>(Points:int):message = "Total Points {Points}"
  170. WinsText<localizes>(Wins:int):message = "{Wins} Total Wins"
  171.  
  172. UpdateStatsBillboard<public>(Player:agent, StatsBillboard:billboard_device):void=
  173. if:
  174. CurrentPlayerStats := GetPlayerStats[Player]
  175. then:
  176. PlayerStatsText := StatsMessage(
  177. PlayerText(Player),
  178. PointsText(CurrentPlayerStats.Points),
  179. WinsText(CurrentPlayerStats.Wins))
  180. StatsBillboard.SetText(PlayerStatsText)
  181.  
  182. UpdateStatsBillboards<public>(Players:[]agent, StatsBillboards:[]billboard_device):void=
  183. var PlayerAndStatsArray:[]player_and_stats =
  184. for:
  185. Agent:Players
  186. Player := player[Agent]
  187. PlayerStats := GetPlayerStats[Player]
  188. do:
  189. player_and_stats:
  190. Player := Player
  191. StatsTable := PlayerStats
  192.  
  193. SortedPlayersAndStats := MergeSort(PlayerAndStatsArray ,MorePointsComparison)
  194. for:
  195. PlayerIndex -> PlayerAndStats : SortedPlayersAndStats
  196. StatsBillboard := StatsBillboards[PlayerIndex]
  197. do:
  198. UpdateStatsBillboard(PlayerAndStats.Player, StatsBillboard)
  199.  
  200. UpdatePlayerReferences<public>(Players:[]player, PlayerReferences:[]player_reference_device):void=
  201. var PlayerAndStatsArray:[]player_and_stats =
  202. for:
  203. Agent:Players
  204. Player := player[Agent]
  205. PlayerStats := GetPlayerStats[Player]
  206. do:
  207. player_and_stats:
  208. Player := Player
  209. StatsTable := PlayerStats
  210.  
  211. SortedPlayersAndStats := MergeSort(PlayerAndStatsArray,MorePointsComparison)
  212.  
  213. for:
  214. PlayerIndex -> PlayerAndStats : SortedPlayersAndStats
  215. PlayerReference := PlayerReferences[PlayerIndex]
  216. do:
  217. PlayerReference.Register(PlayerAndStats.Player)
  218.  
  219.  
  220. ################################################### STATISTICS DATA TABLE ###################################################################
  221.  
  222. player_and_stats<public> := struct:
  223. Player<public>:player
  224. StatsTable<public>:player_stats_table
  225.  
  226. player_stats_table<public>:= class<final><persistable>:
  227.  
  228. Version<public>:int = 0
  229.  
  230. Points<public>:int = 0
  231.  
  232. Wins<public>:int = 0
  233.  
  234. MorePointsComparison<public>(Left:player_and_stats, Right:player_and_stats)<decides><transacts>:player_and_stats=
  235. Left.StatsTable.Points > Right.StatsTable.Points
  236. Left
  237.  
  238. LessPointsComparison<public>(Left:player_and_stats, Right:player_and_stats)<decides><transacts>:player_and_stats=
  239. Left.StatsTable.Points < Right.StatsTable.Points
  240. Left
  241.  
  242. MoreWinsComparison<public>(Left:player_and_stats, Right:player_and_stats)<decides><transacts>:player_and_stats=
  243. Left.StatsTable.Points > Right.StatsTable.Points
  244. Left
  245.  
  246. LessWinsComparison<public>(Left:player_and_stats, Right:player_and_stats)<decides><transacts>:player_and_stats=
  247. Left.StatsTable.Points < Right.StatsTable.Points
  248. Left
  249.  
  250. SlowerLapTimeComparison(Left:player_and_stats, Right:player_and_stats)<decides><transacts>:player_and_stats=
  251. Left.StatsTable.Points > Right.StatsTable.Points
  252. Left
  253.  
  254. FasterLapTimeComparison(Left:player_and_stats, Right:player_and_stats)<decides><transacts>:player_and_stats=
  255. Left.StatsTable.Points < Right.StatsTable.Points
  256. Left
  257.  
  258. MakePlayerStatsTable<constructor>(OldTable:player_stats_table)<transacts> := player_stats_table:
  259. Version := OldTable.Version
  260. Points := OldTable.Points
  261. Wins := OldTable.Wins
  262.  
  263. var PlayerStatsMap:weak_map(player, player_stats_table) = map{}
Advertisement
Add Comment
Please, Sign In to add comment