Skip to content

Instantly share code, notes, and snippets.

@sleepingkingstudios
Created June 13, 2011 22:55
Show Gist options
  • Save sleepingkingstudios/1023943 to your computer and use it in GitHub Desktop.
Save sleepingkingstudios/1023943 to your computer and use it in GitHub Desktop.
module AttributeFiltering
# [ :flying, :not => :psychic]
def is(arg)
return true if arg.class == TrueClass
return false if arg.class == FalseClass || arg.class == NilClass
if arg.class == Array
put "It's an array! #{arg.inspect}}"
return self.and arg
elsif arg.class == Hash
puts "It's a hash! #{arg.inspect}"
arg.each do |key, value|
if key.class == Symbol
case key
when :not
return false unless self.not value
when :and
return false unless self.and value
when :or
return false unless self.or value
else
return false unless self.is value
end # case
end # if
end # each
return true
end # if-elsif
puts "It's a literal! #{arg.class} #{arg}"
return @attributes.include? arg
end # method is
def not(arg)
return !(self.is arg)
end # method not
def and(*args)
[args].flatten.each do |arg|
return false unless self.is arg
end # each
return true
end # method and
def or(*args)
[args].flatten.each do |arg|
return true if self.is arg
end # each
return false
end # method or
protected :not, :and, :or
end # module AttributeFiltering
class AttributeObject
include AttributeFiltering
def initialize(*params)
@attributes = params
end # method initialize
def [](key)
return @attributes[key]
end # method []
def []=(key, value)
@attributes[key] = value
end # method []=
def inspect
return @attributes.inspect
end # method inspect
attr_reader :attributes
end # class AttributeObject
attr_obj = AttributeObject.new :alpha, :bravo, :foxtrot
puts attr_obj.inspect
# test Identity
puts attr_obj.is :alpha
puts !(attr_obj.is :charlie)
# test Negation
puts attr_obj.is [:alpha, :not => :charlie]
ability "Ember", :type => :spell do
desc "The ember spell strikes one target for fire damage, and on a critical hit the
opponent catches fire."
attributes :magic, :projectile, :fire
targets :one_enemy
effects do
target.deal 5, [:fire, :magic] unless target.is :magic_immune
if crit? then target.give :burn, :for => 10
end
end
ability "Frost Shatter" :type => :spell do
desc "The frostshatter spell targets a creature with the frozen condition, removing
the condition but inflicting cold and slashing damage."
attributes :magic, :ice
targets :one_enemy, :where => {|t| t.is :frozen }
effects do
target.deal 10, [:magic, :cold, :slashing]
target.remove :frozen
if crit?
target.location.all_within(4).deal 10, [:magic, :cold, :slashing]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment