Class: Lich::DragonRealms::DRSkill
- Inherits:
-
Object
- Object
- Lich::DragonRealms::DRSkill
- Defined in:
- documented/dragonrealms/drinfomon/drskill.rb
Overview
Represents a skill in the DragonRealms game. This class manages skill data, including experience and rank.
Instance Attribute Summary collapse
-
#baseline ⇒ Object
Returns the value of attribute baseline.
-
#current ⇒ Object
Returns the value of attribute current.
-
#exp ⇒ Object
Returns the value of attribute exp.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#percent ⇒ Object
Returns the value of attribute percent.
-
#rank ⇒ Object
Returns the value of attribute rank.
-
#skillset ⇒ Object
readonly
Returns the value of attribute skillset.
Class Method Summary collapse
-
.clear_mind(val) ⇒ void
Resets the experience of a skill to zero.
-
.exp_modifiers ⇒ Hash
Returns the current experience modifiers.
-
.find_skill(val) ⇒ DRSkill?
Finds a skill by its name.
-
.gained_exp(val) ⇒ Float
Returns the amount of ranks that have been gained since the baseline was last reset.
-
.gained_skills ⇒ Array<Hash>
List of skills that have increased their learning rates.
-
.getmodrank(val) ⇒ Integer
Returns the modified rank of a specified skill, including any modifiers.
-
.getpercent(val) ⇒ Integer
Returns the percentage to the next rank for a specified skill.
-
.getrank(val) ⇒ Integer
Returns the rank of a specified skill.
-
.getskillset(val) ⇒ String
Returns the skillset associated with a specified skill.
-
.getxp(val) ⇒ Integer
Returns the experience points of a specified skill.
-
.handle_exp_change(name, new_exp) ⇒ void
Updates DRStats.gained_skills if the learning rate increased.
-
.include?(val) ⇒ Boolean
Checks if a skill exists in the list.
-
.list ⇒ Array<DRSkill>
Returns the list of all skills.
-
.listall ⇒ void
Lists all skills with their ranks and experience.
-
.lookup_alias(skill) ⇒ String
Some guilds rename skills, like Barbarians call “Primary Magic” as “Inner Fire”.
-
.reset ⇒ Object
Resets the gained skills and start time.
-
.start_time ⇒ Time
Primarily used by ‘learned` script to track how long it’s been tracking your experience gains this session.
-
.update(name, rank, exp, percent) ⇒ void
Updates the skill’s rank, experience, and percentage.
-
.update_mods(name, rank) ⇒ void
Updates the experience modifiers for a skill.
Instance Method Summary collapse
-
#initialize(name, rank, exp, percent) ⇒ DRSkill
constructor
Initializes a new DRSkill instance.
-
#lookup_skillset(skill) ⇒ String
This is an instance method, do not prefix with ‘self`.
Constructor Details
#initialize(name, rank, exp, percent) ⇒ DRSkill
Skills are capped at 34 ranks.
Initializes a new DRSkill instance.
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
#baseline ⇒ Object
Returns the value of attribute baseline.
15 16 17 |
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 15 def baseline @baseline end |
#current ⇒ Object
Returns the value of attribute current.
15 16 17 |
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 15 def current @current end |
#exp ⇒ Object
Returns the value of attribute exp.
15 16 17 |
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 15 def exp @exp end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
14 15 16 |
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 14 def name @name end |
#percent ⇒ Object
Returns the value of attribute percent.
15 16 17 |
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 15 def percent @percent end |
#rank ⇒ Object
Returns the value of attribute rank.
15 16 17 |
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 15 def rank @rank end |
#skillset ⇒ Object (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.
138 139 140 |
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 138 def self.clear_mind(val) self.find_skill(val).exp = 0 end |
.exp_modifiers ⇒ Hash
Returns the current experience 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.
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
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.
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_skills ⇒ Array<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.
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.
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.
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.
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.
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.
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.
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.
98 99 100 |
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 98 def self.include?(val) !self.find_skill(val).nil? end |
.list ⇒ Array<DRSkill>
Returns the list of all skills.
193 194 195 |
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 193 def self.list @@list end |
.listall ⇒ void
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.
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 |
.reset ⇒ Object
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_time ⇒ Time
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.
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.
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.
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.
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 |