Class: Hunter
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Hunter
- Defined in:
- app/models/hunter.rb
Overview
Schema Information
Table name: hunters
id :bigint not null, primary key
charm :integer
cool :integer
experience :integer
harm :integer
luck :integer
name :string
retired :boolean
sharp :integer
tough :integer
weird :integer
created_at :datetime not null
updated_at :datetime not null
playbook_id :bigint
user_id :bigint
Indexes
index_hunters_on_playbook_id (playbook_id)
index_hunters_on_user_id (user_id)
Foreign Keys
fk_rails_... (playbook_id => playbooks.id)
fk_rails_... (user_id => users.id)
The character appearing in the mystery
Constant Summary collapse
- MAX_LUCK =
7
Class Method Summary collapse
-
.policy_class ⇒ Object
This is the Pundit Policy that governs Hunter access.
Instance Method Summary collapse
-
#advanced?(move) ⇒ Boolean
Check whether a move has been advanced by an improvement for this hunter.
-
#available_improvements ⇒ ActiveRecord::Collection
List all improvements that are available based on the hunter's playbook, and excludes improvements the hunter has already taken, and excludes advanced improvement if the hunter does not qualify.
-
#gain_experience(exp) ⇒ Object
Add a negative or positive amount of experience to the hunter.
-
#hunters_move_for(move_id:) ⇒ Object
Returns the Hunters Move otherwise known as the object that represents the relationship between the hunter and the move.
-
#rating=(rating) ⇒ Object
Sets the Hunter's stats to those of the rating.
-
#rating_id=(rating_id) ⇒ Object
Sets the Hunter's stats to those of the rating.
-
#retire! ⇒ Object
Transitions the Hunter to a retired state.
-
#unstable? ⇒ Boolean
Check whether the hunter has lost enough health to fall unstable.
Class Method Details
.policy_class ⇒ Object
This is the Pundit Policy that governs Hunter access
61 62 63 |
# File 'app/models/hunter.rb', line 61 def self.policy_class HunterPolicy end |
Instance Method Details
#advanced?(move) ⇒ Boolean
Check whether a move has been advanced by an improvement for this hunter
123 124 125 |
# File 'app/models/hunter.rb', line 123 def advanced?(move) !!(hunters_move_for(move_id: move.id)&.advanced) end |
#available_improvements ⇒ ActiveRecord::Collection
List all improvements that are available based on the hunter's playbook, and excludes improvements the hunter has already taken, and excludes advanced improvement if the hunter does not qualify
72 73 74 75 76 77 78 |
# File 'app/models/hunter.rb', line 72 def available_improvements availables = playbook.improvements.where.not(id: improvements.select(:id)) unless Improvement.advanced_eligible?(self) availables = availables.not_advanced end availables end |
#gain_experience(exp) ⇒ Object
Add a negative or positive amount of experience to the hunter.
84 85 86 87 |
# File 'app/models/hunter.rb', line 84 def gain_experience(exp) self.experience += exp save end |
#hunters_move_for(move_id:) ⇒ Object
Returns the Hunters Move otherwise known as the object that represents the relationship between the hunter and the move.
93 94 95 |
# File 'app/models/hunter.rb', line 93 def hunters_move_for(move_id:) hunters_moves.find_by(move_id: move_id) end |
#rating=(rating) ⇒ Object
Sets the Hunter's stats to those of the rating. Intended for use in creating the Hunter.
106 107 108 109 |
# File 'app/models/hunter.rb', line 106 def () rate_attrs = .attributes.with_indifferent_access.slice(*Rating::LIST) assign_attributes(rate_attrs) end |
#rating_id=(rating_id) ⇒ Object
Sets the Hunter's stats to those of the rating. Intended for use in creating the Hunter.
115 116 117 |
# File 'app/models/hunter.rb', line 115 def () self. = Rating.find end |
#retire! ⇒ Object
Transitions the Hunter to a retired state
98 99 100 |
# File 'app/models/hunter.rb', line 98 def retire! update!(retired: true) end |
#unstable? ⇒ Boolean
Check whether the hunter has lost enough health to fall unstable
128 129 130 |
# File 'app/models/hunter.rb', line 128 def unstable? harm > 3 end |