smite_ruby 1.4.6 → 1.4.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ccff694141365296222915e4cc61decb5162e706
4
- data.tar.gz: 38f300318daa9cc1c80cd8e70fce3df846cf148e
3
+ metadata.gz: 4fcad5bd4774d5cf3f1c76a330ea0e8f791093ab
4
+ data.tar.gz: 85a1e44fb48a152dae28a493c8582184d55c965d
5
5
  SHA512:
6
- metadata.gz: a73210acf092f72f83cfa9edf71bf007d383d282c487777e3d6801822a0819c70f2e1d73fbfc17c2e1247162c2ab21f611070391790647bad47e877819422e06
7
- data.tar.gz: 658baadac807264383473292c98f37725baceee364111b4e06810a355249727f103074fd3c90407311a048563933591e86a15be677e374bf4631e552e829502f
6
+ metadata.gz: be93cc0b126c2a2073a8385c73695127b5d21ffe98b99317ec9eba583e63a1c26f72bba065bc58e683e1642493e7d8588633e928e7e0a292190762f2ab35fc82
7
+ data.tar.gz: 3aa1b5acac28193f68a3cc30db75e4cf1599d575a724457fe5e4a3b2f03e052032548051b100e834f4c16ce6237bfb8b77a052ddf4e0c07131fec198fbf2638f
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  *.gem
2
- .DS_Store
2
+ .DS_Store
3
+ *.test
@@ -1,14 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- smite_ruby (1.4.5)
4
+ smite_ruby (1.4.673)
5
5
  activesupport
6
6
  httparty
7
7
 
8
8
  GEM
9
9
  remote: http://rubygems.org/
10
10
  specs:
11
- activesupport (4.2.3)
11
+ activesupport (4.2.5.1)
12
12
  i18n (~> 0.7)
13
13
  json (~> 1.7, >= 1.7.7)
14
14
  minitest (~> 5.1)
@@ -24,7 +24,7 @@ GEM
24
24
  multi_xml (>= 0.5.2)
25
25
  i18n (0.7.0)
26
26
  json (1.8.3)
27
- minitest (5.8.3)
27
+ minitest (5.8.4)
28
28
  multi_xml (0.5.5)
29
29
  rspec (3.3.0)
30
30
  rspec-core (~> 3.3.0)
@@ -1,5 +1,23 @@
1
1
  module Smite
2
2
  class Ability < Smite::Object
3
+ def which
4
+ case number
5
+ when 1 then '1st Ability'
6
+ when 2 then '2nd Ability'
7
+ when 3 then '3rd Ability'
8
+ when 4 then 'Ultimate'
9
+ when 5 then 'Passive'
10
+ end
11
+ end
12
+
13
+ def number
14
+ ability_number
15
+ end
16
+
17
+ def name
18
+ summary
19
+ end
20
+
3
21
  def inspect
4
22
  "#<Smite::Ability '#{summary}'>"
5
23
  end
@@ -22,11 +22,13 @@ module Smite
22
22
  ability_fields = data.slice(*ability_map_fields)
23
23
  return data if ability_fields.empty?
24
24
 
25
- data['abilities'] = ability_fields.values.map do |ability_data|
25
+ data['abilities'] = ability_fields.values.each_with_index.map do |ability_data, idx|
26
26
  data_attrs = ability_data.slice('Id', 'Summary', 'URL')
27
27
  desc = ability_data['Description']
28
28
  desc = desc.nil? ? {} : desc['itemDescription']
29
29
 
30
+ data_attrs['god'] = data['name']
31
+ data_attrs['ability_number'] = idx + 1
30
32
  Ability.new(data_attrs.merge(desc))
31
33
  end
32
34
 
@@ -50,24 +52,12 @@ module Smite
50
52
  stat_fields['movement_speed'] = stat_fields.delete('speed')
51
53
  stat_fields['mp5'] = stat_fields.delete('mana_per_five')
52
54
  stat_fields['hp5'] = stat_fields.delete('health_per_five')
55
+ stat_fields['physical_power'] = 0
56
+ stat_fields['magical_power'] = 0
53
57
  data['stats'] = GodStats.new(data['name'], stat_fields)
54
58
  data.except(*stats_filter_fields)
55
59
  end
56
60
 
57
- def transform_item_effect(data)
58
- return unless data['Description'] and data['Value']
59
-
60
- effect = data.delete('Description').tr(' ','')
61
- effect = ActiveSupport::Inflector.underscore(effect)
62
- data['attribute'] = effect
63
-
64
- value = data.delete('Value')
65
- @percentage = value[/%/]
66
- value = value.tr('+', '').to_i
67
- data['amount'] = value
68
- data
69
- end
70
-
71
61
  def transform_match_achievements(data)
