Class: Creatures

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#predicateObject (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

.method_missing(method, *args, &block) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/Olib/combat/creatures.rb', line 64

def self.method_missing(method, *args, &block)
  if respond_to?(method)
    Creatures.new.send(method, *args, &block)
  else
    super(method, *args, &block)
  end
end

.respond_to?(method) ⇒ Boolean

Returns:

  • (Boolean)


72
73
74
75
# File 'lib/Olib/combat/creatures.rb', line 72

def self.respond_to?(method)
  return super(method) unless Creatures.new.respond_to?(method)
  return true
end

Instance Method Details

#bountyObject



54
55
56
# File 'lib/Olib/combat/creatures.rb', line 54

def bounty
  Creatures.new do |creature| creature.name.include?(Bounty.creature) end
end

#deadObject



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

#eachObject



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

Returns:

  • (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