public override void Init() { SC = GetCom <SessionContainer>(); var lgMgr = GetCom <LoginManager>(); lgMgr.OnUserDisconnecting += OnUserDisconnected; UP = GetCom <UserPort>(); RedirectRoomMessage("AddBattleUnitAt"); RedirectRoomMessage("ConstructBuilding"); RedirectRoomMessage("ConstructCrystalMachine"); RedirectRoomMessage("ConstructAccessory"); RedirectRoomMessage("ReconstructBuilding"); RedirectRoomMessage("CancelBuilding"); RedirectRoomMessage("DropSoldierFromCarrier"); RedirectRoomMessage("AddBattleUnit4TestAnyway"); RedirectRoomMessage("AddBuildingUnit4TestAnyway"); RedirectRoomMessage("AddSoldierCarrierUnit4TestAnyway"); RedirectRoomMessage("DestroyBuilding"); UP.OnMessage("Surrender", OnSurrender); UP.OnRequest("GetReplayList", OnGetReplayList); UP.OnRequest("GetMyReplayList", OnGetMyReplayList); UP.OnRequest("GetReplay", OnGetReplay); Room4Server.LoadAllPVPReplays(); BattleLogger = GetCom <ServerBusinessLogger <BattleInfo> >(); }
public void UpdateTable() { Room4Server.LoadAllPVPReplays(); var replayKeys = Room4Server.AllReplayTitles; if (replayKeys == null || replayKeys.Length == 0) { return; } for (int i = 0; i < replayKeys.Length; i++) { var r = Room4Server.GetReplay(replayKeys[i]); var da = new DataAnalysis(); DeserializeReplay(da, r); dac.Retrieve(da.ID, (data) => { var isNew = data == null; if (isNew) { dac.AddNew(da); dac.Close(); } }); } }
// 调取自己最近录像 void OnGetMyReplayList(Session s, IReadableBuffer data, IWriteableBuffer buff) { var maxNum = data.ReadInt(); var usrInfo = s.Usr.Info; var lst = new List <string>(); var arr = usrInfo.MyReplays.ToArray(); for (var i = 0; lst.Count < maxNum && i < arr.Length; i++) { var r = arr[arr.Length - i - 1]; if (Room4Server.AllReplayTitles.FirstIndexOf(r) >= 0) { lst.Add(r); } else { usrInfo.MyReplays.Remove(r); } } buff.Write(lst.Count); foreach (var rid in lst) { var r = Room4Server.GetReplay(rid); r.SerializeHeader(buff); } }
// 调取最近录像列表 void OnGetReplayList(Session s, IReadableBuffer data, IWriteableBuffer buff) { var maxNum = data.ReadInt(); var arr = Room4Server.AllReplayTitles; var lst = new List <string>(); for (var i = 0; lst.Count < maxNum && i < arr.Length; i++) { var n = arr.Length - 1 - i; var t = arr[n]; var r = Room4Server.GetReplay(t); if (t.IndexOf(".crash.") < 0 && r.Length < 0 /* 两分钟 */) { continue; } lst.Add(t); } buff.Write(lst.Count); foreach (var rid in lst) { var r = Room4Server.GetReplay(rid); r.SerializeHeader(buff); } }
// 调取录像 void OnGetReplay(Session s, IReadableBuffer data, IWriteableBuffer buff) { var replayName = data.ReadString(); var r = Room4Server.GetReplay(replayName); buff.Write(r != null); if (r != null) { r.Serialize(buff); } }
// 创建 PVE 战斗房间 public Room4Server CreatePVERoom(string usr, string aiType) { AIType = aiType; var s = SC[usr]; // 创建新房间 var roomID = usr + "_vs_AIRobot"; // 创建 ai var aiID = roomID + "_" + aiType; var r = new Room4Server(roomID, aiID, s, new Vec2(60, 200), "PVP"); r.IsPVP = false; if (s.Usr.Info.WinCount + s.Usr.Info.LoseCount != 0) { var rate = s.Usr.Info.WinCount * 100 / (s.Usr.Info.WinCount + s.Usr.Info.LoseCount); if (rate >= 45) { AIType = AIType1; } else if (rate >= 25) { AIType = AIType2; } else { AIType = AIType3; } } else { AIType = AIType3; } //AIType = "Dumb";//测试用傻瓜AI,不需要则注释. var ai = r.CreateComputerAI(AIType, r.GetNoByUser(aiID)); ai.FindPath = (radius, src, dst, cb) => { RequestPathFromClient(s, radius, src, dst, cb); }; rooms.Add(r); usr2room[usr] = r; return(r); }
// 创建 PVP 战斗房间 public Room4Server CreatePVPRoom(string usr1, string usr2) { var s1 = SC[usr1]; var s2 = SC[usr2]; if (s1 == null || s2 == null) { return(null); } // 创建新房间 var roomID = usr1 + "_vs_" + usr2; var r = new Room4Server(roomID, s1, s2, new Vec2(60, 200), "PVP"); r.IsPVP = true; rooms.Add(r); usr2room[usr1] = r; usr2room[usr2] = r; return(r); }