public async Task BattleProcess() { Info.AllPlayerInfo.Player1Info = new NetInfoModel.PlayerInfo("gezi", "yaya", new List <CardDeck> { new CardDeck("gezi", 0, new List <int> { 1000, 1001, 1002, 1001, 1000, 1002, 1000, 1001, 1000, 1001, 1001, 1000, 1002 }) }); Info.AllPlayerInfo.Player2Info = new NetInfoModel.PlayerInfo("gezi", "yaya", new List <CardDeck> { new CardDeck("gezi", 0, new List <int> { 1001, 1001, 1000, 1000, 1001, 1001, 1000, 1000, 1001, 1001, 1001, 1000, 1002 }) }); await StateCommand.BattleStart(); for (int i = 0; i < 3; i++) { await StateCommand.RoundStart(i); while (true) { await StateCommand.TurnStart(); await StateCommand.WaitForPlayerOperation(); await StateCommand.TurnEnd(); if (Info.GlobalBattleInfo.IsBoothPass) { break; } } await StateCommand.RoundEnd(i); } await StateCommand.BattleEnd(); }
public async Task BattleProcess() { //Debug.LogError("对战开始"); await StateCommand.BattleStart(); for (int i = 0; i < 3; i++) { //Debug.LogError("小局开始"); await StateCommand.RoundStart(i); //await StateCommand.WaitForSelectProperty(); while (true) { Debug.LogError("回合开始"); await StateCommand.TurnStart(); await StateCommand.WaitForPlayerOperation(); if (Info.AgainstInfo.isBoothPass) { break; } await StateCommand.TurnEnd(); } await StateCommand.RoundEnd(i); } await StateCommand.BattleEnd(); Debug.Log("结束对局"); }
//初始化接收响应 private static void InitAsyncConnection() { AsyncConnect = new WebSocket($"ws://{ip}/AsyncInfo"); AsyncConnect.Connect(); AsyncConnect.OnMessage += (sender, e) => { try { Debug.Log("收到信息" + e.Data); object[] receiveInfo = e.Data.ToObject <GeneralCommand>().Datas; NetAcyncType Type = (NetAcyncType)int.Parse(receiveInfo[0].ToString()); switch (Type) { case NetAcyncType.FocusCard: { int X = int.Parse(receiveInfo[2].ToString()); int Y = int.Parse(receiveInfo[3].ToString()); Info.AgainstInfo.OpponentFocusCard = Info.RowsInfo.GetCard(X, Y); break; } case NetAcyncType.PlayCard: { //Debug.Log("触发卡牌同步"); int X = int.Parse(receiveInfo[2].ToString()); int Y = int.Parse(receiveInfo[3].ToString()); //Command.CardCommand.PlayCard(Info.RowsInfo.GetCard(X, Y), false).Wait(); Card targetCard = Info.RowsInfo.GetCard(X, Y); Task.Run(async() => { await GameSystem.TransSystem.PlayCard(new TriggerInfo(targetCard, targetCard), false); Info.AgainstInfo.IsCardEffectCompleted = true; }); break; } case NetAcyncType.SelectRegion: { //Debug.Log("触发区域同步"); int X = int.Parse(receiveInfo[2].ToString()); Info.AgainstInfo.SelectRegion = Info.RowsInfo.GetSingleRowInfoById(X); break; } case NetAcyncType.SelectUnites: { //Debug.Log("收到同步单位信息为" + rawData); List <Location> Locations = receiveInfo[2].ToString().ToObject <List <Location> >(); Info.AgainstInfo.SelectUnits.AddRange(Locations.Select(location => Info.RowsInfo.GetCard(location.x, location.y))); break; } case NetAcyncType.SelectLocation: { Debug.Log("触发坐标同步"); int X = int.Parse(receiveInfo[2].ToString()); int Y = int.Parse(receiveInfo[3].ToString()); //Info.RowsInfo.SingleRowInfos.First(infos => infos.ThisRowCard == Info.RowsInfo.GlobalCardList[X]); Info.AgainstInfo.SelectRegion = Info.RowsInfo.GetSingleRowInfoById(X); Info.AgainstInfo.SelectLocation = Y; Debug.Log($"坐标为:{X}:{Y}"); Debug.Log($"信息为:{"gezi"}:{Info.AgainstInfo.SelectLocation}"); break; } case NetAcyncType.Pass: { GameUI.UiCommand.SetCurrentPass(); break; } case NetAcyncType.Surrender: { Task.Run(async() => { Debug.Log("收到结束指令"); await StateCommand.BattleEnd(true, true); }); break; } case NetAcyncType.ExchangeCard: { Debug.Log("交换卡牌信息"); // Debug.Log("收到信息" + rawData); Location location = receiveInfo[2].ToString().ToObject <Location>(); int randomRank = int.Parse(receiveInfo[3].ToString()); _ = CardCommand.ExchangeCard(Info.RowsInfo.GetCard(location), false, RandomRank: randomRank); break; } case NetAcyncType.RoundStartExchangeOver: if (Info.AgainstInfo.isPlayer1) { Info.AgainstInfo.isPlayer2RoundStartExchangeOver = true; } else { Info.AgainstInfo.isPlayer1RoundStartExchangeOver = true; } break; case NetAcyncType.SelectProperty: { Info.AgainstInfo.SelectProperty = (Region)int.Parse(receiveInfo[2].ToString()); Debug.Log("通过网络同步当前属性为" + Info.AgainstInfo.SelectProperty); break; } case NetAcyncType.SelectBoardCard: Info.AgainstInfo.selectBoardCardRanks = receiveInfo[2].ToString().ToObject <List <int> >();; Info.AgainstInfo.IsFinishSelectBoardCard = (bool)receiveInfo[3]; break; case NetAcyncType.Init: break; default: break; } } catch (System.Exception ex) { Debug.Log(ex); throw; } }; AsyncConnect.OnError += (sender, e) => { Debug.Log("连接失败" + e.Message); Debug.Log("连接失败" + e.Exception); }; Debug.LogError("初始化数据" + new GeneralCommand(NetAcyncType.Init, Info.AgainstInfo.RoomID, Info.AgainstInfo.isPlayer1).ToJson()); AsyncConnect.Send(new GeneralCommand(NetAcyncType.Init, Info.AgainstInfo.RoomID, Info.AgainstInfo.isPlayer1).ToJson()); }