Class: SGK::Gacha::PitySystem
- Inherits:
-
Object
- Object
- SGK::Gacha::PitySystem
- Defined in:
- lib/sgk/gacha/pity_system.rb
Overview
使用例:
engine = SGK::Gacha::Engine.new(GachaCard.all)
pity = SGK::Gacha::PitySystem.new(engine, guarantee_limit: 100, guaranteed_rarity: :ultra_rare)
result = pity.draw(current_pity_count: user_current_pity)
Instance Attribute Summary collapse
-
#engine ⇒ Object
readonly
Returns the value of attribute engine.
-
#guarantee_limit ⇒ Object
readonly
Returns the value of attribute guarantee_limit.
-
#guaranteed_rarity ⇒ Object
readonly
Returns the value of attribute guaranteed_rarity.
Instance Method Summary collapse
-
#draw(current_pity_count: 0) ⇒ Object
カード抽選.
-
#draw_multiple(count, current_pity_count: 0) ⇒ Array<Object>
複数のカードを抽選する.
-
#initialize(engine, guarantee_limit: 100, guaranteed_rarity: :ultra_rare) ⇒ PitySystem
constructor
初期化.
-
#next_guarantee_info(current_pity_count: 0) ⇒ Hash
次の保証までの残り回数と保証回数を取得する.
Constructor Details
#initialize(engine, guarantee_limit: 100, guaranteed_rarity: :ultra_rare) ⇒ PitySystem
初期化
21 22 23 24 25 26 27 28 |
# File 'lib/sgk/gacha/pity_system.rb', line 21 def initialize(engine, guarantee_limit: 100, guaranteed_rarity: :ultra_rare) raise ArgumentError, "Engine must be a SGK::Gacha::Engine instance" unless engine.is_a?(Engine) raise ArgumentError, "Guarantee limit must be positive" unless guarantee_limit.positive? @engine = engine @guarantee_limit = guarantee_limit @guaranteed_rarity = guaranteed_rarity.to_sym end |
Instance Attribute Details
#engine ⇒ Object (readonly)
Returns the value of attribute engine.
13 14 15 |
# File 'lib/sgk/gacha/pity_system.rb', line 13 def engine @engine end |
#guarantee_limit ⇒ Object (readonly)
Returns the value of attribute guarantee_limit.
13 14 15 |
# File 'lib/sgk/gacha/pity_system.rb', line 13 def guarantee_limit @guarantee_limit end |
#guaranteed_rarity ⇒ Object (readonly)
Returns the value of attribute guaranteed_rarity.
13 14 15 |
# File 'lib/sgk/gacha/pity_system.rb', line 13 def guaranteed_rarity @guaranteed_rarity end |
Instance Method Details
#draw(current_pity_count: 0) ⇒ Object
カード抽選
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/sgk/gacha/pity_system.rb', line 35 def draw(current_pity_count: 0) raise ArgumentError, "Pity count must be non-negative" unless current_pity_count >= 0 # 保証カードを返す if current_pity_count >= @guarantee_limit return draw_guaranteed_card end # それ以外の場合は通常の抽選を実行 @engine.draw end |
#draw_multiple(count, current_pity_count: 0) ⇒ Array<Object>
複数のカードを抽選する
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/sgk/gacha/pity_system.rb', line 53 def draw_multiple(count, current_pity_count: 0) raise ArgumentError, "Draw count must be positive" unless count.positive? raise ArgumentError, "Pity count must be non-negative" unless current_pity_count >= 0 results = [] current_count = current_pity_count count.times do card = draw(current_pity_count: current_count) results << card # 保証カードを引いた場合は抽選回数をリセット、それ以外はカウントを増やしていく if is_guaranteed_card?(card) current_count = 0 else current_count += 1 end end results end |
#next_guarantee_info(current_pity_count: 0) ⇒ Hash
次の保証までの残り回数と保証回数を取得する
82 83 84 85 86 87 88 89 90 |
# File 'lib/sgk/gacha/pity_system.rb', line 82 def next_guarantee_info(current_pity_count: 0) raise ArgumentError, "Pity count must be non-negative" unless current_pity_count >= 0 { current_pity_count: current_pity_count, remaining: [@guarantee_limit - current_pity_count, 0].max, guaranteed_at: @guarantee_limit } end |