2019-01-24 08:43:03 +00:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2018-11-28 07:39:08 +00:00
|
|
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
|
|
|
using System.Linq;
|
2018-09-28 09:29:49 +00:00
|
|
|
|
using Newtonsoft.Json;
|
2018-12-26 13:42:17 +00:00
|
|
|
|
using Newtonsoft.Json.Converters;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Game.Beatmaps;
|
2018-11-28 07:39:08 +00:00
|
|
|
|
using osu.Game.Database;
|
2018-11-28 07:33:42 +00:00
|
|
|
|
using osu.Game.Rulesets;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
|
using osu.Game.Users;
|
2018-11-28 07:33:42 +00:00
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-11-28 07:12:57 +00:00
|
|
|
|
namespace osu.Game.Scoring
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2018-11-28 09:33:01 +00:00
|
|
|
|
public class ScoreInfo : IHasFiles<ScoreFileInfo>, IHasPrimaryKey, ISoftDelete
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2018-11-28 07:39:08 +00:00
|
|
|
|
public int ID { get; set; }
|
|
|
|
|
|
2018-12-14 12:09:17 +00:00
|
|
|
|
[JsonProperty("rank")]
|
2018-12-26 13:42:17 +00:00
|
|
|
|
[JsonConverter(typeof(StringEnumConverter))]
|
2018-04-13 09:19:50 +00:00
|
|
|
|
public ScoreRank Rank { get; set; }
|
|
|
|
|
|
2018-12-14 12:09:17 +00:00
|
|
|
|
[JsonProperty("total_score")]
|
2019-02-26 04:10:07 +00:00
|
|
|
|
public long TotalScore { get; set; }
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-12-14 12:09:17 +00:00
|
|
|
|
[JsonProperty("accuracy")]
|
2019-02-27 12:07:17 +00:00
|
|
|
|
[Column(TypeName = "DECIMAL(1,4)")]
|
2018-04-13 09:19:50 +00:00
|
|
|
|
public double Accuracy { get; set; }
|
|
|
|
|
|
2019-01-04 07:33:35 +00:00
|
|
|
|
[JsonProperty(@"pp")]
|
2018-04-13 09:19:50 +00:00
|
|
|
|
public double? PP { get; set; }
|
|
|
|
|
|
2018-12-14 12:09:17 +00:00
|
|
|
|
[JsonProperty("max_combo")]
|
2018-04-13 09:19:50 +00:00
|
|
|
|
public int MaxCombo { get; set; }
|
|
|
|
|
|
2018-12-14 12:09:17 +00:00
|
|
|
|
[JsonIgnore]
|
|
|
|
|
public int Combo { get; set; } // Todo: Shouldn't exist in here
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-12-14 12:09:17 +00:00
|
|
|
|
[JsonIgnore]
|
2018-11-28 08:26:46 +00:00
|
|
|
|
public int RulesetID { get; set; }
|
|
|
|
|
|
2018-12-14 12:09:17 +00:00
|
|
|
|
[JsonProperty("passed")]
|
|
|
|
|
[NotMapped]
|
|
|
|
|
public bool Passed { get; set; } = true;
|
|
|
|
|
|
|
|
|
|
[JsonIgnore]
|
2018-11-30 07:11:09 +00:00
|
|
|
|
public virtual RulesetInfo Ruleset { get; set; }
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-11-30 07:11:09 +00:00
|
|
|
|
private Mod[] mods;
|
|
|
|
|
|
2018-12-14 12:09:17 +00:00
|
|
|
|
[JsonProperty("mods")]
|
2018-11-30 07:11:09 +00:00
|
|
|
|
[NotMapped]
|
2018-11-28 10:47:20 +00:00
|
|
|
|
public Mod[] Mods
|
2018-11-28 07:39:08 +00:00
|
|
|
|
{
|
2018-11-28 10:47:20 +00:00
|
|
|
|
get
|
2018-11-28 07:39:08 +00:00
|
|
|
|
{
|
2018-11-30 09:52:31 +00:00
|
|
|
|
if (mods != null)
|
|
|
|
|
return mods;
|
2018-11-30 07:11:09 +00:00
|
|
|
|
|
|
|
|
|
if (modsJson == null)
|
2018-11-29 09:29:25 +00:00
|
|
|
|
return Array.Empty<Mod>();
|
|
|
|
|
|
2018-11-30 07:11:09 +00:00
|
|
|
|
return getModsFromRuleset(JsonConvert.DeserializeObject<DeserializedMod[]>(modsJson));
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2018-11-30 08:16:00 +00:00
|
|
|
|
modsJson = null;
|
2018-11-30 07:11:09 +00:00
|
|
|
|
mods = value;
|
2018-11-28 07:39:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-30 08:16:00 +00:00
|
|
|
|
private Mod[] getModsFromRuleset(DeserializedMod[] mods) => Ruleset.CreateInstance().GetAllMods().Where(mod => mods.Any(d => d.Acronym == mod.Acronym)).ToArray();
|
2018-11-30 07:11:09 +00:00
|
|
|
|
|
|
|
|
|
private string modsJson;
|
|
|
|
|
|
2018-12-14 12:09:17 +00:00
|
|
|
|
[JsonIgnore]
|
2018-11-30 07:11:09 +00:00
|
|
|
|
[Column("Mods")]
|
|
|
|
|
public string ModsJson
|
|
|
|
|
{
|
2018-11-30 09:52:31 +00:00
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (modsJson != null)
|
|
|
|
|
return modsJson;
|
|
|
|
|
|
|
|
|
|
if (mods == null)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
return modsJson = JsonConvert.SerializeObject(mods);
|
|
|
|
|
}
|
2018-11-30 07:11:09 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
modsJson = value;
|
|
|
|
|
|
|
|
|
|
// we potentially can't update this yet due to Ruleset being late-bound, so instead update on read as necessary.
|
|
|
|
|
mods = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-11-28 10:47:20 +00:00
|
|
|
|
|
2018-12-22 06:17:35 +00:00
|
|
|
|
[NotMapped]
|
|
|
|
|
[JsonProperty("user")]
|
|
|
|
|
public User User { get; set; }
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-12-14 12:09:17 +00:00
|
|
|
|
[JsonIgnore]
|
2018-11-30 07:11:09 +00:00
|
|
|
|
[Column("User")]
|
2018-11-28 07:39:08 +00:00
|
|
|
|
public string UserString
|
|
|
|
|
{
|
|
|
|
|
get => User?.Username;
|
2019-02-25 04:58:19 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (User == null)
|
2019-02-25 06:25:22 +00:00
|
|
|
|
User = new User();
|
|
|
|
|
|
|
|
|
|
User.Username = value;
|
2019-02-25 04:58:19 +00:00
|
|
|
|
}
|
2019-02-23 08:04:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[JsonIgnore]
|
|
|
|
|
[Column("UserID")]
|
2019-02-25 05:40:44 +00:00
|
|
|
|
public long? UserID
|
2019-02-23 08:04:02 +00:00
|
|
|
|
{
|
2019-02-25 05:40:44 +00:00
|
|
|
|
get => User?.Id ?? 1;
|
2019-02-25 04:58:19 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (User == null)
|
2019-02-25 06:25:22 +00:00
|
|
|
|
User = new User();
|
|
|
|
|
|
|
|
|
|
User.Id = value ?? 1;
|
2019-02-25 04:58:19 +00:00
|
|
|
|
}
|
2018-11-28 07:39:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-30 09:06:48 +00:00
|
|
|
|
[JsonIgnore]
|
2018-11-28 08:26:39 +00:00
|
|
|
|
public int BeatmapInfoID { get; set; }
|
|
|
|
|
|
2018-12-14 12:09:17 +00:00
|
|
|
|
[JsonIgnore]
|
2018-11-30 07:11:09 +00:00
|
|
|
|
public virtual BeatmapInfo Beatmap { get; set; }
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-12-14 12:09:17 +00:00
|
|
|
|
[JsonIgnore]
|
2018-11-28 09:52:57 +00:00
|
|
|
|
public long? OnlineScoreID { get; set; }
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-12-14 12:09:17 +00:00
|
|
|
|
[JsonIgnore]
|
2018-11-28 11:16:20 +00:00
|
|
|
|
public DateTimeOffset Date { get; set; }
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-12-14 12:09:17 +00:00
|
|
|
|
[JsonProperty("statistics")]
|
2018-12-05 10:44:01 +00:00
|
|
|
|
public Dictionary<HitResult, int> Statistics = new Dictionary<HitResult, int>();
|
2018-11-28 07:39:08 +00:00
|
|
|
|
|
2018-12-14 12:09:17 +00:00
|
|
|
|
[JsonIgnore]
|
2018-11-30 07:11:09 +00:00
|
|
|
|
[Column("Statistics")]
|
|
|
|
|
public string StatisticsJson
|
2018-11-30 05:27:08 +00:00
|
|
|
|
{
|
|
|
|
|
get => JsonConvert.SerializeObject(Statistics);
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value == null)
|
2018-11-30 07:11:09 +00:00
|
|
|
|
{
|
|
|
|
|
Statistics.Clear();
|
2018-11-30 05:27:08 +00:00
|
|
|
|
return;
|
2018-11-30 07:11:09 +00:00
|
|
|
|
}
|
2018-11-30 05:27:08 +00:00
|
|
|
|
|
2018-12-05 10:44:01 +00:00
|
|
|
|
Statistics = JsonConvert.DeserializeObject<Dictionary<HitResult, int>>(value);
|
2018-11-30 05:27:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-30 09:06:48 +00:00
|
|
|
|
[JsonIgnore]
|
2018-11-28 07:39:08 +00:00
|
|
|
|
public List<ScoreFileInfo> Files { get; set; }
|
|
|
|
|
|
2018-12-14 12:09:17 +00:00
|
|
|
|
[JsonIgnore]
|
2018-11-30 08:36:06 +00:00
|
|
|
|
public string Hash { get; set; }
|
|
|
|
|
|
2018-12-14 12:09:17 +00:00
|
|
|
|
[JsonIgnore]
|
2018-11-28 07:39:08 +00:00
|
|
|
|
public bool DeletePending { get; set; }
|
2018-11-30 07:11:09 +00:00
|
|
|
|
|
|
|
|
|
[Serializable]
|
2018-11-30 08:16:00 +00:00
|
|
|
|
protected class DeserializedMod : IMod
|
2018-11-30 07:11:09 +00:00
|
|
|
|
{
|
2018-11-30 08:16:00 +00:00
|
|
|
|
public string Acronym { get; set; }
|
2018-11-30 07:11:09 +00:00
|
|
|
|
}
|
2019-02-25 09:42:08 +00:00
|
|
|
|
|
|
|
|
|
public override string ToString() => $"{User} playing {Beatmap}";
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|