Class: Lich::DragonRealms::DRSkill

Inherits:
Object
  • Object
show all
Defined in:
documented/dragonrealms/drinfomon/drskill.rb

Overview

Represents a skill in the DragonRealms game. This class manages skill data, including experience and rank.

Examples:

Creating a new skill

skill = Lich::DragonRealms::DRSkill.new("Evasion", 10, 100, 50)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, rank, exp, percent) ⇒ DRSkill

Note:

Skills are capped at 34 ranks.

Initializes a new DRSkill instance.

Parameters:

  • name (String)

    The name of the skill.

  • rank (Integer)

    The earned ranks in the skill.

  • exp (Integer)

    The experience points for the skill.

  • percent (Integer)

    The percentage to the next rank (0 to 100).



24
25
26
27
28
29
30
31
32
33
34
35
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 24

def initialize(name, rank, exp, percent)
  @name = name # skill name like 'Evasion'
  @rank = rank.to_i # earned ranks in the skill
  # Skill mindstate x/34
  # Hardcode caped skills to 34/34
  @exp = rank.to_i >= 1750 ? 34 : exp.to_i
  @percent = percent.to_i # percent to next rank from 0 to 100
  @baseline = rank.to_i + (percent.to_i / 100.0)
  @current = rank.to_i + (percent.to_i / 100.0)
  @skillset = lookup_skillset(@name)
  @@list.push(self) unless @@list.find { |skill| skill.name == @name }
end

Instance Attribute Details

#baselineObject

Returns the value of attribute baseline.



15
16
17
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 15

def baseline
  @baseline
end

#currentObject

Returns the value of attribute current.



15
16
17
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 15

def current
  @current
end

#expObject

Returns the value of attribute exp.



15
16
17
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 15

def exp
  @exp
end

#nameObject (readonly)

Returns the value of attribute name.



14
15
16
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 14

def name
  @name
end

#percentObject

Returns the value of attribute percent.



15
16
17
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 15

def percent
  @percent
end

#rankObject

Returns the value of attribute rank.



15
16
17
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 15

def rank
  @rank
end

#skillsetObject (readonly)

Returns the value of attribute skillset.



14
15
16
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 14

def skillset
  @skillset
end

Class Method Details

.clear_mind(val) ⇒ void

This method returns an undefined value.

Resets the experience of a skill to zero.

Parameters:

  • val (String)

    The name of the skill.



138
139
140
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 138

def self.clear_mind(val)
  self.find_skill(val).exp = 0
end

.exp_modifiersHash

Returns the current experience modifiers.

Returns:

  • (Hash)

    A hash of skill names and their corresponding modifiers.



131
132
133
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 131

def self.exp_modifiers
  @@exp_modifiers
end

.find_skill(val) ⇒ DRSkill?

Finds a skill by its name.

Parameters:

  • val (String)

    The name of the skill.

Returns:

  • (DRSkill, nil)

    The DRSkill instance if found, nil otherwise.



200
201
202
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 200

def self.find_skill(val)
  @@list.find { |data| data.name == self.lookup_alias(val) }
end

.gained_exp(val) ⇒ Float

Note:

This method should not be confused with DRSkill.getxp(..) which returns the current learning rate.

Returns the amount of ranks that have been gained since the baseline was last reset. This allows you to track rank gain for a given play session.

Note, don’t confuse the ‘exp’ in this method name with DRSkill.getxp(..) which returns the current learning rate of the skill. Returns the amount of ranks gained since the last reset.

Parameters:

  • val (String)

    The name of the skill.

Returns:

  • (Float)

    The amount of ranks gained.



72
73
74
75
76
77
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 72

def self.gained_exp(val)
  skill = self.find_skill(val)
  if skill
    return skill.current ? (skill.current - skill.baseline).round(2) : 0.00
  end
end

.gained_skillsArray<Hash>

List of skills that have increased their learning rates. Primarily used by ‘exp-monitor` script to echo which skills gained experience after you performed an action. Returns the list of skills that have increased their learning rates.

Returns:

  • (Array<Hash>)

    An array of hashes containing skill names and their experience changes.



58
59
60
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 58

def self.gained_skills
  @@gained_skills
end

.getmodrank(val) ⇒ Integer

Returns the modified rank of a specified skill, including any modifiers.

Parameters:

  • val (String)

    The name of the skill.

Returns:

  • (Integer)

    The modified rank of the skill.



152
153
154
155
156
157
158
159
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 152

def self.getmodrank(val)
  skill = self.find_skill(val)
  if skill
    rank = skill.rank.to_i
    modifier = self.exp_modifiers[skill.name].to_i
    rank + modifier
  end
end

.getpercent(val) ⇒ Integer

Returns the percentage to the next rank for a specified skill.

Parameters:

  • val (String)

    The name of the skill.

Returns:

  • (Integer)

    The percentage to the next rank.



172
173
174
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 172

def self.getpercent(val)
  self.find_skill(val).percent.to_i
end

.getrank(val) ⇒ Integer

Returns the rank of a specified skill.

Parameters:

  • val (String)

    The name of the skill.

Returns:

  • (Integer)

    The rank of the skill.



145
146
147
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 145

def self.getrank(val)
  self.find_skill(val).rank.to_i
end

.getskillset(val) ⇒ String

Returns the skillset associated with a specified skill.

Parameters:

  • val (String)

    The name of the skill.

Returns:

  • (String)

    The skillset of the skill.



179
180
181
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 179

def self.getskillset(val)
  self.find_skill(val).skillset
end

.getxp(val) ⇒ Integer

Returns the experience points of a specified skill.

Parameters:

  • val (String)

    The name of the skill.

Returns:

  • (Integer)

    The experience points of the skill.



164
165
166
167
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 164

def self.getxp(val)
  skill = self.find_skill(val)
  skill.exp.to_i
end

.handle_exp_change(name, new_exp) ⇒ void

This method returns an undefined value.

Updates DRStats.gained_skills if the learning rate increased. The original consumer of this data is the ‘exp-monitor` script. Updates gained skills if the learning rate increased.

