Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package nl.bartpelle.veteres.content.minigames.raids
- import nl.bartpelle.veteres.model.AttributeKey
- import nl.bartpelle.veteres.model.World
- import nl.bartpelle.veteres.model.entity.Player
- import nl.bartpelle.veteres.util.Misc
- /**
- * Created by Pepsiplaua on 10/19/2019.
- */
- class RaidsSession(var player: Player, var world: World) {
- /**
- * The flag telling the active state of the session.
- */
- var active = false
- /**
- * The best recorded run time the player has achieved in the inferno.
- */
- var bestRunTime: Long = 0
- /**
- * Our starting time, in milliseconds.
- */
- var startingTime: Long = 0
- /**
- * Starts the inferno session at the desired wave offset.
- */
- fun start() {
- //officially "starts" the session.
- this.active = true
- //Grab the player's best run time within the map or return zero.
- this.bestRunTime = player.attribOr(AttributeKey.RAIDS_RUNTIME, 0)
- //Stash this session instance into the player's map
- player.putattrib(AttributeKey.RAIDS_SESSION, this)
- startingTime = System.currentTimeMillis()
- }
- /**
- * The actions we should handle upon ending raids.
- */
- fun end() {
- //switch the session to false to stop our ticking.
- active = false
- //Finish up the session by stopping our stopwatch and formatting.
- val time: Long = (System.currentTimeMillis() - startingTime)
- val runText = Misc.formatLongAsHMS(time)
- var bestText = "N/A"
- //Call our best text, if available.
- if (player.attribOr<Long>(AttributeKey.RAIDS_RUNTIME, 0L) != 0L) {
- bestText = Misc.formatLongAsHMS(bestRunTime)
- }
- player.message("<col=FF0000>You completed Chambers of Xeric in $runText! Best: $bestText")
- //Reassign best run time if it meets the condition.
- if (time < bestRunTime || bestRunTime == 0L) {
- bestRunTime = time
- player.putattrib(AttributeKey.RAIDS_RUNTIME, bestRunTime)
- //Add the entry to the leaderboard repository for display purposes.
- //InfernoLeaderboard.save(player)
- player.message("<col=FF0000>New personal best!")
- }
- }
- fun player(): Player {
- return player
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement