PRoConEvents.MULTIbalancer.SetStats C# (CSharp) Method

SetStats() private method

private SetStats ( PlayerModel player, Hashtable stats ) : void
player PlayerModel
stats System.Collections.Hashtable
return void
        private void SetStats(PlayerModel player, Hashtable stats)
        {
            player.StatsFetchStatus.State = FetchState.Failed;
            if (stats == null) {
            ConsoleDebug("SetStats ^b" + player.Name + "^n stats = null");
            return;
            }

            Dictionary<String,double> propValues = new Dictionary<String,double>();
            propValues["kdRatio"] = -1;
            propValues["timePlayed"] = -1;
            propValues["kills"] = -1;
            propValues["scorePerMinute"] = -1;
            propValues["deaths"] = -1;
            propValues["rsDeaths"] = -1;
            propValues["rsKills"] = -1;
            propValues["rsScore"] = -1;
            propValues["rsTimePlayed"] = -1;

            foreach (DictionaryEntry entry in stats) {
            try {
            if (entry.Key == null) continue;
            String entryKey = (String)(entry.Key.ToString());

            // skip entries we are not interested in
            if (!propValues.ContainsKey(entryKey)) continue;
            if (entry.Value == null) continue;

            String entryValue = (String)(entry.Value.ToString());

            double dValue = -1;
            if (!String.IsNullOrEmpty(entryValue)) Double.TryParse(entryValue, out dValue);
            propValues[entryKey] = (Double.IsNaN(dValue)) ? -1 : dValue;
            } catch (Exception) {}
            }

            // Now set the player values, starting with AllTime
            double allTimeMinutes = Math.Max(1, propValues["timePlayed"] / 60);
            double kills = propValues["kills"];
            kills = (kills < 1) ? 0 : kills;
            double deaths = propValues["deaths"];
            deaths = (deaths < 1) ? 1 : deaths;
            double kdr = propValues["kdRatio"];
            if (kdr < 0) {
            kdr = kills / deaths;
            }

            player.KDR = kdr;
            player.SPM = propValues["scorePerMinute"];
            player.KPM = propValues["kills"] / allTimeMinutes;

            // Using Reset?
            String type = "All-Time";
            if (WhichBattlelogStats == BattlelogStats.Reset && propValues["rsTimePlayed"] > 0) {
            type = "Reset";
            double resetMinutes = Math.Max(1, propValues["rsTimePlayed"] / 60);
            double resetKDR = propValues["rsKills"] / Math.Max(1, propValues["rsDeaths"]);
            if (resetKDR > 0) player.KDR = resetKDR;
            double resetSPM = propValues["rsScore"] / resetMinutes;
            if (resetSPM > 0) player.SPM = resetSPM;
            double resetKPM = propValues["rsKills"] / resetMinutes;
            if (resetKPM > 0) player.KPM = resetKPM;
            }
            player.StatsFetchStatus.State = FetchState.Succeeded;
            player.StatsVerified = true;
            String msg = type + " [bKDR:" + player.KDR.ToString("F2") + ", bSPM:" + player.SPM.ToString("F0") + ", bKPM:" + player.KPM.ToString("F1") + "]";
            String ver = fGameVersion.ToString();
            DebugFetch("^4Player " + ver + " stats updated ^0^b" + player.Name + "^n, " + msg);
        }
MULTIbalancer