示例#1
0
        public bool Equals(DestinyPlayer input)
        {
            if (input == null)
            {
                return(false);
            }

            return
                ((
                     DestinyUserInfo == input.DestinyUserInfo ||
                     (DestinyUserInfo != null && DestinyUserInfo.Equals(input.DestinyUserInfo))
                     ) &&
                 (
                     CharacterClass == input.CharacterClass ||
                     (CharacterClass != null && CharacterClass.Equals(input.CharacterClass))
                 ) &&
                 (
                     ClassHash == input.ClassHash ||
                     (ClassHash.Equals(input.ClassHash))
                 ) &&
                 (
                     RaceHash == input.RaceHash ||
                     (RaceHash.Equals(input.RaceHash))
                 ) &&
                 (
                     GenderHash == input.GenderHash ||
                     (GenderHash.Equals(input.GenderHash))
                 ) &&
                 (
                     CharacterLevel == input.CharacterLevel ||
                     (CharacterLevel.Equals(input.CharacterLevel))
                 ) &&
                 (
                     LightLevel == input.LightLevel ||
                     (LightLevel.Equals(input.LightLevel))
                 ) &&
                 (
                     BungieNetUserInfo == input.BungieNetUserInfo ||
                     (BungieNetUserInfo != null && BungieNetUserInfo.Equals(input.BungieNetUserInfo))
                 ) &&
                 (
                     ClanName == input.ClanName ||
                     (ClanName != null && ClanName.Equals(input.ClanName))
                 ) &&
                 (
                     ClanTag == input.ClanTag ||
                     (ClanTag != null && ClanTag.Equals(input.ClanTag))
                 ) &&
                 (
                     EmblemHash == input.EmblemHash ||
                     (EmblemHash.Equals(input.EmblemHash))
                 ));
        }
示例#2
0
 /// <summary>
 /// <c>true</c> se <paramref name="s"/> faz parte do nome do tanque, do clã ou do jogador
 /// </summary>
 /// <param name="s"></param>
 /// <returns></returns>
 public bool IsGlobalMatch(string s)
 {
     s = s.RemoveDiacritics().ToLowerInvariant();
     if (Name.RemoveDiacritics().ToLowerInvariant().Contains(s))
     {
         return(true);
     }
     if (FullName.RemoveDiacritics().ToLowerInvariant().Contains(s))
     {
         return(true);
     }
     if (ClanTag.RemoveDiacritics().ToLowerInvariant().Contains(s))
     {
         return(true);
     }
     if (GamerTag.RemoveDiacritics().ToLowerInvariant().Contains(s))
     {
         return(true);
     }
     return(false);
 }
        public override global::System.Int32 GetHashCode()
        {
            unchecked
            {
                int hash = 5;
                hash ^= 397 * AccountId.GetHashCode();
                if (Nickname != null)
                {
                    hash ^= 397 * Nickname.GetHashCode();
                }

                if (ClanTag != null)
                {
                    hash ^= 397 * ClanTag.GetHashCode();
                }

                hash ^= 397 * LastBattle.GetHashCode();
                hash ^= 397 * BattlesCount.GetHashCode();
                hash ^= 397 * WinRate.GetHashCode();
                return(hash);
            }
        }
