import Dispatcher from '../dispatcher'
import PlayerAbilityStore from './player_ability'

export default class PlayerStore extends Dispatcher {
  constructor(action, unitGroup) {
    super()
    this.action_   = action
    this.unitID_   = null
    this.abilityQ_ = null
    this.abilityW_ = null
    this.abilityE_ = null
    this.abilityR_ = null

    this.action_.register('player', this.onPlayer.bind(this))
    this.action_.register('unitLeave', this.onUnitLeave.bind(this))
  }
  unitID()   { return this.unitID_ }
  abilityQ() { return this.abilityQ_ }
  abilityW() { return this.abilityW_ }
  abilityE() { return this.abilityE_ }
  abilityR() { return this.abilityR_ }
  onPlayer(payload) {
    this.unitID_   = payload.UnitID
    this.abilityQ_ = new PlayerAbilityStore(this.action_, "Q", payload.Q)
    this.abilityW_ = new PlayerAbilityStore(this.action_, "W", payload.W)
    this.abilityE_ = new PlayerAbilityStore(this.action_, "E", payload.E)
    this.abilityR_ = new PlayerAbilityStore(this.action_, "R", payload.R)
    this.dispatch('change')
  }
  onUnitLeave(payload) {
    if (this.unitID_ === null || payload.UnitID !== this.unitID_) {
      return
    }
    this.unitID_   = null
    this.abilityQ_ = null
    this.abilityW_ = null
    this.abilityE_ = null
    this.abilityR_ = null
    this.dispatch('change')
  }
}

@@ -343,16 +343,76 @@
 = null%0A%0A
+    this.action_.register('stage', this.onStage.bind(this))%0A
     this
@@ -730,16 +730,199 @@
 ityR_ %7D%0A
+  onStage(payload) %7B%0A    this.unitID_   = null%0A    this.abilityQ_ = null%0A    this.abilityW_ = null%0A    this.abilityE_ = null%0A    this.abilityR_ = null%0A    this.dispatch('change')%0A  %7D%0A
   onPlay

Remove a player when a stage is changed