/// <summary> /// Gets a stat value for the specified server. /// </summary> /// <param name="server">The adress of the server. If <see cref="IPAddress.Any"/> is specified it will return the sum of all server stat values.</param> /// <param name="item">The stat to be returned</param> /// <returns>The value of the specified stat item</returns> public long GetValue(IPEndPoint server, StatKeys item) { var retval = 0L; // need cluster statistics if (server.Address == IPAddress.Any) { // check if we can sum the value for all servers if (((int)item & OpSum) != OpSum) throw new ArgumentException($"The values of '{item}' cannot be summarized", nameof(item)); // sum & return foreach (var endpoint in results.Keys) { retval += GetValue(endpoint, item); } } else { // error check // asked for a specific server var tmp = GetRaw(server, item); if (String.IsNullOrEmpty(tmp)) throw new KeyNotFoundException($"Item was not found: {item}"); // return the value if (!Int64.TryParse(tmp, out retval)) throw new InvalidOperationException($"Item '{item}' is not a number. Original value: {tmp}"); } return retval; }
/// <summary> /// Returns the stat value for a specific server. The value is not converted but returned as the server returned it. /// </summary> /// <param name="server">The adress of the server</param> /// <param name="item">The stat value to be returned</param> /// <returns>The value of the stat item</returns> public string GetRaw(IPEndPoint server, StatKeys item) { var index = (int)item; if (index < 0 || index >= KeyNames.Length) { throw new ArgumentOutOfRangeException(nameof(item)); } return(GetRaw(server, KeyNames[index])); }
/// <summary> /// Gets a stat value for the specified server. /// </summary> /// <param name="server">The adress of the server. If <see cref="IPAddress.Any"/> is specified it will return the sum of all server stat values.</param> /// <param name="item">The stat to be returned</param> /// <returns>The value of the specified stat item</returns> public long GetValue(IPEndPoint server, StatKeys item) { var retval = 0L; // need cluster statistics if (server.Address == IPAddress.Any) { // check if we can sum the value for all servers if (((int)item & OpSum) != OpSum) { throw new ArgumentException($"The values of '{item}' cannot be summarized", nameof(item)); } // sum & return foreach (var endpoint in results.Keys) { retval += GetValue(endpoint, item); } } else { // error check // asked for a specific server var tmp = GetRaw(server, item); if (String.IsNullOrEmpty(tmp)) { throw new KeyNotFoundException($"Item was not found: {item}"); } // return the value if (!Int64.TryParse(tmp, out retval)) { throw new InvalidOperationException($"Item '{item}' is not a number. Original value: {tmp}"); } } return(retval); }
public static float GetStat(StatKeys key) { switch (key) { case StatKeys.DelinkersHit: return(DelinkersHit); case StatKeys.EjectorsHit: return(EjectorsHit); case StatKeys.FreezersHit: return(FreezersHit); case StatKeys.GloopersHit: return(GloopersHit); case StatKeys.InfectorsHit: return(InfectorsHit); case StatKeys.ShockersHit: return(ShockersHit); case StatKeys.HighScore: return(HighScore); case StatKeys.LongestChain: return(LongestChain); case StatKeys.TotalScore: return(TotalScore); case StatKeys.MaxCombo: return(MaxCombo); default: return(-1); } }
/// <summary> /// Returns the stat value for a specific server. The value is not converted but returned as the server returned it. /// </summary> /// <param name="server">The adress of the server</param> /// <param name="item">The stat value to be returned</param> /// <returns>The value of the stat item</returns> public string GetRaw(IPEndPoint server, StatKeys item) { var index = (int)item; if (index < 0 || index >= KeyNames.Length) throw new ArgumentOutOfRangeException(nameof(item)); return GetRaw(server, KeyNames[index]); }
static void SaveStat <T>(StatKeys key, T value) { Util.SaveToPlayerPrefs(keyNames[key], value); }
static void LoadStat <T>(StatKeys key, out T value) { Util.TryLoadFromPlayerPrefs <T>(keyNames[key], out value); }