From a6bf3266556a6da6340670c5bbf4896c079d86cd Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sun, 2 Mar 2025 16:24:39 -0800 Subject: [PATCH] Add new models --- app/models/character_skill.rb | 15 +++++++++++++++ app/models/charge_attack.rb | 14 ++++++++++++++ app/models/effect.rb | 16 ++++++++++++++++ app/models/skill.rb | 24 ++++++++++++++++++++++++ app/models/skill_effect.rb | 17 +++++++++++++++++ app/models/skill_value.rb | 7 +++++++ app/models/summon_aura.rb | 14 ++++++++++++++ app/models/summon_call.rb | 12 ++++++++++++ app/models/weapon_skill.rb | 15 +++++++++++++++ 9 files changed, 134 insertions(+) create mode 100644 app/models/character_skill.rb create mode 100644 app/models/charge_attack.rb create mode 100644 app/models/effect.rb create mode 100644 app/models/skill.rb create mode 100644 app/models/skill_effect.rb create mode 100644 app/models/skill_value.rb create mode 100644 app/models/summon_aura.rb create mode 100644 app/models/summon_call.rb create mode 100644 app/models/weapon_skill.rb diff --git a/app/models/character_skill.rb b/app/models/character_skill.rb new file mode 100644 index 0000000..72778d7 --- /dev/null +++ b/app/models/character_skill.rb @@ -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 diff --git a/app/models/charge_attack.rb b/app/models/charge_attack.rb new file mode 100644 index 0000000..48b2c3b --- /dev/null +++ b/app/models/charge_attack.rb @@ -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 diff --git a/app/models/effect.rb b/app/models/effect.rb new file mode 100644 index 0000000..893e0b7 --- /dev/null +++ b/app/models/effect.rb @@ -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 diff --git a/app/models/skill.rb b/app/models/skill.rb new file mode 100644 index 0000000..4ad33ff --- /dev/null +++ b/app/models/skill.rb @@ -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 diff --git a/app/models/skill_effect.rb b/app/models/skill_effect.rb new file mode 100644 index 0000000..29ae75b --- /dev/null +++ b/app/models/skill_effect.rb @@ -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 diff --git a/app/models/skill_value.rb b/app/models/skill_value.rb new file mode 100644 index 0000000..a6b9913 --- /dev/null +++ b/app/models/skill_value.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class SkillValue < ApplicationRecord + belongs_to :skill + + validates :level, presence: true, uniqueness: { scope: :skill_id } +end diff --git a/app/models/summon_aura.rb b/app/models/summon_aura.rb new file mode 100644 index 0000000..1424a54 --- /dev/null +++ b/app/models/summon_aura.rb @@ -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 diff --git a/app/models/summon_call.rb b/app/models/summon_call.rb new file mode 100644 index 0000000..72ad7d7 --- /dev/null +++ b/app/models/summon_call.rb @@ -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 diff --git a/app/models/weapon_skill.rb b/app/models/weapon_skill.rb new file mode 100644 index 0000000..3572841 --- /dev/null +++ b/app/models/weapon_skill.rb @@ -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