Class: Sorare::Rewards::CardPicker

Inherits:
FlatPicker show all
Defined in:
lib/sorare/rewards/card_picker.rb

Overview

CardPicker allows to randomly pick card rewards for a league

Instance Attribute Summary collapse

Attributes inherited from FlatPicker

#counter, #elements

Instance Method Summary collapse

Methods inherited from FlatPicker

#add, #pick!, #picked_count

Constructor Details

#initialize(league, rarity, quality, rarity_limit: true, cooldown_limit: true) ⇒ CardPicker

Returns a new instance of CardPicker.



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/sorare/rewards/card_picker.rb', line 11

def initialize(league, rarity, quality, rarity_limit: true, cooldown_limit: true)
  super(league.public_seed, league.salt)
  @league = league
  @rarity = rarity
  @quality = quality
  @limits = %i[overall].tap do |l|
    l << :cooldowned if cooldown_limit
    l << :limited if rarity_limit
  end

  load_picker
end

Instance Attribute Details

#leagueObject (readonly)

Returns the value of attribute league.



9
10
11
# File 'lib/sorare/rewards/card_picker.rb', line 9

def league
  @league
end

#limitsObject (readonly)

Returns the value of attribute limits.



9
10
11
# File 'lib/sorare/rewards/card_picker.rb', line 9

def limits
  @limits
end

#qualityObject (readonly)

Returns the value of attribute quality.



9
10
11
# File 'lib/sorare/rewards/card_picker.rb', line 9

def quality
  @quality
end

#rarityObject (readonly)

Returns the value of attribute rarity.



9
10
11
# File 'lib/sorare/rewards/card_picker.rb', line 9

def rarity
  @rarity
end

Instance Method Details

#pickObject



24
25
26
27
28
29
# File 'lib/sorare/rewards/card_picker.rb', line 24

def pick
  player = super
  return player if valid_pick?(player)

  pick
end

#valid_pick?(player) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
# File 'lib/sorare/rewards/card_picker.rb', line 31

def valid_pick?(player)
  current_player_limit = limits.map { |l| supply_for(player).send(l) }.min
  picked_count(player) <= current_player_limit
end