Exemple #1
0
        /// <summary>
        /// Joins a player into the guild.
        /// </summary>
        /// <param name="player">The player to join into the guild.</param>
        /// <param name="rank">Integer index of the rank to give this new member.</param>
        /// <param name="initiator">The player who initiated this change (null if done by the api or some other method).</param>
        public void AddMember(Player player, int rank, Player initiator = null)
        {
            if (player != null && !Members.Any(m => m.Key == player.Id))
            {
                using (var context = DbInterface.CreatePlayerContext(readOnly: false))
                {
                    var dbPlayer = context.Players.FirstOrDefault(p => p.Id == player.Id);
                    if (dbPlayer != null)
                    {
                        dbPlayer.DbGuild       = this;
                        dbPlayer.GuildRank     = rank;
                        dbPlayer.GuildJoinDate = DateTime.UtcNow;
                        context.ChangeTracker.DetectChanges();
                        DetachGuildFromDbContext(context, this);
                        context.SaveChanges();

                        player.Guild         = this;
                        player.GuildRank     = rank;
                        player.GuildJoinDate = DateTime.UtcNow;

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

                        // Send our new guild list to everyone that's online.
                        UpdateMemberList();

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

                        LogActivity(Id, player, initiator, GuildActivityType.Joined);
                    }
                }
            }
        }