Class: Smite::Item
Instance Attribute Summary
Attributes inherited from Object
#data
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Object
#attributes, #method_missing
Constructor Details
#initialize(data) ⇒ Item
Returns a new instance of Item.
4
5
6
7
8
9
10
11
12
|
# File 'lib/smite/item.rb', line 4
def initialize(data)
super(data)
effects = @data.delete('item_description')
@data['passive'] = effects['SecondaryDescription']
@data['description'] = effects['Description']
@data['active_effects'] = effects['Menuitems'].map do |eff|
ItemEffect.new(device_name, eff)
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Smite::Object
Class Method Details
.magical_item_trees ⇒ Object
18
19
20
|
# File 'lib/smite/item.rb', line 18
def self.magical_item_trees
[7610, 8247, 9631, 9847, 9849, 9855, 9858, 9860, 10603, 11123]
end
|
.physical_item_trees ⇒ Object
14
15
16
|
# File 'lib/smite/item.rb', line 14
def self.physical_item_trees
[7573, 7827, 7922, 8268, 9624, 9812, 9825, 9830, 9833, 10190, 10662, 11122, 11468, 12667, 12671]
end
|
Instance Method Details
#active? ⇒ Boolean
Also known as:
relic?
34
35
36
|
# File 'lib/smite/item.rb', line 34
def active?
type == 'Active' || type == 'Relic'
end
|
#aura? ⇒ Boolean
55
56
57
|
# File 'lib/smite/item.rb', line 55
def aura?
!!(passive =~ /AURA/)
end
|
#consumable? ⇒ Boolean
39
40
41
|
# File 'lib/smite/item.rb', line 39
def consumable?
type == 'Consumable'
end
|
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/smite/item.rb', line 75
def cost
return @cost unless @cost.nil?
@cost = price
child_id = child_item_id
until child_id == 0
child = Smite::Game.item(child_id)
@cost += child.price
child_id = child.child_item_id
end
@cost
end
|
108
109
110
|
# File 'lib/smite/item.rb', line 108
def effects
active_effects + passive_effects
end
|
104
105
106
|
# File 'lib/smite/item.rb', line 104
def inspect
"#<Smite::Item #{item_id} '#{device_name}'>"
end
|
#item? ⇒ Boolean
43
44
45
|
# File 'lib/smite/item.rb', line 43
def item?
type == 'Item'
end
|
#item_tree_root ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/smite/item.rb', line 22
def item_tree_root
return @root unless @root.nil?
@root = self
child_id = @root.child_item_id
until child_id == 0
@root = Smite::Game.item(child_id)
child_id = @root.child_item_id
end
@root
end
|
#magic? ⇒ Boolean
Also known as:
magical?
99
100
101
|
# File 'lib/smite/item.rb', line 99
def magic?
@magic ||= !Smite::Item.physical_item_trees.include?(item_tree_root.item_id)
end
|
#max_stacks ⇒ Object
68
69
70
71
72
73
|
# File 'lib/smite/item.rb', line 68
def max_stacks
@max_stacks = 1 unless stacking?
return @max_stacks unless @max_stacks.nil?
@max_stacks ||= passive.match(/max\.?.+?(\d+)/i)[1].to_i
end
|
91
92
93
|
# File 'lib/smite/item.rb', line 91
def name
device_name
end
|
#passive? ⇒ Boolean
51
52
53
|
# File 'lib/smite/item.rb', line 51
def passive?
!passive.empty?
end
|
#passive_effects ⇒ Object
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
# File 'lib/smite/item.rb', line 112
def passive_effects
@passive_effects = [] unless passive?
return @passive_effects unless @passive_effects.nil?
fx = Smite::Game.item_effects + ['magical_protection', 'lifesteal']
fx = fx.map { |e| e.tr('_', ' ') + "s?" }.join('\b|')
amt = '(\+?[\.\d]+%?)'
r1 = /gain #{amt} (#{fx}\b)(?: and #{amt} (#{fx}\b))?/i
r2 = /increas(?:es?|ing)?(?: your)? (#{fx}\b) by #{amt}(?: and (#{fx}\b) by #{amt})?/i
r3 = /grant(?:s you|ing)? #{amt} (#{fx}\b) and #{amt} (#{fx}\b)/i
r4 = /your (#{fx}\b) increases by #{amt}/i
scanned = [r1,r2,r3,r4].inject([]) { |arr, regex| arr << (passive.scan(regex)[0]||[]).compact }
scanned = scanned.reject(&:empty?)
scanned = scanned.map do |e|
e.each_slice(2).to_a.map do |a|
a = a.minmax
a[1] = a[1][-1] == 's' ? a[1][0...-1] : a[1]
{ 'Description' => a[1], 'Value' => a[0] }
end
end
@passive_effects = scanned.flatten.map do |effect_data|
ItemEffect.new(name, effect_data)
end
end
|
#physical? ⇒ Boolean
95
96
97
|
# File 'lib/smite/item.rb', line 95
def physical?
@physical ||= !Smite::Item.magical_item_trees.include?(item_tree_root.item_id)
end
|
#stacking?(perma_stacks = false) ⇒ Boolean
59
60
61
62
63
64
65
66
|
# File 'lib/smite/item.rb', line 59
def stacking?(perma_stacks = false)
return false unless passive?
if perma_stacks
!!(passive =~ /(per|for each).+?kill/i)
else
!!(passive =~ /stack/i)
end
end
|
#starter? ⇒ Boolean
47
48
49
|
# File 'lib/smite/item.rb', line 47
def starter?
starting_item
end
|
87
88
89
|
# File 'lib/smite/item.rb', line 87
def tier
item_tier
end
|