using UnityEngine;
|
using System;
|
|
|
namespace vnxbqy.UI
|
{
|
|
|
public class CrossServerLogin : Singleton<CrossServerLogin>
|
{
|
bool m_Busy = false;
|
public bool busy {
|
get { return m_Busy; }
|
set { m_Busy = value; }
|
}
|
|
public bool reconnectBackGround { get; set; }
|
|
Clock loginOverTimeClock;
|
int reLoginTimes = 0;
|
|
public CrossServerOneVsOne oneVsOnePlayerData { get; private set; }
|
|
LoginModel loginModel { get { return ModelCenter.Instance.GetModel<LoginModel>(); } }
|
|
public void Init()
|
{
|
SnxxzGame.Instance.AddApplicationOutAction(OnApplicationOut);
|
}
|
|
public void UnInit()
|
{
|
SnxxzGame.Instance.RemoveApplicationOutAction(OnApplicationOut);
|
}
|
|
public string ipBuf { get; private set; }
|
public int portBuf { get; private set; }
|
public int gamePortBuf { get; private set; }
|
public string accountBuf { get; private set; }
|
public string passwordBuf { get; private set; }
|
|
|
public void InitOneVsOnePlayerInfo(HC001_tagGCCrossRealmPKMatchOK.tagGCCrossRealmPKMatchPlayer player)
|
{
|
oneVsOnePlayerData = new CrossServerOneVsOne()
|
{
|
isClient = false,
|
myName = PlayerDatas.Instance.baseData.PlayerName,
|
myJob = PlayerDatas.Instance.baseData.Job,
|
myFace = AvatarHelper.GetMyAvatarID(),
|
myFacePic = AvatarHelper.GetMyAvatarFrameID(),
|
myBornPoint = 1,
|
opponentName = player.PlayerName.Replace("@gm", ""),
|
opponentJob = player.Job,
|
opponentFace = (int)player.Face,
|
opponentFacePic = (int)player.FacePic,
|
opponentLevel = player.LV,
|
opponentPlayerId = (int)player.PlayerID,
|
};
|
LoadingWin.isCrossServerOneVsOne = true;
|
}
|
|
public void UpdatePKPlayerInfo(GA_Player player)
|
{
|
oneVsOnePlayerData = new CrossServerOneVsOne()
|
{
|
isClient = oneVsOnePlayerData.isClient,
|
myName = oneVsOnePlayerData.myName,
|
myJob = oneVsOnePlayerData.myJob,
|
myFace = oneVsOnePlayerData.myFace,
|
myFacePic = oneVsOnePlayerData.myFacePic,
|
myBornPoint = oneVsOnePlayerData.myBornPoint,
|
opponentName = oneVsOnePlayerData.opponentName,
|
opponentJob = oneVsOnePlayerData.opponentJob,
|
opponentFace = oneVsOnePlayerData.opponentFace,
|
opponentFacePic = oneVsOnePlayerData.opponentFacePic,
|
opponentMaxHp = player.ActorInfo.MaxHp,
|
opponentLevel = oneVsOnePlayerData.opponentLevel,
|
opponentPlayerId = oneVsOnePlayerData.opponentPlayerId,
|
MaxProDef = (int)player.ActorInfo.maxProDef,
|
mirrorPlayerID = (int)player.ServerInstID,
|
};
|
}
|
|
//挑战机器人 ID固定为 1-对应高分段机器人,2-中分段,3-低分段
|
public void InitOneVsOneClientPlayerInfo(HC001_tagGCCrossRealmPKMatchOK.tagGCCrossRealmPKMatchPlayer player)
|
{
|
int playerID = (int)player.PlayerID;
|
ulong maxHP = 100000;
|
if (playerID == 1)
|
{
|
maxHP = PlayerDatas.Instance.extersion.MaxHP * 2;
|
}
|
else if (playerID == 2)
|
{
|
maxHP = (ulong)(PlayerDatas.Instance.extersion.MaxHP*0.8);
|
}
|
else if (playerID == 3)
|
{
|
maxHP = (ulong)(PlayerDatas.Instance.extersion.MaxHP * 0.4);
|
}
|
|
oneVsOnePlayerData = new CrossServerOneVsOne()
|
{
|
isClient = false,
|
myName = PlayerDatas.Instance.baseData.PlayerName,
|
myJob = PlayerDatas.Instance.baseData.Job,
|
myFace = AvatarHelper.GetMyAvatarID(),
|
myFacePic = AvatarHelper.GetMyAvatarFrameID(),
|
myBornPoint = 1,
|
opponentName = player.PlayerName.Replace("@gm", ""),
|
opponentJob = player.Job,
|
opponentFace = (int)player.Face,
|
opponentFacePic = (int)player.FacePic,
|
opponentLevel = player.LV,
|
opponentPlayerId = (int)player.PlayerID,
|
opponentMaxHp = maxHP
|
};
|
}
|
|
//public void CrossServerOneVsOneLogin()
|
//{
|
// var loginModel = ModelCenter.Instance.GetModel<LoginModel>();
|
// var account = loginModel.accountBuf;
|
// var ip = GameNetSystem.Instance.crossServerData.ip;
|
// var port = GameNetSystem.Instance.crossServerData.port;
|
|
// LoadingWin.isCrossServerOneVsOne = true;
|
// WindowCenter.Instance.Open<LoadingWin>();
|
// SetWaitForLoginCrossServerState(false);
|
|
// AccountLogin(account, ip, port, false);
|
//}
|
|
//public void SetWaitForLoginCrossServerState(bool state)
|
//{
|
// oneVsOnePlayerData = oneVsOnePlayerData.SetWaitForLoginCrossServer(false);
|
//}
|
|
public bool IsEnterCrossServerPreparing()
|
{
|
return oneVsOnePlayerData.IsCrossServerOneVsOneEntering();
|
}
|
|
public void CrossServerBossLogin()
|
{
|
var loginModel = ModelCenter.Instance.GetModel<LoginModel>();
|
var account = loginModel.accountBuf;
|
var ip = GameNetSystem.Instance.crossServerData.ip;
|
var port = GameNetSystem.Instance.crossServerData.port;
|
|
WindowCenter.Instance.Open<LoadingWin>();
|
AccountLogin(account, ip, port, false);
|
}
|
|
public void AccountLogin(string account, string ip, int gamePort, bool reconnectBackGround)
|
{
|
if (Application.internetReachability == NetworkReachability.NotReachable)
|
{
|
ConfirmCancel.ShowPopConfirm(
|
Language.Get("Mail101"),
|
Language.Get("L1116"),
|
() => { }
|
);
|
return;
|
}
|
|
if (busy)
|
{
|
return;
|
}
|
|
reLoginTimes = 0;
|
busy = true;
|
try
|
{
|
this.reconnectBackGround = reconnectBackGround;
|
accountBuf = account;
|
ipBuf = ip;
|
gamePortBuf = gamePort;
|
|
StopLoginOverTimeProcess();
|
loginOverTimeClock = Clock.AlarmAt(DateTime.Now.AddSeconds(30), () =>
|
{
|
busy = false;
|
ReAccountLogin();
|
});
|
|
GameNetSystem.Instance.BeginConnectCrossServer(ipBuf, gamePortBuf, OnGameServerConnected);
|
NetLinkWin.Show();
|
}
|
catch (Exception ex)
|
{
|
Debug.Log(ex);
|
busy = false;
|
}
|
}
|
|
public void ReAccountLogin()
|
{
|
if (busy)
|
{
|
return;
|
}
|
|
busy = true;
|
reLoginTimes++;
|
if (reLoginTimes > 1)
|
{
|
ProcessLoginFailure();
|
return;
|
}
|
|
try
|
{
|
this.reconnectBackGround = true;
|
StopLoginOverTimeProcess();
|
loginOverTimeClock = Clock.AlarmAt(DateTime.Now.AddSeconds(30), () =>
|
{
|
busy = false;
|
ReAccountLogin();
|
});
|
GameNetSystem.Instance.BeginConnectCrossServer(ipBuf, gamePortBuf, OnGameServerConnected);
|
NetLinkWin.Show();
|
}
|
catch (Exception ex)
|
{
|
Debug.Log(ex);
|
busy = false;
|
}
|
}
|
|
public void StopLoginOverTimeProcess()
|
{
|
if (loginOverTimeClock != null)
|
{
|
Clock.Stop(loginOverTimeClock);
|
}
|
|
loginOverTimeClock = null;
|
}
|
|
private void OnGameServerConnected(bool ok)
|
{
|
if (ok)
|
{
|
var sendInfo = new C0123_tagCClientPackVersion();
|
sendInfo.Version = LoginModel.DwVersionNo;
|
GameNetSystem.Instance.SendToCrossServer(sendInfo);
|
}
|
else
|
{
|
busy = false;
|
}
|
}
|
|
public void AccessLogin(H0101_tagServerPrepared _serverInfo)
|
{
|
GameNetSystem.Instance.SendToCrossServer(loginModel.Get0101SendPackage(_serverInfo)); // 登录
|
NetLinkWin.Show();
|
}
|
|
public void CheckClientVersion()
|
{
|
var sendInfo = new C010D_tagCClientVersion();
|
sendInfo.Version = "10.1000.1";
|
GameNetSystem.Instance.SendToCrossServer(sendInfo);
|
NetLinkWin.Show();
|
}
|
|
public void OnGetPlayerLoginInfo(byte _type)
|
{
|
NetLinkWin.Hide();
|
busy = false;
|
if (Application.internetReachability == NetworkReachability.NotReachable)
|
{
|
ConfirmCancel.ShowPopConfirm(
|
Language.Get("Mail101"),
|
Language.Get("L1116"),
|
() => { }
|
);
|
return;
|
}
|
|
var tagCRoleLoginAsk = new C0108_tagCRoleLoginAsk();
|
tagCRoleLoginAsk.Type = (byte)_type;//进入游戏
|
tagCRoleLoginAsk.ClientID = ynmbxxjUtil.Instance.RegistrationID;
|
GameNetSystem.Instance.SendToCrossServer(tagCRoleLoginAsk);
|
|
NetLinkWin.Show();
|
}
|
|
private void ProcessLoginFailure()
|
{
|
StopLoginOverTimeProcess();
|
busy = false;
|
|
|
var sendInfo = new CC003_tagCGForceQuitCrossState();
|
GameNetSystem.Instance.SendInfo(sendInfo);
|
GameNetSystem.Instance.crossServerConnected_Loigc = false;
|
Clock.AlarmAt(DateTime.Now + new TimeSpan(2 * TimeSpan.TicksPerSecond), () =>
|
{
|
GameNetSystem.Instance.Reconnect();
|
});
|
}
|
|
private void OnApplicationOut()
|
{
|
var sendInfo = new C0103_tagCPlayerLogOut();
|
sendInfo.Type = 1;
|
GameNetSystem.Instance.SendToCrossServer(sendInfo);
|
}
|
|
}
|
|
public struct CrossServerOneVsOne
|
{
|
public bool isClient;
|
public int roomId;
|
public bool waitForLoginCrossServer;
|
public float autoEnsureTime;
|
public float validTimeLimited;
|
public string myName;
|
public int myJob;
|
public int myFace;
|
public int myFacePic;
|
public int myBornPoint;//1-左;2-右
|
public int opponentPlayerId;
|
public string opponentName;
|
public int opponentJob;
|
public int opponentFace;
|
public int opponentFacePic;
|
public int opponentLevel;
|
public ulong opponentMaxHp;
|
public int MaxProDef;// 最大护盾
|
public int mirrorPlayerID; //镜像玩家ID
|
|
|
public bool IsCrossServerOneVsOneEntering()
|
{
|
return false;
|
}
|
|
}
|
|
}
|
|