1<?php
2
3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
4// See the LICENCE file in the repository root for full licence text.
5
6namespace App\Models\LegacyMatch;
7
8use App\Models\Beatmap;
9use App\Models\Traits\Scoreable;
10
11/**
12 * @property int $count100
13 * @property int $count300
14 * @property int $count50
15 * @property int $countgeki
16 * @property int $countkatu
17 * @property int $countmiss
18 * @property int|null $enabled_mods
19 * @property int $frame
20 * @property Game $game
21 * @property int $game_id
22 * @property int $maxcombo
23 * @property int $pass
24 * @property int $perfect
25 * @property mixed $rank
26 * @property int $score
27 * @property int $slot
28 * @property int $team
29 * @property int $user_id
30 */
31class Score extends Model
32{
33 use Scoreable {
34 getEnabledModsAttribute as private _getEnabledMods;
35 }
36
37 const TEAMS = [
38 0 => 'none',
39 1 => 'blue',
40 2 => 'red',
41 ];
42
43 public $incrementing = false;
44 public $timestamps = false;
45
46 protected $casts = [
47 'pass' => 'bool',
48 ];
49 protected $primaryKey = ':composite';
50 protected $primaryKeys = ['game_id', 'slot'];
51 protected $table = 'game_scores';
52
53 public function game()
54 {
55 return $this->belongsTo(Game::class, 'game_id');
56 }
57
58 public function getMode(): string
59 {
60 return Beatmap::modeStr($this->game->play_mode);
61 }
62
63 public function getDateJsonAttribute(): ?string
64 {
65 return $this->game?->start_time_json;
66 }
67
68 public function getEnabledModsAttribute($value)
69 {
70 return $this->_getEnabledMods($value | ($this->game->getAttributes()['mods'] ?? 0));
71 }
72
73 public function getRankAttribute($value): string
74 {
75 if ($value === '0') {
76 $this->recalculateRank();
77 }
78
79 return $this->attributes['rank'];
80 }
81
82 public function getScoringType()
83 {
84 return $this->game->scoring_type;
85 }
86
87 public function getTeamAttribute($value)
88 {
89 return self::TEAMS[$value];
90 }
91
92 public function scopeDefault($query)
93 {
94 return $query->orderBy('slot', 'asc');
95 }
96}