//随机生成地图内各传送门的目标地图 public static void CreateRandomGates(int MapCode, FazhenMapData MapData) { //取得这个地图编号对应的传送门静态数据 SystemFazhenMapData sysMapData = null; if (!m_AllMapGatesStaticData.TryGetValue(MapCode, out sysMapData)) { return; } if (null == sysMapData) { return; } List <int> randgates = new List <int>(); foreach (int gateid in sysMapData.listGateID) { { int index = Global.GetRandomNumber(0, randgates.Count + 1); randgates.Insert(index, gateid); } } if (randgates.Count != sysMapData.listDestMapCode.Count) { return; } GameMap gameMap = null; if (!GameManager.MapMgr.DictMaps.TryGetValue(MapData.MapCode, out gameMap) || null == gameMap) { return; } lock (MapData.Telegates) { for (int i = 0; i < randgates.Count; i++) { MapTeleport mapTeleport = null; if (!gameMap.MapTeleportDict.TryGetValue(sysMapData.listGateID[i], out mapTeleport) || null == mapTeleport) { continue; } SingleFazhenTelegateData newGatedata = new SingleFazhenTelegateData(); newGatedata.usedAlready = false; newGatedata.gateId = randgates[i]; newGatedata.destMapCode = sysMapData.listDestMapCode[i]; newGatedata.SpecialDestMapCode = sysMapData.SpecialDestMapCode; newGatedata.SpecialDestX = sysMapData.SpecialDestX; newGatedata.SpecialDestY = sysMapData.SpecialDestY; newGatedata.destX = mapTeleport.ToX; newGatedata.destY = mapTeleport.ToY; MapData.Telegates[newGatedata.gateId] = newGatedata; } } }
public bool OnInitGame(GameClient client) { KuaFuServerLoginData kuaFuServerLoginData = Global.GetClientKuaFuServerLoginData(client); //在跨服主线地图中,这个值表示存储编号 client.ClientData.MapCode = (int)kuaFuServerLoginData.GameId; client.ClientData.PosX = 0; client.ClientData.PosY = 0; List <int> enterFlags = Global.GetRoleParamsIntListFromDB(client, RoleParamName.EnterKuaFuMapFlag); if (enterFlags != null && enterFlags.Count >= (int)EKuaFuMapEnterFlag.Max) { int fromMapCode = enterFlags[(int)EKuaFuMapEnterFlag.FromMapCode]; int fromTeleport = enterFlags[(int)EKuaFuMapEnterFlag.FromTeleport]; int targetBossId = enterFlags[(int)EKuaFuMapEnterFlag.TargetBossId]; if (fromMapCode > 0 && fromTeleport > 0) { // 要通过传送点进入跨服主线,必须检测是否能真正使用这个传送点 GameMap fromGameMap = null; MapTeleport mapTeleport = null; if (GameManager.MapMgr.DictMaps.TryGetValue(fromMapCode, out fromGameMap) && fromGameMap.MapTeleportDict.TryGetValue(fromTeleport, out mapTeleport)) { GameMap toGameMap = null; if (GameManager.MapMgr.DictMaps.TryGetValue(mapTeleport.ToMapID, out toGameMap) && toGameMap.CanMove(mapTeleport.ToX / toGameMap.MapGridWidth, mapTeleport.ToY / toGameMap.MapGridHeight)) { client.ClientData.MapCode = mapTeleport.ToMapID; client.ClientData.PosX = mapTeleport.ToX; client.ClientData.PosY = mapTeleport.ToY; } } } if (targetBossId > 0) { Global.ProcessVipLevelUp(client); if (Global.IsVip(client) && client.ClientData.VipLevel >= GameManager.systemParamsList.GetParamValueIntByName("VIPBossChuanSong", 4)) { int bossX, bossY, radis; if (GameManager.MonsterZoneMgr.GetMonsterBirthPoint(client.ClientData.MapCode, targetBossId, out bossX, out bossY, out radis)) { radis = 1; Point newPos = Global.GetMapPoint(ObjectTypes.OT_CLIENT, client.ClientData.MapCode, bossX, bossY, radis); client.ClientData.PosX = (int)newPos.X; client.ClientData.PosY = (int)newPos.Y; } } } } return(true); }
/// <summary> /// 加载地图传送点字典 /// </summary> private void LoadMapTeleportDict() { //首先根据地图编号定位地图文件 string name = string.Format("Map/{0}/teleports.xml", MapCode); XElement xml = null; try { xml = Global.GetGameResXml(name); } catch (Exception) { throw new Exception(string.Format("启动时加载xml文件: {0} 失败", name)); } IEnumerable <XElement> images = xml.Element("Teleports").Elements(); if (null == images) { return; } // Read the entire XML foreach (var image_item in images) { int code = (int)Global.GetSafeAttributeLong(image_item, "Key"); int to = (int)Global.GetSafeAttributeLong(image_item, "To"); int toX = (int)Global.GetSafeAttributeLong(image_item, "ToX"); int toY = (int)Global.GetSafeAttributeLong(image_item, "ToY"); int x = (int)Global.GetSafeAttributeLong(image_item, "X"); int y = (int)Global.GetSafeAttributeLong(image_item, "Y"); int radius = (int)Global.GetSafeAttributeLong(image_item, "Radius"); MapTeleport mapTeleport = new MapTeleport() { Code = code, MapID = -1, X = x, Y = y, ToX = toX, ToY = toY, ToMapID = to, Radius = radius, }; MapTeleportDict[code] = mapTeleport; } xml = null; }
public static void CreateRandomGates(int MapCode, FazhenMapData MapData) { SystemFazhenMapData sysMapData = null; if (LuoLanFaZhenCopySceneManager.m_AllMapGatesStaticData.TryGetValue(MapCode, out sysMapData)) { if (null != sysMapData) { List <int> randgates = new List <int>(); foreach (int gateid in sysMapData.listGateID) { int index = Global.GetRandomNumber(0, randgates.Count + 1); randgates.Insert(index, gateid); } if (randgates.Count == sysMapData.listDestMapCode.Count) { GameMap gameMap = null; if (GameManager.MapMgr.DictMaps.TryGetValue(MapData.MapCode, out gameMap) && null != gameMap) { lock (MapData.Telegates) { for (int i = 0; i < randgates.Count; i++) { MapTeleport mapTeleport = null; if (gameMap.MapTeleportDict.TryGetValue(sysMapData.listGateID[i], out mapTeleport) && null != mapTeleport) { SingleFazhenTelegateData newGatedata = new SingleFazhenTelegateData(); newGatedata.usedAlready = false; newGatedata.gateId = randgates[i]; newGatedata.destMapCode = sysMapData.listDestMapCode[i]; newGatedata.SpecialDestMapCode = sysMapData.SpecialDestMapCode; newGatedata.SpecialDestX = sysMapData.SpecialDestX; newGatedata.SpecialDestY = sysMapData.SpecialDestY; newGatedata.destX = mapTeleport.ToX; newGatedata.destY = mapTeleport.ToY; MapData.Telegates[newGatedata.gateId] = newGatedata; } } } } } } } }
public bool ProcessKuaFuMapEnterCmd(GameClient client, int nID, byte[] bytes, string[] cmdParams) { try { int result = 0; int toMapCode = Global.SafeConvertToInt32(cmdParams[0]); int line = Global.SafeConvertToInt32(cmdParams[1]); int toBoss = 0; int teleportId = 0; if (cmdParams.Length >= 3) { toBoss = Global.SafeConvertToInt32(cmdParams[2]); } if (cmdParams.Length >= 4) { teleportId = Global.SafeConvertToInt32(cmdParams[3]); } KuaFuLineData kuaFuLineData; if (!KuaFuMapManager.getInstance().IsKuaFuMap(toMapCode)) { result = -12; } else if (!this.RuntimeData.LineMap2KuaFuLineDataDict.TryGetValue(new IntPairKey(line, toMapCode), out kuaFuLineData)) { result = -12; } else if (!Global.CanEnterMap(client, toMapCode) || (toMapCode == client.ClientData.MapCode && kuaFuLineData.MapType != 1)) { result = -12; } else { if (toMapCode == client.ClientData.MapCode && kuaFuLineData.MapType == 1) { List <KuaFuLineData> list = KuaFuWorldClient.getInstance().GetKuaFuLineDataList(toMapCode) as List <KuaFuLineData>; if (null == list) { result = -12; goto IL_67F; } KuaFuLineData currentLineData = list.Find((KuaFuLineData x) => x.ServerId == GameManager.KuaFuServerId); if (currentLineData != null && currentLineData.Line == kuaFuLineData.Line) { result = -4011; goto IL_67F; } } if (!KuaFuMapManager.getInstance().IsKuaFuMap(client.ClientData.MapCode) && !this.CheckMap(client)) { result = -21; } else if (!this.IsGongNengOpened(client, false)) { result = -12; } else if (kuaFuLineData.OnlineCount >= kuaFuLineData.MaxOnlineCount) { result = -100; } else { int fromMapCode = client.ClientData.MapCode; if (teleportId > 0) { GameMap fromGameMap = null; if (!GameManager.MapMgr.DictMaps.TryGetValue(fromMapCode, out fromGameMap)) { result = -3; goto IL_67F; } MapTeleport mapTeleport = null; if (!fromGameMap.MapTeleportDict.TryGetValue(teleportId, out mapTeleport) || mapTeleport.ToMapID != toMapCode) { result = -12; goto IL_67F; } if (Global.GetTwoPointDistance(client.CurrentPos, new Point((double)mapTeleport.X, (double)mapTeleport.Y)) > 800.0) { result = -301; goto IL_67F; } } KuaFuServerLoginData kuaFuServerLoginData = Global.GetClientKuaFuServerLoginData(client); int kuaFuServerId; if (kuaFuLineData.MapType == 1) { if (!GlobalNew.IsGongNengOpened(client, GongNengIDs.Reborn, true)) { result = -400; goto IL_67F; } string signToken; string signKey; int rt = KuaFuWorldClient.getInstance().EnterPTKuaFuMap(client.ServerId, client.ClientData.LocalRoleID, client.ClientData.ServerPTID, kuaFuLineData.MapCode, kuaFuLineData.Line, kuaFuServerLoginData, out signToken, out signKey); if (rt == -4010) { KuaFuWorldRoleData kuaFuWorldRoleData = new KuaFuWorldRoleData { LocalRoleID = client.ClientData.LocalRoleID, UserID = client.strUserID, WorldRoleID = client.ClientData.WorldRoleID, Channel = client.ClientData.Channel, PTID = client.ClientData.ServerPTID, ServerID = client.ServerId, ZoneID = client.ClientData.ZoneID }; rt = KuaFuWorldClient.getInstance().RegPTKuaFuRoleData(ref kuaFuWorldRoleData); rt = KuaFuWorldClient.getInstance().EnterPTKuaFuMap(client.ServerId, client.ClientData.LocalRoleID, client.ClientData.ServerPTID, kuaFuLineData.MapCode, kuaFuLineData.Line, kuaFuServerLoginData, out signToken, out signKey); } if (rt < 0) { result = rt; goto IL_67F; } KFRebornRoleData rebornRoleData = KuaFuWorldClient.getInstance().Reborn_GetRebornRoleData(client.ClientData.ServerPTID, client.ClientData.LocalRoleID); if (null == rebornRoleData) { result = KuaFuWorldClient.getInstance().Reborn_RoleReborn(client.ClientData.ServerPTID, client.ClientData.LocalRoleID, client.ClientData.RoleName, client.ClientData.RebornLevel); if (result < 0) { goto IL_67F; } LogManager.WriteLog(LogTypes.Analysis, string.Format("Reborn_RoleReborn ptId={0} roleId={1} roleName={2} rebornLevel={3}", new object[] { client.ClientData.ServerPTID, client.ClientData.LocalRoleID, client.ClientData.RoleName, client.ClientData.RebornLevel }), null, true); } kuaFuServerLoginData.PTID = client.ClientData.ServerPTID; kuaFuServerLoginData.RoleId = client.ClientData.LocalRoleID; kuaFuServerLoginData.SignToken = signToken; kuaFuServerLoginData.TempRoleID = rt; kuaFuServerLoginData.SignCode = MD5Helper.get_md5_string(kuaFuServerLoginData.SignDataString() + signKey).ToLower(); kuaFuServerId = kuaFuServerLoginData.TargetServerID; } else { kuaFuServerLoginData.SignCode = null; kuaFuServerId = YongZheZhanChangClient.getInstance().EnterKuaFuMap(client.ClientData.LocalRoleID, kuaFuLineData.MapCode, kuaFuLineData.Line, client.ServerId, Global.GetClientKuaFuServerLoginData(client)); } kuaFuServerLoginData.Line = line; if (kuaFuServerId > 0) { bool flag = 0 == 0; int needMoney = (teleportId > 0) ? 0 : Global.GetMapTransNeedMoney(toMapCode); if (Global.GetTotalBindTongQianAndTongQianVal(client) < needMoney) { GameManager.ClientMgr.NotifyImportantMsg(client, StringUtil.substitute(GLang.GetLang(171, new object[0]), new object[] { needMoney, Global.GetMapName(toMapCode) }), GameInfoTypeIndexes.Error, ShowGameInfoTypes.ErrAndBox, 27); result = -9; Global.GetClientKuaFuServerLoginData(client).RoleId = 0; } else { int[] enterFlags = new int[5]; enterFlags[0] = fromMapCode; enterFlags[1] = teleportId; enterFlags[2] = toBoss; Global.SaveRoleParamsIntListToDB(client, new List <int>(enterFlags), "EnterKuaFuMapFlag", true); GlobalNew.RecordSwitchKuaFuServerLog(client); client.sendCmd <KuaFuServerLoginData>(14000, Global.GetClientKuaFuServerLoginData(client), false); } } else { Global.GetClientKuaFuServerLoginData(client).RoleId = 0; result = kuaFuServerId; } } } IL_67F: client.sendCmd <int>(nID, result, false); return(true); } catch (Exception ex) { DataHelper.WriteFormatExceptionLog(ex, Global.GetDebugHelperInfo(client.ClientSocket), false, false); } return(false); }
public bool ProcessKuaFuMapEnterCmd(GameClient client, int nID, byte[] bytes, string[] cmdParams) { try { int result = StdErrorCode.Error_Success_No_Info; int toMapCode = Global.SafeConvertToInt32(cmdParams[0]); int line = Global.SafeConvertToInt32(cmdParams[1]); int toBoss = 0; int teleportId = 0; if (cmdParams.Length >= 3) { toBoss = Global.SafeConvertToInt32(cmdParams[2]); } if (cmdParams.Length >= 4) { teleportId = Global.SafeConvertToInt32(cmdParams[3]); } do { if (!KuaFuMapManager.getInstance().IsKuaFuMap(toMapCode)) { result = StdErrorCode.Error_Operation_Denied; break; } if (!Global.CanEnterMap(client, toMapCode) || toMapCode == client.ClientData.MapCode) { result = StdErrorCode.Error_Operation_Denied; break; } // 新增需求,跨服主线地图能够直接进入另一个跨服主线地图 if (!KuaFuMapManager.getInstance().IsKuaFuMap(client.ClientData.MapCode) && !CheckMap(client)) { result = StdErrorCode.Error_Denied_In_Current_Map; break; } if (!IsGongNengOpened(client)) { result = StdErrorCode.Error_Operation_Denied; break; } KuaFuLineData kuaFuLineData; if (!RuntimeData.LineMap2KuaFuLineDataDict.TryGetValue(new IntPairKey(line, toMapCode), out kuaFuLineData)) { result = StdErrorCode.Error_Operation_Denied; break; } if (kuaFuLineData.OnlineCount >= kuaFuLineData.MaxOnlineCount) { result = StdErrorCode.Error_Server_Connections_Limit; break; } int fromMapCode = client.ClientData.MapCode; if (teleportId > 0) { // 要通过传送点进入跨服主线,必须检测是否能真正使用这个传送点 GameMap fromGameMap = null; if (!GameManager.MapMgr.DictMaps.TryGetValue(fromMapCode, out fromGameMap)) { result = StdErrorCode.Error_Config_Fault; break; } MapTeleport mapTeleport = null; if (!fromGameMap.MapTeleportDict.TryGetValue(teleportId, out mapTeleport) || mapTeleport.ToMapID != toMapCode) { result = StdErrorCode.Error_Operation_Denied; break; } // 这里要增加一个位置判断,玩家是否在传送点附近, CMD_SPR_MAPCHANGE 里面没有判断,这里先放宽松一点 if (Global.GetTwoPointDistance(client.CurrentPos, new Point(mapTeleport.X, mapTeleport.Y)) > 800) { result = StdErrorCode.Error_Too_Far; break; } } int kuaFuServerId = YongZheZhanChangClient.getInstance().EnterKuaFuMap(client.ClientData.RoleID, kuaFuLineData.MapCode, kuaFuLineData.Line, client.ServerId, Global.GetClientKuaFuServerLoginData(client)); if (kuaFuServerId > 0) { // 废弃这个判断,两个跨服主线地图配在同一台服务器上,仍然统一短线重连<客户端并不需要知道没有跨到另一个服务器> if (false && kuaFuServerId == GameManager.ServerId) { Global.GotoMap(client, toMapCode); } else { // 使用传送点,不扣金币 int needMoney = teleportId > 0 ? 0 : Global.GetMapTransNeedMoney(toMapCode); if (Global.GetTotalBindTongQianAndTongQianVal(client) < needMoney) { GameManager.ClientMgr.NotifyImportantMsg(client, StringUtil.substitute(Global.GetLang("金币不足【{0}】,无法传送到【{1}】!"), needMoney, Global.GetMapName(toMapCode)), GameInfoTypeIndexes.Error, ShowGameInfoTypes.ErrAndBox, (int)HintErrCodeTypes.NoTongQian); result = StdErrorCode.Error_JinBi_Not_Enough; } else { int[] enterFlags = new int[(int)EKuaFuMapEnterFlag.Max]; enterFlags[(int)EKuaFuMapEnterFlag.FromMapCode] = fromMapCode; enterFlags[(int)EKuaFuMapEnterFlag.FromTeleport] = teleportId; enterFlags[(int)EKuaFuMapEnterFlag.TargetBossId] = toBoss; Global.SaveRoleParamsIntListToDB(client, new List <int>(enterFlags), RoleParamName.EnterKuaFuMapFlag, true); GlobalNew.RecordSwitchKuaFuServerLog(client); client.sendCmd((int)TCPGameServerCmds.CMD_SPR_KF_SWITCH_SERVER, Global.GetClientKuaFuServerLoginData(client)); } } } else { Global.GetClientKuaFuServerLoginData(client).RoleId = 0; result = kuaFuServerId; } } while (false); client.sendCmd(nID, result); return(true); } catch (Exception ex) { DataHelper.WriteFormatExceptionLog(ex, Global.GetDebugHelperInfo(client.ClientSocket), false); } return(false); }