Module: Lich::DragonRealms::DRCS

Defined in:
documented/dragonrealms/commons/common-summoning.rb

Constant Summary collapse

LACK_CHARGE =

Shared response for elemental charge depletion Shared response for elemental charge depletion

'You lack the elemental charge'.freeze
SUMMON_WEAPON_RESPONSES =
[
  LACK_CHARGE,
  'you draw out'
].freeze
BREAK_WEAPON_RESPONSES =
[
  'Focusing your will',
  'disrupting its matrix',
  "You can't break",
  'Break what'
].freeze
MOON_SKILL_TO_SHAPE =

Moon Mage skill-to-shape mapping for moonblades/staves Moon Mage skill-to-shape mapping for moonblades/staves

{
  'Staves'          => 'blunt',
  'Twohanded Edged' => 'huge',
  'Large Edged'     => 'heavy',
  'Small Edged'     => 'normal'
}.freeze
MOON_SHAPE_RESPONSES =
[
  'you adjust the magic that defines its shape',
  'already has',
  'You fumble around'
].freeze
WM_SHAPE_FAILURES =
[
  LACK_CHARGE,
  'You reach out',
  'You fumble around',
  "You don't know how to manipulate your weapon in that way"
].freeze
TURN_WEAPON_RESPONSES =
[LACK_CHARGE, 'You reach out'].freeze
PUSH_WEAPON_RESPONSES =
[LACK_CHARGE, 'Closing your eyes', "That's as"].freeze
PULL_WEAPON_RESPONSES =
[LACK_CHARGE, 'Closing your eyes', "That's as"].freeze
SUMMON_ADMITTANCE_RESPONSES =
[
  'You align yourself to it',
  'further increasing your proximity',
  'Going any further while in this plane would be fatal',
  'Summon allows Warrior Mages to draw',
  'You are a bit too distracted'
].freeze
WM_ELEMENT_ADJECTIVES =

Default element adjectives for Warrior Mage summoned weapons Default element adjectives for Warrior Mage summoned weapons

%w[stone fiery icy electric].freeze

Class Method Summary collapse

Class Method Details

.break_summoned_weapon(item) ⇒ void

This method returns an undefined value.

Breaks a summoned weapon.

Parameters:

  • item (String, nil)

    the item to break



122
123
124
125
126
# File 'documented/dragonrealms/commons/common-summoning.rb', line 122

def break_summoned_weapon(item)
  return if item.nil?

  DRC.bput("break my #{item}", *BREAK_WEAPON_RESPONSES)
end

.get_ingot(ingot, swap) ⇒ Boolean

Retrieves an ingot for use in summoning.

Parameters:

  • ingot (String, nil)

    the type of ingot to retrieve

  • swap (Boolean)

    whether to swap the ingot

Returns:

  • (Boolean)

    true if the ingot was successfully retrieved



93
94
95
96
97
98
99
100
101
102
# File 'documented/dragonrealms/commons/common-summoning.rb', line 93

def get_ingot(ingot, swap)
  return true unless ingot

  unless DRCI.get_item?("#{ingot} ingot")
    Lich::Messaging.msg("bold", "DRCS: Could not get #{ingot} ingot")
    return false
  end
  DRC.bput('swap', 'You move') if swap
  true
end

.identify_summoned_weapon(settings = nil) ⇒ String?

Identifies the summoned weapon in hand.

Parameters:

  • settings (OpenStruct, nil) (defaults to: nil)

    optional settings for identification

Returns:

  • (String, nil)

    the identified weapon or nil if not found



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'documented/dragonrealms/commons/common-summoning.rb', line 174

