[Search queries for spells clinton@unknownlamer.org**20080430211222] hunk ./src/queries.lisp 81 + +;;; Interface for spell class + +(defgeneric find-spell-by-name (spell-name)) +(defgeneric find-spells-by-alignment (alignment)) +(defgeneric find-spells-by-school (school) + (:documentation "Find spells within a given # or + #. If given a SCHOOL all spells from all subschools + are returned.")) +(defgeneric find-spells-by-caster-class (class level) + (:documentation "Find spells usable by CLASS. If LEVEL is nil then + find all spells for caster CLASS. LEVEL is the spell level not the + caster level.")) +(defgeneric find-spells-by-spell-level (level) + (:documentation "Find spells at LEVEL. If LEVEL is an integer fetch + all spells for all classes of spell level LEVEL, if LEVEL is a + # fetch all spells for that level/class.")) + +(defmethod find-spell-by-name ((spell-name string)) + (get-instance-by-value 'spell 'name spell-name)) + +(defmethod find-spells-by-alignment ((alignment (eql nil))) + (values nil nil)) + +(defmethod find-spells-by-alignment ((alignment symbol)) + (get-instances-by-value 'spell 'alignment alignment)) + +(defmethod find-spells-by-school ((school spell-school)) + (if-bind spells + (append (get-instances-by-value 'spell 'school school) + (apply #'append + (mapcar #'find-spells-by-school + (spell-school-subschools school)))) + (values spells t) + (values nil nil))) + +(defmethod find-spells-by-school ((school spell-subschool)) + (if-bind spells (get-instances-by-value 'spell 'school school) + (values spells t) + (values nil nil))) + +(defmethod find-spells-by-caster-class ((class symbol) level) + (find-spells-by-caster-class (find-player-class class) level)) + +(defmethod find-spells-by-caster-class ((class player-class) (level integer)) + (find-spells-by-spell-level (find-spell-level class level))) + +(defmethod find-spells-by-caster-class ((class player-class) (level (eql nil))) + (apply #'append + (mapcar #'find-spells-by-spell-level + (get-instances-by-value 'spell-level + 'spell-level->player-class + class)))) + +(defmethod find-spells-by-caster-class ((class (eql nil)) level) + (values nil nil)) + +(defmethod find-spells-by-spell-level ((level spell-level)) + (mapcar #'spell + (get-instances-by-value 'spell-level<->spell 'level level))) + +(defmethod find-spells-by-spell-level ((level integer)) + (apply #'append + (mapcar #'find-spells-by-spell-level + (get-instances-by-value 'spell-level 'level level)))) + + +;;; Compound classes