Class: Lich::Gemstone::Spellsong

Inherits:
Object
  • Object
show all
Defined in:
documented/attributes/spellsong.rb

Overview

Represents a spellsong in the Lich5 project. This class manages the duration and effects of bard spells.

Examples:

Creating a spellsong

Lich::Gemstone::Spellsong.sync

Class Method Summary collapse

Class Method Details

.armorcostArray<Integer>

Returns the armor cost for spells.

Examples:

Lich::Gemstone::Spellsong.armorcost

Returns:

  • (Array<Integer>)

    The armor cost values.



328
329
330
# File 'documented/attributes/spellsong.rb', line 328

def self.armorcost
  [14, 5]
end

.costInteger

Returns the cost of renewing the spellsong.

Examples:

Lich::Gemstone::Spellsong.cost

Returns:

  • (Integer)

    The renewal cost.



197
198
199
# File 'documented/attributes/spellsong.rb', line 197

def self.cost
  self.renew_cost
end

.depressionpushdownInteger

Calculates the push down value for depression.

Examples:

Lich::Gemstone::Spellsong.depressionpushdown

Returns:

  • (Integer)

    The push down value.



170
171
172
# File 'documented/attributes/spellsong.rb', line 170

def self.depressionpushdown
  20 + Skills.mltelepathy
end

.depressionslowInteger

Calculates the slow value for depression.

Examples:

Lich::Gemstone::Spellsong.depressionslow

Returns:

  • (Integer)

    The slow value.



178
179
180
181
182
183
# File 'documented/attributes/spellsong.rb', line 178

def self.depressionslow
  thresholds = [10, 25, 45, 70, 100]
  bonus = -2
  thresholds.each { |val| if Skills.mltelepathy >= val then bonus -= 1 end }
  bonus
end

.durationFloat

Calculates the duration of the spellsong based on various stats.

Examples:

Lich::Gemstone::Spellsong.duration

Returns:

  • (Float)

    The duration of the spellsong in seconds.



73
74
75
76
77
78
79
# File 'documented/attributes/spellsong.rb', line 73

def self.duration
  return @@song_duration if @@duration_calcs == [Stats.level, Stats.log[1], Stats.inf[1], Skills.mltelepathy]
  return @@song_duration if [Stats.level, Stats.log[1], Stats.inf[1], Skills.mltelepathy].include?(nil)
  @@duration_calcs = [Stats.level, Stats.log[1], Stats.inf[1], Skills.mltelepathy]
  total = self.duration_base_level(Stats.level)
  return (@@song_duration = total + Stats.log[1] + (Stats.inf[1] * 3) + (Skills.mltelepathy * 2))
end

.duration_base_level(level = Stats.level) ⇒ Integer

Calculates the base duration of the spellsong based on the level.

Examples:

Lich::Gemstone::Spellsong.duration_base_level(50)

Parameters:

  • level (Integer) (defaults to: Stats.level)

    The level of the bard.

Returns:

  • (Integer)

    The base duration in seconds.



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'documented/attributes/spellsong.rb', line 86

def self.duration_base_level(level = Stats.level)
  total = 120
  case level
  when (0..25)
    total += level * 4
  when (26..50)
    total += 100 + (level - 25) * 3
  when (51..75)
    total += 175 + (level - 50) * 2
  when (76..100)
    total += 225 + (level - 75)
  else
    Lich.log("unhandled case in Spellsong.duration level=#{level}")
  end
  return total
end

.fortcostArray<Integer>

Returns the fortitude cost for spells.

Examples:

Lich::Gemstone::Spellsong.fortcost

Returns:

  • (Array<Integer>)

    The fortitude cost values.



304
305
306
# File 'documented/attributes/spellsong.rb', line 304

def self.fortcost
  [3, 1]
end

.holdingtargetsInteger

Calculates the number of targets that can be held.

Examples:

Lich::Gemstone::Spellsong.holdingtargets

Returns:

  • (Integer)

    The number of holding targets.



189
190
191
# File 'documented/attributes/spellsong.rb', line 189

def self.holdingtargets
  1 + ((Spells.bard - 1) / 7).truncate
end

.luckcostArray<Integer>

Calculates the cost for the luck spell.

Examples:

Lich::Gemstone::Spellsong.luckcost

Returns:

  • (Array<Integer>)

    The cost values.



288
289
290
# File 'documented/attributes/spellsong.rb', line 288

def self.luckcost
  [6 + ((Spells.bard - 6) / 4), (6 + ((Spells.bard - 6) / 4) / 2).round]
end

.manacostArray<Integer>

Returns the mana cost for spells.

Examples:

Lich::Gemstone::Spellsong.manacost

Returns:

  • (Array<Integer>)

    The mana cost values.



296
297
298
# File 'documented/attributes/spellsong.rb', line 296

def self.manacost
  [18, 15]
end

.mirrorscostArray<Integer>

Calculates the cost for the mirrors spell.

Examples:

Lich::Gemstone::Spellsong.mirrorscost