示例#4
0
        public Source Load()
        {
            Debug.WriteLine("Loading " + tsvFile);
            string[] text = File.ReadAllLines(tsvFile);
            if (text.Length < 1)
            {
                throw new ArgumentException("TSV does not have any data. Check format of spreadsheet.");
            }

            // Build a map of the incoming data
            string headerRow = text[0];

            string[] columns         = headerRow.Split('\t').Where(s => !string.IsNullOrWhiteSpace(s)).ToArray();
            int      numberOfHeaders = columns.Length;

            PropertyEnum[] resolved = new PropertyEnum[numberOfHeaders];
            for (int i = 0; i < numberOfHeaders; ++i)
            {
                string header = columns[i].ToLowerInvariant()
                                .Replace("your ", "")
                                .Replace(" ", "")
                                .Replace("_", "")
                                .Replace(":", "")
                                .Replace("-", "")
                                .Replace("'s", "")
                                .Replace("teamcaptain", "captain")
                                .Replace("teammember", "player")
                ;
                if (string.IsNullOrWhiteSpace(header))
                {
                    Console.WriteLine($"Warning: Unable to resolve header, it is blank after processing: \"{header}\", (was \"{columns[i]}\")");
                    resolved[i] = PropertyEnum.UNKNOWN;
                }
                // Quick case
                else if (propertyValueStringMap.ContainsKey(header))
                {
                    resolved[i] = propertyValueStringMap[header];
                }
                else
                {
                    // Need to do some searching
                    int playerNum = 0;
                    if (header.Contains("captain"))
                    {
                        playerNum = 1;
                        header    = header.Replace("captain", "");
                    }
                    else
                    {
                        for (playerNum = 10; playerNum > 0; --playerNum)
                        {
                            if (header.Contains(playerNum.ToString()))
                            {
                                header = header.Replace(playerNum.ToString(), "");
                                break;
                            }
                        }
                    }

                    var matchedKey = propertyValueStringMap.Keys.FirstOrDefault(key => header.StartsWith(key));
                    if (matchedKey != null)
                    {
                        // For player num = 0 (not found), this will just return the appropriate header.
                        resolved[i] = (playerNum * (int)PropertyEnum.PlayerN_Offset) + propertyValueStringMap[matchedKey];
                    }
                    else if (playerNum == 0)
                    {
                        resolved[i] = PropertyEnum.UNKNOWN;
                        Console.WriteLine("Warning: Unable to resolve header: " + header);
                    }
                    else
                    {
                        resolved[i] = PropertyEnum.UNKNOWN;
                        Console.WriteLine("Warning: Unable to resolve header for player " + playerNum + ": " + header);
                    }
                }
            }

            // Now read the data...
            // Most tsv files will be team sheets, but for draft cups and verif they could be player records instead.
            // Each row therefore might be a single team with players, or a single player entry.
            List <Team>   teams   = new List <Team>();
            List <Player> players = new List <Player>();

            // From 1 as [0] is header row
            for (int lineIndex = 1; lineIndex < text.Length; ++lineIndex)
            {
                string line = text[lineIndex];
                if (!line.Contains('\t'))
                {
                    continue;
                }

                string[] cells = line.Split('\t').ToArray();

                // Warn if the values exceeds the number of defined headers (but don't bother if we're only one over and it's empty -- trailing tab)
                if (numberOfHeaders < cells.Length && (numberOfHeaders != cells.Length - 1 || !string.IsNullOrWhiteSpace(cells[cells.Length - 1])))
                {
                    Console.WriteLine($"Warning: Line {lineIndex} contains more cells in this row {cells.Length} than headers {numberOfHeaders}.");
                    Debug.WriteLine(line);
                }

                SortedDictionary <int, Player> rowPlayers = new SortedDictionary <int, Player>();
                Team t = new Team();

                for (int i = 0; i < cells.Length && i < numberOfHeaders; ++i)
                {
                    int          playerNum        = 0;
                    PropertyEnum resolvedProperty = resolved[i];
                    if (resolvedProperty > PropertyEnum.PlayerN_Offset)
                    {
                        playerNum        = (int)resolved[i] / (int)PropertyEnum.PlayerN_Offset;
                        resolvedProperty = (PropertyEnum)((int)resolved[i] % (int)PropertyEnum.PlayerN_Offset);
                    }

                    string value = cells[i];
                    if (string.IsNullOrWhiteSpace(value))
                    {
                        continue;
                    }

                    switch (resolvedProperty)
                    {
                    case PropertyEnum.UNKNOWN:
                    {
                        continue;
                    }

                    case PropertyEnum.Country:
                    {
                        var p = GetCurrentPlayer(ref rowPlayers, playerNum, tsvFile);
                        p.Country = value;
                        break;
                    }

                    case PropertyEnum.DiscordId:
                    {
                        var p = GetCurrentPlayer(ref rowPlayers, playerNum, tsvFile);
                        if (value.Length >= 14 && value.Length < 21)
                        {
                            // First, test is decimal (of length 17+)
                            bool isDecimal = value.Length >= 17 && value.All("0123456789".Contains);
                            if (isDecimal)
                            {
                                p.AddDiscordId(value, source);
                            }
                            // Otherwise test if we can get from a hex string (of length 14+ to give the correct 17 digit decimal)
                            else if (ulong.TryParse(value, NumberStyles.HexNumber, CultureInfo.CurrentCulture, out ulong parsedId))
                            {
                                p.AddDiscordId(value, source);
                            }
                            else
                            {
                                Console.WriteLine($"Warning: DiscordId was specified ({lineIndex},{i}), but the value could not be parsed from a decimal or hex string. {value}.");
                                Debug.WriteLine(line);
                            }
                        }
                        else
                        {
                            Console.WriteLine($"Warning: DiscordId was specified ({lineIndex},{i}), but the value length does not fit into a discord id. {value}.");
                            Debug.WriteLine(line);
                        }
                        break;
                    }

                    case PropertyEnum.DiscordName:
                    {
                        var p = GetCurrentPlayer(ref rowPlayers, playerNum, tsvFile);
                        if (Discord.DISCORD_NAME_REGEX.IsMatch(value))
                        {
                            p.AddDiscordUsername(value, source);
                        }
                        else if (FriendCode.TryParse(value, out FriendCode friendCode))
                        {
                            p.AddFCs(friendCode, source);
                            Console.WriteLine($"Warning: This value was declared as a Discord name but looks like a friend code. Bad data formatting? {value} on ({lineIndex},{i}).");
                        }
                        else
                        {
                            Console.WriteLine($"Warning: DiscordName was specified ({lineIndex},{i}), but the value was not in a Discord format of name#0000. {value}.");
                            Debug.WriteLine(line);
                        }
                        break;
                    }

                    case PropertyEnum.FC:
                    {
                        var p = GetCurrentPlayer(ref rowPlayers, playerNum, tsvFile);
                        if (FriendCode.TryParse(value, out FriendCode friendCode))
                        {
                            p.AddFCs(friendCode, source);
                        }
                        else
                        {
                            Console.WriteLine($"Warning: FC was specified ({lineIndex},{i}), but the value was not in an FC format of 0000-0000-0000 or 0000 0000 0000. {value}.");
                            Debug.WriteLine(line);
                        }
                        break;
                    }

                    case PropertyEnum.Div:
                    {
                        t.AddDivision(new Division(value, divType, season), source);

                        if (divType == DivType.Unknown)
                        {
                            Console.WriteLine($"Warning: Div was specified ({lineIndex},{i}), but I don't know what type of division this file represents.");
                        }
                        break;
                    }

                    case PropertyEnum.LUTIDiv:
                    {
                        t.AddDivision(new Division(value, DivType.LUTI, season), source);
                        break;
                    }

                    case PropertyEnum.EBTVDiv:
                    {
                        t.AddDivision(new Division(value, DivType.EBTV, season), source);
                        break;
                    }

                    case PropertyEnum.DSBDiv:
                    {
                        t.AddDivision(new Division(value, DivType.DSB, season), source);
                        break;
                    }

                    case PropertyEnum.Timestamp:
                    {
                        // TODO - not supported right now. In future we could customise the source timestamp for this entry.
                        break;
                    }

                    case PropertyEnum.Name:
                    {
                        var p = GetCurrentPlayer(ref rowPlayers, playerNum, tsvFile);

                        var playerName = value.Trim();
                        playerName = t.Tag?.StripFromPlayer(playerName) ?? playerName;
                        p.AddName(playerName, source);

                        if (FriendCode.TryParse(value, out FriendCode friendCode))
                        {
                            p.AddFCs(friendCode, source);
                            Console.WriteLine($"Warning: This value was declared as a name but looks like a friend code. Bad data formatting? {value} on ({lineIndex},{i}).");
                            Debug.WriteLine(line);
                        }
                        break;
                    }

                    case PropertyEnum.Role:
                    {
                        var p = GetCurrentPlayer(ref rowPlayers, playerNum, tsvFile);
                        p.AddWeapons(value.Split(',').Select(s => s.Trim()).Where(s => !string.IsNullOrWhiteSpace(s)));
                        break;
                    }

                    case PropertyEnum.Pronouns:
                    {
                        var p = GetCurrentPlayer(ref rowPlayers, playerNum, tsvFile);
                        p.PronounInformation.SetPronoun(value, source);
                        break;
                    }

                    case PropertyEnum.Tag:
                    {
                        t.AddClanTag(value, source);
                        break;
                    }

                    case PropertyEnum.TeamName:
                    {
                        t.AddName(value, source);
                        break;
                    }

                    case PropertyEnum.Twitter:
                    {
                        var p = GetCurrentPlayer(ref rowPlayers, playerNum, tsvFile);
                        p.AddTwitter(value, source);
                        break;
                    }

                    case PropertyEnum.Twitch:
                    {
                        var p = GetCurrentPlayer(ref rowPlayers, playerNum, tsvFile);
                        p.AddTwitch(value, source);
                        break;
                    }

                    case PropertyEnum.Team_Offset:
                    case PropertyEnum.UnspecifiedPlayer_Offset:
                    case PropertyEnum.PlayerN_Offset:
                    default:
                    {
                        Console.WriteLine($"Warning: Unhandled header {resolvedProperty}. {value}. Line {lineIndex}:");
                        Debug.WriteLine(line);
                        break;
                    }
                    }
                }

                // End of the row, add the data.
                foreach (var pair in rowPlayers)
                {
                    // Don't add empty players
                    Player p = pair.Value;
                    if (p.Name.Equals(Builtins.UnknownPlayerName))
                    {
                        continue;
                    }
                    // Don't add the team to the player if it's not complete (e.g. single player record)
                    if (!t.Name.Equals(Builtins.UnknownTeamName))
                    {
                        p.TeamInformation.Add(t.Id, source);
                    }
                    players.Add(p);
                }

                // Don't bother adding the team if it has no players
                if (players.Count > 0)
                {
                    // Don't register a team if that information doesn't exist.
                    if (!t.Name.Equals(Builtins.UnknownTeamName))
                    {
                        // Recalculate the ClanTag layout
                        if (t.Tag != null)
                        {
                            t.Tag.CalculateTagOption(players[0].Name.Value);
                        }
                        else
                        {
                            ClanTag?newTag = ClanTag.CalculateTagFromNames(players.Select(p => p.Name.Value).ToArray(), source);

                            if (newTag != null)
                            {
                                t.AddClanTag(newTag);
                            }
                        }
                        teams.Add(t);
                    }
                }
            }

            source.Players = players.ToArray();
            source.Teams   = teams.ToArray();
            return(source);
        }
