class Smite::GodStats

Attributes

items[R]
level[R]
name[R]
stacks[R]

Public Class Methods

new(god_name, data, params = { level: 0 }) click to toggle source
Calls superclass method Smite::Object::new
# File lib/smite/god_stats.rb, line 5
def initialize(god_name, data, params = { level: 0 })
  super(data)
  @name   = god_name
  @items  = params[:items] || []

  # make sure level is between 0 and 20 (0 for base stats)
  @level  = [[params[:level].to_i, 20].min, 0].max
  @stacks = params[:stacks] || {}
end

Public Instance Methods

at_level(new_level) click to toggle source
# File lib/smite/god_stats.rb, line 46
def at_level(new_level)
  GodStats.new(name, @data, { level: new_level, items: items, stacks: stacks })
end
attack_speed() click to toggle source
# File lib/smite/god_stats.rb, line 85
def attack_speed
  [value_for(:attack_speed), 2.5].min
end
bonus_from_items() click to toggle source
# File lib/smite/god_stats.rb, line 63
def bonus_from_items
  return @item_bonus unless @item_bonus.nil?

  @item_bonus = {}
  @item_bonus[:flat] = default_bonus.dup
  @item_bonus[:perc] = default_bonus.dup
  return @item_bonus if items.empty?

  bonus_from_active_item_effects
  bonus_from_passive_item_effects

  @item_bonus
end
inspect() click to toggle source
# File lib/smite/god_stats.rb, line 110
def inspect
  "#<Smite::GodStats '#{name}' Level #{level}>"
end
magic_power() click to toggle source
# File lib/smite/god_stats.rb, line 81
def magic_power
  magical_power
end
magical_protection() click to toggle source
# File lib/smite/god_stats.rb, line 77
def magical_protection
  magic_protection
end
method_missing(method) click to toggle source
Calls superclass method Smite::Object#method_missing
# File lib/smite/god_stats.rb, line 114
def method_missing(method)
  if data.member?(method.to_s) && !(method.to_s =~ /level/)
    value_for(method)
  else
    super
  end
end
movement_speed() click to toggle source
# File lib/smite/god_stats.rb, line 89
def movement_speed
  raw_speed = value_for(:movement_speed)

  ret = if raw_speed <= 457
    raw_speed
  elsif raw_speed <= 540.5
    dr = raw_speed - 457
    457 + 0.8 * dr
  else
    dr = raw_speed - 540.5
    457 + (540.5 - 457) * 0.8 + dr * 0.5
  end
  ret.round
end
summary() click to toggle source
# File lib/smite/god_stats.rb, line 104
def summary
  attributes.each_with_object({}) do |attr, hash|
    hash[attr.to_sym] = send(attr.to_sym)
  end
end
with_items(new_items, stacks = @stacks) click to toggle source
# File lib/smite/god_stats.rb, line 50
def with_items(new_items, stacks = @stacks)
  stacks.delete_if { |k,v| v.nil? }
  stack_map = new_items.each_with_object({}) do |item, hash|
    base_stacks = item.stacking? ? 0 : 1

    given_stacks    = stacks[item.name.downcase] || base_stacks
    actual_stacks   = [given_stacks, base_stacks].max
    actual_stacks   = [actual_stacks, item.max_stacks ].min.to_i
    hash[item.name.downcase] = actual_stacks
  end
  GodStats.new(name, @data, { level: level, items: new_items, stacks: stack_map })
end

Private Instance Methods

bonus_from_active_item_effects() click to toggle source
# File lib/smite/god_stats.rb, line 138
def bonus_from_active_item_effects
  # Active effects first
  items.map(&:active_effects).flatten.select do |effect|
    next unless attributes.include?(effect.attribute)

    if effect.percentage?
      @item_bonus[:perc][effect.attribute.to_sym] += effect.amount/100.0
    else
      @item_bonus[:flat][effect.attribute.to_sym] += effect.amount
    end
  end
end
bonus_from_passive_item_effects() click to toggle source
# File lib/smite/god_stats.rb, line 151
def bonus_from_passive_item_effects
  # passive (potentially stacking) effects second
  items.select do |item|
    item.passive_effects.each do |effect|
      next unless attributes.include?(effect.attribute)

      multiplier =  @stacks[item.name.downcase]
      if effect.percentage?
        @item_bonus[:perc][effect.attribute.to_sym] += multiplier * effect.amount/100.0
      else
        @item_bonus[:flat][effect.attribute.to_sym] += multiplier * effect.amount
      end
    end
  end
end
default_bonus() click to toggle source
# File lib/smite/god_stats.rb, line 218
def default_bonus
  @default_bonus ||= attributes.each_with_object({}) { |attr, hash| hash[attr.to_sym] = 0 }
end
from_god_passive(attribute) click to toggle source
# File lib/smite/god_stats.rb, line 167
def from_god_passive(attribute)
  return 0 unless attribute.to_s =~ /power/

  if attribute == :physical_power
    case name
    when 'Mercury'
      (movement_speed - 375) * 0.25
    when 'Vamana'
      physical_protection * 0.20
    else
      0
    end
  else
    case name
    when 'Scylla'
      case level
      when 0..8   then 0
      when 9..13  then 20
      when 14..17 then 40
      when 18..19 then 60
      when 20     then 80
      end
    when 'Ares'
      30 * items.count(&:aura?)
    when 'Kukulkan'
      mana * 0.05
    else
      0
    end
  end
end
from_item_passive(attribute) click to toggle source
# File lib/smite/god_stats.rb, line 199
def from_item_passive(attribute)
  case attribute.to_s
  when /magical_power/i
    if items.any? { |i| i.name =~ /Book of Thoth/i }
      mana * 0.03
    else
      0
    end
  when /physical_power/i
    if items.any? { |i| i.name =~ /Transcendence/i }
      mana * 0.03
    else
      0
    end
  else
    0
  end
end
magical_power_per_level() click to toggle source
# File lib/smite/god_stats.rb, line 226
def magical_power_per_level
  0
end
movement_speed_per_level() click to toggle source
# File lib/smite/god_stats.rb, line 222
def movement_speed_per_level
  0
end
physical_power_per_level() click to toggle source
# File lib/smite/god_stats.rb, line 230
def physical_power_per_level
  0
end
value_for(attribute) click to toggle source
# File lib/smite/god_stats.rb, line 124
def value_for(attribute)
  scaling         = send("#{attribute}_per_level".to_sym) * level.to_f
  flat_from_items = bonus_from_items[:flat][attribute.to_sym]
  perc_from_items = bonus_from_items[:perc][attribute.to_sym]

  passive     = from_god_passive(attribute) + from_item_passive(attribute)
  base        = data[attribute.to_s]

  flat_amount = (flat_from_items + base + scaling + passive)

  ret = (flat_amount * (perc_from_items + 1)).round(2)
  attribute =~ /5|attack/ ? ret : ret.round
end