72
62
  ach_fields = data.slice(*match_achievement_map_fields)
73
63
  return data if ach_fields.empty?
@@ -61,6 +61,14 @@ module Smite
61
61
  @gods ||= client.gods.map(&God.method(:new))
62
62
  end
63
63
 
64
+ def roles
65
+ @roles ||= gods.map { |g| g.roles.strip }.uniq
66
+ end
67
+
68
+ def pantheons
69
+ @pantheons ||= gods.map(&:pantheon).uniq
70
+ end
71
+
64
72
  def devices
65
73
  @devices ||= client.items.map(&Item.method(:new))
66
74
  end
@@ -77,6 +85,10 @@ module Smite
77
85
  @actives ||= devices.select(&:active?)
78
86
  end
79
87
 
88
+ def item_effects
89
+ @effects ||= devices.map(&:active_effects).flatten.map(&:attribute).uniq
90
+ end
91
+
80
92
  private
81
93
 
82
94
  def device_hash
@@ -11,7 +11,7 @@ module Smite
11
11
  end
12
12
 
13
13
  def ranged?
14
- !!(type =~ /Ranged/i)
14
+ !!(type =~ /Ranged/i) || !!(name =~ /Sylvanus/i)
15
15
  end
16
16
 
17
17
  def melee?
@@ -19,12 +19,73 @@ module Smite
19
19
  end
20
20
 
21
21
  def physical?
22
- !!(type =~ /Physical/i)
22
+ !!(type =~ /Physical/i) || !!(role =~ /Hunter|Warrior|Assassin/i)
23
23
  end
24
24
 
25
25
  def magic?
26
26
  !physical?
27
27
  end
28
+ alias_method :magical?, :magic?
29
+
30
+ def role
31
+ @role ||= roles.strip
32
+ end
33
+
34
+ def mage?
35
+ !!(roles =~ /Mage/)
36
+ end
37
+
38
+ def hunter?
39
+ !!(roles =~ /Hunter/)
40
+ end
41
+
42
+ def assassin?
43
+ !!(roles =~ /Assassin/)
44
+ end
45
+
46
+ def guardian?
47
+ !!(roles =~ /Guardian/)
48
+ end
49
+
50
+ def warrior?
51
+ !!(roles =~ /Warrior/)
52
+ end
53
+
54
+ def hindu?
55
+ !!(pantheon =~ /Hindu/)
56
+ end
57
+
58
+ def mayan?
59
+ !!(pantheon =~ /Mayan/)
60
+ end
61
+
62
+ def greek?
63
+ !!(pantheon =~ /Greek/)
64
+ end
65
+
66
+ def roman?
67
+ !!(pantheon =~ /Roman/)
68
+ end
69
+
70
+ def egyptian?
71
+ !!(pantheon =~ /Egyptian/)
72
+ end
73
+
74
+ def japanese?
75
+ !!(pantheon =~ /Japanese/)
76
+ end
77
+
78
+ def norse?
79
+ !!(pantheon =~ /Norse/)
80
+ end
81
+
82
+ def chinese?
83
+ !!(pantheon =~ /Chinese/)
84
+ end
85
+
86
+ def short_lore
87
+ lore.split('.')[0..2].join('.') + '.'
88
+ end
28
89
 
29
90
  def inspect
30
91
  "#<Smite::God #{id} '#{name}'>"
@@ -1,125 +1,206 @@
1
1
  module Smite
2
2
  class GodStats < Smite::Object
3
- attr_reader :name, :level, :items
3
+ attr_reader :name, :level, :items, :stacks
4
4
 
5
- def initialize(god_name, data, params = { level: 1 })
5
+ def initialize(god_name, data, params = { level: 0 })
6
6
  super(data)
7
- @name = god_name
8
- @items = params[:items] || []
9
- @level = [[(params[:level].to_i - 1), 19].min, 0].max
7
+ @name = god_name
8
+
9
+ # make sure ratatoskr only has 1 acorn and items are unique
10
+ @items = (params[:items] || []).uniq do |a|
11
+ a.name =~ /acorn/i ? 'acorn' : a.name
12
+ end
13
+
14
+ # make sure only 6 items total
15
+ @items = @items[0..5]
16
+
17
+ # make sure ratatoskr has at least 1 acorn
18
+ if god_name.downcase == 'ratatoskr'
19
+ if !@items.any? { |i| i.name =~ /acorn/i }
20
+ @items[0] = Smite::Game.item('magic acorn')
21
+ end
22
+ end
23
+
24
+ # make sure level is between 0 and 20 (0 for base stats)
25
+ @level = [[params[:level].to_i, 20].min, 0].max
26
+ @stacks = params[:stacks] || {}
10
27
  end
