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.

Examples:

module Creature
  extend Lich::Common::CreatureFacade
  def self.instance_class = CreatureInstance
  private_class_method :instance_class
end

Instance Method Summary collapse

Instance Method Details

#[](id) ⇒ Object?

Lookup creature instance by id.

Parameters:

  • id (Integer, String) —

    server creature id.

Returns:

  • (Object, nil) —

    the game's creature instance



44
45
46
# File 'documented/common/creature/creature_facade.rb', line 44

def [](id)
  instance_class[id]
end

#all ⇒ Array

Returns every registered instance.

Returns:

  • (Array) —

    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.

Parameters:

  • max_age_seconds (Integer) (defaults to: instance_class.cleanup_max_age) —

    age cutoff in seconds; defaults to the configured cleanup_max_age.

Returns:

  • (Integer) —

    number of instances removed.



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(**options)
  instance_class.configure(**options)
end

#debug_on(level = :changes) ⇒ Boolean, Symbol

Toggles live echo of status, flag, and registration changes.

Parameters:

  • level (Boolean, Symbol) (defaults to: :changes) —

    false disables debug output; true or :changes reports changes only; :all reports every <crtrStatus> flag; :active reports only active <crtrStatus> flags.

Returns:

  • (Boolean, Symbol) —

    the configured debug value.



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.

Parameters:

  • filters (Array<String, Symbol>) —

    optional ANDed status/classification filters.

Returns:

  • (Array)


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.

Parameters:

  • name (String, nil) —

    display name (may be nil for an id-first feed).

  • id (Integer, String) —

    server creature id.

  • noun (String, nil) (defaults to: nil) —

    noun, when available.

Returns:

  • (Object, nil) —

    the registered instance, or nil when auto-registration is disabled or the registry is full.



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.

Returns:

  • (Hash) —

    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.

Parameters:

  • filters (Array<String, Symbol>) —

    optional ANDed status/classification filters.

Returns:

  • (Array)


54
55
56
# File 'documented/common/creature/creature_facade.rb', line 54

def targets(*filters)
  instance_class.targets(*filters)
end