summaryrefslogtreecommitdiff
path: root/app/models/equipment.rb
blob: 12e8ae7f4a5f56e5a8b47d5292ce98f7d69b5160 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class Equipment < ApplicationRecord
  belongs_to :character
  belongs_to :item
  enum slot: [:mainhand, :offhand, :head, :neck, :back, :torso, :grip,
              :left_ring, :right_ring, :waist, :legs, :feet, :curio]
  validates :slot, presence: true, uniqueness: { scope: :character }

  def self.random_break_slot
    roll = rand
    if roll >= 0.99933333
      [:neck, :left_ring, :right_ring].sample
    elsif roll >= 0.999
      [:back, :waist, :curio].sample
    elsif roll >= 0.998
      [:mainhand, :offhand, :head, :torso, :grip, :legs, :feet].sample
    end
  end

  def slot
    self[:slot].to_sym
  end

  def effects
    self.item.whatnot[:equip_effects]
  end

  def break_check
    false
  end
end