class Pool

Public Instance Methods

can_purchase?(card) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# File lib/ascension/pool.rb, line 46
def to_s
  "#{runes} (#{mechana_runes}) / #{power}"
end
use_rune_type(type, max, modify=true) click to toggle source
# 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