/// <summary> /// 刷新士兵 /// </summary> public static async ETVoid SpawnArmy(this MobaControllerComponent self) { TimerComponent timerComponent = Game.Scene.GetComponent <TimerComponent>(); long instanceId = self.InstanceId; Moba5V5Room room = self.GetParent <Moba5V5Room>(); //刷新初始波士兵 await timerComponent.WaitAsync(10000); room.Broadcast(new A1009_NewArmyWave_M2C()); self.wave += 1; while (true) { await timerComponent.WaitAsync(35000); //士兵每波刷新周期 if (self.InstanceId != instanceId) { return; } if (self.isGameOver) { return; } if (self.wave > 6) { room.Broadcast(new A1009_NewArmyWave_M2C()); } else //第7波开始刷新炮车 { room.Broadcast(new A1010_NewArmyWave_M2C()); } self.wave += 1; //波次+1 } }
/// <summary> /// 玩家移动房间广播 index当前移动进度 offset发送坐标的数量 /// </summary> public static void BroadcastPath(this GamerPathComponent self, List <Vector3> path, int index, int offset) { Gamer gamer = self.GetParent <Gamer>(); Vector3 unitPos = gamer.Position; A1006_PathfindingResult_M2C pathfindingResult = new A1006_PathfindingResult_M2C(); pathfindingResult.X = unitPos.x; //当前位置 pathfindingResult.Y = unitPos.y; pathfindingResult.Z = unitPos.z; pathfindingResult.UserID = gamer.UserID; for (int i = 0; i < offset; ++i) //预测的坐标个数 先广播后移动 不包含当前坐标 { if (index + i >= self.ABPath.Result.Count) //预测坐标的序列不能大于坐标总数 { break; } Vector3 v = self.ABPath.Result[index + i]; pathfindingResult.Xs.Add(v.x); pathfindingResult.Ys.Add(v.y); pathfindingResult.Zs.Add(v.z); } //找到玩家所在房间进行广播 Moba5V5Room room = Game.Scene.GetComponent <Moba5V5Component>().GetGamingRoom(gamer); room.Broadcast(pathfindingResult); }
/// <summary> /// 房间满员时通知客户端加载场景 /// </summary> /// <param name="self"></param> public static void RoomReady(this MobaControllerComponent self) { Moba5V5Room room = self.GetParent <Moba5V5Room>(); //机器人设置为已准备 for (int i = 0; i < room.gamers.Length; i++) { if (room.gamers[i].UserID == 0) { room.isReadys[i] = true; } } //向玩家发送加载请求 等待玩家准备 self.HeroList = BattleHelp.GetRandomTeam(10); //排除一个时:9, new List<long>() { mainId } A1004_CreateMoba5V5Secene_M2C message = new A1004_CreateMoba5V5Secene_M2C(); for (int i = 0; i < self.HeroList.Count; i++) { message.Gamers.Add(new GamerInfo() { UserID = room.gamers[i].UserID, HeroID = self.HeroList[i], Index = i + 1 }); } room.Broadcast(message); }
/// <summary> /// 刷新野怪 /// </summary> public static async ETVoid SpawnWild(this MobaControllerComponent self) { TimerComponent timerComponent = Game.Scene.GetComponent <TimerComponent>(); Moba5V5Room room = self.GetParent <Moba5V5Room>(); await timerComponent.WaitAsync(30000); room.Broadcast(new A1011_SpawnMonster_M2C()); }
/// <summary> /// 所有玩家已就绪游戏开始 /// </summary> /// <param name="self"></param> public static void GameStart(this MobaControllerComponent self) { //正式开始游戏前的准备 Moba5V5Room room = self.GetParent <Moba5V5Room>(); Moba5V5Component moba = Game.Scene.GetComponent <Moba5V5Component>(); //更改房间状态为游戏中 moba.FreeRooms.Remove(room.Id); moba.GamingRooms.Add(room.Id, room); //更改玩家状态为游戏中 for (int i = 0; i < room.gamers.Length; i++) { if (room.gamers[i].UserID != 0) { Gamer gamer = room.gamers[i]; moba.Waiting.Remove(gamer.UserID); moba.Playing.Add(gamer.UserID, room); } } //服务端加载游戏逻辑 for (int i = 0; i < room.gamers.Length; i++) { room.gamers[i].AddComponent <GamerMoveComponent>(); room.gamers[i].AddComponent <GamerPathComponent>(); room.gamers[i].Position = new Vector3(-10, 0, -10); } //开始服务端游戏计时 self.isGameStarted = true; self.gameStartTime = TimeHelper.ClientNow(); self.lastFrameCostTime = self.gameStartTime; self.SpawnArmy().NoAwait(); //周期刷新士兵 self.SpawnWild().NoAwait(); //刷新野怪 room.Broadcast(new A1008_GameStart_M2C()); }