Module: Go2

Defined in:
lib/Olib/go2.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.cost(to) ⇒ Object

Thanks Tillmen



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/Olib/go2.rb', line 50

def Go2.cost(to)
  cost = 0
  Map.findpath(Room.current.id, to).each { |id|
    Room[id].tags.each { |tag|          
      if tag =~ /^silver-cost:#{id-1}:(.*)$/
        cost_string = $1
        if cost_string =~ /^[0-9]+$/
          cost += cost_string.to_i
        else
          cost = StringProc.new(cost_string).call.to_i
        end
      end
    }
  }
  cost
end

.room(target) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/Olib/go2.rb', line 36

def Go2.room(target)
  starting_room = Room.current.id
  unless Room.current.id == target || Room.current.tags.include?(target)
    Char.unhide if hidden
    Go2.run(target)
    if block_given?
      yield
      starting_room
    end
  end
  Go2
end

.run(target) ⇒ Object



32
33
34
# File 'lib/Olib/go2.rb', line 32

def Go2.run(target)
  Script.run "go2", ("%s _disable_confirm_" % target)
end

.tagsObject

Returns Array.

Returns:

  • Array



21
22
23
# File 'lib/Olib/go2.rb', line 21

def Go2.tags
  Map.tags.select { |tag| !tag.include? "=" }.uniq
end

Instance Method Details

#tagObject

dynamically assign all of our Go2#methods



28
29
30
# File 'lib/Olib/go2.rb', line 28

Go2.tags.each do |tag|    
  Go2.define_singleton_method(tag.methodize) do Go2.room(tag) end
end