Advertisement
Guest User

raidssession

a guest
Nov 21st, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. package nl.bartpelle.veteres.content.minigames.raids
  2.  
  3. import nl.bartpelle.veteres.model.AttributeKey
  4. import nl.bartpelle.veteres.model.World
  5. import nl.bartpelle.veteres.model.entity.Player
  6. import nl.bartpelle.veteres.util.Misc
  7.  
  8. /**
  9. * Created by Pepsiplaua on 10/19/2019.
  10. */
  11. class RaidsSession(var player: Player, var world: World) {
  12.  
  13. /**
  14. * The flag telling the active state of the session.
  15. */
  16. var active = false
  17.  
  18.  
  19. /**
  20. * The best recorded run time the player has achieved in the inferno.
  21. */
  22. var bestRunTime: Long = 0
  23.  
  24. /**
  25. * Our starting time, in milliseconds.
  26. */
  27. var startingTime: Long = 0
  28.  
  29. /**
  30. * Starts the inferno session at the desired wave offset.
  31. */
  32. fun start() {
  33.  
  34. //officially "starts" the session.
  35. this.active = true
  36.  
  37. //Grab the player's best run time within the map or return zero.
  38. this.bestRunTime = player.attribOr(AttributeKey.RAIDS_RUNTIME, 0)
  39.  
  40. //Stash this session instance into the player's map
  41. player.putattrib(AttributeKey.RAIDS_SESSION, this)
  42.  
  43. startingTime = System.currentTimeMillis()
  44.  
  45. }
  46.  
  47.  
  48. /**
  49. * The actions we should handle upon ending raids.
  50. */
  51. fun end() {
  52.  
  53. //switch the session to false to stop our ticking.
  54. active = false
  55.  
  56. //Finish up the session by stopping our stopwatch and formatting.
  57. val time: Long = (System.currentTimeMillis() - startingTime)
  58. val runText = Misc.formatLongAsHMS(time)
  59. var bestText = "N/A"
  60.  
  61. //Call our best text, if available.
  62. if (player.attribOr<Long>(AttributeKey.RAIDS_RUNTIME, 0L) != 0L) {
  63. bestText = Misc.formatLongAsHMS(bestRunTime)
  64. }
  65.  
  66. player.message("<col=FF0000>You completed Chambers of Xeric in $runText! Best: $bestText")
  67.  
  68. //Reassign best run time if it meets the condition.
  69. if (time < bestRunTime || bestRunTime == 0L) {
  70. bestRunTime = time
  71. player.putattrib(AttributeKey.RAIDS_RUNTIME, bestRunTime)
  72.  
  73. //Add the entry to the leaderboard repository for display purposes.
  74. //InfernoLeaderboard.save(player)
  75. player.message("<col=FF0000>New personal best!")
  76. }
  77.  
  78. }
  79.  
  80. fun player(): Player {
  81. return player
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement