Add new models
This commit is contained in:
parent
7b88932e2c
commit
a6bf326655
9 changed files with 134 additions and 0 deletions
15
app/models/character_skill.rb
Normal file
15
app/models/character_skill.rb
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class CharacterSkill < ApplicationRecord
|
||||
belongs_to :skill
|
||||
belongs_to :alt_skill, class_name: 'Skill', optional: true
|
||||
belongs_to :character, primary_key: 'granblue_id', foreign_key: 'character_granblue_id', optional: true
|
||||
|
||||
validates :character_granblue_id, presence: true
|
||||
validates :position, presence: true
|
||||
validates :position, uniqueness: { scope: %i[character_granblue_id unlock_level] }
|
||||
|
||||
scope :by_position, ->(position) { where(position: position) }
|
||||
scope :unlocked_at, ->(level) { where('unlock_level <= ?', level) }
|
||||
scope :improved_at, ->(level) { where('improve_level <= ?', level) }
|
||||
end
|
||||
14
app/models/charge_attack.rb
Normal file
14
app/models/charge_attack.rb
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ChargeAttack < ApplicationRecord
|
||||
belongs_to :skill
|
||||
belongs_to :alt_skill, class_name: 'Skill', optional: true
|
||||
|
||||
validates :owner_id, presence: true
|
||||
validates :owner_type, presence: true
|
||||
validates :uncap_level, uniqueness: { scope: %i[owner_id owner_type] }
|
||||
|
||||
scope :for_character, -> { where(owner_type: 'character') }
|
||||
scope :for_weapon, -> { where(owner_type: 'weapon') }
|
||||
scope :by_uncap_level, ->(level) { where(uncap_level: level) }
|
||||
end
|
||||
16
app/models/effect.rb
Normal file
16
app/models/effect.rb
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Effect < ApplicationRecord
|
||||
belongs_to :effect_family, class_name: 'Effect', optional: true
|
||||
has_many :child_effects, class_name: 'Effect', foreign_key: 'effect_family_id'
|
||||
has_many :skill_effects
|
||||
has_many :skills, through: :skill_effects
|
||||
|
||||
validates :name_en, presence: true
|
||||
validates :effect_type, presence: true
|
||||
|
||||
enum effect_type: { buff: 1, debuff: 2, special: 3 }
|
||||
|
||||
scope :by_class, ->(effect_class) { where(effect_class: effect_class) }
|
||||
scope :stackable, -> { where(stackable: true) }
|
||||
end
|
||||
24
app/models/skill.rb
Normal file
24
app/models/skill.rb
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Skill < ApplicationRecord
|
||||
has_many :skill_values
|
||||
has_many :skill_effects
|
||||
has_many :effects, through: :skill_effects
|
||||
has_many :character_skills
|
||||
has_many :weapon_skills
|
||||
has_many :summon_calls
|
||||
has_many :charge_attacks
|
||||
has_many :alt_character_skills, class_name: 'CharacterSkill', foreign_key: 'alt_skill_id'
|
||||
has_many :alt_summon_calls, class_name: 'SummonCall', foreign_key: 'alt_skill_id'
|
||||
has_many :alt_charge_attacks, class_name: 'ChargeAttack', foreign_key: 'alt_skill_id'
|
||||
|
||||
validates :name_en, presence: true
|
||||
validates :skill_type, presence: true
|
||||
|
||||
enum skill_type: { character: 1, weapon: 2, summon_call: 3, charge_attack: 4 }
|
||||
enum border_type: { damage: 1, healing: 2, buff: 3, debuff: 4, field: 5 }
|
||||
|
||||
def value_at_level(level)
|
||||
skill_values.find_by(level: level)
|
||||
end
|
||||
end
|
||||
17
app/models/skill_effect.rb
Normal file
17
app/models/skill_effect.rb
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class SkillEffect < ApplicationRecord
|
||||
belongs_to :skill
|
||||
belongs_to :effect
|
||||
|
||||
validates :target_type, presence: true
|
||||
validates :duration_type, presence: true
|
||||
|
||||
enum target_type: { self: 1, ally: 2, all_allies: 3, enemy: 4, all_enemies: 5 }
|
||||
enum duration_type: { turns: 1, seconds: 2, indefinite: 3, one_time: 4 }
|
||||
|
||||
scope :local, -> { where(local: true) }
|
||||
scope :global, -> { where(local: false) }
|
||||
scope :permanent, -> { where(permanent: true) }
|
||||
scope :undispellable, -> { where(undispellable: true) }
|
||||
end
|
||||
7
app/models/skill_value.rb
Normal file
7
app/models/skill_value.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class SkillValue < ApplicationRecord
|
||||
belongs_to :skill
|
||||
|
||||
validates :level, presence: true, uniqueness: { scope: :skill_id }
|
||||
end
|
||||
14
app/models/summon_aura.rb
Normal file
14
app/models/summon_aura.rb
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
# frozen_string_literal.rb
|
||||
|
||||
class SummonAura < ApplicationRecord
|
||||
belongs_to :summon, primary_key: 'granblue_id', foreign_key: 'summon_granblue_id', optional: true
|
||||
|
||||
validates :summon_granblue_id, presence: true
|
||||
validates :aura_type, presence: true
|
||||
validates :aura_type, uniqueness: { scope: %i[summon_granblue_id uncap_level] }
|
||||
|
||||
enum aura_type: { main: 1, sub: 2 }
|
||||
enum boost_type: { weapon_skill: 1, elemental: 2, stat: 3 }
|
||||
|
||||
scope :by_uncap_level, ->(level) { where(uncap_level: level) }
|
||||
end
|
||||
12
app/models/summon_call.rb
Normal file
12
app/models/summon_call.rb
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class SummonCall < ApplicationRecord
|
||||
belongs_to :skill
|
||||
belongs_to :alt_skill, class_name: 'Skill', optional: true
|
||||
belongs_to :summon, primary_key: 'granblue_id', foreign_key: 'summon_granblue_id', optional: true
|
||||
|
||||
validates :summon_granblue_id, presence: true
|
||||
validates :uncap_level, uniqueness: { scope: :summon_granblue_id }
|
||||
|
||||
scope :by_uncap_level, ->(level) { where(uncap_level: level) }
|
||||
end
|
||||
15
app/models/weapon_skill.rb
Normal file
15
app/models/weapon_skill.rb
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class WeaponSkill < ApplicationRecord
|
||||
belongs_to :skill
|
||||
belongs_to :weapon, primary_key: 'granblue_id', foreign_key: 'weapon_granblue_id', optional: true
|
||||
|
||||
validates :weapon_granblue_id, presence: true
|
||||
validates :position, presence: true
|
||||
validates :position, uniqueness: { scope: %i[weapon_granblue_id unlock_level] }
|
||||
|
||||
scope :by_position, ->(position) { where(position: position) }
|
||||
scope :unlocked_at, ->(level) { where('unlock_level <= ?', level) }
|
||||
scope :by_series, ->(series) { where(skill_series: series) }
|
||||
scope :by_modifier, ->(modifier) { where(skill_modifier: modifier) }
|
||||
end
|
||||
Loading…
Reference in a new issue