public async Task Handle(WorldClient client, GuildKickPacket packet) { if (!_guildManager.HasGuild || _guildManager.GuildRank > 3) { _packetFactory.SendGuildKickMember(client, false, packet.CharacterId); return; } var removedId = packet.CharacterId; var ok = await _guildManager.TryRemoveMember(removedId); if (!ok) { _packetFactory.SendGuildKickMember(client, false, removedId); return; } // Update guild members. foreach (var member in _guildManager.GuildMembers.ToList()) { if (!_gameWorld.Players.ContainsKey(member.Id)) { continue; } var guildPlayer = _gameWorld.Players[member.Id]; if (guildPlayer.Id == removedId) { await guildPlayer.GuildManager.Clear(); } else { var temp = guildPlayer.GuildManager.GuildMembers.FirstOrDefault(x => x.Id == removedId); if (temp != null) { guildPlayer.GuildManager.GuildMembers.Remove(temp); } } _packetFactory.SendGuildMemberRemove(guildPlayer.GameSession.Client, removedId); } _packetFactory.SendGuildKickMember(client, true, removedId); }
public async Task Handle(WorldClient client, GuildLeavePacket packet) { if (!_guildManager.HasGuild) { return; } var ok = await _guildManager.TryRemoveMember(_gameSession.CharId); if (!ok) { _packetFactory.SendGuildMemberLeaveResult(client, false); return; } foreach (var member in _guildManager.GuildMembers.ToList()) { if (!_gameWorld.Players.ContainsKey(member.Id)) { continue; } var guildPlayer = _gameWorld.Players[member.Id]; if (guildPlayer.Id == _gameSession.CharId) { await guildPlayer.GuildManager.Clear(); } else { var temp = guildPlayer.GuildManager.GuildMembers.FirstOrDefault(x => x.Id == _gameSession.CharId); if (temp != null) { guildPlayer.GuildManager.GuildMembers.Remove(temp); } _packetFactory.SendGuildMemberLeave(guildPlayer.GameSession.Client, _gameSession.CharId); } } _packetFactory.SendGuildMemberLeaveResult(client, true); }