Returns:

  • (Array<Integer>)

    The cost values.



224
225
226
# File 'documented/attributes/spellsong.rb', line 224

def self.mirrorscost
  [19 + ((Spells.bard - 19) / 5).truncate, 8 + ((Spells.bard - 19) / 10).truncate]
end

.mirrorsdodgebonusInteger

Calculates the dodge bonus for the mirrors spell.

Examples:

Lich::Gemstone::Spellsong.mirrorsdodgebonus

Returns:

  • (Integer)

    The dodge bonus value.



216
217
218
# File 'documented/attributes/spellsong.rb', line 216

def self.mirrorsdodgebonus
  20 + ((Spells.bard - 19) / 2).round
end

.renew_costInteger

Calculates the total renewal cost for active spellsongs.

Examples:

Lich::Gemstone::Spellsong.renew_cost

Returns:

  • (Integer)

    The total renewal cost.



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'documented/attributes/spellsong.rb', line 107

def self.renew_cost
  # fixme: multi-spell penalty?
  total = num_active = 0
  [1003, 1006, 1009, 1010, 1012, 1014, 1018, 1019, 1025].each { |song_num|
    if (song = Spell[song_num])
      if song.active?
        total += song.renew_cost
        num_active += 1
      end
    else
      echo "self.renew_cost: warning: can't find song number #{song_num}"
    end
  }
  return total
end

.renewedTime

Updates the renewed time to the current time.

Examples:

Lich::Gemstone::Spellsong.renewed

Returns:

  • (Time)

    The updated renewed time.



30
31
32
# File 'documented/attributes/spellsong.rb', line 30

def self.renewed
  @@renewed = Time.now
end

.renewed=(val) ⇒ Time

Sets the renewed time to a specified value.

Examples:

Lich::Gemstone::Spellsong.renewed = Time.now

Parameters:

  • val (Time)

    The new renewed time.

Returns:

  • (Time)

    The updated renewed time.



39
40
41
# File 'documented/attributes/spellsong.rb', line 39

def self.renewed=(val)
  @@renewed = val
end

.renewed_atTime

Returns the last renewed time.

Examples:

Lich::Gemstone::Spellsong.renewed_at

Returns:

  • (Time)

    The last renewed time.



47
48
49
# File 'documented/attributes/spellsong.rb', line 47

def self.renewed_at
  @@renewed
end

.serializeFloat

Serializes the current state of the spellsong.

Examples:

Lich::Gemstone::Spellsong.serialize

Returns:

  • (Float)

    The time left for the spellsong.



65
66
67
# File 'documented/attributes/spellsong.rb', line 65

def self.serialize
  self.timeleft
end

.shieldcostArray<Integer>

Returns the shield cost for spells.

Examples:

Lich::Gemstone::Spellsong.shieldcost

Returns:

  • (Array<Integer>)

    The shield cost values.



312
313
314
# File 'documented/attributes/spellsong.rb', line 312

def self.shieldcost
  [9, 4]
end

.sonicarmorbonusInteger

Calculates the sonic armor bonus.

Examples:

Lich::Gemstone::Spellsong.sonicarmorbonus

Returns:

  • (Integer)

    The sonic armor bonus value.



240
241
242
# File 'documented/attributes/spellsong.rb', line 240

def self.sonicarmorbonus
  self.sonicbonus + 15
end

.sonicarmordurabilityInteger

Calculates the durability of the sonic armor.

Examples:

Lich::Gemstone::Spellsong.sonicarmordurability

Returns:

  • (Integer)

    The durability value.



127
128
129
# File 'documented/attributes/spellsong.rb', line 127

def self.sonicarmordurability
  210 + (Stats.level / 2).round + Skills.to_bonus(Skills.elair)
end

.sonicbladebonusInteger

Calculates the sonic blade bonus.

Examples:

Lich::Gemstone::Spellsong.sonicbladebonus

Returns:

  • (Integer)

    The sonic blade bonus value.



248
249
250
# File 'documented/attributes/spellsong.rb', line 248

def self.sonicbladebonus
  self.sonicbonus + 10
end

.sonicbladedurabilityInteger

Calculates the durability of the sonic blade.

Examples:

Lich::Gemstone::Spellsong.sonicbladedurability

Returns:

  • (Integer)

    The durability value.



135
136
137
# File 'documented/attributes/spellsong.rb', line 135

def self.sonicbladedurability
  160 + (Stats.level / 2).round + Skills.to_bonus(Skills.elair)
end

.sonicbonusInteger

Calculates the sonic bonus based on bard level.

Examples:

Lich::Gemstone::Spellsong.sonicbonus

Returns:

  • (Integer)

    The sonic bonus value.



232
233
234
# File 'documented/attributes/spellsong.rb', line 232

def self.sonicbonus
  (Spells.bard / 2).round
end

.sonicshieldbonusInteger

Calculates the sonic shield bonus.

Examples:

Lich::Gemstone::Spellsong.sonicshieldbonus

Returns:

  • (Integer)

    The sonic shield bonus value.



