示例#1
0
        /// <summary>
        /// Load all guilds and alliances from the database
        /// </summary>
        public static bool LoadAllGuilds()
        {
            lock (m_guilds.SyncRoot)
            {
                m_guilds.Clear();                 //clear guild list before loading!
            }
            m_lastID = 0;

            //load guilds
            var guildObjs = GameServer.Database.SelectAllObjects <DBGuild>();

            foreach (var obj in guildObjs)
            {
                var myguild = new Guild(obj);

                if (obj.Ranks == null ||
                    obj.Ranks.Length < 10 ||
                    obj.Ranks[0] == null ||
                    obj.Ranks[1] == null ||
                    obj.Ranks[2] == null ||
                    obj.Ranks[3] == null ||
                    obj.Ranks[4] == null ||
                    obj.Ranks[5] == null ||
                    obj.Ranks[6] == null ||
                    obj.Ranks[7] == null ||
                    obj.Ranks[8] == null ||
                    obj.Ranks[9] == null)
                {
                    log.ErrorFormat("GuildMgr: Ranks missing for {0}, creating new ones!", myguild.Name);

                    RepairRanks(myguild);

                    // now reload the guild to fix the relations
                    myguild = new Guild(DOLDB <DBGuild> .SelectObjects(DB.Column(nameof(DBGuild.GuildID)).IsEqualTo(obj.GuildID)).FirstOrDefault());
                }

                AddGuild(myguild);

                var guildCharacters = DOLDB <DOLCharacters> .SelectObjects(DB.Column(nameof(DOLCharacters.GuildID)).IsEqualTo(myguild.GuildID));

                var tempList = new Dictionary <string, GuildMemberDisplay>(guildCharacters.Count);

                foreach (DOLCharacters ch in guildCharacters)
                {
                    var member = new GuildMemberDisplay(ch.ObjectId,
                                                        ch.Name,
                                                        ch.Level.ToString(),
                                                        ch.Class.ToString(),
                                                        ch.GuildRank.ToString(),
                                                        "0",
                                                        ch.LastPlayed.ToShortDateString(),
                                                        ch.GuildNote);
                    tempList.Add(ch.ObjectId, member);
                }

                m_guildXAllMembers.Add(myguild.GuildID, tempList);
            }

            //load alliances
            var allianceObjs = GameServer.Database.SelectAllObjects <DBAlliance>();

            foreach (DBAlliance dball in allianceObjs)
            {
                var myalliance = new Alliance();
                myalliance.LoadFromDatabase(dball);

                if (dball != null && dball.DBguilds != null)
                {
                    foreach (DBGuild mydbgui in dball.DBguilds)
                    {
                        var gui = GetGuildByName(mydbgui.GuildName);
                        myalliance.Guilds.Add(gui);
                        gui.alliance = myalliance;
                    }
                }
            }

            return(true);
        }
示例#2
0
        /// <summary>
        /// Load all guilds and alliances from the database
        /// </summary>
        public static bool LoadAllGuilds()
        {
            lock (m_guilds.SyncRoot)
            {
                m_guilds.Clear(); //clear guild list before loading!
            }
            m_lastID = 0;

            //load guilds
            var guildObjs = GameServer.Database.SelectAllObjects<DBGuild>();
            foreach (var obj in guildObjs)
            {
                var myguild = new Guild(obj);

                if (obj.Ranks == null ||
                    obj.Ranks.Length < 10 ||
                    obj.Ranks[0] == null ||
                    obj.Ranks[1] == null ||
                    obj.Ranks[2] == null ||
                    obj.Ranks[3] == null ||
                    obj.Ranks[4] == null ||
                    obj.Ranks[5] == null ||
                    obj.Ranks[6] == null ||
                    obj.Ranks[7] == null ||
                    obj.Ranks[8] == null ||
                    obj.Ranks[9] == null)
                {
                    log.ErrorFormat("GuildMgr: Ranks missing for {0}, creating new ones!", myguild.Name);

                    RepairRanks(myguild);

                    // now reload the guild to fix the relations
                    myguild = new Guild(GameServer.Database.SelectObject<DBGuild>("GuildID = '" + obj.GuildID + "'"));
                }

                AddGuild(myguild);

                var guildCharacters = GameServer.Database.SelectObjects<DOLCharacters>(string.Format("GuildID = '" + GameServer.Database.Escape(myguild.GuildID) + "'"));
                var tempList = new Dictionary<string, GuildMemberDisplay>(guildCharacters.Count);

                foreach (DOLCharacters ch in guildCharacters)
                {
                    var member = new GuildMemberDisplay(ch.ObjectId,
                                                        ch.Name,
                                                        ch.Level.ToString(),
                                                        ch.Class.ToString(),
                                                        ch.GuildRank.ToString(),
                                                        "0",
                                                        ch.LastPlayed.ToShortDateString(),
                                                        ch.GuildNote);
                    tempList.Add(ch.ObjectId, member);
                }

                m_guildXAllMembers.Add(myguild.GuildID, tempList);
            }

            //load alliances
            var allianceObjs = GameServer.Database.SelectAllObjects<DBAlliance>();
            foreach (DBAlliance dball in allianceObjs)
            {
                var myalliance = new Alliance();
                myalliance.LoadFromDatabase(dball);

                if (dball != null && dball.DBguilds != null)
                {
                    foreach (DBGuild mydbgui in dball.DBguilds)
                    {
                        var gui = GetGuildByName(mydbgui.GuildName);
                        myalliance.Guilds.Add(gui);
                        gui.alliance = myalliance;
                    }
                }
            }

            return true;
        }