lib/gamefic/action.rb in gamefic-1.0.0 vs lib/gamefic/action.rb in gamefic-1.1.0

- old
+ new

@@ -1,36 +1,37 @@ module Gamefic + # Exception raised when the Action's proc arity is not compatible with the + # number of queries + class ActionArgumentError < ArgumentError + end + # Actions manage the execution of commands that Characters can perform. # class Action attr_reader :order_key, :queries attr_writer :meta @@order_key_seed = 0 - def initialize(plot, verb, *queries, &proc) + def initialize(verb, *queries, &proc) if !verb.kind_of?(Symbol) verb = verb.to_s verb = nil if verb == '' end - @plot = plot @order_key = @@order_key_seed @@order_key_seed += 1 @proc = proc if (verb.kind_of?(Symbol) == false and !verb.nil?) - raise "Action verbs must be symbols" + raise "Action verbs must be symbols #{verb}" end if !@proc.nil? - if (queries.length + 1 != @proc.arity) and (queries.length == 0 and @proc.arity != -1) - raise "Number of queries is not compatible with proc arguments" + if (queries.length + 1 != @proc.arity) and (@proc.arity > 0) + raise ActionArgumentError.new("Number of queries is not compatible with proc arguments") end end @verb = verb @queries = queries - if !plot.nil? - plot.send :add_action, self - end end # Get the specificity of the Action. # Specificity indicates how narrowly the Action's queries filter matches. # Actions with higher specificity are given higher priority when searching @@ -42,17 +43,15 @@ def specificity spec = 0 if verb.nil? spec = -100 end - magnitude = 1 @queries.each { |q| if q.kind_of?(Query::Base) - spec += (q.specificity * magnitude) + spec += q.specificity else - spec += magnitude + spec += 1 end - #magnitude = magnitude * 10 } return spec end # Get the verb associated with this Action.