321 lines
16 KiB
C#
321 lines
16 KiB
C#
using asap.core;
|
||
using GameCore;
|
||
using NSubstitute;
|
||
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.Events;
|
||
|
||
namespace game
|
||
{
|
||
public class FriendAddPanelBackendOperation
|
||
{
|
||
FishingFriendAddPanel m_Panel;
|
||
public UnityAction<FriendAddItemData> m_Callback = null; // 回调事件
|
||
FriendAddItemData m_Data;
|
||
FriendAddPanelBackendOperationFromType m_FromType = FriendAddPanelBackendOperationFromType.FromTypeInvalid;
|
||
|
||
public UnityAction<FriendAddPanelBackendOperation, string, int> m_CallbackWithStringAndInt = null;
|
||
|
||
public FriendAddItemData Data
|
||
{
|
||
get { return m_Data; }
|
||
}
|
||
|
||
public async void StartInvite(string playfabID, UnityAction<FriendAddPanelBackendOperation, string, int> Callback)
|
||
{
|
||
try
|
||
{
|
||
m_CallbackWithStringAndInt = Callback;
|
||
string json = await GContext.container.Resolve<FriendService>().AddFriend(playfabID);
|
||
if (!string.IsNullOrEmpty(json))
|
||
{
|
||
// code 1:添加好友成功;-1:我的好友已满;-2:对方好友已满;-3:获取对方好友列表失败;-4:我加对方好友失败;-5:对方加我好友失败;2:已经添加过对方好友;
|
||
AddFriendResp addFriendResp = Newtonsoft.Json.JsonConvert.DeserializeObject<AddFriendResp>(json);
|
||
if (addFriendResp != null)
|
||
{
|
||
#if AGG
|
||
using (var e = GEvent.GameEvent("friend_send"))
|
||
{
|
||
e.AddContent("playfabid", GContext.container.Resolve<IUserService>().UserId)
|
||
.AddContent("friendplayfabid", playfabID)
|
||
.AddContent("code", addFriendResp.Code)
|
||
.AddContent("friendcode", GContext.container.Resolve<FriendService>().GetInvitationCodeByPlayFabID(playfabID));
|
||
}
|
||
#endif
|
||
GContext.Publish(new ResetWaitTime() { waitTime = 10f });
|
||
switch (addFriendResp.Code)
|
||
{
|
||
case FriendHelper.Code_OK:
|
||
case FriendHelper.Code_AddFriend_HaveAddedBefore_OK:
|
||
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_90"));
|
||
if (m_CallbackWithStringAndInt != null)
|
||
{
|
||
m_CallbackWithStringAndInt(this, playfabID, FriendHelper.Code_OK);
|
||
}
|
||
break;
|
||
case FriendHelper.Code_AddFriend_FriendHaveNoLimit:
|
||
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_91"));
|
||
if (m_CallbackWithStringAndInt != null)
|
||
{
|
||
m_CallbackWithStringAndInt(this, playfabID, FriendHelper.Code_AddFriend_FriendHaveNoLimit);
|
||
}
|
||
break;
|
||
case FriendHelper.Code_AddFriend_IHaveNoLimit:
|
||
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_92"));
|
||
if (m_CallbackWithStringAndInt != null)
|
||
{
|
||
m_CallbackWithStringAndInt(this, playfabID, FriendHelper.Code_AddFriend_IHaveNoLimit);
|
||
}
|
||
break;
|
||
case FriendHelper.Code_AddFriend_GetFriendList_Failed_PlayFabError:
|
||
case FriendHelper.Code_AddFriend_IAddFriend_Failed_PlayFabError:
|
||
case FriendHelper.Code_AddFriend_FriendAddMe_Failed_PlayFabError:
|
||
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_93"));
|
||
if (m_CallbackWithStringAndInt != null)
|
||
{
|
||
m_CallbackWithStringAndInt(this, playfabID, FriendHelper.Code_AddFriend_GetFriendList_Failed_PlayFabError);
|
||
}
|
||
break;
|
||
default:
|
||
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_93"));
|
||
if (m_CallbackWithStringAndInt != null)
|
||
{
|
||
m_CallbackWithStringAndInt(this, playfabID, FriendHelper.Code_AddFriend_GetFriendList_Failed_PlayFabError);
|
||
}
|
||
break;
|
||
}
|
||
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string msg = "[FriendAddPanelBackendOperation] StartInvite encountered a fatal problem.";
|
||
Debug.LogError($"{msg}-{ex.Message} \r\n {ex.StackTrace}");
|
||
}
|
||
}
|
||
|
||
public async void StartRecommendedInvite(FishingFriendAddPanel panel, FriendAddItemData data, UnityAction<FriendAddItemData> failCallback)
|
||
{
|
||
m_Panel = panel;
|
||
m_Data = data;
|
||
m_Callback = failCallback;
|
||
m_FromType = FriendAddPanelBackendOperationFromType.FromTypeRecommended;
|
||
|
||
string json = await GContext.container.Resolve<FriendService>().AddFriend(m_Data.FriendInfo.PlayFabId);
|
||
|
||
if (!string.IsNullOrEmpty(json))
|
||
{
|
||
// code 1:添加好友成功;-1:我的好友已满;-2:对方好友已满;-3:获取对方好友列表失败;-4:我加对方好友失败;-5:对方加我好友失败;2:已经添加过对方好友;
|
||
AddFriendResp addFriendResp = Newtonsoft.Json.JsonConvert.DeserializeObject<AddFriendResp>(json);
|
||
if (addFriendResp != null)
|
||
{
|
||
#if AGG
|
||
using (var e = GEvent.GameEvent("friend_send"))
|
||
{
|
||
e.AddContent("playfabid", GContext.container.Resolve<IUserService>().UserId)
|
||
.AddContent("friendplayfabid", m_Data.FriendInfo.PlayFabId)
|
||
.AddContent("code", addFriendResp.Code)
|
||
.AddContent("friendcode", GContext.container.Resolve<FriendService>().GetInvitationCodeByPlayFabID(m_Data.FriendInfo.PlayFabId));
|
||
}
|
||
#endif
|
||
|
||
switch (addFriendResp.Code)
|
||
{
|
||
case FriendHelper.Code_OK:
|
||
case FriendHelper.Code_AddFriend_HaveAddedBefore_OK:
|
||
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_90"));
|
||
//if (m_Callback != null)
|
||
//{
|
||
// m_Callback(m_Data);
|
||
//}
|
||
break;
|
||
case FriendHelper.Code_AddFriend_FriendHaveNoLimit:
|
||
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_91"));
|
||
if (m_Callback != null)
|
||
{
|
||
m_Callback(m_Data);
|
||
}
|
||
break;
|
||
case FriendHelper.Code_AddFriend_IHaveNoLimit:
|
||
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_92"));
|
||
if (m_Callback != null)
|
||
{
|
||
m_Callback(m_Data);
|
||
}
|
||
break;
|
||
case FriendHelper.Code_AddFriend_GetFriendList_Failed_PlayFabError:
|
||
case FriendHelper.Code_AddFriend_IAddFriend_Failed_PlayFabError:
|
||
case FriendHelper.Code_AddFriend_FriendAddMe_Failed_PlayFabError:
|
||
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_93"));
|
||
if (m_Callback != null)
|
||
{
|
||
m_Callback(m_Data);
|
||
}
|
||
break;
|
||
default:
|
||
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_93"));
|
||
if (m_Callback != null)
|
||
{
|
||
m_Callback(m_Data);
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
public async void StartInvitedAccept(FishingFriendAddPanel panel, FriendAddItemData data, UnityAction<FriendAddItemData> callback)
|
||
{
|
||
m_Panel = panel;
|
||
m_Data = data;
|
||
m_Callback = callback;
|
||
m_FromType = FriendAddPanelBackendOperationFromType.FromTypeInvited;
|
||
|
||
string json = await GContext.container.Resolve<FriendService>().AcceptFriend(FriendHelper.Accept_Type_Accept,
|
||
GContext.container.Resolve<IUserService>().UserId, m_Data.FriendInfo.PlayFabId);
|
||
|
||
if (!string.IsNullOrEmpty(json))
|
||
{
|
||
AcceptFriendResp acceptFriendResp = Newtonsoft.Json.JsonConvert.DeserializeObject<AcceptFriendResp>(json);
|
||
if (acceptFriendResp != null)
|
||
{
|
||
#if AGG
|
||
using (var e = GEvent.GameEvent("friend_request"))
|
||
{
|
||
e.AddContent("playfabid", GContext.container.Resolve<IUserService>().UserId)
|
||
.AddContent("friendplayfabid", m_Data.FriendInfo.PlayFabId)
|
||
.AddContent("code", acceptFriendResp.Code)
|
||
.AddContent("friendcode", GContext.container.Resolve<FriendService>().GetInvitationCodeByPlayFabID(GContext.container.Resolve<IUserService>().UserId));
|
||
}
|
||
#endif
|
||
|
||
switch (acceptFriendResp.Code)
|
||
{
|
||
case FriendHelper.Code_OK:
|
||
case FriendHelper.Code_AddFriend_HaveAddedBefore_OK:
|
||
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_95"));
|
||
GContext.Publish(new ResetWaitTime() { waitTime = 10f });
|
||
//if (m_Callback != null)
|
||
//{
|
||
// m_Callback(m_Data);
|
||
//}
|
||
break;
|
||
case FriendHelper.Code_AddFriend_FriendHaveNoLimit:
|
||
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_91"));
|
||
if (m_Callback != null)
|
||
{
|
||
m_Callback(m_Data);
|
||
}
|
||
break;
|
||
case FriendHelper.Code_AddFriend_IHaveNoLimit:
|
||
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_92"));
|
||
if (m_Callback != null)
|
||
{
|
||
m_Callback(m_Data);
|
||
}
|
||
break;
|
||
case FriendHelper.Code_AddFriend_GetFriendList_Failed_PlayFabError:
|
||
case FriendHelper.Code_AcceptFriend_IAddFriend_Failed_PlayFabError:
|
||
case FriendHelper.Code_AcceptFriend_FriendAddMe_Failed_PlayFabError:
|
||
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_93"));
|
||
if (m_Callback != null)
|
||
{
|
||
m_Callback(m_Data);
|
||
}
|
||
break;
|
||
default:
|
||
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_93"));
|
||
if (m_Callback != null)
|
||
{
|
||
m_Callback(m_Data);
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
public async void StartInvitedIgnore(FishingFriendAddPanel panel, FriendAddItemData data, UnityAction<FriendAddItemData> callback)
|
||
{
|
||
m_Panel = panel;
|
||
m_Data = data;
|
||
m_Callback = callback;
|
||
m_FromType = FriendAddPanelBackendOperationFromType.FromTypeInvited;
|
||
|
||
string json = await GContext.container.Resolve<FriendService>().AcceptFriend(FriendHelper.Accept_Type_Ignore,
|
||
GContext.container.Resolve<IUserService>().UserId, m_Data.FriendInfo.PlayFabId);
|
||
|
||
if (!string.IsNullOrEmpty(json))
|
||
{
|
||
AcceptFriendResp acceptFriendResp = Newtonsoft.Json.JsonConvert.DeserializeObject<AcceptFriendResp>(json);
|
||
if (acceptFriendResp != null)
|
||
{
|
||
#if AGG
|
||
using (var e = GEvent.GameEvent("friend_request"))
|
||
{
|
||
e.AddContent("playfabid", GContext.container.Resolve<IUserService>().UserId)
|
||
.AddContent("friendplayfabid", m_Data.FriendInfo.PlayFabId)
|
||
.AddContent("code", acceptFriendResp.Code)
|
||
.AddContent("friendcode", GContext.container.Resolve<FriendService>().GetInvitationCodeByPlayFabID(GContext.container.Resolve<IUserService>().UserId));
|
||
}
|
||
#endif
|
||
|
||
switch (acceptFriendResp.Code)
|
||
{
|
||
case FriendHelper.Code_OK:
|
||
case FriendHelper.Code_AcceptFriend_Ignore_OK:
|
||
//ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_90"));
|
||
//if (m_Callback != null)
|
||
//{
|
||
// m_Callback(m_Data);
|
||
//}
|
||
break;
|
||
case FriendHelper.Code_AddFriend_FriendHaveNoLimit:
|
||
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_91"));
|
||
if (m_Callback != null)
|
||
{
|
||
m_Callback(m_Data);
|
||
}
|
||
break;
|
||
case FriendHelper.Code_AddFriend_IHaveNoLimit:
|
||
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_92"));
|
||
if (m_Callback != null)
|
||
{
|
||
m_Callback(m_Data);
|
||
}
|
||
break;
|
||
case FriendHelper.Code_AddFriend_GetFriendList_Failed_PlayFabError:
|
||
case FriendHelper.Code_AcceptFriend_IAddFriend_Failed_PlayFabError:
|
||
case FriendHelper.Code_AcceptFriend_FriendAddMe_Failed_PlayFabError:
|
||
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_93"));
|
||
if (m_Callback != null)
|
||
{
|
||
m_Callback(m_Data);
|
||
}
|
||
break;
|
||
default:
|
||
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_93"));
|
||
if (m_Callback != null)
|
||
{
|
||
m_Callback(m_Data);
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
public void Clear()
|
||
{
|
||
m_Panel = null;
|
||
m_Data = null;
|
||
m_Callback = null;
|
||
m_FromType = FriendAddPanelBackendOperationFromType.FromTypeInvalid;
|
||
m_CallbackWithStringAndInt = null;
|
||
}
|
||
}
|
||
}
|