Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Run code for each @target.
- def each_target(current_hero, other_hero, target, position)
- current_field = current_hero.field
- other_field = other_hero.field
- case target
- # your hero and creatures
- when 'self:all'
- current_field.position.each { |slot| yield slot unless slot.empty? }
- yield current_hero
- # your creatures
- when 'self:creatures'
- current_field.position.each { |slot| yield slot unless slot.empty? }
- # one of your creatures
- when 'self:one'
- yield current_field.position[position] unless current_field.position[position].empty?
- # your hero
- when 'self:hero'
- yield current_hero
- # enemy hero and creatures
- when 'foe:all'
- other_field.position.each { |slot| yield slot unless slot.empty? }
- yield other_hero
- # enemy creatures
- when 'foe:creatures'
- other_field.position.each { |slot| yield slot unless slot.empty? }
- # one of enemy creatures
- when 'foe:one'
- yield other_field.position[position] unless other_field.position[position].empty?
- # enemy hero
- when 'foe:hero'
- yield other_hero
- end
- end
- # …
- card_abilities.each do |ability|
- case ability['name']
- # Damage to enemy hero and opposite creature equals
- # to opposite creature's attack
- when 'damage'
- # self method
- each_target(current_hero, other_hero, ability['target'], position) do |t|
- t.do_damage(ability['param'].to_i, :magic)
- end
- when 'heal'
- each_target(current_hero, other_hero, ability['target'], position) do |t|
- t.do_heal(ability['param'].to_i)
- end
- # …
Add Comment
Please, Sign In to add comment