     for id in @orderIds()
       continue  if id in skipIds
 
-      action = @getAction(id)
-      player = @getPlayer(id)
-      team = @getTeam(id)
-
-      switch action.type
+      switch @getAction(id).type
         when 'switch' then @performSwitch(id)
         when 'move'   then @performMove(id)
 

    team = @getTeam(player.id)
    index = team.indexOf(toPokemon)

    # TODO: Fail harder if pokemon not in team
    if index == -1
      console.log "#{player.username} made an invalid switch to #{toPokemon}."
      return

    @makeSwitch(player, index)

  hasWeather: (weatherName) =>

  # toPosition - the index of the pokemon to switch to
  #
  makeSwitch: (player, toPosition) =>
    # TODO: Fail harder if pokemon not in team
    # TODO: Add more cases of invalid indices (such as fainted poke or activePokemon)
    pokemon = @getTeam(player.id).at(toPosition)
    unless pokemon
      console.log "#{player.username} made an invalid switch to position #{toPosition}."
      return

    # Record the switch
    @playerActions[player.id] =
      type: 'switch'
      to: toPosition

    delete @requests[player.id]

    # Continue the turn if each player has moved.
