 moment = require 'moment'
 
 respawnTimeouts = {}
-healTimeouts = {}
+healIntervals = {}
 
 # A participant in the hammersportening.
 #

    if @storage.nextRespawn? and ! respawnTimeouts[@id()]
      msDelay = moment(@storage.nextRespawn).diff(moment())
      fn = => @respawn()
      respawnTimeouts[@id] = setTimeout fn, msDelay

    # Reset the healing timeout if necessary.
    if @hp() > 0 and @hp() < @maxHP() and ! @storage.inCombat and ! healTimeouts[@id()]
      @healOverTime()

  id: -> @user.id


    @storage.nextRespawn = moment().add('ms', @reviveTime()).valueOf()
    respawnTimeouts[@id()] = setTimeout fn, @reviveTime()

  # Internal: Invoked every second for each known Challenger. Heal at a fixed rate if applicable.
  #
  healOverTime: ->
    return unless @isAlive()
    return if @isInCombat()
    return if @hp() >= @maxHP()

    @storage.hp = Math.min(@maxHP(), @hp() + @healingRate())

  # Public: Mark this Challenger as being in an active Match.
  #
  startCombat: ->
    @storage.inCombat = true

  # Public: The Match has ended. Resume healing or schedule a respawn.
  #
  stopCombat: ->
    @storage.inCombat = false
    @kill() if @hp() <= 0

  displayName: -> "@#{@user.name}"