示例#5
0
 private void clanButton_Click(object sender, EventArgs e)
 {
     ClanTag.Set(clanTextBox.Text);
 }
        public virtual global::System.Boolean Equals(FindPlayers_Players_AccountsSearchResponseItem?other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }

            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            if (other.GetType() != GetType())
            {
                return(false);
            }

            return((AccountId == other.AccountId) && ((Nickname is null && other.Nickname is null) || Nickname != null && Nickname.Equals(other.Nickname)) && ((ClanTag is null && other.ClanTag is null) || ClanTag != null && ClanTag.Equals(other.ClanTag)) && LastBattle.Equals(other.LastBattle) && BattlesCount == other.BattlesCount && WinRate == other.WinRate);
        }
示例#7
0
        private string ToStringFull()
        {
            var sb = new StringBuilder(1024);

            sb.Append(TeamName.SanitizeToCsv());
            sb.Append(",");

            sb.Append(GamerTag.SanitizeToCsv());
            sb.Append(",");

            if (!string.IsNullOrWhiteSpace(CheckedInAt))
            {
                sb.Append(CheckedInAt.SanitizeToCsv());
            }

            sb.Append(",");

            if (!string.IsNullOrWhiteSpace(TeamNameAgain))
            {
                sb.Append(TeamNameAgain.SanitizeToCsv());
            }

            sb.Append(",");

            if (!string.IsNullOrWhiteSpace(ClanTag))
            {
                sb.Append(ClanTag.SanitizeToCsv());
            }

            sb.Append(",");

            if (!string.IsNullOrWhiteSpace(ClanUrl))
            {
                sb.Append(ClanUrl.SanitizeToCsv());
            }

            sb.Append(",");

            if (!string.IsNullOrWhiteSpace(PreferredServer))
            {
                sb.Append(PreferredServer.SanitizeToCsv());
            }

            sb.Append(",");

            if (!string.IsNullOrWhiteSpace(AlternateServer))
            {
                sb.Append(AlternateServer.SanitizeToCsv());
            }

            sb.Append(",");

            if (TeamContactMailAddress != null)
            {
                sb.Append(TeamContactMailAddress.Address.SanitizeToCsv());
            }

            sb.Append(",");

            // new fields

            sb.Append(OriginalLine);
            sb.Append(",");

            sb.Append(IsValid ? "1" : "0");
            sb.Append(",");

            if (!IsValid)
            {
                sb.Append(InvalidReasons.SanitizeToCsv());
            }

            sb.Append(",");

            if (ClanId.HasValue)
            {
                sb.Append(ClanId.Value);
            }

            sb.Append(",");

            if (Player != null)
            {
                sb.Append(Player.Id);
            }

            sb.Append(",");

            if (Player?.CurrentClanId != null)
            {
                sb.Append(Player.CurrentClanId.Value);
            }

            sb.Append(",");

            if (Player?.CurrentClanTag != null)
            {
                sb.Append(Player.CurrentClanTag);
            }

            sb.Append(",");

            if (Player != null)
            {
                sb.Append(Player.Moment.ToString("yyyy-MM-dd HH:mm:ss"));
            }

            sb.Append(",");

            sb.Append(PreferredServerLocation);
            sb.Append(",");

            sb.Append(AlternateServerLocation);
            sb.Append(",");

            if (Player == null)
            {
                sb.Append(",,,,,,,");
            }
            else
            {
                sb.Append($"{Player.Battles.ToString("N0", CultureInfo.InvariantCulture).SanitizeToCsv()}," +
                          $"{Player.WinRate.ToString("N4", CultureInfo.InvariantCulture).SanitizeToCsv()}," +
                          $"{Player.AvgTier.ToString("N2", CultureInfo.InvariantCulture).SanitizeToCsv()}," +
                          $"{Player.Wn8.ToString("N0", CultureInfo.InvariantCulture).SanitizeToCsv()}," +
                          $"{Player.Tier10Battles.ToString("N0", CultureInfo.InvariantCulture).SanitizeToCsv()}," +
                          $"{Player.Tier10WinRate.ToString("N4", CultureInfo.InvariantCulture).SanitizeToCsv()}," +
                          $"{Player.Tier10Wn8.ToString("N0", CultureInfo.InvariantCulture).SanitizeToCsv()}," +
                          $"{Player.Tier10DirectDamage.ToString("N0", CultureInfo.InvariantCulture).SanitizeToCsv()}");
            }

            return(sb.ToString());
        }
