summaryrefslogtreecommitdiff
path: root/app/models/character.rb
blob: a158d88deb514c1b8898a44c2780c4ccd7f14cf8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Character < ApplicationRecord
  belongs_to :user
  belongs_to :activity, optional: true
  has_many :character_items
  has_many :items, through: :character_items
  validates :name, presence: true

  def shift_item(gid, amount)
    CharacterItem.transaction do
      item = self.character_items.find_or_initialize_by(item: Item.find_by_gid(gid))
      item.increment(:quantity, amount)
      item.save
    end
  end
end