You are here

Basic Item representation in Ruby

  1. class Item
  2.   attr_accessor :id, :name, :icon, :quality, :bonding, :class_id, :equip_inventory_type,
  3.                 :equip_subclass, :strength, :agility, :stamina, :intellect, :spirit,
  4.                 :armor, :added_armor, :sockets, :max_durability, :allowed_classes, 
  5.                 :required_level, :attack_power, :crit_rating, :expertise_rating, 
  6.                 :haste_rating, :hit_rating, :spellpower, :resilience, :spells, :item_set, :source
  7.  
  8.   def initialize
  9.     @id                   = 0
  10.     @name                 = ''
  11.     @icon                 = ''
  12.     @quality              = 0
  13.  
  14.     @bonding              = 0
  15.     @class_id             = 0
  16.     @equip_inventory_type = 0
  17.     @equip_subclass       = ''
  18.  
  19.     @strength             = 0
  20.     @agility              = 0
  21.     @stamina              = 0
  22.     @intellect            = 0
  23.     @spirit               = 0
  24.     @armor                = 0
  25.     @added_armor          = 0
  26.     @sockets              = Array.new
  27.  
  28.     @allowed_classes      = Array.new
  29.     @required_level       = 0
  30.     @attack_power         = 0
  31.     @crit_rating          = 0
  32.     @expertise_rating     = 0
  33.     @haste_rating         = 0
  34.     @hit_rating           = 0
  35.     @spellpower           = 0
  36.     @resilience           = 0
  37.  
  38.     @spells               = 0
  39.  
  40.     @item_set             = nil
  41.     @source               = nil
  42.   end
  43. end
  44.  
  45. class Spell
  46.   attr_accessor :trigger, :desc
  47.  
  48.   def initialize
  49.     @trigger = 0
  50.     @desc    = ''
  51.   end
  52. end
  53.  
  54. class ItemSet
  55.   attr_accessor :name, :items, :bonuses;
  56.  
  57.   def initialize
  58.     @name    = ''
  59.     @items   = Array.new
  60.     @bonuses = Hash.new
  61.   end
  62. end
  63.  
  64. class ItemSource
  65.   attr_accessor :source_type, :area_id, :area_name, :creature_id, :creature_name,
  66.                 :difficulty, :drop_rate
  67.  
  68.   def initialize
  69.     @source_type   = ''
  70.     @area_id       = 0
  71.     @creature_id   = 0
  72.     @creature_name = ''
  73.     @difficulty    = ''
  74.     @drop_rate     = ''
  75.   end
  76. end

This is the Item class and helper classes for the Ruby XML parser implementations.

Articles: 
Source code: