Пример #1
0
        public GameChampion[] GetEnemies(GameChampion player)
        {
            var enemies   = BlueTeam;
            var enemylist = new List <GameChampion>();

            if (player.PlayerStats.TeamColor.ToLower() != TeamColor.Blue)
            {
                enemies = RedTeam;
            }

            foreach (var enemy in enemies)
            {
                if (enemy.Location.Current == player.Location.Current)
                {
                    enemylist.Add(enemy);
                }
            }

            return(enemylist.ToArray());
        }
Пример #2
0
    public TimelineEvent(int a_Time, JSONNode a_JSONEvent)
    {
        Time = a_Time;
        Team = a_JSONEvent["team"].AsInt;

        Baron  = a_JSONEvent["baron"].AsInt == 1 ? MonsterState.Up : MonsterState.Down;
        Dragon = a_JSONEvent["dragon"].AsInt == 1 ? MonsterState.Up : MonsterState.Down;

        if (a_JSONEvent["role"] != null && a_JSONEvent["role"].Value != "")
        {
            try
            {
                String t_Role = a_JSONEvent["role"].Value.ToLower();
                t_Role           = char.ToUpper(t_Role[0]) + t_Role.Substring(1);
                InvolvedChampion = Game.Teams[Team].GetChampion((Role)Enum.Parse(typeof(Role), t_Role));
            }
            catch { }
        }

        for (int t_Team = 0; t_Team < 2; t_Team++)
        {
            foreach (Role t_Role in Enum.GetValues(typeof(Role)))
            {
                var t_JSONChampion = a_JSONEvent["state"][t_Team][t_Role.ToString().ToLower()];
                Teams[t_Team].Champions.Add(t_Role, new ChampionState(t_JSONChampion["death_timer"].AsFloat, t_JSONChampion["troll"].AsInt == 1, t_JSONChampion["afk"].AsInt == 1, t_JSONChampion["tilt"].AsInt == 1));
            }
        }

        switch (a_JSONEvent["name"].Value)
        {
        case "connect":
            Type = EventType.Connect;
            break;

        case "tilt":
            Type = EventType.Tilt;
            break;

        case "invade":
            Type = EventType.Invade;
            break;

        case "empty_jungle":
            Type = EventType.EmptyJungle;
            break;

        case "executed":
            Type = EventType.Executed;
            break;

        case "tower_destroyed":
            Type = EventType.TowerDestroyed;
            break;

        case "useless_objective":
            Type = EventType.UselessObjective;
            break;

        case "inhibitor_destroyed":
            Type = EventType.InhibitorDestroyed;
            break;

        case "game_over":
            Type = EventType.GameOver;
            break;

        case "kill":
            Type = EventType.Kill;
            break;

        case "death":
            Type = EventType.Death;
            break;

        case "surrender":
            Type = EventType.Surrender;
            break;

        case "play":
            Type = EventType.Play;
            break;

        case "end_of_timeline":
            Type = EventType.EndOfTimeline;
            break;

        case "laning_phase":
            Type = EventType.LaningPhase;
            break;

        case "post_laning_phase":
            Type = EventType.PostLaningPhase;
            break;

        case "bot_tower_attack":
            Type = EventType.BotTowerAttack;
            break;

        case "mid_tower_attack":
            Type = EventType.MidTowerAttack;
            break;

        case "top_tower_attack":
            Type = EventType.TopTowerAttack;
            break;

        case "base_tower_attack":
            Type = EventType.BaseTowerAttack;
            break;

        case "bot_tower":
            Type = EventType.BotTowerDestroyed;
            break;

        case "mid_tower":
            Type = EventType.MidTowerDestroyed;
            break;

        case "top_tower":
            Type = EventType.TopTowerDestroyed;
            break;

        case "base_tower":
            Type = EventType.BaseTowerDestroyed;
            break;

        case "teamfight":
            Type = EventType.Teamfight;
            break;

        case "start_dragon":
            Type = EventType.StartDragon;
            break;

        case "start_baron":
            Type = EventType.StartBaron;
            break;

        case "get_dragon":
            Type = EventType.GetDragon;
            Debug.Log("yay we have a dragon game");
            break;

        case "get_baron":
            Type = EventType.GetBaron;
            Debug.Log("yay we have a baron game");
            break;

        case "dragon":
            Type = EventType.Dragon;
            break;

        case "baron":
            Type = EventType.Baron;
            break;

        default:
            Debug.LogWarning("Event will occur that hasn't got a type: " + (a_JSONEvent["name"].Value));
            break;
        }
    }