11
28
 
12
29
  def at_level(new_level)
13
- GodStats.new(name, @data, { level: new_level, items: items })
30
+ GodStats.new(name, @data, { level: new_level, items: items, stacks: stacks })
14
31
  end
15
32
 
16
- def with_items(new_items)
17
- GodStats.new(name, @data, { level: level, items: new_items })
33
+ def with_items(new_items, stacks = @stacks)
34
+ stacks.delete_if { |k,v| v.nil? }
35
+ GodStats.new(name, @data, { level: level, items: new_items, stacks: stacks })
18
36
  end
19
37
 
20
- def movement_speed
21
- from_items = bonus_from_items[:movement_speed]
22
- base = data['movement_speed']
23
- scaling = movement_speed_per_level * level
24
-
25
- from_items + base + scaling
26
- end
38
+ def bonus_from_items
39
+ return @item_bonus unless @item_bonus.nil?
27
40
 
28
- def health
29
- from_items = bonus_from_items[:health]
30
- base = data['health']
31
- scaling = health_per_level * level
41
+ @item_bonus = {}
42
+ @item_bonus[:flat] = default_bonus.dup
43
+ @item_bonus[:perc] = default_bonus.dup
32
44
 
33
- from_items + base + scaling
34
- end
45
+ # only accept physical items for physical gods and vice versa
46
+ physical = Smite::Game.god(@name).physical?
47
+ @items = @items.select do |item|
48
+ physical ? item.physical? : item.magic?
49
+ end
50
+ return @item_bonus if items.empty?
35
51
 
36
- def mana
37
- from_items = bonus_from_items[:mana]
38
- base = data['mana']
39
- scaling = mana_per_level * level
52
+ bonus_from_active_item_effects
53
+ bonus_from_passive_item_effects
40
54
 
41
- from_items + base + scaling
55
+ @item_bonus
42
56
  end
43
57
 
44
- def mp5
45
- from_items = bonus_from_items[:mp5]
46
- base = data['mp5']
47
- scaling = (mp5_per_level * level.to_f).to_i
48
-
49
- from_items + base + scaling
58
+ def magical_protection
59
+ magic_protection
50
60
  end
51
61
 
52
- def hp5
53
- from_items = bonus_from_items[:hp5]
54
- base = data['hp5']
55
- scaling = (hp5_per_level * level.to_f).to_i
56
-
57
- from_items + base + scaling
62
+ def magic_power
63
+ magical_power
58
64
  end
59
65
 
60
66
  def attack_speed
61
- from_items = bonus_from_items[:attack_speed]
62
- base = data['attack_speed']
63
- scaling = (attack_speed_per_level * level.to_f).to_i
64
-
65
- from_items + base + scaling
67
+ [value_for(:attack_speed), 2.5].min
66
68
  end
67
69
 
68
- def magical_power
69
- from_items = bonus_from_items[:magical_power]
70
- base = data['magical_power']
71
- scaling = magical_power_per_level * level
72
-
73
- from_items + base + scaling
70
+ def movement_speed
71
+ raw_speed = value_for(:movement_speed)
72
+
73
+ ret = if raw_speed <= 457
74
+ raw_speed
75
+ elsif raw_speed <= 540.5
76
+ dr = raw_speed - 457
77
+ 457 + 0.8 * dr
78
+ else
79
+ dr = raw_speed - 540.5
80
+ 457 + (540.5 - 457) * 0.8 + dr * 0.5
81
+ end
82
+ ret.round
74
83
  end
75
84
 
76
- def magic_protection
77
- from_items = bonus_from_items[:magic_protection]
78
- base = data['magic_protection']
79
- scaling = (magic_protection_per_level * level.to_f).to_i
80
-
81
- from_items + base + scaling
85
+ def summary
86
+ attributes.each_with_object({}) do |attr, hash|
87
+ hash[attr.to_sym] = send(attr.to_sym)
88
+ end
82
89
  end
83
90
 
84
- def physical_power
85
- from_items = bonus_from_items[:physical_power]
86
- base = data['physical_power']
87
- scaling = physical_power_per_level * level
88
-
89
- from_items + base + scaling
91
+ def inspect
92
+ "#<Smite::GodStats '#{name}' Level #{level}>"
90
93
  end
91
94
 
92
- def physical_protection
93
- from_items = bonus_from_items[:physical_protection]
94
- base = data['physical_protection']
95
- scaling = (physical_protection_per_level * level.to_f).to_i
96
-
97
- from_items + base + scaling
95
+ def method_missing(method)
96
+ if data.member?(method.to_s) && !(method.to_s =~ /level/)
97
+ value_for(method)
98
+ else
99
+ super
100
+ end
98
101
  end
