Module: Lich::Gemstone::Fog

Defined in:
documented/gemstone/fog.rb

Overview

Fog return spells and society abilities that take a character home.

Wraps Spirit Guide (130), Symbol of Return (Voln), Traveler's Song (1020), Sigil of Escape (Sunfist), and Familiar Gate (930), with fallback chains and Rift detection that match bigshot's fog_return logic. Policy stays with the caller: which method a profile picks, whether to fog at all, and any custom command list are the script's responsibility.

Constant Summary collapse

RIFT_ROOM =

The Rift's exit: a fog that lands here needs a second cast to go on (bigshot fog_return_spirit, fog_return_voln).

2635
CONFIRM_TIMEOUT =

Seconds to wait for the room to change after a send. A fog resolves in one server pulse, so 8 is generous for the four that fog; a Traveler's Song is a walk to the destination and gets its own, longer budget.

8
TRAVELERS_SONG_TIMEOUT =
60
MAX_ROOM_UID =

Real room UIDs are small integers. Above this the id is xmlparser's MD5 stand-in for a room that arrived with no UID (xmlparser.rb, the branch), which is not unique across same-text rooms.

1_000_000_000
METHODS =

The five fog return methods, in order.

Returns:

  • (Array<Symbol>) —

    [:spirit_guide, :symbol_of_return, :travelers_song, :sigil_of_escape, :familiar_gate]

%i[spirit_guide symbol_of_return travelers_song sigil_of_escape familiar_gate].freeze
NUMBERS =

bigshot's fog_return setting (1-5; 6 is the profile's own commands)

{ 1 => :spirit_guide, 2 => :symbol_of_return, 3 => :travelers_song, 4 => :sigil_of_escape, 5 => :familiar_gate }.freeze
SPELLS =

Spell numbers for the three fog return spells.

Symbol of Return and Sigil of Escape are society abilities, not spells, so they are not listed here.

Returns:

  • (Hash{Symbol => Integer}) —

    maps :spirit_guide, :travelers_song, :familiar_gate to their spell numbers

{ spirit_guide: 130, travelers_song: 1020, familiar_gate: 930 }.freeze

Class Method Summary collapse

Class Method Details

.available ⇒ Array<Symbol>

Returns every method the character can use right now.

Returns:

  • (Array<Symbol>) —

    every method the character can use right now



97
98
99
# File 'documented/gemstone/fog.rb', line 97

def self.available
  METHODS.select { |m| available?(m) }
end

.available?(method) ⇒ Boolean

Known and affordable right now.

Returns:

  • (Boolean)


84
85
86
87
88
89
90
91
92
93
94
# File 'documented/gemstone/fog.rb', line 84

def self.available?(method)
  name = normalize(method)
  case name
  when :spirit_guide, :travelers_song, :familiar_gate
    num = SPELLS[name]
    spell_known?(num) && Spell[num].affordable?
  when :symbol_of_return then voln&.available?('return') || false
  when :sigil_of_escape then sunfist&.available?('escape') || false
  else false
  end
end

.cast_and_settle(num, timeout: CONFIRM_TIMEOUT) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



202
203
204
205
206
207
208
# File 'documented/gemstone/fog.rb', line 202

def self.cast_and_settle(num, timeout: CONFIRM_TIMEOUT)
  start = here
  Spell[num].cast
  sleep 0.5
  waitcastrt?
  wait_for_move(start, timeout: timeout)
end

.familiar_gate ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



188
189
190
191
192
193
194
195
196
197
# File 'documented/gemstone/fog.rb', line 188

def self.familiar_gate
  pulse_mana(930)
  return unless available?(:familiar_gate)

  Spell[930].cast
  fput 'go portal'
  sleep 0.5
  waitcastrt?
  waitrt?
end