def identify_summoned_weapon(settings = nil)
  if DRStats.moon_mage?
    return DRC.right_hand if DRCMM.is_moon_weapon?(DRC.right_hand)
    return DRC.left_hand  if DRCMM.is_moon_weapon?(DRC.left_hand)
  elsif DRStats.warrior_mage?
    custom_adjective = settings&.summoned_weapons_adjective ? "#{settings.summoned_weapons_adjective}|" : ''
    adjectives = WM_ELEMENT_ADJECTIVES.join('|')
    weapon_regex = /^You tap (?:a|an|some)(?:[\w\s\-]+)(?:(?:#{custom_adjective}#{adjectives}) [\w\s\-]+) that you are holding\.$/
    # For a two-worded weapon like 'short sword' the only way to know
    # which element it was summoned with is by tapping it. That's the only
    # way we can infer if it's a summoned sword or a regular one.
    # However, the <adj> <noun> of the item we return must be what's in
    # their hands, not what the regex matches in the tap.
    return DRC.right_hand if weapon_regex.match?(DRCI.tap(DRC.right_hand).to_s)
    return DRC.left_hand if weapon_regex.match?(DRCI.tap(DRC.left_hand).to_s)
  else
    Lich::Messaging.msg("bold", "DRCS: Unable to identify summoned weapons as a #{DRStats.guild}")
  end
end

.pull_summoned_weaponvoid

This method returns an undefined value.

Pulls the summoned weapon.



220
221
222
223
224
225
226
227
228
# File 'documented/dragonrealms/commons/common-summoning.rb', line 220

def pull_summoned_weapon
  result = DRC.bput("pull my #{DRC.right_hand_noun}", *PULL_WEAPON_RESPONSES)
  if result == LACK_CHARGE
    summon_admittance
    DRC.bput("pull my #{DRC.right_hand_noun}", *PULL_WEAPON_RESPONSES)
  end
  pause 1
  waitrt?
end

.push_summoned_weaponvoid

This method returns an undefined value.

Pushes the summoned weapon.



208
209
210
211
212
213
214
215
216
# File 'documented/dragonrealms/commons/common-summoning.rb', line 208

def push_summoned_weapon
  result = DRC.bput("push my #{DRC.right_hand_noun}", *PUSH_WEAPON_RESPONSES)
  if result == LACK_CHARGE
    summon_admittance
    DRC.bput("push my #{DRC.right_hand_noun}", *PUSH_WEAPON_RESPONSES)
  end
  pause 1
  waitrt?
end

.shape_summoned_weapon(skill, ingot = nil, settings = nil) ⇒ void

This method returns an undefined value.

Shapes a summoned weapon based on the provided skill.

Parameters:

  • skill (String)

    the skill to shape the weapon

  • ingot (String, nil) (defaults to: nil)

    optional ingot type

  • settings (OpenStruct, nil) (defaults to: nil)

    optional settings for shaping



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'documented/dragonrealms/commons/common-summoning.rb', line 134

def shape_summoned_weapon(skill, ingot = nil, settings = nil)
  summoned_weapon = identify_summoned_weapon(settings)
  if DRStats.moon_mage?
    shape = MOON_SKILL_TO_SHAPE[skill]
    if DRCMM.hold_moon_weapon?
      DRC.bput("shape #{summoned_weapon} to #{shape}", *MOON_SHAPE_RESPONSES)
    end
  elsif DRStats.warrior_mage?
    return unless get_ingot(ingot, false)

    result = DRC.bput("shape my #{summoned_weapon} to #{skill}", *(WM_SHAPE_FAILURES + ['What type of weapon were you trying']))
    case result
    when LACK_CHARGE
      summon_admittance
      DRC.bput("shape my #{summoned_weapon} to #{skill}", *WM_SHAPE_FAILURES)
    when 'What type of weapon were you trying'
      # Custom adjectives from https://elanthipedia.play.net/Books_of_Binding tomes
      # aren't recognized for shaping summoned elemental weapons, and the error message
      # itself is misleading. Breaking, turning, pulling, pushing work fine with custom adj.
      unless summoned_weapon.nil?
        adj = settings&.summoned_weapons_adjective || ''
        retry_result = DRC.bput("shape my #{summoned_weapon.sub(adj, '')} to #{skill}", *WM_SHAPE_FAILURES)
        if retry_result == LACK_CHARGE
          summon_admittance
          DRC.bput("shape my #{summoned_weapon.sub(adj, '')} to #{skill}", *WM_SHAPE_FAILURES)
        end
      end
    end
    stow_ingot(ingot)
  else
    Lich::Messaging.msg("bold", "DRCS: Unable to shape weapons as a #{DRStats.guild}")
  end
  pause 1
  waitrt?
end

.stow_ingot(ingot) ⇒ Boolean

Stows an ingot after use.

Parameters:

  • ingot (String, nil)

    the type of ingot to stow

Returns:

  • (Boolean)

    true if the ingot was successfully stowed



108
109
110
111
112
113
114
115
116
# File 'documented/dragonrealms/commons/common-summoning.rb', line 108

def stow_ingot(ingot)
  return true unless ingot

  unless DRCI.put_away_item?("#{ingot} ingot")
    Lich::Messaging.msg("bold", "DRCS: Could not stow #{ingot} ingot")
    return false
  end
  true
end

.summon_admittancevoid

This method returns an undefined value.

Handles the admittance process for summoning.



232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'documented/dragonrealms/commons/common-summoning.rb', line 232

def summon_admittance
  loop do
    result = DRC.bput('summon admittance', *SUMMON_ADMITTANCE_RESPONSES)
    if result == 'You are a bit too distracted'
      DRC.retreat
      next
    end
    break
  end
  pause 1
  waitrt?
  DRC.fix_standing
end

.summon_weapon(_moon = nil, element = nil, ingot = nil, skill = nil) ⇒ void

This method returns an undefined value.

Summons a weapon based on the provided parameters.

Parameters:

  • moon (String, nil)

    optional moon type

  • element (String, nil) (defaults to: nil)

    optional elemental type

  • ingot (String, nil) (defaults to: nil)

    optional ingot type

  • skill (String, nil) (defaults to: nil)

    optional skill type



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'documented/dragonrealms/commons/common-summoning.rb', line 68

def summon_weapon(_moon = nil, element = nil, ingot = nil, skill = nil)
  if DRStats.moon_mage?
    DRCMM.hold_moon_weapon?
  elsif DRStats.warrior_mage?
    return unless get_ingot(ingot, true)

    result = DRC.bput("summon weapon #{element} #{skill}", *SUMMON_WEAPON_RESPONSES)
    if result == LACK_CHARGE
      summon_admittance
      DRC.bput("summon weapon #{element} #{skill}", *SUMMON_WEAPON_RESPONSES)
    end
    stow_ingot(ingot)
  else
    Lich::Messaging.msg("bold", "DRCS: Unable to summon weapons as a #{DRStats.guild}")
  end
  pause 1
  waitrt?
  DRC.fix_standing
end

.turn_summoned_weaponvoid

This method returns an undefined value.

Turns the summoned weapon.



196
197
198
199
200
201
202
203
204
# File 'documented/dragonrealms/commons/common-summoning.rb', line 196

def turn_summoned_weapon
  result = DRC.bput("turn my #{DRC.right_hand_noun}", *TURN_WEAPON_RESPONSES)
  if result == LACK_CHARGE
    summon_admittance
    DRC.bput("turn my #{DRC.right_hand_noun}", *TURN_WEAPON_RESPONSES)
  end
  pause 1
  waitrt?
end