Parameters:

  • name (String)

    The name of the skill.

  • new_exp (Integer)

    The new experience value.



85
86
87
88
89
90
91
92
93
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 85

def self.handle_exp_change(name, new_exp)
  return unless UserVars.echo_exp

  old_exp = DRSkill.getxp(name)
  change = new_exp.to_i - old_exp.to_i
  if change > 0
    DRSkill.gained_skills << { skill: name, change: change }
  end
end

.include?(val) ⇒ Boolean

Checks if a skill exists in the list.

Parameters:

  • val (String)

    The name of the skill.

Returns:

  • (Boolean)

    True if the skill exists, false otherwise.



98
99
100
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 98

def self.include?(val)
  !self.find_skill(val).nil?
end

.listArray<DRSkill>

Returns the list of all skills.

Returns:

  • (Array<DRSkill>)

    An array of all DRSkill instances.



193
194
195
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 193

def self.list
  @@list
end

.listallvoid

This method returns an undefined value.

Lists all skills with their ranks and experience.



185
186
187
188
189
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 185

def self.listall
  @@list.each do |i|
    echo "#{i.name}: #{i.rank}.#{i.percent}% [#{i.exp}/34]"
  end
end

.lookup_alias(skill) ⇒ String

Some guilds rename skills, like Barbarians call “Primary Magic” as “Inner Fire”. Given the canonical or colloquial name, this method returns the value that’s usable with the other methods like ‘getxp(skill)` and `getrank(skill)`. Looks up the alias for a skill based on the guild.

Parameters:

  • skill (String)

    The name of the skill.

Returns:

  • (String)

    The canonical name of the skill.



210
211
212
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 210

def self.lookup_alias(skill)
  @@skills_data[:guild_skill_aliases][DRStats.guild][skill] || skill
end

.resetObject

Resets the gained skills and start time. This method is used to clear the current session’s skill data.



39
40
41
42
43
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 39

def self.reset
  @@gained_skills = []
  @@start_time = Time.now
  @@list.each { |skill| skill.baseline = skill.current }
end

.start_timeTime

Primarily used by ‘learned` script to track how long it’s been tracking your experience gains this session. Returns the start time of the current session.

Returns:

  • (Time)

    The time when tracking started.



49
50
51
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 49

def self.start_time
  @@start_time
end

.update(name, rank, exp, percent) ⇒ void

This method returns an undefined value.

Updates the skill’s rank, experience, and percentage.

Parameters:

  • name (String)

    The name of the skill.

  • rank (Integer)

    The new rank of the skill.

  • exp (Integer)

    The new experience points.

  • percent (Integer)

    The new percentage to the next rank.



108
109
110
111
112
113
114
115
116
117
118
119
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 108

def self.update(name, rank, exp, percent)
  self.handle_exp_change(name, exp)
  skill = self.find_skill(name)
  if skill
    skill.rank = rank.to_i
    skill.exp = skill.rank.to_i >= 1750 ? 34 : exp.to_i
    skill.percent = percent.to_i
    skill.current = rank.to_i + (percent.to_i / 100.0)
  else
    DRSkill.new(name, rank, exp, percent)
  end
end

.update_mods(name, rank) ⇒ void

This method returns an undefined value.

Updates the experience modifiers for a skill.

Parameters:

  • name (String)

    The name of the skill.

  • rank (Integer)

    The new rank to set as a modifier.



125
126
127
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 125

def self.update_mods(name, rank)
  self.exp_modifiers[self.lookup_alias(name)] = rank.to_i
end

Instance Method Details

#lookup_skillset(skill) ⇒ String

This is an instance method, do not prefix with ‘self`. It is called from the initialize method (constructor). When it was defined as a class method then the initialize method complained that this method didn’t yet exist. Looks up the skillset for an instance’s skill.

Parameters:

  • skill (String)

    The name of the skill.

Returns:

  • (String)

    The skillset associated with the skill.



221
222
223
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 221

def lookup_skillset(skill)
  @@skills_data[:skillsets].find { |_skillset, skills| skills.include?(skill) }.first
end