smite_ruby 1.4.5 → 1.4.6

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: 25feb61882b2f684c7b2c3a719151693dd57f673
4
- data.tar.gz: 935a446bc3a1d8688d254de67faf4c8a43c1d9a8
3
+ metadata.gz: ccff694141365296222915e4cc61decb5162e706
4
+ data.tar.gz: 38f300318daa9cc1c80cd8e70fce3df846cf148e
5
5
  SHA512:
6
- metadata.gz: ccccf5f6c6bc2c47de9ad36bfba1a811a794d958fe4a92c1762d79b65ca91f406d4919b9cfd54443ab9e31398d0b614235a5d7e877002db765f08a9610139c96
7
- data.tar.gz: d82637008babe01c8a05129083c20dcb69a10918bd0b2ce5faf42431e8eb75e3b45c74337834f372d917b03847f65b18a3d86e48e71732e55c808721919539d5
6
+ metadata.gz: a73210acf092f72f83cfa9edf71bf007d383d282c487777e3d6801822a0819c70f2e1d73fbfc17c2e1247162c2ab21f611070391790647bad47e877819422e06
7
+ data.tar.gz: 658baadac807264383473292c98f37725baceee364111b4e06810a355249727f103074fd3c90407311a048563933591e86a15be677e374bf4631e552e829502f
@@ -4,21 +4,23 @@ require 'active_support'
4
4
  module Smite
5
5
  end
6
6
 
7
- require_relative './smite/object.rb'
8
- require_relative './smite/queue.rb'
9
- require_relative './smite/motd.rb'
10
- require_relative './smite/recommended_items.rb'
11
- require_relative './smite/achievements.rb'
12
- require_relative './smite/ability.rb'
13
- require_relative './smite/god_rank.rb'
14
- require_relative './smite/god_stats.rb'
15
- require_relative './smite/god.rb'
16
- require_relative './smite/item_effect.rb'
17
- require_relative './smite/item.rb'
18
- require_relative './smite/friend.rb'
19
- require_relative './smite/data_transform.rb'
20
- require_relative './smite/match.rb'
21
- require_relative './smite/recent_match.rb'
22
- require_relative './smite/player.rb'
23
- require_relative './smite/game.rb'
24
- require_relative './smite/client.rb'
7
+ require 'smite/object.rb'
8
+ require 'smite/queue.rb'
9
+ require 'smite/motd.rb'
10
+ require 'smite/recommended_items.rb'
11
+ require 'smite/achievements.rb'
12
+ require 'smite/ability.rb'
13
+ require 'smite/god_rank.rb'
14
+ require 'smite/god_stats.rb'
15
+ require 'smite/god.rb'
16
+ require 'smite/item_effect.rb'
17
+ require 'smite/item.rb'
18
+ require 'smite/friend.rb'
19
+ require 'smite/data_transform.rb'
20
+ require 'smite/match_achievements.rb'
21
+ require 'smite/competitor.rb'
22
+ require 'smite/full_match.rb'
23
+ require 'smite/match_summary.rb'
24
+ require 'smite/player.rb'
25
+ require 'smite/game.rb'
26
+ require 'smite/client.rb'
@@ -1,6 +1,6 @@
1
1
  module Smite
2
2
  class Client
3
- attr_reader :dev_id, :auth_key, :session_id, :lang
3
+ attr_reader :dev_id, :auth_key, :session_id, :lang, :created
4
4
  include HTTParty
5
5
  base_uri 'http://api.smitegame.com/smiteapi.svc/'
6
6
 
@@ -8,6 +8,7 @@ module Smite
8
8
  @dev_id = dev_id
9
9
  @auth_key = auth_key
10
10
  @lang = [1,2,3,7,9,10,11,12,13].include?(lang) ? lang : 1
11
+ @created = Time.now - 20 * 60
11
12
  create_session
12
13
  end
13
14
 
@@ -106,17 +107,20 @@ module Smite
106
107
  def create_session
107
108
  return @session_id if valid_session?
108
109
 
