This commit is contained in:
2025-03-11 09:52:32 -07:00
parent 0e380931b1
commit 97d5bd9ace
18 changed files with 294 additions and 61 deletions

34
app/models/loot.rb Normal file
View File

@ -0,0 +1,34 @@
class Loot < ApplicationRecord
belongs_to :player
def player_name_with_alt
if self.player.alt?
"#{self.player.name} (alt of #{self.player.main_player.name})"
else
self.player.name
end
end
def wowhead
"https://wowhead.com/item=#{self.item_id}"
end
def roll_type_pretty
case self.roll_type
when "mainspec"
"Main Spec"
when "offspec"
"Offspec"
when "minor"
"Minor Upgrade"
when "transmog"
"Transmog"
else
"Unknown"
end
end
def date
self.timestamp&.strftime("%m/%d/%Y")
end
end

View File

@ -5,6 +5,9 @@ class Player < ApplicationRecord
# A Player can have multiple alts
has_many :alternate_players, class_name: "Player", foreign_key: "main_player_id"
# A Player can have many loots
has_many :loots
validate :no_circular_references
def total_wins
@ -35,6 +38,10 @@ class Player < ApplicationRecord
self.main_player
end
def has_alts?
self.alternate_players.count > 0
end
def main_name
if alt?
self.main_player.name
@ -46,4 +53,25 @@ class Player < ApplicationRecord
errors.add(:main_account, "circular reference")
end
end
def get_loot
loot = Loot.where(player_id: self.id)
self.alternate_players.each do |alt|
loot << Loot.where(player_id: alt.id)
end
loot
end
def get_loot_with_roll(roll)
ids = [self.id] + self.alternate_players.pluck(:id)
Loot.where(player_id: ids, roll_type: roll)
end
def get_loot_count
get_loot.size
end
def get_loot_count_with_roll(roll)
get_loot_with_roll(roll).size
end
end