99
102
 
100
- def bonus_from_items
101
- return @item_bonus unless @item_bonus.nil?
103
+ private
104
+
105
+ def value_for(attribute)
106
+ scaling = send("#{attribute}_per_level".to_sym) * level.to_f
107
+ flat_from_items = bonus_from_items[:flat][attribute.to_sym]
108
+ perc_from_items = bonus_from_items[:perc][attribute.to_sym]
109
+
110
+ passive = from_god_passive(attribute) + from_item_passive(attribute)
111
+ base = data[attribute.to_s]
112
+
113
+ flat_amount = (flat_from_items + base + scaling + passive)
114
+
115
+ ret = (flat_amount * (perc_from_items + 1)).round(2)
116
+ attribute =~ /5|attack/ ? ret : ret.round
117
+ end
102
118
 
103
- @item_bonus = default_bonus
104
- items.map(&:effects).flatten.select do |effect|
119
+ def bonus_from_active_item_effects
120
+ # Active effects first
121
+ items.map(&:active_effects).flatten.select do |effect|
105
122
  next unless attributes.include?(effect.attribute)
106
- @item_bonus[effect.attribute.to_sym] += effect.amount
107
- end
108
123
 
109
- @item_bonus
124
+ if effect.percentage?
125
+ @item_bonus[:perc][effect.attribute.to_sym] += effect.amount/100.0
126
+ else
127
+ @item_bonus[:flat][effect.attribute.to_sym] += effect.amount
128
+ end
129
+ end
110
130
  end
111
131
 
112
- def summary
113
- attributes.each_with_object({}) do |attr, hash|
114
- hash[attr.to_sym] = send(attr.to_sym)
132
+ def bonus_from_passive_item_effects
133
+ # passive (potentially stacking) effects second
134
+ items.select do |item|
135
+ item.passive_effects.each do |effect|
136
+ next unless attributes.include?(effect.attribute)
137
+
138
+ base_stacks = item.stacking? ? 0 : 1
139
+ multiplier = if @stacks.empty? || @stacks[item.name.downcase].nil?
140
+ base_stacks
141
+ else
142
+ [ [@stacks[item.name.downcase], base_stacks].max , item.max_stacks ].min.to_i
143
+ end
144
+
145
+ if effect.percentage?
146
+ @item_bonus[:perc][effect.attribute.to_sym] += multiplier * effect.amount/100.0
147
+ else
148
+ @item_bonus[:flat][effect.attribute.to_sym] += multiplier * effect.amount
149
+ end
150
+ end
115
151
  end
116
152
  end
117
153
 
118
- def inspect
119
- "#<Smite::GodStats '#{name}' Level #{level + 1}>"
154
+ def from_god_passive(attribute)
155
+ return 0 unless attribute.to_s =~ /power/
156
+
157
+ if attribute == :physical_power
158
+ case name
159
+ when 'Mercury'
160
+ (movement_speed - 375) * 0.25
161
+ when 'Vamana'
162
+ physical_protection * 0.20
163
+ else
164
+ 0
165
+ end
166
+ else
167
+ case name
168
+ when 'Scylla'
169
+ case level
170
+ when 0..7 then 0
171
+ when 8..12 then 20
172
+ when 13..16 then 40
173
+ when 17..18 then 60
174
+ when 19 then 80
175
+ end
176
+ when 'Ares'
177
+ 30 * items.count(&:aura?)
178
+ when 'Kukulkan'
179
+ mana * 0.05
180
+ else
181
+ 0
182
+ end
183
+ end
120
184
  end
121
185
 
122
- private
186
+ def from_item_passive(attribute)
187
+ case attribute.to_s
188
+ when /magical_power/i
189
+ if items.any? { |i| i.name =~ /Book of Thoth/i }
190
+ mana * 0.03
191
+ else
192
+ 0
193
+ end
194
+ when /physical_power/i
195
+ if items.any? { |i| i.name =~ /Transcendence/i }
196
+ mana * 0.03
197
+ else
198
+ 0
199
+ end
200
+ else
201
+ 0
202
+ end
203
+ end
123
204
 
124
205
  def default_bonus
125
206
  @default_bonus ||= attributes.each_with_object({}) { |attr, hash| hash[attr.to_sym] = 0 }
@@ -128,5 +209,13 @@ module Smite
128
209
  def movement_speed_per_level
129
210
  0
130
211
  end
212
+
213
+ def magical_power_per_level
214
+ 0
215
+ end
216
+
217
+ def physical_power_per_level
218
+ 0
219
+ end
131
220
  end
132
221
  end