Beispiel #1
0
        /// <summary>
        /// Loads a guild and it's members from the database
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static Guild LoadGuild(Guid id)
        {
            if (!Guilds.TryGetValue(id, out Guild found))
            {
                using (var context = DbInterface.CreatePlayerContext())
                {
                    var guild = context.Guilds.Where(g => g.Id == id).Include(g => g.Bank).FirstOrDefault();
                    if (guild != null)
                    {
                        //Load Members
                        var members = context.Players.Where(p => p.DbGuild.Id == id).ToDictionary(t => t.Id, t => new Tuple <Guid, string, int, int, Guid, Guid>(t.Id, t.Name, t.GuildRank, t.Level, t.ClassId, t.MapId));
                        foreach (var member in members)
                        {
                            var gmember = new GuildMember(member.Value.Item1, member.Value.Item2, member.Value.Item3, member.Value.Item4, ClassBase.GetName(member.Value.Item5), MapBase.GetName(member.Value.Item6));
                            guild.Members.AddOrUpdate(member.Key, gmember, (key, oldValue) => gmember);
                        }

                        SlotHelper.ValidateSlots(guild.Bank, guild.BankSlotsCount);
                        guild.Bank = guild.Bank.OrderBy(bankSlot => bankSlot?.Slot).ToList();

                        Guilds.AddOrUpdate(id, guild, (key, oldValue) => guild);

                        return(guild);
                    }
                }
            }
            else
            {
                return(found);
            }
            return(null);
        }
Beispiel #2
0
 /// <summary>
 /// Updates the number of bank slots alotted to this guild for use, only expanding because we don't want to risk wiping items
 /// </summary>
 /// <param name="count"></param>
 public void ExpandBankSlots(int count)
 {
     if (count > BankSlotsCount)
     {
         lock (mLock)
         {
             BankSlotsCount = count;
             SlotHelper.ValidateSlots(Bank, BankSlotsCount);
             DbInterface.Pool.QueueWorkItem(Save);
         }
     }
 }
Beispiel #3
0
        /// <summary>
        /// Create a new Guild instance.
        /// </summary>
        /// <param name="creator">The <see cref="Player"/> that created the guild.</param>
        /// <param name="name">The Name of the guild.</param>
        public static Guild CreateGuild(Player creator, string name)
        {
            name = name.Trim();

            if (creator != null && FieldChecking.IsValidGuildName(name, Strings.Regex.guildname))
            {
                using (var context = DbInterface.CreatePlayerContext(readOnly: false))
                {
                    var guild = new Guild()
                    {
                        Name         = name,
                        FoundingDate = DateTime.UtcNow
                    };

                    SlotHelper.ValidateSlots(guild.Bank, Options.Instance.Guild.GuildBankSlots);
                    guild.Bank = guild.Bank.OrderBy(bankSlot => bankSlot?.Slot).ToList();

                    var player = context.Players.FirstOrDefault(p => p.Id == creator.Id);
                    if (player != null)
                    {
                        player.DbGuild       = guild;
                        player.GuildRank     = 0;
                        player.GuildJoinDate = DateTime.UtcNow;


                        context.ChangeTracker.DetectChanges();
                        context.SaveChanges();

                        var member = new GuildMember(player.Id, player.Name, player.GuildRank, player.Level, player.ClassName, player.MapName);
                        guild.Members.AddOrUpdate(player.Id, member, (key, oldValue) => member);

                        creator.Guild         = guild;
                        creator.GuildRank     = 0;
                        creator.GuildJoinDate = DateTime.UtcNow;

                        // Send our entity data to nearby players.
                        PacketSender.SendEntityDataToProximity(Player.FindOnline(creator.Id));

                        Guilds.AddOrUpdate(guild.Id, guild, (key, oldValue) => guild);

                        LogActivity(guild.Id, creator, null, GuildActivityType.Created, name);

                        return(guild);
                    }
                }
            }
            return(null);
        }