.here ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Where we are, as the server reports it. XMLData.room_id is set for an unmapped room too - Room.current is nil there, and a map id would compare nil to nil and call a real move a failure - so it is the primary mark. It is never absent (xmlparser defaults it to 0 and every write goes through to_i), but it is not always unique: a room with no UID gets an MD5 of its title, description and exits, so two unmapped rooms whose text reads the same share an id. The room counter, which steps once per room stream, breaks that tie.



245
# File 'documented/gemstone/fog.rb', line 245

def self.here = { id: XMLData.room_id.to_s, count: XMLData.room_count.to_i }

.known?(method) ⇒ Boolean

Does this character have the method at all.

Returns:

  • (Boolean)


73
74
75
76
77
78
79
80
81
# File 'documented/gemstone/fog.rb', line 73

def self.known?(method)
  name = normalize(method)
  case name
  when :spirit_guide, :travelers_song, :familiar_gate then spell_known?(SPELLS[name])
  when :symbol_of_return then voln&.known?('return') || false
  when :sigil_of_escape then sunfist&.known?('escape') || false
  else false
  end
end

.moved_from?(start) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

A move is a different server room id. When the id is unchanged it may still be a move between two same-text unmapped rooms, so the counter decides: an MD5 id means the room has no UID, and a counter that has stepped there is a new room stream rather than a refresh of this one. A real UID is unique, so an unchanged one is never a move.

Returns:

  • (Boolean)


253
254
255
256
257
258
259
# File 'documented/gemstone/fog.rb', line 253

def self.moved_from?(start)
  now = here
  return true if now[:id] != start[:id]
  return false unless uidless?(now[:id])

  now[:count] > start[:count]
end

.normalize(method) ⇒ Symbol?

Parameters:

  • method (Symbol, Integer, String) —

    a METHODS name or bigshot's number

Returns:

  • (Symbol, nil)


64
65
66
67
68
69
70
# File 'documented/gemstone/fog.rb', line 64

def self.normalize(method)
  return NUMBERS[method] if method.is_a?(Integer)
  return NUMBERS[method.to_i] if method.to_s =~ /\A\d+\z/

  sym = method.to_s.downcase.to_sym
  METHODS.include?(sym) ? sym : nil
end

.pulse_mana(num) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

MANA PULSE before a known spell we cannot afford (bigshot mana_pulse).



222
223
224
225
226
227
# File 'documented/gemstone/fog.rb', line 222

def self.pulse_mana(num)
  return unless spell_known?(num) && !Spell[num].affordable?

  dothistimeout 'mana pulse', 2, /An invigorating rush of mana pulses through you|You are too mentally fatigued|You're already at full mana|Your mana control skills are not yet advanced/i
  sleep 0.2
end

.return(method, rift: false, resting_room: nil) ⇒ Boolean

Go home by method. Waits out roundtime first, pulses mana when the spell is known but unaffordable, and answers whether the room changed.

Spirit Guide and Symbol of Return fall back to each other when the first does not move us, and cast a second time when the first cast lands in the Rift and the destination is elsewhere - bigshot's rules, kept.

Parameters:

  • method (Symbol, Integer, String)
  • rift (Boolean) (defaults to: false) —

    the destination is reached through the Rift

  • resting_room (Integer, nil) (defaults to: nil) —

    with rift, the room the fog is for

Returns:

  • (Boolean) —

    whether the room changed



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'documented/gemstone/fog.rb', line 113

def self.return(method, rift: false, resting_room: nil)
  method = normalize(method)
  return false if method.nil?

  start = here
  sleep 0.5
  waitcastrt?
  waitrt?
  case method
  when :spirit_guide then spirit_guide(rift: rift, resting_room: resting_room)
  when :symbol_of_return then symbol_of_return(rift: rift, resting_room: resting_room)
  when :travelers_song then travelers_song
  when :sigil_of_escape then sigil_of_escape
  when :familiar_gate then familiar_gate
  end
  moved_from?(start)
end

.room_id ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The map id, for the Rift check only.



270
# File 'documented/gemstone/fog.rb', line 270

def self.room_id = Room.current&.id

