maldición()   B
last analyzed

Complexity

Conditions 6

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
dl 0
loc 21
rs 7.8867
c 0
b 0
f 0
1
# encoding: UTF-8
2
3
# Tirada de dados, Sigmar
4
def dado_sigmar
5
  # Returns a random dice-face string
6
  %w(hammer comet plus blank eagle eagle)[rand(6)]
7
end
8
9
# Tirada de dados, 2d6 del tesoro, individual
10
def dado_tesoro
11
  # Returns a value from 1 to 6 (normal dice)
12
  rand(6) + 1
13
end
14
15
# Main method 2d6 + Sigmar dice
16
def tesoro(sigmar, dado1, dado2)
17
  # 12 values (2d6) ordered
18
  valores = %w(pifia vacia maldición trampa monstruo oro
19
               perg pot comida alijo cofre)
20
  # Requests (send) a method, named equals to the values.
21
  send(valores[dado1 + dado2 - 2], sigmar, dado1, dado2)
22
end
23
24
# posibles 5 valores del dado sigmar
25
def caras_sigmar
26
  # El sexto es eagle x2
27
  %w(eagle plus blank hammer comet)
28
end
29
30
# Resultados dependiendo de Sigmar
31
# --------------------------------
32
33
def buscar_tesoros (tipo, sigmar, *doble) # DB in YAML format
34
  bt  = load_yaml('buscar_tesoros')[tipo]
35
  sig = doble ? sigmar + '2' : sigmar
36
  bt[sig] || bt['default']
37
end
38
39
def pifia(sigmar, _dado1, _dado2) # 2
40
  buscar_tesoros('pifia', sigmar)
41
end
42
43
def vacia(sigmar, _dado1, _dado2) # 3
44
  buscar_tesoros('vacía', sigmar)
45
end
46
47
def maldición(sigmar, dado1, dado2) # 4
0 ignored issues
show
Coding Style introduced by
The method maldición seems to be too complex. Perceived cyclomatic complexity is 11 with a maxiumum of 6 permitted.
Loading history...
Coding Style introduced by
This method is 19 lines long. Your coding style permits a maximum length of 10.
Loading history...
Complexity Coding Style introduced by
The method maldición seems to be too complex. Perceived complexity is 8 with a maxiumum of 7 permitted.
Loading history...
coding-style introduced by
Use only ascii symbols in identifiers.
Loading history...
Coding Style introduced by
Your coding style requires you to use snake_case for method names. That is all lowercase with underscores to seperate words.
Loading history...
48
  doble = dado1 == dado2 # special condition
49
  case sigmar
50
  when 'eagle'  then
51
    "Maldición: #{doble ? 'Legañas: Tu siguiente tirada de ataque causará daños      a la miniatura más cercana' : 'Hirsutismo: -1 Reputación salvo enanos'} "
0 ignored issues
show
Coding Style introduced by
This line is 158 characters long. Your coding style permits a maximum length of 80
Loading history...
52
  when 'plus'   then
53
    "Maldición: #{doble ? 'Indispuesto: Tu siguiente hechizo o tirada de
0 ignored issues
show
Coding Style introduced by
Your coding style requires you to prefer if/unless over the ternary operator if the expression spans multiple lines.
Loading history...
54
     defensa fallará' : 'Alopecia: -1 Reputación si eres enano o mujer.'} "
55
  when 'blank'  then
56
    "Maldición: #{doble ? 'Patán: Tu siguiente tirada de tesoros tirará un dado
0 ignored issues
show
Coding Style introduced by
Your coding style requires you to prefer if/unless over the ternary operator if the expression spans multiple lines.
Loading history...
57
     menos' : 'Yuyu: En un momento dado, el MB puede hacer repetir 1d6.'} "
58
  when 'hammer' then
59
    "Maldición: #{doble ? 'Masoquismo: Golpéate sin armas con cada 1 que saques
0 ignored issues
show
Coding Style introduced by
Your coding style requires you to prefer if/unless over the ternary operator if the expression spans multiple lines.
Loading history...
60
    hasta el final del reto' : 'Alopecia: -1 Reputación si eres enano o
61
    mujer.'} "
62
  when 'comet'  then
63
    "Maldición: #{doble ? 'Mirado por un tuerto: El oro que obtengas en
0 ignored issues
show
Coding Style introduced by
Your coding style requires you to prefer if/unless over the ternary operator if the expression spans multiple lines.
Loading history...
64
     adelante, es falso.' : 'Infortunio: El MB podrá hacer repetir una tirada
65
     cualquiera.'} "
66
  end
67
end
68
69
def trampa(sigmar, _dado1, _dado2) # 5
70
  buscar_tesoros('trampa', sigmar)
71
end
72
73
def monstruo(sigmar, _dado1, _dado2) # 6
74
  buscar_tesoros('monstruo', sigmar)
75
end
76
77
def oro(sigmar, _dado1, _dado2) # 7
78
  buscar_tesoros('oro', sigmar)
79
end
80
81
def perg(sigmar, _dado1, _dado2) # 8
82
  buscar_tesoros('pergamino', sigmar)
83
end
84
85
def pot(sigmar, _dado1, _dado2) # 9
86
  buscar_tesoros('poción', sigmar)
87
end
88
89
def comida(sigmar, _dado1, _dado2) # 10
90
  buscar_tesoros('comida', sigmar)
91
end
92 View Code Duplication
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
93
def alijo(sigmar, _dado1, _dado2) # 11
94
  r = %w(gema runa gema gema joya)
95
  c = [gema_random, runa_random, 'estropeada', gema_random, joya_random]
96
  r[caras_sigmar.index(sigmar)] + ': ' + c[caras_sigmar.index(sigmar)]
97
end
98 View Code Duplication
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
99
def cofre(sigmar, _dado1, _dado2) # 12
100
  r = %w(gema joya runa objeto artefacto)
101
  c = [gema_random, joya_random, runa_random, 'mágico', 'de reto']
102
  r[caras_sigmar.index(sigmar)] + ': ' + c[caras_sigmar.index(sigmar)]
103
end
104
105
# Genera una gema al azar
106
def gema_random
107
  gemas.sample.name
108
end
109
110
# Genera una joya al azar
111
def joya_random
112
  joyas.sample.name
113
end
114
115
# Genera una runa al azar
116
def runa_random
117
  runas.sample.name
118
end
119