Class: Pool
Instance Method Summary collapse
- #can_purchase?(card) ⇒ Boolean
- #deplete_runes(card) ⇒ Object
- #to_s ⇒ Object
- #use_rune_type(type, max, modify = true) ⇒ Object
Instance Method Details
#can_purchase?(card) ⇒ Boolean
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ascension/pool.rb', line 19 def can_purchase?(card) remaining = card.rune_cost raise "bad rune cost #{card.name}" unless remaining if card.mechana? && card.construct? remaining = use_rune_type(:mechana_runes,remaining,false) end if card.construct? remaining = use_rune_type(:construct_runes,remaining,false) end if remaining > 0 remaining = use_rune_type(:runes,remaining,false) end remaining == 0 end |
#deplete_runes(card) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ascension/pool.rb', line 33 def deplete_runes(card) remaining = card.rune_cost if card.mechana? && card.construct? remaining = use_rune_type(:mechana_runes,remaining) end if card.construct? remaining = use_rune_type(:construct_runes,remaining) end if remaining > 0 remaining = use_rune_type(:runes,remaining) end raise "not enough runes" if remaining > 0 end |
#to_s ⇒ Object
46 47 48 |
# File 'lib/ascension/pool.rb', line 46 def to_s "#{runes} (#{mechana_runes}) / #{power}" end |
#use_rune_type(type, max, modify = true) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/ascension/pool.rb', line 8 def use_rune_type(type, max, modify=true) raise "bad max" unless max pool = send(type) if max >= pool send("#{type}=",0) if modify max - pool else send("#{type}=",pool - max) if modify 0 end end |