Module: Partyhat::Calculators
- Defined in:
- lib/partyhat/calculators.rb,
lib/partyhat/calculators/combat.rb
Class Method Summary collapse
-
.combat(stats) ⇒ Object
Calculate a user’s combat level with the given stats hash The method defaults to runescape starter stats if any of the skills are missing from the hash.
Class Method Details
.combat(stats) ⇒ Object
Calculate a user’s combat level with the given stats hash The method defaults to runescape starter stats if any of the skills are missing from the hash.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/partyhat/calculators/combat.rb', line 6 def self.combat stats return nil if stats.nil? || stats.empty? # Default combat calculator stats default_stats = { :attack => 1, :defence => 1, :strength => 1, :constitution => 10, :ranged => 1, :prayer => 1, :magic => 1, :summoning => 1 } # Replace non-set values with defaults values = default_stats.inject({}) { |h, (k, v)| h[k] = stats[k].level.to_i || v; h } # Level calculations base_level = (values[:defence] + values[:constitution] + (values[:prayer] / 2).floor + (values[:summoning] / 2).floor) * 0.25 base_melee = (values[:attack] + values[:strength]) * 0.325 base_range = (values[:ranged] * 1.5).floor * 0.325 base_magic = (values[:magic] * 1.5).floor * 0.325 combat_level = base_level + [base_melee, base_range, base_magic].max # Remainder calculations remainder_diff = combat_level + 1 remainder_diff = combat_level.ceil - combat_level if combat_level.is_a?(Float) remainders = { :strength_attack => (remainder_diff / (1.0/3.0)).ceil, :defence_constitution => (remainder_diff / 0.25).ceil, :prayer_summoning => (remainder_diff / 0.125).ceil } { :level => combat_level, :remainders => remainders } end |