module AR::Game::DefenseBehavior 
  
  #add attr_accessor properties here... 
  #if you don't need them serialized on save

  #...initialize them here
  def self.init ar_object 
    #add attr_serializeable properties here... 
    #if you do need them serialized on save
    #ar_object.attr_serializeable :prop1, :prop2, &block
    ar_object.class.attr_serializeable :defense_techniques do |techs, kase|
      case kase
      when :load
        techs.map.map{|t| Object.const_get(t.to_s).new}
      when :unload
        techs.map(&:class)
      end
    end
    ar_object.defense_techniques=[]

  end

  def self.extended ar_object
    self.init ar_object
    ar_object.resolutions <<  conditional_release_defense_choice_on_action_began
    #add to object's event subscriptions and resolutions here...

  end 

  def self.conditional_release_defense_choice_on_action_began
    AR::Events::Resolution.new event_class: AR::Events::ActionBeganEvent, as: "primary_target" do |e|
      a = e.action
      if a.class == AR::Game::AttackAction
        p = e.performer
        t = e.primary_target
        if t.action_points > 0  
          AR::Events::DefenseChoice.new defender: t, attacker: p 
        end
      end
    end
  end

end
