add forge chain support to weapons
This commit is contained in:
parent
405d0ea88c
commit
85d9060dc9
2 changed files with 34 additions and 0 deletions
|
|
@ -136,6 +136,28 @@ class Weapon < ApplicationRecord
|
|||
scope :flash_exclusive, -> { by_promotion(GranblueEnums::PROMOTIONS[:Flash]).where.not('? = ANY(promotions)', GranblueEnums::PROMOTIONS[:Legend]) }
|
||||
scope :legend_exclusive, -> { by_promotion(GranblueEnums::PROMOTIONS[:Legend]).where.not('? = ANY(promotions)', GranblueEnums::PROMOTIONS[:Flash]) }
|
||||
|
||||
# Forge chain scopes
|
||||
scope :in_forge_chain, ->(chain_id) { where(forge_chain_id: chain_id).order(:forge_order) }
|
||||
|
||||
# Forge chain methods
|
||||
def forged_from_weapon
|
||||
return nil unless forged_from.present?
|
||||
|
||||
Weapon.find_by(granblue_id: forged_from)
|
||||
end
|
||||
|
||||
def forge_chain(same_element: true)
|
||||
return [] unless forge_chain_id.present?
|
||||
|
||||
chain = Weapon.in_forge_chain(forge_chain_id)
|
||||
same_element ? chain.where(element: element) : chain
|
||||
end
|
||||
|
||||
def forges_to(same_element: true)
|
||||
weapons = Weapon.where(forged_from: granblue_id)
|
||||
same_element ? weapons.where(element: element) : weapons
|
||||
end
|
||||
|
||||
# Promotion helpers
|
||||
def flash?
|
||||
promotions.include?(GranblueEnums::PROMOTIONS[:Flash])
|
||||
|
|
|
|||
12
db/migrate/20251221210000_add_forge_columns_to_weapons.rb
Normal file
12
db/migrate/20251221210000_add_forge_columns_to_weapons.rb
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddForgeColumnsToWeapons < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
add_column :weapons, :forged_from, :string
|
||||
add_column :weapons, :forge_chain_id, :uuid
|
||||
add_column :weapons, :forge_order, :integer
|
||||
|
||||
add_index :weapons, :forged_from
|
||||
add_index :weapons, :forge_chain_id
|
||||
end
|
||||
end
|
||||
Loading…
Reference in a new issue