Пример #3
0
        /// <summary>
        /// get sopcast link or livestream link
        /// </summary>
        /// <param name="url">an url that load data for sopcast link, values is: all | today | online.</param>
        /// <param name="isLiveStream">determine that load sopcast or livestream</param>
        /// <returns>a collection of champion</returns>
        public async Task <List <GameChampion> > GetLiveChampionAsync(string url, bool isLiveStream = false)
        {
            List <GameChampion> champions = new List <GameChampion>();
            string sourceUrl;

            if (isLiveStream)
            {
                sourceUrl = ConfigurationManager.AppSettings["LiveSourceUrl"];
            }
            else
            {
                sourceUrl = ConfigurationManager.AppSettings["SopcastSourceUrl"];
            }

            if (string.IsNullOrEmpty(sourceUrl))
            {
                return(champions);
            }

            // download html from url
            sourceUrl = sourceUrl.TrimEnd('/');
            switch (url)
            {
            case "online": sourceUrl += "/truc-tuyen";
                break;

            case "today": sourceUrl += "/hom-nay";
                break;

            default:     // all
                break;
            }
            Debug.WriteLine("url: " + sourceUrl);

            //using (var webClient = new WebClient())
            //{
            //    webClient.Encoding = Encoding.UTF8;
            //    webClient.Headers.Add(HttpRequestHeader.AcceptCharset, "UTF-8");
            //    html = await webClient.DownloadStringTaskAsync(sourceUrl);
            //}
            //html = await DownloadHtmlAsync(sourceUrl);

            //if (string.IsNullOrEmpty(html) || string.IsNullOrWhiteSpace(html)) return champions;

            //// parse data

            //HtmlDocument doc = new HtmlDocument();
            //doc.LoadHtml(html);

            //if (doc.DocumentNode == null ||
            //    doc.DocumentNode.Descendants().Any() == false)
            //    return champions; // no data found

            var doc = await LoadHtmlDocAsync(sourceUrl);

            if (doc == null)
            {
                return(champions);
            }

            // get all div
            var rows = doc.SelectNodes("//div[@class='content']/div");

            if (rows == null || rows.Count == 0)
            {
                return(champions);
            }

            string host = ConfigurationManager.AppSettings["HostCrawlerUrl"];

            if (string.IsNullOrEmpty(host) == false)
            {
                host = host.TrimEnd('/');
            }
            int rowCount = rows.Count;

            for (int i = 0; i < rowCount; i++)
            {
                var row      = rows[i];
                var rowClass = row.GetAttributeValue("class", string.Empty); // expect row-tall
                // if (string.IsNullOrEmpty(rowClass)) continue;

                if (rowClass.Contains("row-tall")) // champion row
                {
                    GameChampion champ = new GameChampion();
                    champ.Champion  = row.SelectSingleNode(".//div[@class='left']/a").InnerText();
                    champ.FlagClass = row.SelectSingleNode(".//div[@class='left']/span").AttributeValue("class", string.Empty);
                    Debug.WriteLine("{0} : {1}", champ.Champion, champ.FlagClass, 1);

                    // get sibling row for matches

                    try
                    {
                        HtmlNode sibling = row.NextSibling;
                        while (sibling != null)
                        {
                            var sibClass = sibling.GetAttributeValue("class", string.Empty);
                            if (!string.IsNullOrEmpty(sibClass) && !sibClass.Contains("row-tall"))
                            {
                                // todo: check attr itemscope

                                // match row
                                GameMatch match = new GameMatch();
                                match.Date  = sibling.SelectSingleNode("./div[contains(@class,'time-playing')]").InnerText();
                                match.Team1 = sibling.SelectSingleNode("./div[contains(@class,'ply') and contains(@class,'t-home')]").InnerText();
                                match.Team2 = sibling.SelectSingleNode("./div[contains(@class,'ply') and contains(@class,'t-away')]").InnerText();
                                match.Score = sibling.SelectSingleNode("./div[contains(@class,'sco')]").InnerText();
                                var matchUrl = sibling.SelectSingleNode("./div[contains(@class,'live-centre')]/a").AttributeValue("href", string.Empty);
                                match.Url = host + "/" + matchUrl.TrimStart('/');
                                // http://vi.live3s.com/link-sopcast/hang-2-duc/eintr-frankfurt-vs-nurnberg-link893026
                                var elapsed = sibling.SelectSingleNode("./div[@class='min']/span");
                                if (elapsed != null)
                                {
                                    match.ElapsedTime = elapsed.InnerText; // elapsedTime get by ajax
                                    var    sid     = elapsed.GetAttributeValue("id", string.Empty);
                                    string pattern = ".*-(\\d+)";
                                    if (string.IsNullOrEmpty(sid) == false && Regex.IsMatch(sid, pattern))
                                    {
                                        var grs = Regex.Match(sid, pattern);
                                        match.Id = grs.Groups[1].Value;
                                    }
                                }

                                Debug.WriteLine("> {0} - {1} - {2} - {3}", match.Date, match.Team1, match.Score, match.Team2);

                                // add match to champion
                                champ.Matches.Add(match);

                                // get next sibling
                                sibling = sibling.NextSibling;
                                i++; // skip match row
                            }
                            else
                            {
                                break; // next sibling is champion
                            }
                        }
                    }
                    catch (Exception ex) {
                        Debug.WriteLine("parse data error: " + ex.Message);
                    } // parse data error

                    champions.Add(champ);
                }
            }

            return(champions);
        }