109
- response = api_call('createsession', [], false)
110
- @session_id = response['session_id']
110
+ response = api_call('createsession', [], false)
111
+ @session_id = response['session_id']
112
+ @created = Time.now
111
113
  end
112
114
 
113
115
  def valid_session?
114
- !!(test_session =~ /successful/i)
116
+ (created + (15 * 60)) > Time.now
115
117
  end
116
118
 
117
119
  private
118
120
 
119
121
  def api_call(method, params = [], session = true)
122
+ create_session if !valid_session? && session
123
+
120
124
  request = request_str(method, params, session)
121
125
  self.class.get(request)
122
126
  end
@@ -0,0 +1,31 @@
1
+ module Smite
2
+ class Competitor < Smite::Object
3
+ def initialize(data)
4
+ data['Queue'] = data['name']
5
+ super
6
+ @data = DataTransform.transform_items(@data)
7
+ @data = DataTransform.transform_match_achievements(@data)
8
+ @data = DataTransform.transform_match_summary(@data)
9
+ end
10
+
11
+ def to_player
12
+ Smite::Game.player(player_id)
13
+ end
14
+
15
+ def partied?
16
+ party_id != 0
17
+ end
18
+
19
+ def winner?
20
+ win_status == 'Winner'
21
+ end
22
+
23
+ def loser?
24
+ !winner?
25
+ end
26
+
27
+ def inspect
28
+ "#<Smite::Competitor '#{match}' '#{player_name}'>"
29
+ end
30
+ end
31
+ end
@@ -24,7 +24,8 @@ module Smite
24
24
 
25
25
  data['abilities'] = ability_fields.values.map do |ability_data|
26
26
  data_attrs = ability_data.slice('Id', 'Summary', 'URL')
27
- desc = ability_data['Description']['itemDescription']
27
+ desc = ability_data['Description']
28
+ desc = desc.nil? ? {} : desc['itemDescription']
28
29
 
29
30
  Ability.new(data_attrs.merge(desc))
30
31
  end
@@ -32,13 +33,13 @@ module Smite
32
33
  data.except(*ability_filter_fields)
33
34
  end
34
35
 
35
- def transform_recent_match(data)
36
+ def transform_match_summary(data)
36
37
  return data unless data['queue']
37
38
 
38
39
  if data['queue'] =~ /League/
39
40
  data
40
41
  else
41
- data.except(*recent_match_filter_fields)
42
+ data.except(*match_summary_filter_fields)
42
43
  end
43
44
  end
44
45
 
@@ -67,8 +68,40 @@ module Smite
67
68
  data
68
69
  end
69
70
 
71
+ def transform_match_achievements(data)
72
+ ach_fields = data.slice(*match_achievement_map_fields)
73
+ return data if ach_fields.empty?
74
+
75
+ data['match_achievements'] = MatchAchievements.new(ach_fields)
76
+ data.except(*match_achievement_filter_fields)
77
+ end
78
+
70
79
  private
71
80
 
81
+ def match_achievement_map_fields
82
+ %w[
83
+ kills_bot
84
+ kills_double
85
+ kills_fire_giant
86
+ kills_first_blood
87
+ kills_gold_fury
88
+ kills_penta
89
+ kills_phoenix
90
+ kills_player
91
+ kills_quadra
92
+ kills_siege_juggernaut
93
+ kills_single
94
+ kills_triple
95
+ kills_wild_juggernaut
96
+ player_name
97
+ match
98
+ ]
99
+ end
100
+
101
+ def match_achievement_filter_fields
102
+ match_achievement_map_fields - %w(player_name match)
103
+ end
104
+
72
105
  def item_map_fields
73
106
  %w(
74
107
  active_id1 active_id2 item_id1 item_id2
@@ -80,6 +113,9 @@ module Smite
80
113
  item_map_fields + %w(
81
114
  item_1 item_2 item_3 item_4 item_5
82
115
  item_6 active_1 active_2 active_3
116
+ item_active_1 item_active_2 item_active_3
117
+ item_purch_1 item_purch_2 item_purch_3
118
+ item_purch_4 item_purch_5 item_purch_6
83
119
  )
84
120
  end
85
121
 
@@ -98,7 +134,7 @@ module Smite
98
134
  )
