| 1 | #!/usr/bin/ruby |
|---|
| 2 | |
|---|
| 3 | require 'fm' |
|---|
| 4 | require 'fm/mixins' |
|---|
| 5 | require 'fm/exceptions' |
|---|
| 6 | require 'fm/composedobject' |
|---|
| 7 | require 'fm/perception' |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | # |
|---|
| 11 | # The FaerieMUD::AnimatedObject class, a derivative of FaerieMUD::ComposedObject. |
|---|
| 12 | # AnimatedObjects are objects which can be controlled by a Spirit, and have Perception. |
|---|
| 13 | # |
|---|
| 14 | # == Subversion ID |
|---|
| 15 | # |
|---|
| 16 | # $Id$ |
|---|
| 17 | # |
|---|
| 18 | # == Authors |
|---|
| 19 | # |
|---|
| 20 | # * Michael Granger <ged@FaerieMUD.org> |
|---|
| 21 | # |
|---|
| 22 | # :include: LICENSE |
|---|
| 23 | # |
|---|
| 24 | #--- |
|---|
| 25 | # |
|---|
| 26 | # Please see the file LICENSE for licensing details. |
|---|
| 27 | # |
|---|
| 28 | class FaerieMUD::AnimatedObject < FaerieMUD::ComposedObject |
|---|
| 29 | contributors :ged |
|---|
| 30 | |
|---|
| 31 | include FaerieMUD::AccessorFunctions |
|---|
| 32 | |
|---|
| 33 | # SVN Revision |
|---|
| 34 | SVNRev = %q$Rev$ |
|---|
| 35 | |
|---|
| 36 | # SVN Id |
|---|
| 37 | SVNId = %q$Id$ |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | ############################################################# |
|---|
| 42 | ### I N S T A N C E M E T H O D S |
|---|
| 43 | ############################################################# |
|---|
| 44 | |
|---|
| 45 | ### Create a new FaerieMUD::AnimatedObject. |
|---|
| 46 | def initialize( args={} ) |
|---|
| 47 | @affinities = {} |
|---|
| 48 | @description = nil |
|---|
| 49 | @name = nil |
|---|
| 50 | @controller = nil |
|---|
| 51 | @perception = FaerieMUD::Perception::new( self ) |
|---|
| 52 | |
|---|
| 53 | super |
|---|
| 54 | end |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | ### Copy initializer -- initialize a cloned or duped AnimatedObject with |
|---|
| 58 | ### cloned values from the +original+. |
|---|
| 59 | def initialize_copy( original ) |
|---|
| 60 | super |
|---|
| 61 | |
|---|
| 62 | @affinities = original.affinities.clone |
|---|
| 63 | @description = "%s (Cloned)" % original.description |
|---|
| 64 | @name = "Clone of %s" % original.name |
|---|
| 65 | @controller = nil |
|---|
| 66 | end |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | ###### |
|---|
| 70 | public |
|---|
| 71 | ###### |
|---|
| 72 | |
|---|
| 73 | # The Spirit objects for which this AnimatedObject has an affinity. The |
|---|
| 74 | # Presence necessary to animate the object for which a Spirit has an |
|---|
| 75 | # affinity is greatly reduced. |
|---|
| 76 | attr_accessor :affinities |
|---|
| 77 | |
|---|
| 78 | # A short (25 characters or so) description of the object. |
|---|
| 79 | attr_accessor :description |
|---|
| 80 | |
|---|
| 81 | # A one-word unique name for the object, used when identifying it for |
|---|
| 82 | # animation. |
|---|
| 83 | attr_accessor :name |
|---|
| 84 | |
|---|
| 85 | # The controlling FaerieMUD::Spirit object (might also be a |
|---|
| 86 | # Bifurcation). |
|---|
| 87 | attr_locked_accessor :controller |
|---|
| 88 | |
|---|
| 89 | |
|---|
| 90 | ### Provide a description of the given +events+ to the connected |
|---|
| 91 | ### controller/s. More-specific subclasses should probably override this |
|---|
| 92 | ### method to provide vetting, contextualization, distortion, and grouping |
|---|
| 93 | ### of incoming events. This implementation just writes a sentence per event |
|---|
| 94 | ### to the controlling Spirit. |
|---|
| 95 | def describe_event( event ) |
|---|
| 96 | @controller.output( event.as_sentence ) |
|---|
| 97 | end |
|---|
| 98 | |
|---|
| 99 | end # class FaerieMUD::AnimatedObject |
|---|