示例#8
0
        private string ToStringSimple()
        {
            var sb = new StringBuilder(1024);

            sb.Append(GamerTag.SanitizeToCsv());
            sb.Append(",");

            sb.Append(TeamName.SanitizeToCsv());
            sb.Append(",");

            if (!string.IsNullOrWhiteSpace(ClanTag))
            {
                sb.Append(ClanTag.SanitizeToCsv());
            }
            sb.Append(",");

            // new fields

            sb.Append(OriginalLine);
            sb.Append(",");

            // Division
            sb.Append(",");

            // Group
            sb.Append(",");

            sb.Append(IsValid ? "1" : "0");
            sb.Append(",");

            if (!IsValid)
            {
                sb.Append(InvalidReasons.SanitizeToCsv());
            }

            sb.Append(",");

            if (ClanId.HasValue)
            {
                sb.Append(ClanId.Value);
            }

            sb.Append(",");

            if (Player != null)
            {
                sb.Append(Player.Id);
            }

            sb.Append(",");

            if (Player?.CurrentClanId != null)
            {
                sb.Append(Player.CurrentClanId.Value);
            }

            sb.Append(",");

            if (Player?.CurrentClanTag != null)
            {
                sb.Append(Player.CurrentClanTag);
            }

            sb.Append(",");

            if (Player != null)
            {
                sb.Append(Player.Moment.ToString("yyyy-MM-dd HH:mm:ss"));
            }
            sb.Append(",");

            if (Player == null)
            {
                sb.Append(",,,,,,,");
            }
            else
            {
                sb.Append($"{Player.Battles.ToString("N0", CultureInfo.InvariantCulture).SanitizeToCsv()}," +
                          $"{Player.WinRate.ToString("N4", CultureInfo.InvariantCulture).SanitizeToCsv()}," +
                          $"{Player.AvgTier.ToString("N2", CultureInfo.InvariantCulture).SanitizeToCsv()}," +
                          $"{Player.Wn8.ToString("N0", CultureInfo.InvariantCulture).SanitizeToCsv()}," +
                          $"{Player.Tier10Battles.ToString("N0", CultureInfo.InvariantCulture).SanitizeToCsv()}," +
                          $"{Player.Tier10WinRate.ToString("N4", CultureInfo.InvariantCulture).SanitizeToCsv()}," +
                          $"{Player.Tier10Wn8.ToString("N0", CultureInfo.InvariantCulture).SanitizeToCsv()}," +
                          $"{Player.Tier10DirectDamage.ToString("N0", CultureInfo.InvariantCulture).SanitizeToCsv()}");
            }

            return(sb.ToString());
        }
