private SC GetDataFromSC(string nickname) { WebClient client = new WebClient(); string webform = client.DownloadString("http://gmt.star-conflict.com/pubapi/v1/userinfo.php?nickname=" + nickname); SC sc = JsonConvert.DeserializeObject <SC>(webform); // or SC sc = JsonToSC(webform); if (sc.code == 1) { return(sc); } if (sc.data.clan == null) { sc.data.clan = new SCdataClan(); sc.data.clan.name = ""; sc.data.clan.tag = ""; } if (sc.data.clan.tag == null) { sc.data.clan.tag = "-----"; } if (sc.data.pvp == null || sc.data.pvp.gamePlayed == null || sc.data.pvp.gameWin == null || sc.data.pvp.totalAssists == null || sc.data.pvp.totalBattleTime == null || sc.data.pvp.totalDeath == null || sc.data.pvp.totalDmgDone == null || sc.data.pvp.totalHealingDone == null || sc.data.pvp.totalKill == null || sc.data.pvp.totalVpDmgDone == null) { sc.data.pvp = new SCdataPvp(); sc.data.pvp.gamePlayed = 0; sc.data.pvp.gameWin = 0; sc.data.pvp.totalAssists = 0; sc.data.pvp.totalBattleTime = 0; sc.data.pvp.totalDmgDone = 0; sc.data.pvp.totalHealingDone = 0; sc.data.pvp.totalKill = 0; sc.data.pvp.totalVpDmgDone = 0; } return(sc); }
private Players GetStatistic(Players player) { if (player.Signature != null) { return(player); } Space space = GetDataFromSpace(player.Uid); SC sc = GetDataFromSC(player.Nickname); Int64 gamePlayed, gameWin, totalAssists, totalBattleTime, totalDeath, totalDmgDone, totalHealingDone, totalKill, totalVpDmgDone; gamePlayed = gameWin = totalAssists = totalBattleTime = totalDeath = totalDmgDone = totalHealingDone = totalKill = totalVpDmgDone = 0; if (player.Uid == 0) { player.Signature = "bot"; return(player); } if (player.Team == 1) { player.Signature += "ally"; } if (space.result > 0) { player.Signature += "10"; SpaceBigdata dataFromSpace = space.bigdata[space.bigdata.Count - 1]; gamePlayed = sc.data.pvp.gamePlayed - dataFromSpace.gamePlayed; gameWin = sc.data.pvp.gameWin - dataFromSpace.gameWin; totalAssists = sc.data.pvp.totalAssists - dataFromSpace.totalAssists; totalBattleTime = sc.data.pvp.totalBattleTime - dataFromSpace.totalBattleTime; totalDeath = sc.data.pvp.totalDeath - dataFromSpace.totalDeath; totalDmgDone = sc.data.pvp.totalDmgDone - dataFromSpace.totalDmgDone; totalHealingDone = sc.data.pvp.totalHealingDone - dataFromSpace.totalHealingDone; totalKill = sc.data.pvp.totalKill - dataFromSpace.totalKill; totalVpDmgDone = sc.data.pvp.totalVpDmgDone - dataFromSpace.totalVpDmgDone; } if (gamePlayed == 0) { gamePlayed = sc.data.pvp.gamePlayed; gameWin = sc.data.pvp.gameWin; totalAssists = sc.data.pvp.totalAssists; totalBattleTime = sc.data.pvp.totalBattleTime; totalDeath = sc.data.pvp.totalDeath; totalDmgDone = sc.data.pvp.totalDmgDone; totalHealingDone = sc.data.pvp.totalHealingDone; totalKill = sc.data.pvp.totalKill; totalVpDmgDone = sc.data.pvp.totalVpDmgDone; } if (totalDeath == 0) { totalDeath = 1; } if (gamePlayed == 0) { gamePlayed = 1; } float WL; float KD = totalKill / (float)totalDeath; float KDA = (totalKill + totalAssists) / (float)totalDeath; float WinRate = gameWin / (float)gamePlayed * 100; Int64 DPG = totalDmgDone / gamePlayed; Int64 HPG = totalHealingDone / gamePlayed; if (gamePlayed - gameWin == 0) { WL = (float)gameWin / gamePlayed; } else { WL = (float)gameWin / (gamePlayed - gameWin); } player.KD = Math.Round(KD, 2); player.KDA = Math.Round(KDA, 2); player.WinRate = Math.Round(WinRate, 0); player.WL = Math.Round(WL, 2); player.DPG = DPG; player.HPG = HPG; player.Carma = sc.data.karma; player.Signature += "ok"; player.ClanName = sc.data.clan.name; player.ClanTag = sc.data.clan.tag; return(player); }