Class: Creatures
- Inherits:
-
Object
- Object
- Creatures
- Includes:
- Enumerable
- Defined in:
- lib/Olib/combat/creatures.rb,
lib/Olib/combat/metadata.rb
Overview
a collection for managing all of the creatures in a room
Defined Under Namespace
Modules: Metadata
Constant Summary collapse
- ARCHETYPES =
%i[ undead living weak grimswarm antimagic flying lowly bandit aggressive ]
- STATES =
%i[ prone sitting kneeling sleeping webbed immobile stunned flying ]
- KINDS =
ARCHETYPES + STATES
- ALL =
-> creature { true }
Instance Attribute Summary collapse
-
#predicate ⇒ Object
readonly
Returns the value of attribute predicate.
Class Method Summary collapse
Instance Method Summary collapse
- #bounty ⇒ Object
- #dead ⇒ Object
- #each ⇒ Object
-
#initialize(&predicate) ⇒ Creatures
constructor
A new instance of Creatures.
- #method_missing(method, *args) ⇒ Object
- #respond_to_missing?(method, include_private = false) ⇒ Boolean
Constructor Details
#initialize(&predicate) ⇒ Creatures
Returns a new instance of Creatures.
26 27 28 |
# File 'lib/Olib/combat/creatures.rb', line 26 def initialize(&predicate) @predicate = predicate end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/Olib/combat/creatures.rb', line 40 def method_missing(method, *args) if to_a.respond_to?(method) to_a.send(method, *args) else super(method, *args) end end |
Instance Attribute Details
#predicate ⇒ Object (readonly)
Returns the value of attribute predicate.
24 25 26 |
# File 'lib/Olib/combat/creatures.rb', line 24 def predicate @predicate end |
Class Method Details
Instance Method Details
#bounty ⇒ Object
54 55 56 |
# File 'lib/Olib/combat/creatures.rb', line 54 def bounty Creatures.new do |creature| creature.name.include?(Bounty.creature) end end |
#dead ⇒ Object
58 59 60 61 62 |
# File 'lib/Olib/combat/creatures.rb', line 58 def dead GameObj.npcs.to_a .select do |c| c.status.include?("dead") end .map do |obj| Creature.new(obj) end end |
#each ⇒ Object
30 31 32 33 34 |
# File 'lib/Olib/combat/creatures.rb', line 30 def each() GameObj.targets.to_a.map do |obj| Creature.new(obj) end .select(&@predicate) .each do |creature| yield(creature) if GameObj[creature.id] end end |
#respond_to_missing?(method, include_private = false) ⇒ Boolean
36 37 38 |
# File 'lib/Olib/combat/creatures.rb', line 36 def respond_to_missing?(method, include_private = false) to_a.respond_to?(method) or super end |