99
135
  end
100
136
 
101
- def recent_match_filter_fields
137
+ def match_summary_filter_fields
102
138
  %w(
103
139
  ban1 ban2 ban3 ban4 ban5 ban6
104
140
  ban1_id ban2_id ban3_id
@@ -0,0 +1,57 @@
1
+ module Smite
2
+ class FullMatch < Smite::Object
3
+ attr_accessor :queue, :match
4
+
5
+ def initialize(data)
6
+ data = { 'competitors' => data.map { |k, v| Smite::Competitor.new(k) } }
7
+ super
8
+ @queue = competitors[0].queue
9
+ @match = competitors[0].match
10
+ end
11
+
12
+ def teams
13
+ { team1: team1, team2: team2 }
14
+ end
15
+
16
+ def parties
17
+ competitors.group_by(&:party_id)
18
+ end
19
+
20
+ def players
21
+ competitors
22
+ end
23
+
24
+ def size
25
+ competitors.count
26
+ end
27
+
28
+ def ranked?
29
+ queue =~ /Ranked/
30
+ end
31
+
32
+ def size_str
33
+ "#{size/2} v #{size/2}"
34
+ end
35
+
36
+ def team1
37
+ competitors[0...size/2]
38
+ end
39
+
40
+ def team2
41
+ competitors[size/2..-1]
42
+ end
43
+
44
+ def winning_team
45
+ return @winner unless @winner.nil?
46
+
47
+ @winner = teams.find do |team, competitors|
48
+ competitors.all? { |competitor| competitor.winner? }
49
+ end
50
+ @winner = @winner[0]
51
+ end
52
+
53
+ def inspect
54
+ "#<Smite::FullMatch #{match} #{queue}>"
55
+ end
56
+ end
57
+ end
@@ -22,12 +22,13 @@ module Smite
22
22
  end
23
23
 
24
24
  def match(match_id)
25
- @matches ||= {}
26
- @matches[match_id] ||= Match.new(client.match_details(match_id))
25
+ match_data = client.match_details(match_id)
26
+ match_data.empty? ? nil : FullMatch.new(match_data)
27
27
  end
28
28
 
29
- def player(player_name)
30
- Player.new(player_name)
29
+ def player(player_name_or_id)
30
+ player_data = client.player(player_name_or_id)
31
+ player_data.empty? ? nil : Player.new(player_data[0])
31
32
  end
32
33
 
33
34
  def motd_now
@@ -5,16 +5,11 @@ module Smite
5
5
  end
6
6
 
7
7
  def level
8
- case rank
9
- when 0 then 'none'
10
- when (1..4) then 'gold'
11
- when (5..9) then 'legendary'
12
- when 10 then 'diamond'
13
- end
8
+ self.class.level(rank)
14
9
  end
15
10
 
16
11
  def mastery
17
- mastered ? 'mastered' : 'unmastered'
12
+ mastered? ? 'mastered' : 'unmastered'
18
13
  end
19
14
 
20
15
  def mastered?
@@ -24,5 +19,14 @@ module Smite
24
19
  def inspect
25
20
  "#<Smite::GodRank '#{god.name}' Lvl. #{rank} (#{level})>"
26
21
  end
22
+
23
+ def self.level(rank)
24
+ case rank
25
+ when 0 then 'none'
26
+ when (1..4) then 'gold'
27
+ when (5..9) then 'legendary'
28
+ when 10 then 'diamond'
29
+ end
30
+ end
27
31
  end
28
32
  end
@@ -6,7 +6,7 @@ module Smite
6
6
  super(data)
7
7
  @name = god_name
8
8
  @items = params[:items] || []
9
- @level = (params[:level].to_i - 1) % 20
9
+ @level = [[(params[:level].to_i - 1), 19].min, 0].max
10
10
  end
11
11
 
12
12
  def at_level(new_level)
@@ -18,14 +18,15 @@ module Smite
18
18
  end
19
19
 
20
20
  def movement_speed
21
- from_items = item_bonus[:movement_speed]
21
+ from_items = bonus_from_items[:movement_speed]
22
22
  base = data['movement_speed']
23
+ scaling = movement_speed_per_level * level
23
24
 
24
- from_items + base
25
+ from_items + base + scaling
25
26
  end
26
27
 
27
28
  def health
28
- from_items = item_bonus[:health]
29
+ from_items = bonus_from_items[:health]
29
30
  base = data['health']
30
31
  scaling = health_per_level * level
31
32
 
@@ -33,7 +34,7 @@ module Smite
33
34
  end
34
35
 
35
36
  def mana
36
- from_items = item_bonus[:mana]
37
+ from_items = bonus_from_items[:mana]
37
38
  base = data['mana']
38
39
  scaling = mana_per_level * level
39
40
 
@@ -41,7 +42,7 @@ module Smite
41
42
  end
42
43
 
43
44
  def mp5
44
- from_items = item_bonus[:mp5]
45
+ from_items = bonus_from_items[:mp5]
45
46
  base = data['mp5']
46
47
  scaling = (mp5_per_level * level.to_f).to_i
47
48
 
@@ -49,7 +50,7 @@ module Smite
49
50
  end
50
51
 
51
52
  def hp5
52
- from_items = item_bonus[:hp5]
53
+ from_items = bonus_from_items[:hp5]
53
54
  base = data['hp5']
54
55
  scaling = (hp5_per_level * level.to_f).to_i
55
56
 
@@ -57,38 +58,46 @@ module Smite
57
58
  end
58
59
 
59
60
  def attack_speed
60
- from_items = item_bonus[:attack_speed]
61
+ from_items = bonus_from_items[:attack_speed]
61
62
  base = data['attack_speed']
62
63
  scaling = (attack_speed_per_level * level.to_f).to_i
63
64
 
64
65
  from_items + base + scaling
65
66
  end
66
67
 
67
- def magic_power
68
- from_items = item_bonus[:magic_power]
69
- base = data['magic_power']
70
- scaling = magic_power_per_level * level
68
+ def magical_power
69
+ from_items = bonus_from_items[:magical_power]
70
+ base = data['magical_power']
71
+ scaling = magical_power_per_level * level
71
72
 
72
73
  from_items + base + scaling
73
74
  end
74
75
 
75
76
  def magic_protection
76
- from_items = item_bonus[:magic_protection]
77
+ from_items = bonus_from_items[:magic_protection]
77
78
  base = data['magic_protection']
78
79
  scaling = (magic_protection_per_level * level.to_f).to_i
79
80
 
80
81
  from_items + base + scaling
81
82
  end
82
83
 
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
90
+ end
91
+
83
92
  def physical_protection
84
- from_items = item_bonus[:physical_protection]
93
+ from_items = bonus_from_items[:physical_protection]
85
94
  base = data['physical_protection']
86
95
  scaling = (physical_protection_per_level * level.to_f).to_i
87
96
 
88
97
  from_items + base + scaling
89
98
  end
90
99
 
91
- def item_bonus
100
+ def bonus_from_items
92
101
  return @item_bonus unless @item_bonus.nil?
93
102
 
94
103
  @item_bonus = default_bonus
@@ -115,5 +124,9 @@ module Smite
115
124
  def default_bonus
116
125
  @default_bonus ||= attributes.each_with_object({}) { |attr, hash| hash[attr.to_sym] = 0 }
117
126
  end
127
+
128
+ def movement_speed_per_level
129
+ 0
130
+ end
118
131
  end
119
132
  end
@@ -1,6 +1,6 @@
1
1
  module Smite
2
2
  class ItemEffect < Smite::Object
3
- attr_reader :device_name, :percentage
3
+ attr_reader :device_name
4
4
 
5
5
  def initialize(item, data)
6
6
  @device_name = item
@@ -8,7 +8,7 @@ module Smite
8
8
  end
9
9
 
10
10
  def percentage?
11
- !@percentage.nil?
11
+ !percentage.nil?
12
12
  end
13
13
 
14
14
  def inspect