| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427 | using GFGGame;using ET;namespace ET{    //推送好友每日重置    public class NoticeFriendDailyReset : AMHandler<S2C_NoticeFriendDailyReset>    {        protected override async ETTask Run(Session session, S2C_NoticeFriendDailyReset message)        {            FriendSProxy.ReqAllFriendInfos().Coroutine();            await ETTask.CompletedTask;        }    }    //推送其他玩家信息变化    public class NoticeRoleInfoChanged : AMHandler<S2C_NoticeFriendInfo>    {        protected override async ETTask Run(Session session, S2C_NoticeFriendInfo message)        {            OtherRoleInfoData roleInfo = new OtherRoleInfoData();            roleInfo.roleId = message.RoleInfo.RoleId;            roleInfo.roleLv = message.RoleInfo.RoleLvl;            roleInfo.roleName = message.RoleInfo.RoleName;            roleInfo.offlineTimeSec = message.RoleInfo.OfflineTimeSec;            FriendDataManager.Instance.ChangeFriendInfo(roleInfo);            EventAgent.DispatchEvent(ConstMessage.FRIEND_REFRESH);            await ETTask.CompletedTask;        }    }    //推送申请添加好友信息    public class NoticeApplyForFriend : AMHandler<S2C_NoticeApplyForFriend>    {        protected override async ETTask Run(Session session, S2C_NoticeApplyForFriend message)        {            if(FriendDataManager.Instance.CheckInApplyList(message.FriendInfo.RoleInfo.RoleId))            {                return;            }            OtherRoleInfoData roleInfo = new OtherRoleInfoData();            roleInfo.roleId = message.FriendInfo.RoleInfo.RoleId;            roleInfo.roleName = message.FriendInfo.RoleInfo.RoleName;            roleInfo.roleLv = message.FriendInfo.RoleInfo.RoleLvl;            roleInfo.offlineTimeSec = message.FriendInfo.RoleInfo.OfflineTimeSec;            roleInfo.headId = message.FriendInfo.RoleInfo.HeadItemId;            roleInfo.headBorderId = message.FriendInfo.RoleInfo.HeadBorderItemId;            FriendInfoData friendInfo = new FriendInfoData();            friendInfo.roleInfo = roleInfo;            friendInfo.type = message.FriendInfo.Type;            friendInfo.giveGiftState = message.FriendInfo.GiveGiftState;            friendInfo.takeGiftState = message.FriendInfo.TakeGiftState;            FriendDataManager.Instance.AddApplyData(friendInfo);            EventAgent.DispatchEvent(ConstMessage.FRIEND_APPLY_CHANGE);            EventAgent.DispatchEvent(ConstMessage.RED_CHANGE);            await ETTask.CompletedTask;        }    }    //推送新增好友    public class NoticeAddFriends : AMHandler<S2C_NoticeAddFriends>    {        protected override async ETTask Run(Session session, S2C_NoticeAddFriends message)        {            for (int i = 0; i < message.FriendList.Count; i++)            {                OtherRoleInfoData roleInfo = new OtherRoleInfoData();                roleInfo.roleId = message.FriendList[i].RoleInfo.RoleId;                roleInfo.roleName = message.FriendList[i].RoleInfo.RoleName;                roleInfo.roleLv = message.FriendList[i].RoleInfo.RoleLvl;                roleInfo.offlineTimeSec = message.FriendList[i].RoleInfo.OfflineTimeSec;                roleInfo.headId = message.FriendList[i].RoleInfo.HeadItemId;                roleInfo.headBorderId = message.FriendList[i].RoleInfo.HeadBorderItemId;                FriendInfoData friendInfo = new FriendInfoData();                friendInfo.roleInfo = roleInfo;                friendInfo.type = message.FriendList[i].Type;                friendInfo.giveGiftState = message.FriendList[i].GiveGiftState;                friendInfo.takeGiftState = message.FriendList[i].TakeGiftState;                FriendDataManager.Instance.AddFriend(friendInfo);                FriendDataManager.Instance.RemoveApplyData(message.FriendList[i].RoleInfo.RoleId);            }            EventAgent.DispatchEvent(ConstMessage.FRIEND_ADD);            EventAgent.DispatchEvent(ConstMessage.RED_CHANGE);            await ETTask.CompletedTask;        }    }    //推送删除好友    public class NoticeDeleteFriend : AMHandler<S2C_NoticeDeleteFriend>    {        protected override async ETTask Run(Session session, S2C_NoticeDeleteFriend message)        {            FriendDataManager.Instance.RemoveFriend(message.FriendId);            EventAgent.DispatchEvent(ConstMessage.FRIEND_REMOVE);            EventAgent.DispatchEvent(ConstMessage.RED_CHANGE);            await ETTask.CompletedTask;        }    }    //推送领取赠送状态    public class NoticeTakeGiftStates : AMHandler<S2C_NoticeTakeGiftStates>    {        protected override async ETTask Run(Session session, S2C_NoticeTakeGiftStates message)        {            FriendDataManager.Instance.ChangeTakeGiftStates(message.FriendId, message.TakeGiftState);            EventAgent.DispatchEvent(ConstMessage.FRIEND_REFRESH);            EventAgent.DispatchEvent(ConstMessage.RED_CHANGE);            await ETTask.CompletedTask;        }    }}namespace GFGGame{    public static class FriendSProxy    {        //请求所有好友信息        public static async ETTask<bool> ReqAllFriendInfos()        {            S2C_GetAllFriendInfos response = null;            response = (S2C_GetAllFriendInfos)await MessageHelper.SendToServer(new C2S_GetAllFriendInfos());            if (response != null)            {                if (response.Error == ErrorCode.ERR_Success)                {                    FriendDataManager.Instance.ClearAddFriend();                    for (int i = 0; i < response.FriendList.Count; i++)                    {                        OtherRoleInfoData roleInfo = new OtherRoleInfoData();                        roleInfo.roleId = response.FriendList[i].RoleInfo.RoleId;                        roleInfo.roleName = response.FriendList[i].RoleInfo.RoleName;                        roleInfo.roleLv = response.FriendList[i].RoleInfo.RoleLvl;                        roleInfo.offlineTimeSec = response.FriendList[i].RoleInfo.OfflineTimeSec;                        roleInfo.headId = response.FriendList[i].RoleInfo.HeadItemId;                        roleInfo.headBorderId = response.FriendList[i].RoleInfo.HeadBorderItemId;                        FriendInfoData friendInfo = new FriendInfoData();                        friendInfo.roleInfo = roleInfo;                        friendInfo.type = response.FriendList[i].Type;                        friendInfo.giveGiftState = response.FriendList[i].GiveGiftState;                        friendInfo.takeGiftState = response.FriendList[i].TakeGiftState;                        if (response.FriendList[i].Type == FriendType.Good)                        {                            FriendDataManager.Instance.AddFriend(friendInfo);                        }                        else if (response.FriendList[i].Type == FriendType.Apply)                        {                            if (!FriendDataManager.Instance.CheckInApplyList(friendInfo.roleInfo.roleId))                            {                                FriendDataManager.Instance.AddApplyData(friendInfo);                            }                        }                    }                    EventAgent.DispatchEvent(ConstMessage.FRIEND_ADD);                    return true;                }            }            return false;        }        //赠送        public static async ETTask<bool> ReqGiveGiftToFriend(long friendId)        {            S2C_GiveGiftToFriend response = null;            response = (S2C_GiveGiftToFriend)await MessageHelper.SendToServer(new C2S_GiveGiftToFriend() { FriendId = friendId });            if (response != null)            {                if (response.Error == ErrorCode.ERR_Success)                {                    FriendDataManager.Instance.ChangeGiveGiftStates(response.FriendId, response.GiveGiftState);                    PromptController.Instance.ShowFloatTextPrompt(string.Format("赠送好友体力*{0}", GlobalCfgArray.globalCfg.onceGivePowerCount));                    EventAgent.DispatchEvent(ConstMessage.FRIEND_REFRESH);                    return true;                }            }            return false;        }        //一键赠送        public static async ETTask<bool> ReqGiveGiftToAllFriend()        {            S2C_GiveGiftToAllFriends response = null;            response = (S2C_GiveGiftToAllFriends)await MessageHelper.SendToServer(new C2S_GiveGiftToAllFriends());            if (response != null)            {                if (response.Error == ErrorCode.ERR_Success)                {                    for (int i = 0; i < response.FriendIds.Count; i++)                    {                        FriendDataManager.Instance.ChangeGiveGiftStates(response.FriendIds[i], response.GiveGiftStates[i]);                    }                    if (response.FriendIds.Count > 0)                    {                        PromptController.Instance.ShowFloatTextPrompt(string.Format("送出{0}份体力", response.FriendIds.Count));                    }                    else                    {                        PromptController.Instance.ShowFloatTextPrompt("无好友可赠送体力");                    }                    EventAgent.DispatchEvent(ConstMessage.FRIEND_REFRESH);                    return true;                }            }            return false;        }        //领取并赠送赠送        public static async ETTask<bool> ReqTakeGiftFromFriend(long friendId)        {            S2C_TakeGiftFromFriend response = null;            response = (S2C_TakeGiftFromFriend)await MessageHelper.SendToServer(new C2S_TakeGiftFromFriend() { FriendId = friendId });            if (response != null)            {                if (response.Error == ErrorCode.ERR_Success)                {                    FriendDataManager.Instance.ChangeGiveTakeGiftStates(response.FriendId, response.GiveGiftState, response.TakeGiftState);                    PromptController.Instance.ShowFloatTextPrompt(string.Format("领取成功,获得体力*{0}", GlobalCfgArray.globalCfg.onceGivePowerCount));                    EventAgent.DispatchEvent(ConstMessage.FRIEND_REFRESH);                    EventAgent.DispatchEvent(ConstMessage.RED_CHANGE);                    return true;                }            }            return false;        }        //一键领取并赠送        public static async ETTask<bool> ReqTakeGiftFromAllFriend()        {            S2C_TakeGiftFromAllFriend response = null;            response = (S2C_TakeGiftFromAllFriend)await MessageHelper.SendToServer(new C2S_TakeGiftFromAllFriend());            if (response != null)            {                if (response.Error == ErrorCode.ERR_Success)                {                    for (int i = 0; i < response.FriendIds.Count; i++)                    {                        FriendDataManager.Instance.ChangeGiveTakeGiftStates(response.FriendIds[i], response.GiveGiftStates[i], response.TakeGiftStates[i]);                    }                    if (FriendDataManager.Instance.Count >= FriendDataManager.Instance.maxGetPowerCount)                    {                        PromptController.Instance.ShowFloatTextPrompt("今日体力已全部领取");                    }                    else                    {                        PromptController.Instance.ShowFloatTextPrompt(string.Format("已领取{0}体力", response.FriendIds.Count * GlobalCfgArray.globalCfg.onceGivePowerCount));                    }                    EventAgent.DispatchEvent(ConstMessage.RED_CHANGE);                    EventAgent.DispatchEvent(ConstMessage.FRIEND_REFRESH);                    return true;                }            }            EventAgent.DispatchEvent(ConstMessage.RED_CHANGE);            return false;        }        //请求搜索其他玩家        public static async ETTask<bool> ReqSearchRole(long roleID, string roleName)        {            S2C_SearchRole response = null;            response = (S2C_SearchRole)await MessageHelper.SendToServer(new C2S_SearchRole() { RoleId = roleID, RoleName = roleName });            if (response != null)            {                if (response.Error == ErrorCode.ERR_Success)                {                    FriendDataManager.Instance.ClearSearchDatas();                    for (int i = 0; i < response.RoleList.Count; i++)                    {                        OtherRoleInfoData roleInfo = new OtherRoleInfoData();                        roleInfo.roleId = response.RoleList[i].RoleId;                        roleInfo.roleName = response.RoleList[i].RoleName;                        roleInfo.roleLv = response.RoleList[i].RoleLvl;                        roleInfo.offlineTimeSec = response.RoleList[i].OfflineTimeSec;                        roleInfo.headId = response.RoleList[i].HeadItemId;                        roleInfo.headBorderId = response.RoleList[i].HeadBorderItemId;                        FriendDataManager.Instance.AddSearchData(roleInfo);                    }                    return true;                }            }            return false;        }        //请求推荐好友        public static async ETTask<bool> ReqRecommendFriends(long roleId = 1 )        {            S2C_GetRecommendFriends response = null;            response = (S2C_GetRecommendFriends)await MessageHelper.SendToServer(new C2S_GetRecommendFriends() { RoleId = roleId });            if (response != null)            {                if (response.Error == ErrorCode.ERR_Success)                {                    FriendDataManager.Instance.ClearRecommendDatas();                    for (int i = 0; i < response.RoleList.Count; i++)                    {                        OtherRoleInfoData roleInfo = new OtherRoleInfoData();                        roleInfo.roleId = response.RoleList[i].RoleId;                        roleInfo.roleName = response.RoleList[i].RoleName;                        roleInfo.roleLv = response.RoleList[i].RoleLvl;                        roleInfo.offlineTimeSec = response.RoleList[i].OfflineTimeSec;                        roleInfo.headId = response.RoleList[i].HeadItemId;                        roleInfo.headBorderId = response.RoleList[i].HeadBorderItemId;                        FriendDataManager.Instance.AddRecommendData(roleInfo);                    }                    return true;                }            }            return false;        }        //申请添加好友        public static async ETTask<bool> ReqApplyForFriend(long friendId)        {            S2C_RequestApplyForFriend response = null;            response = (S2C_RequestApplyForFriend)await MessageHelper.SendToServer(new C2S_RequestApplyForFriend() { FriendId = friendId });            if (response != null)            {                if (response.Error == ErrorCode.ERR_Success)                {                    return true;                }            }            return false;        }        //同意添加好友        public static async ETTask<bool> ReqAcceptApplyForFriend(long friendId)        {            S2C_AcceptApplyForFriend response = null;            response = (S2C_AcceptApplyForFriend)await MessageHelper.SendToServer(new C2S_AcceptApplyForFriend() { FriendId = friendId });            if (response != null)            {                if (response.Error == ErrorCode.ERR_Success)                {                    // FriendDataManager.Instance.RemoveApplyData(roleId);                    return true;                }            }            return false;        }        //拒绝添加好友        public static async ETTask<bool> ReqRefuseApplyForFriend(long friendId)        {            S2C_RefuseApplyForFriend response = null;            response = (S2C_RefuseApplyForFriend)await MessageHelper.SendToServer(new C2S_RefuseApplyForFriend() { FriendId = friendId });            if (response != null)            {                if (response.Error == ErrorCode.ERR_Success)                {                    FriendDataManager.Instance.RemoveApplyData(friendId);                    EventAgent.DispatchEvent(ConstMessage.RED_CHANGE);                    EventAgent.DispatchEvent(ConstMessage.FRIEND_APPLY_CHANGE);                    return true;                }            }            return false;        }        //一键同意添加好友        public static async ETTask<bool> ReqAcceptAllApplyForFriend()        {            S2C_AcceptAllApplyForFriend response = null;            response = (S2C_AcceptAllApplyForFriend)await MessageHelper.SendToServer(new C2S_AcceptAllApplyForFriend());            if (response != null)            {                if (response.Error == ErrorCode.ERR_Success)                {                    return true;                }            }            return false;        }        //一键拒绝添加好友        public static async ETTask<bool> ReqRefuseAllApplyForFriend()        {            S2C_RefuseAllApplyForFriend response = null;            response = (S2C_RefuseAllApplyForFriend)await MessageHelper.SendToServer(new C2S_RefuseAllApplyForFriend());            if (response != null)            {                if (response.Error == ErrorCode.ERR_Success)                {                    FriendDataManager.Instance.ClearApplyDatas();                    EventAgent.DispatchEvent(ConstMessage.RED_CHANGE);                    EventAgent.DispatchEvent(ConstMessage.FRIEND_APPLY_CHANGE);                    return true;                }            }            return false;        }        //请求删除好友        public static async ETTask<bool> ReqDeleteFriend(long friendId)        {            S2C_RequestDeleteFriend response = null;            response = (S2C_RequestDeleteFriend)await MessageHelper.SendToServer(new C2S_RequestDeleteFriend() { FriendId = friendId });            if (response != null)            {                if (response.Error == ErrorCode.ERR_Success)                {                    FriendDataManager.Instance.RemoveFriend(response.FriendId);                    PromptController.Instance.ShowFloatTextPrompt("好友已删除");                    EventAgent.DispatchEvent(ConstMessage.FRIEND_REMOVE);                    return true;                }            }            return false;        }    }}
 |