264
265
266
# File 'documented/attributes/spellsong.rb', line 264

def self.sonicshieldbonus
  self.sonicbonus + 10
end

.sonicshielddurabilityInteger

Calculates the durability of the sonic shield.

Examples:

Lich::Gemstone::Spellsong.sonicshielddurability

Returns:

  • (Integer)

    The durability value.



151
152
153
# File 'documented/attributes/spellsong.rb', line 151

def self.sonicshielddurability
  125 + (Stats.level / 2).round + Skills.to_bonus(Skills.elair)
end

.sonicweaponbonusInteger

Returns the sonic weapon bonus.

Examples:

Lich::Gemstone::Spellsong.sonicweaponbonus

Returns:

  • (Integer)

    The sonic weapon bonus value.



256
257
258
# File 'documented/attributes/spellsong.rb', line 256

def self.sonicweaponbonus
  self.sonicbladebonus
end

.sonicweapondurabilityInteger

Returns the durability of the sonic weapon.

Examples:

Lich::Gemstone::Spellsong.sonicweapondurability

Returns:

  • (Integer)

    The durability value.



143
144
145
# File 'documented/attributes/spellsong.rb', line 143

def self.sonicweapondurability
  self.sonicbladedurability
end

.swordcostArray<Integer>

Returns the sword cost for spells.

Examples:

Lich::Gemstone::Spellsong.swordcost

Returns:

  • (Array<Integer>)

    The sword cost values.



336
337
338
# File 'documented/attributes/spellsong.rb', line 336

def self.swordcost
  [25, 15]
end

.syncString

Synchronizes the spellsong duration based on active bard spells.

Examples:

Lich::Gemstone::Spellsong.sync

Returns:

  • (String)

    A message indicating the status of the synchronization.

Raises:

  • (StandardError)

    If no active bard spells are found.



20
21
22
23
24
# File 'documented/attributes/spellsong.rb', line 20

def self.sync
  timed_spell = Effects::Spells.to_h.keys.find { |k| k.to_s.match(/10[0-9][0-9]/) }
  return 'No active bard spells' if timed_spell.nil?
  @@renewed = Time.at(Time.now.to_f - self.timeleft.to_f + (Effects::Spells.time_left(timed_spell) * 60.to_f)) # duration
end

.timeleftFloat

Calculates the remaining time left for the spellsong.

Examples:

Lich::Gemstone::Spellsong.timeleft

Returns:

  • (Float)

    The time left in minutes.

Raises:

  • (StandardError)

    If the profession is not Bard.



56
57
58
59
# File 'documented/attributes/spellsong.rb', line 56

def self.timeleft
  return 0.0 if Stats.prof != 'Bard'
  (self.duration - ((Time.now.to_f - @@renewed.to_f) % self.duration)) / 60.to_f
end

.tonisdodgebonusInteger

Calculates the dodge bonus for the tonis spell.

Examples:

Lich::Gemstone::Spellsong.tonisdodgebonus

Returns:

  • (Integer)

    The dodge bonus value.



205
206
207
208
209
210
# File 'documented/attributes/spellsong.rb', line 205

def self.tonisdodgebonus
  thresholds = [1, 2, 3, 5, 8, 10, 14, 17, 21, 26, 31, 36, 42, 49, 55, 63, 70, 78, 87, 96]
  bonus = 20
  thresholds.each { |val| if Skills.elair >= val then bonus += 1 end }
  bonus
end

.tonishastebonusInteger

Calculates the haste bonus for the tonis spell.

Examples:

Lich::Gemstone::Spellsong.tonishastebonus

Returns:

  • (Integer)

    The haste bonus value.



159
160
161
162
163
164
# File 'documented/attributes/spellsong.rb', line 159

def self.tonishastebonus
  bonus = -1
  thresholds = [30, 75]
  thresholds.each { |val| if Skills.elair >= val then bonus -= 1 end }
  bonus
end

.valorbonusInteger

Calculates the valor bonus based on bard level.

Examples:

Lich::Gemstone::Spellsong.valorbonus

Returns:

  • (Integer)

    The valor bonus value.



272
273
274
# File 'documented/attributes/spellsong.rb', line 272

def self.valorbonus
  10 + (([Spells.bard, Stats.level].min - 10) / 2).round
end

.valorcostArray<Integer>

Calculates the cost for the valor spell.

Examples:

Lich::Gemstone::Spellsong.valorcost

Returns:

  • (Array<Integer>)

    The cost values.



280
281
282
# File 'documented/attributes/spellsong.rb', line 280

def self.valorcost
  [10 + (self.valorbonus / 2), 3 + (self.valorbonus / 5)]
end

.weaponcostArray<Integer>

Returns the weapon cost for spells.

Examples:

Lich::Gemstone::Spellsong.weaponcost

Returns:

  • (Array<Integer>)

    The weapon cost values.



320
321
322
# File 'documented/attributes/spellsong.rb', line 320

def self.weaponcost
  [12, 4]
end