Guest User

Untitled

a guest
Apr 25th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.54 KB | None | 0 0
  1. # Run code for each @target.
  2. def each_target(current_hero, other_hero, target, position)
  3.     current_field = current_hero.field
  4.     other_field = other_hero.field
  5.     case target
  6.         # your hero and creatures
  7.         when 'self:all'
  8.             current_field.position.each { |slot| yield slot unless slot.empty? }
  9.             yield current_hero
  10.  
  11.         # your creatures
  12.         when 'self:creatures'
  13.             current_field.position.each { |slot| yield slot unless slot.empty? }
  14.  
  15.         # one of your creatures
  16.         when 'self:one'
  17.             yield current_field.position[position] unless current_field.position[position].empty?
  18.  
  19.         # your hero
  20.         when 'self:hero'
  21.             yield current_hero
  22.  
  23.         # enemy hero and creatures
  24.         when 'foe:all'
  25.             other_field.position.each { |slot| yield slot unless slot.empty? }
  26.             yield other_hero
  27.  
  28.         # enemy creatures
  29.         when 'foe:creatures'
  30.             other_field.position.each { |slot| yield slot unless slot.empty? }
  31.  
  32.         # one of enemy creatures
  33.         when 'foe:one'
  34.             yield other_field.position[position] unless other_field.position[position].empty?
  35.  
  36.         # enemy hero
  37.         when 'foe:hero'
  38.             yield other_hero
  39.     end
  40. end
  41. # …
  42. card_abilities.each do |ability|
  43.     case ability['name']
  44.         # Damage to enemy hero and opposite creature equals
  45.         # to opposite creature's attack
  46.         when 'damage'
  47.             # self method
  48.             each_target(current_hero, other_hero, ability['target'], position) do |t|
  49.                 t.do_damage(ability['param'].to_i, :magic)
  50.             end
  51.  
  52.         when 'heal'
  53.             each_target(current_hero, other_hero, ability['target'], position) do |t|
  54.                 t.do_heal(ability['param'].to_i)
  55.             end
  56. # …
Add Comment
Please, Sign In to add comment