示例#9
0
        /// <summary>
        ///     Validates the record (only internal coerence)
        /// </summary>
        public void Validate()
        {
            if (string.IsNullOrWhiteSpace(TeamName))
            {
                AddInvalidReason("Team Name is empty.");
            }

            if (string.IsNullOrWhiteSpace(GamerTag))
            {
                AddInvalidReason("Gamer Tag is empty.");
            }
            else if (!GamerTagRegex.IsMatch(GamerTag))
            {
                AddInvalidReason($"Gamer Tag [{GamerTag}] is invalid.");
            }

            if (string.IsNullOrWhiteSpace(ClanTag) == false)
            {
                ClanTag = ClanTag.Trim('[', ']', '{', '}', '<', '>', ' ', '\t');
            }

            if (!string.IsNullOrWhiteSpace(ClanTag) && !ClanTagRegex.IsMatch(ClanTag))
            {
                AddInvalidReason($"Clan Tag [{ClanTag}] is invalid.");
            }

            if (Type == RecordType.Simple)
            {
                return;
            }

            if (string.IsNullOrEmpty(CheckedInAt))
            {
                // Is it a problem?
                CheckedInAt = string.Empty;
            }

            if (string.IsNullOrEmpty(TeamNameAgain))
            {
                // Is it a problem?
                TeamNameAgain = string.Empty;
            }

            if (!string.IsNullOrWhiteSpace(ClanUrl))
            {
                var match = ClanUrlRegex.Match(ClanUrl);
                if (!match.Success)
                {
                    AddInvalidReason($"Clan URL (field 6, '{ClanUrl}') is invalid.");
                }

                ClanTagFromUrl = match.Groups["clanTag"].Value.ToUpperInvariant();
            }

            if (!string.IsNullOrWhiteSpace(PreferredServer))
            {
                var location = ParseServer(PreferredServer);
                if (location == ServerLocation.Unknown)
                {
                    AddInvalidReason($"Could not detect the preferred server ('{PreferredServer}') on field 7.");
                }

                PreferredServerLocation = location;
            }

            if (!string.IsNullOrWhiteSpace(AlternateServer))
            {
                var location = ParseServer(AlternateServer);
                if (location == ServerLocation.Unknown)
                {
                    AddInvalidReason($"Could not detect the alternate server on '{AlternateServer}' on field 8");
                }

                AlternateServerLocation = location;
            }

            HandleServerPreferences();

            if (!string.IsNullOrWhiteSpace(TeamContactMail))
            {
                try
                {
                    TeamContactMailAddress = new MailAddress(TeamContactMail);
                }
                catch (Exception)
                {
                    AddInvalidReason($"Team Contact Gamer E-Mail (field 9, '{TeamContactMail}') is invalid.");
                }
            }
        }