urbanterror 0.4 → 0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/urbanterror.rb +26 -54
  2. metadata +3 -3
@@ -52,65 +52,37 @@ class UrbanTerror
52
52
  end
53
53
  end
54
54
 
55
- def self.gearCalc(gearArray)
56
- initial = 63
57
- selected_i = 0
58
- selected = []
59
- gearMaster = {
60
- 'grenades' => 1,
61
- 'snipers' => 2,
62
- 'spas' => 4,
63
- 'pistols' => 8,
64
- 'autos' => 16,
65
- 'negev' => 32
66
- }
67
-
68
- gearArray.each do |w|
69
- if gearMaster.has_key? w
70
- selected << gearMaster[w]
71
- end
72
- end
55
+ GEAR_TYPES = {
56
+ 'grenades' => 1,
57
+ 'snipers' => 2,
58
+ 'spas' => 4,
59
+ 'pistols' => 8,
60
+ 'autos' => 16,
61
+ 'negev' => 32
62
+ }
73
63
 
74
- selected_i = selected.inject(:+)
75
- return initial - selected_i
64
+ MAX_GEAR = 63
65
+
66
+ def self.gearCalc(gearArray)
67
+ MAX_GEAR - gearArray.select{|w| GEAR_TYPES.has_key? w }.map{|w| GEAR_TYPES[w] }.reduce(:+)
76
68
  end
77
69
 
78
70
  def self.reverseGearCalc(number)
79
- weapons = []
80
- gearMaster = {
81
- 1 => 'grenades',
82
- 2 => 'snipers',
83
- 4 => 'spas',
84
- 8 => 'pistols',
85
- 16 => 'autos',
86
- 32 => 'negev'
87
- }
88
-
89
- gearMaster.each do |num, weapon|
90
- if number & num == 0
91
- weapons << weapon
92
- end
93
- end
94
- return weapons
71
+ GEAR_TYPES.select{|weapon, gear_val| number & gear_val == 0 }.map(&:first)
95
72
  end
73
+
74
+ GAME_MODES = {
75
+ 0 => ['Free For All', 'FFA'],
76
+ 3 => ['Team Death Match', 'TDM'],
77
+ 4 => ['Team Survivor', 'TS'],
78
+ 5 => ['Follow the Leader', 'FTL'],
79
+ 6 => ['Capture and Hold', 'CAH'],
80
+ 7 => ['Capture the Flag', 'CTF'],
81
+ 8 => ['Bomb mode', 'BOMB']
82
+ }
96
83
 
97
84
  def self.matchType(number, abbreviate=false)
98
- # 0=FreeForAll, 3=TeamDeathMatch, 4=Team Survivor, 5=Follow the Leader, 6=Capture and Hold, 7=Capture The Flag, 8=Bombmode
99
- match = {
100
- 0 => ['Free For All', 'FFA'],
101
- 3 => ['Team Death Match', 'TDM'],
102
- 4 => ['Team Survivor', 'TS'],
103
- 5 => ['Follow the Leader', 'FTL'],
104
- 6 => ['Capture and Hold', 'CAH'],
105
- 7 => ['Capture the Flag', 'CTF'],
106
- 8 => ['Bomb mode', 'BOMB']
107
- }
108
-
109
- throw "#{number} is not a valid gametype." if not match.has_key? number
110
- if abbreviate
111
- match[number][1]
112
- else
113
- match[number][0]
114
- end
85
+ raise "#{number} is not a valid gametype." unless GAME_MODES.has_key? number
86
+ match[number][abbreviate ? 1 : 0]
115
87
  end
116
- end
88
+ end
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: urbanterror
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 1
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 4
9
- version: "0.4"
8
+ - 5
9
+ version: "0.5"
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ricky Elrod