private void SetMatch()
        {
            var playersList          = ReplayMatch.ReplayMatchPlayers.ToList();
            var matchAwardDictionary = ReplayMatch.ReplayMatchAward.ToDictionary(x => x.PlayerId, x => x.Award);

            // load up correct build information
            HeroesIcons.LoadHeroesBuild(ReplayMatch.ReplayBuild);

            var playerParties = PlayerParties.FindPlayerParties(playersList);

            foreach (var player in playersList)
            {
                if (player.Team == 4)
                {
                    continue;
                }

                MatchPlayerBase matchPlayerBase = new MatchPlayerBase(InternalService, Website, player);
                matchPlayerBase.SetPlayerInfo(player.IsAutoSelect, playerParties, matchAwardDictionary);

                // add to collection
                if (player.Team == 0)
                {
                    MatchOverviewTeam1List.Add(matchPlayerBase);
                }
                else if (player.Team == 1)
                {
                    MatchOverviewTeam2List.Add(matchPlayerBase);
                }

                if (player.PlayerId == UserProfile.PlayerId)
                {
                    UserHero      = player.Character;
                    UserHeroImage = HeroesIcons.HeroBuilds().GetHeroInfo(player.Character).GetHeroPortrait();
                    WinnerResult  = player.IsWinner ? "Win" : "Loss";
                }
            }

            GameMode   = ReplayMatch.GameMode.GetFriendlyName();
            MapName    = ReplayMatch.MapName;
            TimeStamp  = ReplayMatch.TimeStamp.Value;
            GameLength = ReplayMatch.ReplayLength;
            Build      = ReplayMatch.ReplayBuild;
            ReplayId   = ReplayMatch.ReplayId;
        }
        /// <summary>
        /// Attempt to auto translate Hero name using talents, returns true if succeeded
        /// </summary>
        /// <param name="talents"></param>
        /// <param name="character">Translated hero name</param>
        /// <returns></returns>
        private bool AutoTranslateHeroNameByTalent(Talent[] talents, out string character)
        {
            int talentCount = talents.Count();

            character = string.Empty;

            while (talentCount > 0)
            {
                if (HeroesIcons.HeroBuilds().GetHeroNameFromTalentReferenceName(talents[talentCount - 1].TalentName, out character))
                {
                    return(true);
                }
                else
                {
                    talentCount--;
                }
            }

            return(false);
        }
Пример #3
0
        private void PlayerRelatedData()
        {
            Player[] players = GetPlayers();

            foreach (var player in players.Select((value, index) => new { value, index }))
            {
                if (player.value == null)
                {
                    continue;
                }

                ReplayAllHotsPlayer hotsPlayer = new ReplayAllHotsPlayer
                {
                    BattleTagName     = HeroesHelpers.BattleTags.GetBattleTagName(player.value.Name, player.value.BattleTag),
                    BattleNetId       = player.value.BattleNetId,
                    BattleNetRegionId = player.value.BattleNetRegionId,
                    BattleNetSubId    = player.value.BattleNetSubId,
                    BattleNetTId      = player.value.BattleNetTId,
                    AccountLevel      = player.value.AccountLevel,
                    LastSeen          = Replay.Timestamp,
                    LastSeenBefore    = null,
                    Seen = 1,
                };

                long playerId;

                // check if player is already in the database, update if found, otherwise add a new record
                if (ReplaysDb.HotsPlayer.IsExistingRecord(ReplaysContext, hotsPlayer))
                {
                    playerId = ReplaysDb.HotsPlayer.UpdateRecord(ReplaysContext, hotsPlayer);
                }
                else
                {
                    playerId = ReplaysDb.HotsPlayer.CreateRecord(ReplaysContext, hotsPlayer);
                }

                if (player.value.Character == null && Replay.GameMode == Heroes.ReplayParser.GameMode.Custom)
                {
                    player.value.Team      = 4;
                    player.value.Character = "None";

                    ReplayMatchPlayer replayPlayer = new ReplayMatchPlayer
                    {
                        ReplayId          = ReplayId,
                        PlayerId          = playerId,
                        Character         = player.value.Character,
                        CharacterLevel    = player.value.CharacterLevel,
                        Difficulty        = player.value.Difficulty.ToString(),
                        Handicap          = player.value.Handicap,
                        IsAutoSelect      = player.value.IsAutoSelect,
                        IsSilenced        = player.value.IsSilenced,
                        IsWinner          = player.value.IsWinner,
                        MountAndMountTint = player.value.MountAndMountTint,
                        PartyValue        = player.value.PartyValue,
                        PlayerNumber      = -1,
                        SkinAndSkinTint   = player.value.SkinAndSkinTint,
                        Team         = player.value.Team,
                        AccountLevel = player.value.AccountLevel,
                    };

                    ReplaysDb.MatchPlayer.CreateRecord(ReplaysContext, replayPlayer);
                }
                else
                {
                    string character = HeroesIcons.HeroBuilds().GetRealHeroNameFromHeroUnitName(player.value.HeroUnits.FirstOrDefault().Name);
                    if (string.IsNullOrEmpty(character))
                    {
                        throw new TranslationException(RetrieveAllMapAndHeroNames());
                    }

                    ReplayMatchPlayer replayPlayer = new ReplayMatchPlayer
                    {
                        ReplayId          = ReplayId,
                        PlayerId          = playerId,
                        Character         = character,
                        CharacterLevel    = player.value.CharacterLevel,
                        Difficulty        = player.value.Difficulty.ToString(),
                        Handicap          = player.value.Handicap,
                        IsAutoSelect      = player.value.IsAutoSelect,
                        IsSilenced        = player.value.IsSilenced,
                        IsWinner          = player.value.IsWinner,
                        MountAndMountTint = player.value.MountAndMountTint,
                        PartyValue        = player.value.PartyValue,
                        PlayerNumber      = player.index,
                        SkinAndSkinTint   = player.value.SkinAndSkinTint,
                        Team         = player.value.Team,
                        AccountLevel = player.value.AccountLevel,
                    };

                    ReplaysDb.MatchPlayer.CreateRecord(ReplaysContext, replayPlayer);

                    AddScoreResults(player.value.ScoreResult, playerId);
                    AddPlayerTalents(player.value.Talents, playerId, character);
                    AddMatchAwards(player.value.ScoreResult.MatchAwards, playerId);
                }

                AddPlayerHeroes(player.value.PlayerCollectionDictionary, playerId);
            } // end foreach loop for players
        }