Class: Creatures

Inherits:
Interface::Queryable show all
Defined in:
lib/Olib/combat/creatures.rb

Overview

a collection for managing all of the creatures in a room

Constant Summary collapse

METADATA_URL =
"https://cdn.rawgit.com/ondreian/gemstone_data_project/c40a5dfb/creatures.json"
ARCHETYPES =
[
  :undead, :living, :weak, :grimswarm,
  :antimagic, :flying, :lowly, :bandit,
  :aggressive,
]
STATES =
[
  :dead, :sleeping, :webbed, :immobile,  
  :stunned, :prone, :sitting, 
  :kneeling, :flying
]
METADATA =
fetch_metadata!
BY_NAME =
.reduce(Hash.new) do |by_name, record|
  by_name[record["name"]] = record
  by_name
end

Class Method Summary collapse

Methods inherited from Interface::Queryable

each, empty?, find, first, map, reject, sample, select, size, sort, where

Class Method Details

.bountyObject


69
70
71
72
73
# File 'lib/Olib/combat/creatures.rb', line 69

def self.bounty
  select do |creature|
    creature.name.include?(Bounty.creature)
  end
end

.fetchObject


44
45
46
47
48
49
50
51
52
53
# File 'lib/Olib/combat/creatures.rb', line 44

def Creatures.fetch
  unsafe.select do |creature| 
    creature.aggressive?
  end.reject do |creature| 
      creature.tags.include?(:companion) || 
      creature.tags.include?(:familiar)  || 
      creature.gone?                     || 
      creature.name =~ /nest/
  end
end

.fetch_metadata!Object


22
23
24
25
26
27
28
29
30
# File 'lib/Olib/combat/creatures.rb', line 22

def Creatures.fetch_metadata!
  begin
    JSON.parse Net::HTTP.get URI 
  rescue
    puts $!
    puts $!.backtrace[0..1]
    []
  end
end

.livingObject


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

def self.living
  reject do |creature|
    creature.undead?
  end
end

.unsafeObject


38
39
40
41
42
# File 'lib/Olib/combat/creatures.rb', line 38

def Creatures.unsafe
  (GameObj.npcs || [])
    .map do |obj| Creature.new obj end
    .reject do |creature| creature.gone? end
end