using System; using System.Collections.Generic; namespace ET { [ActorMessageHandler] public class R2M_DeleteUserHandler : AMActorRpcHandler { protected override async ETTask Run(Scene scene, R2M_DeleteUser request, M2R_DeleteUser response, Action reply) { try { //********************** Log.Debug($"*********************************************************UserId = {request.UserId} 删除角色"); // User user = await UserComponent.Instance.Query(request.UserId); // if (user == null) // { // response.Message = $"没有这个玩家"; // Log.Error($"服务器没有这个玩家Id={ request.UserId}"); // reply(); // return; // } // long unitId = user.Id; // Unit unit = MapUnitComponent.Instance.Get(unitId); // if (unit == null) // { // return; // // } // else // { // Team team = TeamComponent.Instance.Get(unit.TeamLeaderId); // if (team.TeamState == TeamState.Fight) // { // response.Message = "战斗中不能删除角色!"; // reply(); // return; // } // } // user.hasRole = false; // // await DBComponent.Instance.Save(user); // // await DBComponent.Instance.Remove(unitId); // await C2M_DeleteFriend(unitId); // await DBComponent.Instance.Remove(unitId); // await DBComponent.Instance.Remove(unitId); // await DBComponent.Instance.Remove(unitId); // await DBComponent.Instance.Remove(t => t.Nickname.Equals(user.NickName)); // await DeleteConsignment(unitId); // await DeleteFamily(user.NickName, unitId); reply(); Log.Debug($"UserId = {request.UserId}删除角色完成"); } catch (System.Exception e) { Log.Error(e); } } private async ETTask DeleteFamily(string name, long unitId) { Family family = await FamilyComponent.Instance.Query(name); if(family != null) await family.ForceDeleteMember(unitId); } private async ETTask C2M_DeleteFriend(long unitId) { IEnumerable list = await FriendComponent.Instance.GetFriends(unitId); foreach (long id in list) { await FriendComponent.Instance.DeleteFriend(id, unitId); } FriendComponent.Instance.FriendDic.Remove(unitId); await DBComponent.Instance.Remove(unitId); } private async ETTask DeleteConsignment(long unitId) { await DBComponent.Instance.Remove(t => t.UnitId == unitId); } } }