AdvancedLogParser.InfoGather.GetCharacters C# (CSharp) Method

GetCharacters() public static method

public static GetCharacters ( ) : void
return void
        public static void GetCharacters()
        {
            currentLoader.status.Text = "Querying characters...";
            Application.DoEvents();
            try
            {
                using (MySqlDataReader reader = MySqlHelper.ExecuteReader(ConnectionString, "SELECT * FROM characters"))
                {
                    currentLoader.status.Text = "Loading characters...";
                    Application.DoEvents();
                    while (reader.Read())
                    {
                        uint id;
                        ushort serverId;
                        uint playerId;
                        string name;
                        uint level;
                        uint race;
                        uint subRace;
                        string deity;
                        uint gender;
                        uint hitPoints;
                        uint xp;
                        uint gp;
                        uint wealth;
                        uint ethics;
                        uint morals;
                        uint class1;
                        uint level1;
                        uint class2;
                        uint level2;
                        uint class3;
                        uint level3;
                        uint strength;
                        uint dexterity;
                        uint constitution;
                        uint intelligence;
                        uint wisdom;
                        uint charisma;
                        uint damage;
                        uint deaths;
                        uint status;
                        bool isOnline;
                        bool isDeleted;
                        bool isPlayable;
                        sbyte retiredStatus;

                        try
                        {
                            id = (uint)reader.GetValue(0);
                            serverId = (ushort)reader.GetValue(1);
                            playerId = (uint)reader.GetValue(2);
                            name = (string)reader.GetValue(3);
                            level = (byte)reader.GetValue(4);
                            race = (byte)reader.GetValue(5);
                            subRace = (byte)reader.GetValue(6);
                            deity = (string)reader.GetValue(7);
                            gender = (byte)reader.GetValue(8);
                            hitPoints = (ushort)reader.GetValue(9);
                            xp = (uint)reader.GetValue(10);
                            gp = (uint)reader.GetValue(11);
                            wealth = (uint)reader.GetValue(12);
                            ethics = (byte)reader.GetValue(13);
                            morals = (byte)reader.GetValue(14);
                            class1 = (ushort)reader.GetValue(15);
                            level1 = (byte)reader.GetValue(16);
                            class2 = (ushort)reader.GetValue(17);
                            level2 = (byte)reader.GetValue(18);
                            class3 = (ushort)reader.GetValue(19);
                            level3 = (byte)reader.GetValue(20);

                            strength = (byte)reader.GetValue(23);
                            dexterity = (byte)reader.GetValue(24);
                            constitution = (byte)reader.GetValue(25);
                            intelligence = (byte)reader.GetValue(26);
                            wisdom = (byte)reader.GetValue(27);
                            charisma = (byte)reader.GetValue(28);

                            damage = (ushort)reader.GetValue(30);
                            deaths = (ushort)reader.GetValue(31);
                            status = (uint)reader.GetValue(32);
                            isOnline = (bool)reader.GetValue(33);
                            isDeleted = (bool)reader.GetValue(34);
                            isPlayable = (bool)reader.GetValue(35);
                            retiredStatus = (sbyte)reader.GetValue(38);
                        }
                        catch
                        {
                            continue;
                        }
                        if (name.ToLower().Contains("test"))
                        {
                            continue;
                        }
                        Character newChar = new AdvancedLogParser.Character()
                        {
                            Charisma = charisma,
                            Class1 = class1,
                            Class2 = class2,
                            Class3 = class3,
                            Constitution = constitution,
                            Damage = damage,
                            Deaths = deaths,
                            Deity = deity,
                            Dexterity = dexterity,
                            DMTime = 0.0f,
                            Ethics = ethics,
                            Gender = gender,
                            GP = gp,
                            HitPoints = hitPoints,
                            Id = id,
                            Intelligence = intelligence,
                            IsDeleted = isDeleted,
                            IsOnline = isOnline,
                            IsPlayable = isPlayable,
                            Level = level,
                            Level1 = level1,
                            Level2 = level2,
                            Level3 = level3,
                            Morals = morals,
                            Name = name,
                            PlayerId = playerId,
                            Race = race,
                            RetiredStatus = retiredStatus,
                            ServerId = serverId,
                            Status = status,
                            Strength = strength,
                            SubRace = subRace,
                            Wealth = wealth,
                            Wisdom = wisdom,
                            XP = xp
                        };

                        if (morals >= 70)
                        {
                            if (ethics >= 70) newChar.Alignment = Alignment.LawfulGood;
                            else if (ethics >= 31) newChar.Alignment = Alignment.NeutralGood;
                            else newChar.Alignment = Alignment.ChaoticGood;
                        }
                        else if (morals >= 31)
                        {
                            if (ethics >= 70) newChar.Alignment = Alignment.LawfulNeutral;
                            else if (ethics >= 31) newChar.Alignment = Alignment.TrueNeutral;
                            else newChar.Alignment = Alignment.ChaoticNeutral;
                        }
                        else
                        {
                            if (ethics >= 70) newChar.Alignment = Alignment.LawfulEvil;
                            else if (ethics >= 31) newChar.Alignment = Alignment.NeutralEvil;
                            else newChar.Alignment = Alignment.ChaoticEvil;
                        }

                        Characters.List.Add(id, newChar);
                        try
                        {
                            Players.ListByPlayerId[playerId].Characters.Add(newChar);
                        }
                        catch { }
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                Application.Exit();
            }
        }

Usage Example

Beispiel #1
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            InfoGather.DatabasePassword = ConfigurationSettings.AppSettings["DatabasePassword"];
            InfoGather.DatabaseSchema   = ConfigurationSettings.AppSettings["DatabaseSchema"];
            InfoGather.DatabaseServer   = ConfigurationSettings.AppSettings["DatabaseServer"];
            InfoGather.DatabasePort     = ConfigurationSettings.AppSettings["DatabasePort"];
            InfoGather.DatabaseUser     = ConfigurationSettings.AppSettings["DatabaseUser"];
            InfoGather.BuildConnectionString();
            Players.ListByPlayerId = new Dictionary <uint, Player>();
            Players.ListByKey      = new Dictionary <string, Player>();
            Characters.List        = new Dictionary <uint, Character>();
            Logs.AdvancementAlerts = new Dictionary <uint, Log>();
            Logs.DeathAlerts       = new Dictionary <uint, Log>();
            Logs.EnforcementAlerts = new Dictionary <uint, Log>();
            Logs.RecentLogins      = new Dictionary <uint, Log>();
            Servers.List           = new Dictionary <uint, Server>();
            if (InfoGather.GetPlayers())
            {
                InfoGather.GetCharacters();
                InfoGather.CountBankValue();
                InfoGather.CountpChestValue();
                InfoGather.GetAlerts();
                InfoGather.GetLogins();
                InfoGather.IdentifyLogins();
                InfoGather.GetDMTime();
                InfoGather.currentLoader.Close();
                InfoGather.currentLoader.Dispose();
                if (ServerFocus >= 0)
                {
                    foreach (Server srv in Servers.List.Values)
                    {
                        if (srv.ServerId == Math.Abs(ServerFocus))
                        {
                            Application.Run(new ServerView(srv));
                        }
                    }
                }
                else
                {
                    foreach (Server srv in Servers.List.Values)
                    {
                        new ServerView(srv).Show();
                    }
                    new ServerView(null).Show();
                    Application.Run(new PrimaryDisplay());
                }
            }
        }