Skip to content

Instantly share code, notes, and snippets.

@benphelps
Created August 29, 2012 04:00
Show Gist options
  • Save benphelps/3506669 to your computer and use it in GitHub Desktop.
Save benphelps/3506669 to your computer and use it in GitHub Desktop.
class Armor < ActiveRecord::Base
attr_accessible :back_id, :character_id, :chest_id, :feet_id, :hands_id, :head_id, :legs_id, :shoulder_id, :waist_id, :finger_id
belongs_to :character
[:back, :chest, :feet, :hands, :head, :legs, :shoulder, :waist, :finger].each do |part|
belongs_to part, :class_name => 'ArmorItem'
end
end
class ArmorItem < ActiveRecord::Base
attr_accessible :armor_tier_id, :bonus_id, :enchant_id, :name, :stat_set_id
belongs_to :armor_tier
belongs_to :enchant
belongs_to :bonus
belongs_to :stat_set
def stat
StatSet.find(stat_set_id)
end
[:agility, :stamina, :strength, :intellect].each do |stat|
define_method stat do
armor_tier.stat.send(stat) + stat_set.send(stat)
end
end
end
class ArmorMaterial < ActiveRecord::Base
attr_accessible :name
has_many :armor_tiers
end
class ArmorTier < ActiveRecord::Base
attr_accessible :level, :name, :deviation, :stat_set_id, :armor_material_id
belongs_to :armor_material
belongs_to :stat_set
attr_reader :stat
def stat
StatSet.find(stat_set_id)
end
end
class Bonus < ActiveRecord::Base
attr_accessible :name
has_many :stat_set
end
class Character < ActiveRecord::Base
attr_accessible :level, :name
belongs_to :order
belongs_to :user
has_one :armor
[:agility, :stamina, :strength, :intellect].each do |stat|
define_method stat do
armor_tier.stat.stat) + stat_set.send(stat)
(level.to_f * order.send(stat)).round
end
end
def health
((level.to_f * 10) + (order.stamina * level.to_f)).round
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment