lib/mwo/weapon.rb in mwo-0.0.1 vs lib/mwo/weapon.rb in mwo-0.0.2

- old
+ new

@@ -1,8 +1,21 @@ class MWO::Weapon - attr_accessor :weapon_id, :name, :type, :num_firing, :damage, :heatpenalty, :heat, :factions + attr_accessor :weapon_id, :name, :type, :num_firing, :damage, :heatpenalty, :heat, :inner_sphere, :clan, + :category, :health, :slots, :projectileclass, :heatdamage, + :minheatpenaltylevel, :impulse, :cooldown, :ammo_type, :ammo_per_shot, + :min_range, :long_range, :max_range, :tons, :duration, :lifetime, + :speed, :volleydelay, :gravity, :max_depth, :vis_range, :heat_penalty_id, + :maxheight, :radius, :artemis_ammo_type, :formation_size, + :formation_size_per_index, :spread,:null_range, :peakdist, :peaktime, + :minheight, :uselock, :trackingstrength, :hitpoints, :use_tag, :formation_speed, :emp, :coneoffire, + :heatinctime, :trgheatinctime, :crit_dam_mult, :crit_chance_increase, :rof, + :groupedlocally, :explode_chance, :internal_explosion_dmg, :num_per_shot, + :tag, :tag_spread_factor, :tag_decay, :tag_duration, :needlock, + :shots_during_cooldown, :jamming_chance, :jammed_time, :splash_percent, + :volleysize, :falloffexponent + extend MWO::Utils def initialize args = {} args.each do |k,v| instance_variable_set("@#{k}", v) unless v.nil? @@ -19,18 +32,16 @@ if attrs["category"] == "weapon" weapon = {weapon_id: weapon_id.to_i, name: attrs["name"], - category: attrs["category"], - stats: {}} + category: attrs["category"] + } if attrs["factions"] - weapon[:factions] = {} - attrs["factions"].each do |k,v| - weapon[:factions][to_symbol(k)] = v - end + weapon[:clan] = attrs["factions"]["Clan"] + weapon[:inner_sphere] = attrs["factions"]["InnerSphere"] end attrs["stats"].each do |k,v| weapon[to_symbol(k)] = v end @@ -38,9 +49,29 @@ weapons << new(weapon) end end - return weapons + return weapons.extend MWO::CollectionUtils + end + + def self.energy + all.filter({type: 'Energy'}) + end + + def self.ballistic + all.filter({type: 'Ballistic'}) + end + + def self.missile + all.filter({type: 'Missile'}) + end + + def self.inner_sphere + all.filter({inner_sphere: true}) + end + + def self.clan + all.filter({clan: true}) end end