Class: Smite::GodStats

Inherits:
Object
  • Object
show all
Defined in:
lib/smite/god_stats.rb

Instance Attribute Summary collapse

Attributes inherited from Object

#data

Instance Method Summary collapse

Methods inherited from Object

#attributes

Constructor Details

#initialize(god_name, data, params = { level: 0 }) ⇒ GodStats

Returns a new instance of GodStats.



5
6
7
8
9
10
11
12
13
# 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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method) ⇒ Object



114
115
116
117
118
119
120
# 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

Instance Attribute Details

#itemsObject (readonly)

Returns the value of attribute items.



3
4
5
# File 'lib/smite/god_stats.rb', line 3

def items
  @items
end

#levelObject (readonly)

Returns the value of attribute level.



3
4
5
# File 'lib/smite/god_stats.rb', line 3

def level
  @level
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/smite/god_stats.rb', line 3

def name
  @name
end

#stacksObject (readonly)

Returns the value of attribute stacks.



3
4
5
# File 'lib/smite/god_stats.rb', line 3

def stacks
  @stacks
end

Instance Method Details

#at_level(new_level) ⇒ Object



46
47
48
# 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_speedObject



85
86
87
# File 'lib/smite/god_stats.rb', line 85

def attack_speed
  [value_for(:attack_speed), 2.5].min
end

#bonus_from_itemsObject



63
64
65
66
67
68
69
70
71
72
73
74
75
# 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

#inspectObject



110
111
112
# File 'lib/smite/god_stats.rb', line 110

def inspect
  "#<Smite::GodStats '#{name}' Level #{level}>"
end

#magic_powerObject



81
82
83
# File 'lib/smite/god_stats.rb', line 81

def magic_power
  magical_power
end

#magical_protectionObject



77
78
79
# File 'lib/smite/god_stats.rb', line 77

def magical_protection
  magic_protection
end

#movement_speedObject



89
90
91
92
93
94
95
96
97
98
99
100
101
102
# 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

#summaryObject



104
105
106
107
108
# 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) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
# 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