1
|
|
|
#!/usr/bin/ruby |
2
|
|
|
# encoding: UTF-8 |
3
|
|
|
|
4
|
|
|
# Clase principal de cualquier item |
5
|
1 |
|
class Item < Hash |
6
|
1 |
|
attr_accessor :id, :enchants, :max, :precio, |
7
|
|
|
:runas, :joyas, :ranuras, :gemas, |
8
|
|
|
:legendario, :unico, :artefacto, :size |
9
|
|
|
|
10
|
1 |
|
def initialize(args) |
11
|
|
|
args.each do |k, v| |
12
|
|
|
instance_variable_set("@#{k}".to_sym, v) unless v.nil? |
13
|
|
|
end |
14
|
|
|
end |
15
|
|
|
|
16
|
1 |
|
def enchanted? |
17
|
|
|
enchants |
18
|
|
|
end |
19
|
|
|
|
20
|
1 |
|
def item |
21
|
|
|
self.class.to_s.downcase |
22
|
|
|
end |
23
|
|
|
|
24
|
1 |
|
def engarzado? |
25
|
|
|
gemas || joyas || runas |
26
|
|
|
end |
27
|
|
|
|
28
|
1 |
|
def mundano? |
29
|
|
|
gemas.nil? && joyas.nil? && runas.nil? && ranuras.nil? |
30
|
|
|
end |
31
|
|
|
|
32
|
1 |
|
def ranuras_libres |
33
|
|
|
total = 0 |
34
|
|
|
total += ranuras if ranuras |
35
|
|
|
total -= gemas.size if gemas |
36
|
|
|
total -= runas.size if runas |
37
|
|
|
total -= joyas.size if joyas |
38
|
|
|
total |
39
|
|
|
end |
40
|
|
|
|
41
|
1 |
|
def precio_venta |
|
|
|
|
42
|
|
|
pvp = precio |
43
|
|
|
pvp += (enchants.count * 100) if enchants |
44
|
|
|
pvp += (runas.count * 100) if runas |
45
|
|
|
pvp += (joyas.count * 100) if joyas |
46
|
|
|
if gemas |
47
|
|
|
gemas.each do |g| |
48
|
|
|
pvp += [10, 25, 50, 100, 250, 500, 50][g / 8] |
49
|
|
|
end |
50
|
|
|
end |
51
|
|
|
if ranuras_libres > 0 |
52
|
|
|
ranuras_libres.times do |_i| |
53
|
|
|
pvp *= 1.1 |
54
|
|
|
end |
55
|
|
|
end |
56
|
|
|
pvp.to_i |
57
|
|
|
end |
58
|
|
|
|
59
|
1 |
|
def img_path |
60
|
|
|
carpeta = enchanted? ? "magic/#{name + enchants.size.to_s}" : name |
61
|
|
|
"'../images/#{item}s/#{carpeta}.png'" |
62
|
|
|
end |
63
|
|
|
|
64
|
1 |
|
def tier? |
65
|
|
|
combo = false |
66
|
|
|
mix = { 'gemas' => gemas, 'runas' => runas, 'joyas' => joyas } |
67
|
|
|
tiers.each do |t| |
68
|
|
|
combo = t if t['mix'] == mix |
69
|
|
|
end |
70
|
|
|
combo |
71
|
|
|
end |
72
|
|
|
|
73
|
1 |
|
def tier_color |
74
|
|
|
tier? ? tier?['color'] : 'black' |
75
|
|
|
end |
76
|
|
|
end |
77
|
|
|
|