public void Start() { Stats = new XMLFileAsset <StatKeeper.Stats>(Path.Combine(Plugin.Instance.Directory, "Stats/" + Player.Id + ".xml")); Stats.Instance.SteamID = (ulong)Player.CSteamID; //TODO: Add tracking of acc when player is in combat Player.Events.OnDeath += (UnturnedPlayer player, SDG.Unturned.EDeathCause cause, SDG.Unturned.ELimb limb, Steamworks.CSteamID m) => { UnturnedPlayer murderer = UnturnedPlayer.FromCSteamID(m); if (murderer != null && PlayerTool.getSteamPlayer(m) != null && cause != SDG.Unturned.EDeathCause.SUICIDE) { XMLFileAsset <Stats> killerStats = murderer.GetComponent <StatsPlayerComponent>().Stats; if (limb == SDG.Unturned.ELimb.SKULL) { killerStats.Instance.HeadShots += 1; } killerStats.Instance.Kills += 1; killerStats.Instance.RecalculateStats(); killerStats.Save(); } Stats.Instance.Deaths += 1; Stats.Instance.RecalculateStats(); Stats.Save(); Plugin.Instance.UpdateRank(); }; Stats.Instance.RecalculateStats(); Plugin.Instance.UpdateRank(); }
public void Start() { Stats = new XMLFileAsset <StatKeeper.Stats>(Path.Combine(Plugin.Instance.Directory, "Stats/" + Player.Id + ".xml")); Stats.Instance.SteamID = (ulong)Player.CSteamID; Player.Events.OnDeath += (UnturnedPlayer player, SDG.Unturned.EDeathCause cause, SDG.Unturned.ELimb limb, Steamworks.CSteamID m) => { UnturnedPlayer murderer = UnturnedPlayer.FromCSteamID(m); if (murderer != null && PlayerTool.getSteamPlayer(m) != null) { XMLFileAsset <Stats> killerStats = murderer.GetComponent <StatsPlayerComponent>().Stats; killerStats.Instance.Kills[cause.ToString()] = killerStats.Instance.GetKills(cause.ToString()) + 1; killerStats.Instance.RecalculateStats(); killerStats.Save(); } Stats.Instance.Deaths[cause.ToString()] = Stats.Instance.GetDeaths(cause.ToString()) + 1; Stats.Instance.RecalculateStats(); Stats.Save(); }; Stats.Instance.RecalculateStats(); }
public void OnDisable() { Stats.Instance.RecalculateStats(); Stats.Save(); }
void IPersister.Save() => _whitelistAsset.Save();
public void UpdateRank() { List <string> RankList = new List <string>(); List <string> FilePaths = new List <string>(); string SteamIDOne = ""; string SteamIDTwo = ""; int TempValOne = 0; int TempValTwo = 0; foreach (string file in System.IO.Directory.EnumerateFiles(Path.Combine(Instance.Directory, "Stats/"))) { FilePaths.Add(file); } while (FilePaths.Count > 0) { if (FilePaths.Count > 1) { for (int i = 0; i < (FilePaths.Count - 1); i++) { XmlDocument doc = new XmlDocument(); doc.Load(FilePaths[i]); XmlNodeList kills = doc.GetElementsByTagName("Kills"); XmlNodeList deaths = doc.GetElementsByTagName("Deaths"); XmlNodeList steamID = doc.GetElementsByTagName("SteamID"); if (kills.Count > 0 && deaths.Count > 0) { TempValOne = int.Parse(kills[0].InnerXml) + int.Parse(deaths[0].InnerXml); SteamIDOne = steamID[0].InnerXml; } doc.Load(FilePaths[i + 1]); kills = doc.GetElementsByTagName("Kills"); deaths = doc.GetElementsByTagName("Deaths"); steamID = doc.GetElementsByTagName("SteamID"); if (kills.Count > 0 && deaths.Count > 0) { TempValTwo = int.Parse(kills[0].InnerXml) + int.Parse(deaths[0].InnerXml); SteamIDTwo = steamID[0].InnerXml; } if (TempValOne > TempValTwo) { RankList.Add(SteamIDTwo); FilePaths.RemoveAt(i + 1); } else { RankList.Add(SteamIDOne); FilePaths.RemoveAt(i); } } } else { XmlDocument doc = new XmlDocument(); doc.Load(FilePaths[0]); XmlNodeList steamID = doc.GetElementsByTagName("SteamID"); RankList.Add(steamID[0].InnerXml); FilePaths.RemoveAt(0); } } for (int i = 0; i < RankList.Count; i++) { XMLFileAsset <Stats> PlayerStats = new XMLFileAsset <StatKeeper.Stats>(Path.Combine(Instance.Directory, "Stats/" + RankList[i] + ".xml")); PlayerStats.Instance.Rank = i + 1; PlayerStats.Save(); } // Find way to sort through players without adding their ID to a list foreach (SteamPlayer player in Provider.clients) { UnturnedPlayer uPlayer = UnturnedPlayer.FromCSteamID(player.playerID.steamID); UpdateStats(uPlayer); } }