using vnxbqy.UI; using System; using System.Collections.Generic; using UnityEngine; using System.Text.RegularExpressions; using LitJson; using System.Text; //Arena主控制代码 public class ArenaModel : ILModel { public bool bFirstStageLoadCheck = false; public bool bArenaOpen = false; public string RobotName = ""; public int RankType = 28; public int SelectRewardType = 1; //更新匹配用户信息 public event Action UpdateMatchUserEvent; public event Action UpdateBattlePlayerEvent; //更新匹配用户信息 public event Action UpdateBattleRecordListEvent; public event Action UpdatePKInfoListEvent; public Redpoint redpoint = new Redpoint(78129001); //查询列表 public List ArenaBattleRecordList = new List(); //个人信息 public ArenaPlayerInfo playerInfo; public uint WinnerID; // 胜方ID(本次战斗结束) public bool bCheckRedPoint = false; public int freeMaxMatchNum { get; private set; } //每次挑战免费次数 public int buyMaxMatchNum { get; private set; } //每日可购买次数 public int ScoreMin { get; private set; } //最低积分 public int ScoreMax { get; private set; } //最高积分 public int RecordMax { get; private set; } //对战记录条数(不超过50) public int freeRefreshPlayerMax { get; private set; } //每次挑战免费刷新次数,0为不限 public int SelectMatchPlayer { get; set; } //当前选择的用户 public List m_PlayerInfo = new List(); //场景配置 public uint OPPONENT_PLAYERID = 999999; public FightResultSupplement resultSupplement; public int myPlace { get; private set; } //我的位置,1-左;2-右 public string opponentName { get; private set; } public uint roundWiner = 0; //获胜者 id public int currentRecordIndex = 0; public ArenaPKUpInfo ArenaPKUpInfoData { get; set; } public bool bILAI; public bool bFirstShow = true; public bool IsArenaWork = true; DungeonModel m_DungeonModel; public IL_HA922_tagGCArenaMatchList pkList; bool IsSendCloseArena = false; public int skipFightLV = 200; //跳过战斗等级 public bool isSkipFightChoose { get { return LocalSave.GetBool("ArenaSkipChallenge" + PlayerDatas.Instance.baseData.PlayerID); } set { LocalSave.SetBool("ArenaSkipChallenge" + PlayerDatas.Instance.baseData.PlayerID, value); } } DungeonModel dungeonModel { get { return m_DungeonModel ?? (m_DungeonModel = ModelCenter.Instance.GetModel()); } } protected override void Init() { try { DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent += OnPlayerLoginOk; playerInfo = new ArenaPlayerInfo(); RobotName = Language.Get("ArenaRobotName"); RankType = 28; SelectRewardType = 1; ////// ScoreMin = GeneralDefine.ArenaSetList[0]; ScoreMax = GeneralDefine.ArenaSetList[1]; var fun = FuncConfigConfig.Get("ArenaSet"); freeMaxMatchNum = int.Parse(fun.Numerical3); RecordMax = int.Parse(fun.Numerical4); freeRefreshPlayerMax = int.Parse(fun.Numerical5); ArenaManager.ParseAwardFuncConfig(); ArenaManager.ParseItemJobSkill(); //r0,代表机器人参数,r1,真人 ,初始化 List r0 = new List(); List r1 = new List(); for (int i = 0; i < 5; i++) r0.Add(i); for (int i = 0; i < 33; i++) r1.Add(i); ArenaManager.playInfo.Add(0, r0); ArenaManager.playInfo.Add(1, r1); //获取副本 游戏时间,准备时间,退出时间 dungeonModel.currentDungeon = new Dungeon(ArenaManager.MapID, 0); var dungeonId = dungeonModel.GetDungeonId(dungeonModel.currentDungeon); var dungeonConfig = DungeonConfig.Get(dungeonId); ArenaManagerModel.Instance.s_StepTimes = LitJson.JsonMapper.ToObject(dungeonConfig.StepTime); fun = FuncConfigConfig.Get("ArenaSet1"); skipFightLV = int.Parse(fun.Numerical1); } catch (System.Exception ex) { OperationLogCollect.Instance.BugReportSys(ex.ToString()); Debug.LogError(ex); } } protected override void UnInit() { DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent -= OnPlayerLoginOk; playerInfo = null; } public void OnPlayerLoginOk() { bFirstShow = true; bCheckRedPoint = false; if(IsSendCloseArena) { RequestExitClientDungeon(); } } public void LoadStage(HB216_tagMCStartCustomSceneResult vNetData) { if (vNetData.MapID != ArenaManager.MapID) return; if(!ArenaManager.isArenaClient || IsArenaWork) { ArenaManager.isArenaClient = true; DebugEx.Log("ArenaManager.isArenaClient"); ArenaManagerModel.Instance.OnILStageLoadFinish(); return; } FakeMatchOk(); WindowCenter.Instance.Open(); MapTransferUtility.Instance.Clear(); StageLoad.Instance.PushSceneLoadCommand(new StageLoad.StageLoadCommand() { toMapId = ArenaManager.MapID, toLineId = 0, needEmpty = true, needLoadResource = true, serverType = ServerType.Main, isClientLoadMap = true }); PlayerDatas.Instance.baseData.mainServerMapIdRecord = PlayerDatas.Instance.baseData.MapID; PlayerDatas.Instance.baseData.MapID = ArenaManager.MapID; } public bool CheckArenaComplete(int MapID) { if (MapID != ArenaManager.MapID) { IsSendCloseArena = false; return false; } //异地打开或超过180秒时间,都不能进入游戏,自动关闭 int ArenaAllSeconds = LocalSave.GetInt("ArenaAllSeconds"); if (ArenaAllSeconds <= 0) ArenaAllSeconds = TimeUtility.AllSeconds; if (LocalSave.GetInt("MatchInfoPlayerID") <= 0 || TimeUtility.AllSeconds - ArenaAllSeconds > ArenaManagerModel.Instance.s_StepTimes[0]) { bFirstStageLoadCheck = false; //RequestExitClientDungeon(); IsSendCloseArena = true; return true; }else { IsSendCloseArena = false; return false; } } public void CallUpdatePKInfo(int type) { if(UpdatePKInfoListEvent != null) UpdatePKInfoListEvent(1); } public void FirstData() { ArenaBattleRecordList.Clear(); ArenaModel.Instance.SendArenaBattleRecordList(); } public void StartInit() { bILAI = false; WinnerID = 0; } #region //发送命令 // 0-打开界面无匹配数据时时查询,1-强制刷新匹配列表 public void SendRefreshMatch(byte IsRefresh) { IL_CB209_tagCMArenaMatch pack = new IL_CB209_tagCMArenaMatch(); pack.IsRefresh = IsRefresh; GameNetSystem.Instance.SendInfo(pack); } //竞技场挑战玩家 public void SendArenaBattle(uint PlayerID,byte result) { //Debug.Log("竞技场挑战玩家:" + PlayerID+" index:"+ ArenaModel.Instance.SelectMatchPlayer); IL_CB210_tagCMArenaBattle pack = new IL_CB210_tagCMArenaBattle(); pack.TagPlayerID = PlayerID; pack.Result = result; GameNetSystem.Instance.SendInfo(pack); } //竞技场对战记录列表 public void SendArenaBattleRecordList() { IL_CA9A8_tagCGQueryArenaBattleRecord pack = new IL_CA9A8_tagCGQueryArenaBattleRecord(); GameNetSystem.Instance.SendInfo(pack); } public void UpdateRedPoint() { if(bCheckRedPoint) { redpoint.state = RedPointState.Simple; } else { redpoint.state = RedPointState.None; } } #endregion #region //接收命令 public void ReceiveBattLePlayer(IL_HA926_tagGCArenaBattlePlayerInfo vNetData) { UpdateBattlePlayerEvent?.Invoke(vNetData); } //竞技场匹配玩家列表 public void ReceiveMatchData(IL_HA922_tagGCArenaMatchList vNetData) { pkList = vNetData; if (UpdateMatchUserEvent != null) { UpdateMatchUserEvent(vNetData); } } // 竞技场对战记录列表 public void ReceiveBattleRecordList(IL_HA923_tagGCArenaBattleRecordList vNetData) { string nameStr = ""; string inputString = LocalSave.GetString("MatchInfoPlayerIDALL"+PlayerDatas.Instance.PlayerId); int LastPlayerID = LocalSave.GetInt("MatchInfoPlayerID"); int LastPlayerTime = LocalSave.GetInt("ArenaAllSeconds"); for (int i = 0; i < vNetData.RecordCount; i++) { int lastTime = TimeUtility.AllSeconds - LastPlayerTime; int waitTime = ArenaManagerModel.Instance.s_StepTimes[0] + 20; //保存挑战记录 if (lastTime < waitTime && vNetData.BattleRecordList[i].PlayerID == LastPlayerID) { inputString = StringUtility.Contact(inputString, "|", vNetData.BattleRecordList[i].Time.ToString()); LocalSave.SetString("MatchInfoPlayerIDALL" + PlayerDatas.Instance.PlayerId, inputString); } else { int index = inputString.IndexOf(vNetData.BattleRecordList[i].Time.ToString()); if (index == -1) { if (vNetData.BattleRecordList[i].PlayerID < 10000) { nameStr = ArenaModel.Instance.RobotName; } else { nameStr = vNetData.BattleRecordList[i].PlayerName; } SysNotifyMgr.Instance.ShowTip("ArenaFightPlayer", nameStr.Trim().Replace("\0", "")); bCheckRedPoint = true; UpdateRedPoint(); //消息只发一次, inputString = StringUtility.Contact(inputString, "|", vNetData.BattleRecordList[i].Time.ToString()); LocalSave.SetString("MatchInfoPlayerIDALL" + PlayerDatas.Instance.PlayerId, inputString); } } ArenaBattleRecordList.Add(vNetData.BattleRecordList[i]); } //排序,最近的在最前面 ArenaBattleRecordList.Sort((x, y) => { return y.Time.CompareTo(x.Time); }); //删除多余记录 if (ArenaBattleRecordList.Count > RecordMax) { int count = ArenaBattleRecordList.Count - RecordMax; for (int i = ArenaBattleRecordList.Count - 1; i >= RecordMax; i--) { ArenaBattleRecordList.RemoveAt(i); } } if (UpdateBattleRecordListEvent != null) { UpdateBattleRecordListEvent(); } } #endregion #region // 场景载入 stage controller public void FakeMatchOk() { PlayerDatas.Instance.hero.Pos = ArenaManagerModel.leftBornPoint; CameraController.Instance.rotationX = 45; CameraController.Instance.Apply(); PlayerDatas.Instance.hero.EulerAngles = 90; //强杀,再进入 if (m_PlayerInfo.Count <= 0 || ArenaModel.Instance.SelectMatchPlayer == 5) { SelectMatchPlayer = LocalSave.GetInt("MatchInfoSelect"); for (int i = 0; i < 6; i++) //第6个放从挑战记录里的数据 { IL_HA922_tagGCArenaMatchList.tagGCArenaMatchInfo playerInfo = new IL_HA922_tagGCArenaMatchList.tagGCArenaMatchInfo(); playerInfo.PlayerID = (uint)LocalSave.GetInt("MatchInfoPlayerID"); playerInfo.PlayerName = LocalSave.GetString("MatchInfoPlayerName"); playerInfo.Job = (byte)LocalSave.GetInt("MatchInfoJob"); playerInfo.LV = (ushort)LocalSave.GetInt("MatchInfoLV"); playerInfo.RealmLV = (ushort)LocalSave.GetInt("MatchInfoRealmLV"); playerInfo.FightPower = (uint)LocalSave.GetInt("MatchInfoFightPower"); playerInfo.Score = (uint)LocalSave.GetInt("MatchInfoScore"); m_PlayerInfo.Add(playerInfo); } } var teamModel = ModelCenter.Instance.GetModel(); if (teamModel.isMatching) { teamModel.RequestCancelAutoMatchTeam(); } myPlace = 1;// UnityEngine.Random.Range(0, 2); opponentName = m_PlayerInfo[SelectMatchPlayer].PlayerName; int realm = m_PlayerInfo[SelectMatchPlayer].RealmLV; if (m_PlayerInfo[SelectMatchPlayer].PlayerID < 10000) { realm = ArenaModel.Instance.GetRealm(m_PlayerInfo[SelectMatchPlayer].LV); } ArenaPKUpInfoData = new ArenaPKUpInfo() { isClient = true, roomId = ArenaManager.MapID, waitForLoginCrossServer = true, validTimeLimited = Time.time + 30f, autoEnsureTime = Time.time + 3f, myName = PlayerDatas.Instance.baseData.PlayerName, myJob = PlayerDatas.Instance.baseData.Job, myFace = AvatarHelper.GetMyAvatarID(), myFacePic = AvatarHelper.GetMyAvatarID(), myBornPoint = myPlace, opponentName = opponentName, opponentJob = m_PlayerInfo[SelectMatchPlayer].Job, opponentFace = (int)m_PlayerInfo[SelectMatchPlayer].Face, opponentFacePic = (int)m_PlayerInfo[SelectMatchPlayer].FacePic, opponentMaxHp = (ulong)GetLevel((int)m_PlayerInfo[SelectMatchPlayer].LV, 1), opponentLevel = (int)m_PlayerInfo[SelectMatchPlayer].LV, opponentPlayerId = (int)m_PlayerInfo[SelectMatchPlayer].PlayerID, opponentShield = GetLevel((int)m_PlayerInfo[SelectMatchPlayer].LV, 3), MaxProDef = GetLevel((int)m_PlayerInfo[SelectMatchPlayer].LV, 3), realmLV = realm, }; ArenaManager.myName = PlayerDatas.Instance.baseData.PlayerName; ArenaManager.opponentName = opponentName; } //开始加载场景 public void StartClientArena() { ArenaModel.Instance.IsArenaWork = false; ArenaManager.isArenaClient = true; DebugEx.Log("ArenaManager.isArenaClient"); //开始自定义场景 var sendInfo = new CA231_tagCMClientStartCustomScene(); sendInfo.MapID = (uint)ArenaManager.MapID; sendInfo.FuncLineID = 0; GameNetSystem.Instance.SendInfo(sendInfo); } public void FakeWaitFight(int waitSeconds) { var timeTick = new H0431_tagTimeTick(); timeTick.Type = (int)DungeonCoolDownType.WaitStart; timeTick.Tick = (uint)waitSeconds * 1000; GameNetSystem.Instance.PushPackage(timeTick, ServerType.Main); } public void FakeRoundBegin(int round, uint[] winnerIds) { var waitStartTimeTick = new H0431_tagTimeTick(); waitStartTimeTick.Type = (int)DungeonCoolDownType.FightStart; waitStartTimeTick.Tick = (uint)ArenaManagerModel.Instance.s_StepTimes[0] * 1000; GameNetSystem.Instance.PushPackage(waitStartTimeTick, ServerType.Main); var roundWinnerIds = new int[winnerIds.Length]; for (var i = 0; i < roundWinnerIds.Length; i++) { roundWinnerIds[i] = (int)winnerIds[i]; } var missionData = new DungeonMissionData() { roundNum = round, roundWinerIDList = roundWinnerIds, isStart = 1, }; var dungeonModel = ModelCenter.Instance.GetModel(); dungeonModel.UpdateJiaDungeonMission(ArenaManager.MapID, missionData); } public void FakeRoundEnd(bool isOver, int round, uint[] winnerIds) { var roundWinnerIds = new int[winnerIds.Length]; for (var i = 0; i < roundWinnerIds.Length; i++) { roundWinnerIds[i] = (int)winnerIds[i]; } var missionData = new DungeonMissionData() { roundNum = round, roundWinerIDList = roundWinnerIds, prepareTime = isOver ? 0 : ArenaManagerModel.Instance.s_StepTimes[1]*1000, isStart = 0, }; dungeonModel.UpdateJiaDungeonMission(ArenaManager.MapID, missionData); } public void FakeDungeonExit(int seconds) { var exitDungeon = new H0431_tagTimeTick(); exitDungeon.Type = (int)DungeonCoolDownType.LeaveMap; exitDungeon.Tick = (uint)seconds * 1000; GameNetSystem.Instance.PushPackage(exitDungeon, ServerType.Main); } void RequestExitClientDungeon() { var pak = new CA233_tagCMClientExitCustomScene(); GameNetSystem.Instance.SendInfo(pak); } public void StopClientArena() { IsArenaWork = false; ArenaManager.isArenaClient = false; ArenaManager.isArenaPK = false; ArenaManagerModel.Instance.ReleasePlayer(); ClientDungeonStageUtility.SetClientDungeon(false, 0); PlayerDatas.Instance.extersion.pkState = 0; ModelCenter.Instance.GetModel().ResetBufData(); PersonalEnemy.ReleaseAll(); PlayerDatas.Instance.baseData.MapID = PlayerDatas.Instance.baseData.mainServerMapIdRecord; LocalSave.SetInt("MatchInfoPlayerID", 0); LocalSave.SetInt("ArenaAllSeconds", 0); //Debug.LogError(PlayerDatas.Instance.baseData.MapID); StageLoad.Instance.PushSceneLoadCommand(new StageLoad.StageLoadCommand() { toMapId = PlayerDatas.Instance.baseData.MapID, toLineId = 0, needEmpty = true, needLoadResource = true, serverType = ServerType.Main, isClientLoadMap = true, refreshPlayerDatas = true }); } //查找登记表,获取数据 public int GetLevel(int level,int type) { var levelConfig = ArenaRobotLVConfig.Get(level); int value = 0; switch (type) { case 1://hp value = levelConfig.ReMaxHP; break; case 2://fight value = levelConfig.fightPower; break; case 3://shield value = levelConfig.ReDef; break; } return value; } public int GetRealmLarge(int level) { int lvLarge = 0; for(int i = 0;i < 62;i++) { var realmConfig = RealmConfig.Get(i); if (realmConfig.NeedLV >= level) { lvLarge = realmConfig.LvLarge; break; } } return lvLarge; } public int GetRealm(int level) { int lv = 1; for (int i = 0; i < 62; i++) { var realmConfig = RealmConfig.Get(i); if (realmConfig.NeedLV >= level) { lv = realmConfig.Lv; break; } } return lv; } public void BeginRecordBattle() { IL_HA923_tagGCArenaBattleRecordList.tagGCArenaBattleRecord record = ArenaModel.Instance.ArenaBattleRecordList[ArenaModel.Instance.currentRecordIndex]; if (ArenaModel.Instance.playerInfo.GetDayMatchCount() > 0) { if (isSkipFightChoose) { var tmpPlayer = record; uint PlayerID = tmpPlayer.PlayerID; ArenaManager.isArenaClient = true; SendArenaBattle(PlayerID, 0); LocalSave.SetString("MatchInfoPlayerFightNow" + PlayerDatas.Instance.PlayerId, record.Time.ToString()); Clock.AlarmAfter(0.2, () => { ulong fightpower = 0; if (record.PlayerID < 10000) { fightpower = (uint)GetLevel(record.LV, 2); //fight } else { fightpower = (ulong)record.FightPowerEx * 100000000 + record.FightPower; } SendArenaBattle(PlayerID, (byte)(PlayerDatas.Instance.baseData.FightPoint >= fightpower ? 1 : 2)); if (PlayerDatas.Instance.baseData.FightPoint >= fightpower) { string MatchInfoPlayerFightNow = LocalSave.GetString("MatchInfoPlayerFightNow" + PlayerDatas.Instance.PlayerId); if (MatchInfoPlayerFightNow != "") { string inputString = LocalSave.GetString("MatchInfoPlayerFight" + PlayerDatas.Instance.PlayerId); inputString = StringUtility.Contact(inputString, "|", MatchInfoPlayerFightNow); LocalSave.SetString("MatchInfoPlayerFight" + PlayerDatas.Instance.PlayerId, inputString); } } LocalSave.SetString("MatchInfoPlayerFightNow" + PlayerDatas.Instance.PlayerId, ""); }); return; } int tmp = 5; ArenaModel.Instance.SelectMatchPlayer = tmp; //当前选择的用户 IL_HA922_tagGCArenaMatchList.tagGCArenaMatchInfo tmper = new IL_HA922_tagGCArenaMatchList.tagGCArenaMatchInfo(); tmper.PlayerID = record.PlayerID; if (record.PlayerID < 10000) { tmper.PlayerName = ArenaModel.Instance.RobotName; } else { tmper.PlayerName = record.PlayerName; } tmper.Job = record.Job; tmper.LV = record.LV; tmper.RealmLV = record.RealmLV; tmper.FightPower = record.FightPower; tmper.Score = record.Score; //保证强杀,重新进入场景,有数据 ArenaModel.Instance.m_PlayerInfo[tmp] = tmper; ArenaModel.Instance.bFirstStageLoadCheck = true; LocalSave.SetInt("MatchInfoSelect", tmp); LocalSave.SetInt("MatchInfoPlayerID", (int)ArenaModel.Instance.m_PlayerInfo[tmp].PlayerID); LocalSave.SetString("MatchInfoPlayerName", ArenaModel.Instance.m_PlayerInfo[tmp].PlayerName); LocalSave.SetInt("MatchInfoJob", ArenaModel.Instance.m_PlayerInfo[tmp].Job); LocalSave.SetInt("MatchInfoLV", (int)ArenaModel.Instance.m_PlayerInfo[tmp].LV); LocalSave.SetInt("MatchInfoRealmLV", (int)ArenaModel.Instance.m_PlayerInfo[tmp].RealmLV); LocalSave.SetInt("MatchInfoFightPower", (int)ArenaModel.Instance.m_PlayerInfo[tmp].FightPower); LocalSave.SetInt("MatchInfoScore", (int)ArenaModel.Instance.m_PlayerInfo[tmp].Score); LocalSave.SetInt("ArenaAllSeconds", TimeUtility.AllSeconds); LocalSave.SetString("MatchInfoPlayerFightNow" + PlayerDatas.Instance.PlayerId, record.Time.ToString()); ArenaModel.Instance.StartClientArena(); WindowCenter.Instance.CloseIL(); } else { SysNotifyMgr.Instance.ShowTip("ArenaPKTimes"); } } public struct FightResultSupplement { public DateTime endTime; public int overType; public int winPlayerId; public int roundCount; public uint[] roundWinnerId; public string opponentName; } public struct FightObstacle { public int aPosX; public int aPosY; public int bPosX; public int bPosY; public int angle; } public struct ArenaPKUpInfo { public bool isClient; public int roomId; public bool waitForLoginCrossServer; public float validTimeLimited; public float autoEnsureTime; 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 opponentShield; public int MaxProDef;// 最大护盾 public int realmLV; } #endregion //#region // 数据处理 //#endregion }