protected virtual void OnChasePathComplete(List <FixVector3> path) { SyncC2S sync = new SyncC2S(); sync.uintId = id; sync.timestamp = DataManager.GetInstance().GetFrame(); sync.syncState = SyncState.Chase; GetPositionsFromPath(path, sync.positions); PostBattleMessage(MsgCode.SyncMessage, sync); }
// Sync move protected virtual void OnWalkPathComplete(List <FixVector3> path) { DebugUtils.Log(DebugUtils.Type.PathRender, string.Format("Current path point count {0}", path.Count)); SyncC2S sync = new SyncC2S(); sync.uintId = id; sync.timestamp = DataManager.GetInstance().GetFrame(); sync.syncState = SyncState.Walk; GetPositionsFromPath(path, sync.positions); PostBattleMessage(MsgCode.SyncMessage, sync); DebugUtils.LogWarning(DebugUtils.Type.AI_MovableUnit, string.Format("{0} {1} find Walk path count {1}", id, type, sync.positions.Count)); }
private void BroadCastFeedBack(long frame) { byte[] dataS2C = null; UpdateS2C updateS2C = new UpdateS2C(); updateS2C.battleId = 0; updateS2C.timestamp = frame; if (status == LocalBattleStatus.Start) { NoticeS2C noticeS2C = new NoticeS2C(); noticeS2C.type = NoticeType.BattleBegin; dataS2C = ProtobufUtils.Serialize(noticeS2C); localMessageHandlers[MsgCode.NoticeMessage](dataS2C); status = LocalBattleStatus.Normaly; } for (int i = messageList.Count - 1; i >= 0; i--) { if (messageList[i].msgCode == MsgCode.UpdateMessage) { UpdateC2S updateC2S = ProtobufUtils.Deserialize <UpdateC2S>(messageList[i].data); updateS2C.ops.Add(updateC2S.operation); } else if (messageList[i].msgCode == MsgCode.NoticeMessage) { NoticeC2S noticeC2S = ProtobufUtils.Deserialize <NoticeC2S>(messageList[i].data); NoticeS2C noticeS2C = new NoticeS2C(); noticeS2C.type = noticeC2S.type; dataS2C = ProtobufUtils.Serialize(noticeS2C); DebugUtils.Log(DebugUtils.Type.LocalBattleMessage, string.Format("Send {0} feed back succeed ", messageList[i].msgCode)); localMessageHandlers[MsgCode.NoticeMessage](dataS2C); // battle end need to stop send updateS2CS if (noticeC2S.type == NoticeType.BattleResultBlueWin || noticeC2S.type == NoticeType.BattleResultRedWin || noticeC2S.type == NoticeType.BattleResultDraw) { status = LocalBattleStatus.End; } } else if (messageList[i].msgCode == MsgCode.SyncMessage) { SyncC2S syncC2S = ProtobufUtils.Deserialize <SyncC2S>(messageList[i].data); Sync s = new Sync(); s.syncState = syncC2S.syncState; s.unitId = syncC2S.uintId; s.continuedWalkNum = syncC2S.continuedWalkNum; s.timestamp = frame; foreach (Position item in syncC2S.positions) { s.positions.Add(item); } Operation operation = new Operation(); operation.sync = s; operation.opType = OperationType.SyncPath; updateS2C.ops.Add(operation); } else if (messageList[i].msgCode == MsgCode.QuitBattleMessage) { QuitBattleC2S quitBattleC2S = ProtobufUtils.Deserialize <QuitBattleC2S>(messageList[i].data); QuitBattleS2C quitBattleS2C = new QuitBattleS2C(); quitBattleS2C.serverIp = "127.0.0.1"; quitBattleS2C.serverPort = 0; quitBattleS2C.serverType = ServerType.GameServer; dataS2C = ProtobufUtils.Serialize(quitBattleS2C); DebugUtils.Log(DebugUtils.Type.LocalBattleMessage, string.Format("Send {0} feed back succeed ", messageList[i].msgCode)); localMessageHandlers[MsgCode.QuitBattleMessage](dataS2C); status = LocalBattleStatus.End; return; } else if (messageList[i].msgCode == MsgCode.UploadSituationMessage) { UploadSituationC2S uploadSituationC2S = ProtobufUtils.Deserialize <UploadSituationC2S>(messageList[i].data); UploadSituationS2C uploadSituationS2C = new UploadSituationS2C(); uploadSituationS2C.type = uploadSituationC2S.type; dataS2C = ProtobufUtils.Serialize(uploadSituationS2C); DebugUtils.Log(DebugUtils.Type.LocalBattleMessage, string.Format("Send {0} feed back succeed ", messageList[i].msgCode)); Action <byte[]> callback = null; if (localMessageHandlers.TryGetValue(MsgCode.UploadSituationMessage, out callback)) { callback.Invoke(dataS2C); } } else { DebugUtils.LogError(DebugUtils.Type.LocalBattleMessage, string.Format("Can't handle this local message now message code = {0} ", messageList[i].msgCode)); } messageList.RemoveAt(i); } dataS2C = ProtobufUtils.Serialize(updateS2C); for (int i = 0; i < updateS2C.ops.Count; i++) { DebugUtils.Log(DebugUtils.Type.LocalBattleMessage, string.Format("Frame: Send feed back operation {0}", updateS2C.ops[i].opType)); } localMessageHandlers[MsgCode.UpdateMessage](dataS2C); }