Module: Lich::Common::CreatureFacade
- Included in:
- DragonRealms::Creature, Gemstone::Creature
- Defined in:
- documented/common/creature/creature_facade.rb
Overview
The script-facing Creature module both games expose over their creature
registry, composed like CreatureBase (and lib/common/map): the shared
surface lives here, and each game's module Creature extends it, names its
registry class with a private instance_class, and adds or overrides
only what differs for that game.
The methods typed Object or Array below return instances of the
extending game's instance_class: Lich::Gemstone::CreatureInstance
or Lich::DragonRealms::CreatureInstance.
Instance Method Summary collapse
-
#[](id) ⇒ Object?
Lookup creature instance by id.
-
#all ⇒ Array
Every registered instance.
-
#cleanup_old(max_age_seconds = instance_class.cleanup_max_age) ⇒ Integer
Removes creatures unseen for longer than the given age (in seconds).
-
#clear ⇒ void
Clears every instance and the room roster.
-
#clear_room ⇒ void
Empties the current room roster.
-
#configure(**options) ⇒ void
Configures the registry.
-
#debug_on(level = :changes) ⇒ Boolean, Symbol
Toggles live echo of status, flag, and registration changes.
-
#in_room(*filters) ⇒ Array
Returns all tracked creatures currently in the room.
-
#register(name, id, noun = nil) ⇒ Object?
Registers a creature.
-
#stats ⇒ Hash
Registry statistics.
-
#targets(*filters) ⇒ Array
Returns attackable hostile creatures currently in the room, including once-hostile creatures now
sympathetic(Sympathy 1120).
Instance Method Details
#[](id) ⇒ Object?
Lookup creature instance by id.
44 45 46 |
# File 'documented/common/creature/creature_facade.rb', line 44 def [](id) instance_class[id] end |
#all ⇒ Array
Returns every registered instance.
123 124 125 |
# File 'documented/common/creature/creature_facade.rb', line 123 def all instance_class.all end |
#cleanup_old(max_age_seconds = instance_class.cleanup_max_age) ⇒ Integer
Removes creatures unseen for longer than the given age (in seconds).
Positional to match Lich::Common::CreatureBase cleanup_old; a keyword-only
signature would raise ArgumentError against the positional base method.
The registry also sweeps itself on a wall-clock throttle from
register; this is for scripts that want an immediate sweep.
118 119 120 |
# File 'documented/common/creature/creature_facade.rb', line 118 def cleanup_old(max_age_seconds = instance_class.cleanup_max_age) instance_class.cleanup_old(max_age_seconds) end |
#clear ⇒ void
This method returns an undefined value.
Clears every instance and the room roster.
104 105 106 |
# File 'documented/common/creature/creature_facade.rb', line 104 def clear instance_class.clear end |
#clear_room ⇒ void
This method returns an undefined value.
Empties the current room roster.
69 70 71 |
# File 'documented/common/creature/creature_facade.rb', line 69 def clear_room instance_class.clear_room end |
#configure(**options) ⇒ void
This method returns an undefined value.
Configures the registry.
87 88 89 |
# File 'documented/common/creature/creature_facade.rb', line 87 def configure(**) instance_class.configure(**) end |
#debug_on(level = :changes) ⇒ Boolean, Symbol
Toggles live echo of status, flag, and registration changes.
36 37 38 |
# File 'documented/common/creature/creature_facade.rb', line 36 def debug_on(level = :changes) $creature_debug = level end |
#in_room(*filters) ⇒ Array
Returns all tracked creatures currently in the room.
62 63 64 |
# File 'documented/common/creature/creature_facade.rb', line 62 def in_room(*filters) instance_class.in_room(*filters) end |
#register(name, id, noun = nil) ⇒ Object?
Registers a creature.
80 81 82 |
# File 'documented/common/creature/creature_facade.rb', line 80 def register(name, id, noun = nil) instance_class.register(name, id, noun) end |
#stats ⇒ Hash
Returns registry statistics.
92 93 94 95 96 97 98 99 |
# File 'documented/common/creature/creature_facade.rb', line 92 def stats { instances: instance_class.size, max_size: instance_class.max_size, auto_register: instance_class.auto_register?, cleanup_max_age: instance_class.cleanup_max_age } end |
#targets(*filters) ⇒ Array
Returns attackable hostile creatures currently in the room, including
once-hostile creatures now sympathetic (Sympathy 1120). Pass
:not_sympathetic to exclude those.
54 55 56 |
# File 'documented/common/creature/creature_facade.rb', line 54 def targets(*filters) instance_class.targets(*filters) end |