Class: Olib::Go2

Inherits:
Object
  • Object
show all
Defined in:
lib/Olib/go2.rb

Direct Known Subclasses

Go2

Constant Summary collapse

@@teleporter =
{}
@@routines =
{}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.cost(to) ⇒ Object

Thanks Tillmen


94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/Olib/go2.rb', line 94

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

.fwiObject


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/Olib/go2.rb', line 56

def Go2.fwi
  unless Char.fwi_teleporter
    echo "Error: No teleport defined ;var set teleporter=<teleporter>"
    exit
  end
  
  unless Inventory.fwi_teleporter
    echo "Error: Your teleporter could not be found #{Go2.teleporter}"
    exit
  end

  last = Room.current.id
  teleporter = Inventory.fwi_teleporter
  if teleporter.worn?
    teleporter.turn
  else
    teleporter.take.turn.stash
  end

  if Room.current.id == last
    echo "Error: You tried to teleport to FWI in a room that does not allow that"
  end

  Go2
end

.fwi_teleportObject

use the teleporter variable to locate your teleporter and teleport naive of where you are


113
114
115
# File 'lib/Olib/go2.rb', line 113

def Go2.fwi_teleport
  Go2.fwi
end

.lockerObject

TODO create a dictionary of house lockers and the logic to enter a locker insure locker is closed before scripting away from it


120
121
122
123
# File 'lib/Olib/go2.rb', line 120

def Go2.locker
  echo "the go2_locker method currently does not function properly..."
  self
end

.originObject


50
51
52
53
54
# File 'lib/Olib/go2.rb', line 50

def Go2.origin
  Go2.room @@origin[:roomid]
  Char.hide if @@origin[:hidden]
  Go2
end

.rebaseObject


82
83
84
85
86
87
88
89
# File 'lib/Olib/go2.rb', line 82

def Go2.rebase
  @@origin            = {}
  @@origin[:roomid]   = Room.current.id
  @@origin[:hidden]   = hiding?
  @@origin[:location] = Room.current.location
  Olib.debug "rebasing to #{@@origin}"
  Go2
end

.room(roomid) ⇒ Object


41
42
43
44
45
46
47
48
# File 'lib/Olib/go2.rb', line 41

def Go2.room(roomid)
  unless Room.current.id == roomid || Room.current.tags.include?(roomid)
    Char.unhide if hidden
    start_script "go2", [roomid, "_disable_confirm_"]
    wait_while { running? "go2" };
  end
  Go2
end

.tagsObject


25
26
27
28
# File 'lib/Olib/go2.rb', line 25

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

Instance Method Details

#tagObject

dynamically assign all of our Go2#methods


33
34
35
36
37
38
39
# File 'lib/Olib/go2.rb', line 33

Go2.tags.each { |tag|
  method  = Olib.methodize tag
  
  Go2.define_singleton_method(method.to_sym) do
    Go2.room tag
  end
}