.second_cast_from_rift(rift, resting_room, start) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

A fog into the Rift with the destination elsewhere is cast again from 2635 (bigshot: @FOG_RIFT && @RESTING_ROOM_ID != 2635).



213
214
215
216
217
218
# File 'documented/gemstone/fog.rb', line 213

def self.second_cast_from_rift(rift, resting_room, start)
  return unless rift && resting_room.to_i != RIFT_ROOM
  return unless moved_from?(start) && room_id == RIFT_ROOM

  yield
end

.sigil_of_escape ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



178
179
180
181
182
183
184
185
# File 'documented/gemstone/fog.rb', line 178

def self.sigil_of_escape
  return unless available?(:sigil_of_escape)

  fput 'sigil of escape'
  sleep 0.5
  waitcastrt?
  waitrt?
end

.spell_known?(num) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


273
274
275
276
# File 'documented/gemstone/fog.rb', line 273

def self.spell_known?(num)
  spell = Spell[num]
  !spell.nil? && spell.known?
end

.spirit_guide(rift: false, resting_room: nil, from_voln: false) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'documented/gemstone/fog.rb', line 134

def self.spirit_guide(rift: false, resting_room: nil, from_voln: false)
  start = here
  pulse_mana(130)
  if available?(:spirit_guide)
    cast_and_settle(130)
    second_cast_from_rift(rift, resting_room, start) do
      # the first cast may have spent the mana the second needs (bigshot pulses again here)
      pulse_mana(130)
      cast_and_settle(130) if available?(:spirit_guide)
    end
  end
  return true if moved_from?(start)

  # 130 did not move us: Symbol of Return, once (fog_return_spirit)
  symbol_of_return(rift: rift, resting_room: resting_room, from_spirit: true) if !from_voln && known?(:symbol_of_return)
  moved_from?(start)
end

.sunfist ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



284
285
286
# File 'documented/gemstone/fog.rb', line 284

def self.sunfist
  Societies::GuardiansOfSunfist if defined?(Societies::GuardiansOfSunfist)
end

.symbol_of_return(rift: false, resting_room: nil, from_spirit: false) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'documented/gemstone/fog.rb', line 153

def self.symbol_of_return(rift: false, resting_room: nil, from_spirit: false)
  start = here
  if known?(:symbol_of_return)
    fput 'symbol of return'
    wait_for_move(start)
    second_cast_from_rift(rift, resting_room, start) do
      rift_mark = here
      fput 'symbol of return'
      wait_for_move(rift_mark)
    end
  end
  return true if moved_from?(start)

  # the symbol did not move us: Spirit Guide, once (fog_return_voln)
  spirit_guide(rift: rift, resting_room: resting_room, from_voln: true) if !from_spirit && known?(:spirit_guide)
  moved_from?(start)
end

.travelers_song ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



172
173
174
175
# File 'documented/gemstone/fog.rb', line 172

def self.travelers_song
  pulse_mana(1020)
  cast_and_settle(1020, timeout: TRAVELERS_SONG_TIMEOUT) if available?(:travelers_song)
end

.uidless?(id) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

A server room id that is not a real room UID: xmlparser substitutes an MD5 of the room text, far above any UID, when

Returns:

  • (Boolean)


264
265
266
# File 'documented/gemstone/fog.rb', line 264

def self.uidless?(id)
  id.to_i > MAX_ROOM_UID
end

.voln ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



279
280
281
# File 'documented/gemstone/fog.rb', line 279

def self.voln
  Societies::OrderOfVoln if defined?(Societies::OrderOfVoln)
end

.wait_for_move(start, timeout: CONFIRM_TIMEOUT) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



230
231
232
233
234
# File 'documented/gemstone/fog.rb', line 230

def self.wait_for_move(start, timeout: CONFIRM_TIMEOUT)
  deadline = Time.now + timeout
  sleep 0.25 until moved_from?(start) || Time.now > deadline
  moved_from?(start)
end