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
Clears the experience of a specified skill.
-
.convert_rexp_str_to_seconds(time_string) ⇒ Integer
Converts a rested experience time string to seconds.
-
.exp_modifiers ⇒ Hash
Returns the experience modifiers for skills.
-
.find_skill(val) ⇒ DRSkill?
Finds a skill by its name or alias.
-
.gained_exp(val) ⇒ Float
Calculates the gained experience for a skill.
-
.gained_skills ⇒ Array<Hash>
Returns the list of gained skills.
-
.getmodrank(val) ⇒ Integer?
Retrieves the modified rank of a specified skill, including modifiers.
-
.getpercent(val) ⇒ Integer
Retrieves the percentage to the next rank of a specified skill.
-
.getrank(val) ⇒ Integer
Retrieves the rank of a specified skill.
-
.getskillset(val) ⇒ String
Retrieves the skillset associated with a specified skill.
-
.getxp(val) ⇒ Integer
Retrieves the experience points of a specified skill.
-
.handle_exp_change(name, new_exp) ⇒ void
Handles the experience change for a skill and records it if 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 details.
-
.lookup_alias(skill) ⇒ String
Looks up the alias for a skill based on the guild’s skill aliases.
-
.reset ⇒ void
Resets the gained skills and start time.
-
.rested_active? ⇒ Boolean
Checks if rested experience is active.
-
.rested_exp_refresh ⇒ Integer
Returns the refresh time for rested experience.
-
.rested_exp_stored ⇒ Integer
Returns the stored rested experience.
-
.rested_exp_usable ⇒ Integer
Returns the usable rested experience.
-
.start_time ⇒ Time
Returns the start time of the skill tracking.
-
.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.
-
.update_rested_exp(stored, usable, refresh) ⇒ void
Updates the rested experience values.
Instance Method Summary collapse
-
#initialize(name, rank, exp, percent) ⇒ DRSkill
constructor
Initializes a new DRSkill instance.
-
#lookup_skillset(skill) ⇒ String
Looks up the skillset for a given skill.
Constructor Details
#initialize(name, rank, exp, percent) ⇒ DRSkill
Initializes a new DRSkill instance.
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 29 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.
21 22 23 |
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 21 def baseline @baseline end |
#current ⇒ Object
Returns the value of attribute current.
21 22 23 |
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 21 def current @current end |
#exp ⇒ Object
Returns the value of attribute exp.
21 22 23 |
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 21 def exp @exp end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
20 21 22 |
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 20 def name @name end |
#percent ⇒ Object
Returns the value of attribute percent.
21 22 23 |
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 21 def percent @percent end |
#rank ⇒ Object
Returns the value of attribute rank.
21 22 23 |
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 21 def rank @rank end |
#skillset ⇒ Object (readonly)
Returns the value of attribute skillset.
20 21 22 |
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 20 def skillset @skillset end |
Class Method Details
.clear_mind(val) ⇒ void
This method returns an undefined value.
Clears the experience of a specified skill.
164 165 166 |
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 164 def self.clear_mind(val) self.find_skill(val).exp = 0 end |
.convert_rexp_str_to_seconds(time_string) ⇒ Integer
Converts a rested experience time string to seconds.
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 233 def self.convert_rexp_str_to_seconds(time_string) # Handle empty, nil, or specific "zero" cases (less than a minute is zero because it can get stuck there) return 0 if time_string.nil? || time_string.to_s.strip.empty? || time_string.include?("none") || time_string.include?("less than a minute") total_seconds = 0 # Extract hours and optional minutes (e.g., "4:38 hours" or "6 hour") # Ruby's match returns a MatchData object or nil if (hour_match = time_string.match(/(\d+):?(\d+)?\s*hour/)) hours = hour_match[1].to_i total_seconds += hours * 60 * 60 # Handle the minutes part of a "4:38" format if hour_match[2] total_seconds += hour_match[2].to_i * 60 return total_seconds end end # Extract standalone minutes (e.g., "38 minutes") if (minute_match = time_string.match(/(\d+)\s*minute/)) total_seconds += minute_match[1].to_i * 60 end total_seconds end |
.exp_modifiers ⇒ Hash
Returns the experience modifiers for skills.
133 134 135 |
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 133 def self.exp_modifiers @@exp_modifiers end |
.find_skill(val) ⇒ DRSkill?
Finds a skill by its name or alias.
226 227 228 |
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 226 def self.find_skill(val) @@list.find { |data| data.name == self.lookup_alias(val) } end |
.gained_exp(val) ⇒ Float
Calculates the gained experience for a skill.
65 66 67 68 69 70 |
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 65 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>
Returns the list of gained skills.
58 59 60 |
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 58 def self.gained_skills @@gained_skills end |
.getmodrank(val) ⇒ Integer?
Retrieves the modified rank of a specified skill, including modifiers.
178 179 180 181 182 183 184 185 |
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 178 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
Retrieves the percentage to the next rank of a specified skill.
198 199 200 |
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 198 def self.getpercent(val) self.find_skill(val).percent.to_i end |
.getrank(val) ⇒ Integer
Retrieves the rank of a specified skill.
171 172 173 |
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 171 def self.getrank(val) self.find_skill(val).rank.to_i end |
.getskillset(val) ⇒ String
Retrieves the skillset associated with a specified skill.
205 206 207 |
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 205 def self.getskillset(val) self.find_skill(val).skillset end |
.getxp(val) ⇒ Integer
Retrieves the experience points of a specified skill.
190 191 192 193 |
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 190 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.
Handles the experience change for a skill and records it if increased.
76 77 78 79 80 81 82 83 84 |
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 76 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.
89 90 91 |
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 89 def self.include?(val) !self.find_skill(val).nil? end |
.list ⇒ Array<DRSkill>
Returns the list of all skills.
219 220 221 |
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 219 def self.list @@list end |
.listall ⇒ void
This method returns an undefined value.
Lists all skills with their details.
211 212 213 214 215 |
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 211 def self.listall @@list.each do |i| echo "#{i.name}: #{i.rank}.#{i.percent}% [#{i.exp}/34]" end end |
.lookup_alias(skill) ⇒ String
Looks up the alias for a skill based on the guild’s skill aliases.
266 267 268 |
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 266 def self.lookup_alias(skill) @@skills_data[:guild_skill_aliases][DRStats.guild][skill] || skill end |
.reset ⇒ void
This method returns an undefined value.
Resets the gained skills and start time.
44 45 46 47 48 |
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 44 def self.reset @@gained_skills = [] @@start_time = Time.now @@list.each { |skill| skill.baseline = skill.current } end |
.rested_active? ⇒ Boolean
Checks if rested experience is active.
157 158 159 |
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 157 def self.rested_active? @@rexp_stored > 0 && @@rexp_usable > 0 end |
.rested_exp_refresh ⇒ Integer
Returns the refresh time for rested experience.
151 152 153 |
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 151 def self.rested_exp_refresh @@rexp_refresh end |
.rested_exp_stored ⇒ Integer
Returns the stored rested experience.
139 140 141 |
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 139 def self.rested_exp_stored @@rexp_stored end |
.rested_exp_usable ⇒ Integer
Returns the usable rested experience.
145 146 147 |
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 145 def self.rested_exp_usable @@rexp_usable end |
.start_time ⇒ Time
Returns the start time of the skill tracking.
52 53 54 |
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 52 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.
99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 99 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.
116 117 118 |
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 116 def self.update_mods(name, rank) self.exp_modifiers[self.lookup_alias(name)] = rank.to_i end |
.update_rested_exp(stored, usable, refresh) ⇒ void
This method returns an undefined value.
Updates the rested experience values.
125 126 127 128 129 |
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 125 def self.update_rested_exp(stored, usable, refresh) @@rexp_stored = self.convert_rexp_str_to_seconds(stored) @@rexp_usable = self.convert_rexp_str_to_seconds(usable) @@rexp_refresh = self.convert_rexp_str_to_seconds(refresh) end |
Instance Method Details
#lookup_skillset(skill) ⇒ String
Looks up the skillset for a given skill.
273 274 275 |
# File 'documented/dragonrealms/drinfomon/drskill.rb', line 273 def lookup_skillset(skill) @@skills_data[:skillsets].find { |_skillset, skills| skills.include?(skill) }.first end |