using System; using System.Collections.Generic; using SUISS.Cloud.Boomlagoon.JSON; using SUISS.Storage; namespace SUISS.Cloud { public class ScoreRecord : IStorable, IScoreRecord { public string Username { get; set; } public string Sauid { get; set; } public string Sagid { get; set; } public bool IsCheater { get { return this._isCheater; } set { this._isCheater = value; } } public string GameUuid { get; set; } public string CountryCode { get; set; } public string Signature { get; set; } public string Data { get; set; } public int PrimaryScore { get; set; } public int SecondaryScore { get; set; } public int TertiaryScore { get; set; } public int QuaternaryScore { get; set; } public int RankPage { get; set; } public int CountryRankPage { get; set; } public int Rank { get; set; } public int CountryRank { get; set; } public int Votes { get; set; } public bool IslandReady { get; set; } public static ScoreRecord fromJson(JSONValue json) { if (json.Type == JSONValueType.Object) { JSONObject obj = json.Obj; ScoreRecord scoreRecord = new ScoreRecord(); scoreRecord.Sagid = JSONParse.StringField(obj, "sagid", string.Empty); scoreRecord.Rank = JSONParse.IntField(obj, "gameRank", -1); scoreRecord.CountryRank = JSONParse.IntField(obj, "countryRank", -1); scoreRecord.CountryCode = JSONParse.StringField(obj, "countryCode", string.Empty); scoreRecord.Username = JSONParse.StringField(obj, "username", "UnknownPlayer"); scoreRecord.PrimaryScore = JSONParse.IntField(obj, "primaryScore", -1); scoreRecord.SecondaryScore = JSONParse.IntField(obj, "secondaryScore", -1); scoreRecord.TertiaryScore = JSONParse.IntField(obj, "tertiaryScore", -1); scoreRecord.QuaternaryScore = JSONParse.IntField(obj, "quaternaryScore", -1); scoreRecord.Votes = JSONParse.IntField(obj, "votes", 0); scoreRecord.IslandReady = JSONParse.BoolField(obj, "islandReady", scoreRecord.Votes > 0); scoreRecord.GameUuid = JSONParse.StringField(obj, "gameUuid", string.Empty); scoreRecord.Signature = JSONParse.StringField(obj, "signature", string.Empty); scoreRecord.RankPage = JSONParse.IntField(obj, "gameRankPage", 2147483637); scoreRecord.CountryRankPage = JSONParse.IntField(obj, "countryRankPage", 2147483637); scoreRecord.IsCheater = JSONParse.BoolField(obj, "isCheater", false); return scoreRecord; } return null; } void IStorable.FromStorage(IDictionary dict) { if (dict.ContainsKey("Username")) { this.Username = (string)dict["Username"]; } if (dict.ContainsKey("PrimaryScore")) { this.PrimaryScore = (int)dict["PrimaryScore"]; } if (dict.ContainsKey("SecondaryScore")) { this.SecondaryScore = (int)dict["SecondaryScore"]; } if (dict.ContainsKey("TertiaryScore")) { this.TertiaryScore = (int)dict["TertiaryScore"]; } if (dict.ContainsKey("QuaternaryScore")) { this.QuaternaryScore = (int)dict["QuaternaryScore"]; } if (dict.ContainsKey("SagId")) { this.Sagid = (string)dict["SagId"]; } } IDictionary IStorable.ToStorage() { Dictionary dictionary = new Dictionary(); dictionary["Username"] = this.Username; dictionary["PrimaryScore"] = this.PrimaryScore; dictionary["SecondaryScore"] = this.SecondaryScore; dictionary["TertiaryScore"] = this.TertiaryScore; dictionary["QuaternaryScore"] = this.QuaternaryScore; dictionary["SagId"] = this.Sagid; return dictionary; } private bool _isCheater; private const string UsernameKey = "Username"; private const string PrimaryScoreKey = "PrimaryScore"; private const string SecondaryScoreKey = "SecondaryScore"; private const string TertiaryScoreKey = "TertiaryScore"; private const string QuaternaryScoreKey = "QuaternaryScore"; private const string SagidKey = "SagId"; } }