Exemple #1
0
        //随机生成地图内各传送门的目标地图
        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;
                }
            }
        }
Exemple #2
0
        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;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #3
0
        public static TCPProcessCmdResults ProcessFazhenTeleportCMD(TCPManager tcpMgr, TMSKSocket socket, TCPClientPool tcpClientPool, TCPOutPacketPool pool, int nID, byte[] data, int count, out TCPOutPacket tcpOutPacket)
        {
            tcpOutPacket = null;
            string cmdData = null;

            try
            {
                cmdData = new UTF8Encoding().GetString(data, 0, count);
            }
            catch (Exception)
            {
                LogManager.WriteLog(LogTypes.Error, string.Format("解析指令字符串错误, CMD={0}, Client={1}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket, false)), null, true);
                return(TCPProcessCmdResults.RESULT_FAILED);
            }
            try
            {
                string[] fields = cmdData.Split(new char[]
                {
                    ':'
                });
                if (fields.Length != 2)
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("指令参数个数错误, CMD={0}, Client={1}, Recv={2}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket, false), fields.Length), null, true);
                    return(TCPProcessCmdResults.RESULT_FAILED);
                }
                int roleID  = Convert.ToInt32(fields[0]);
                int MapCode = 0;
                if (!int.TryParse(fields[1], out MapCode))
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("ProcessFazhenTeleportCMD, roleID={0}, MapCode={1}", roleID, fields[1]), null, true);
                    return(TCPProcessCmdResults.RESULT_OK);
                }
                GameClient client = GameManager.ClientMgr.FindClient(socket);
                if (KuaFuManager.getInstance().ClientCmdCheckFaild(nID, client, ref roleID))
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("根据RoleID定位GameClient对象失败, CMD={0}, Client={1}, RoleID={2}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket, false), roleID), null, true);
                    return(TCPProcessCmdResults.RESULT_FAILED);
                }
                if (client.ClientData.MapCode != MapCode)
                {
                    return(TCPProcessCmdResults.RESULT_OK);
                }
                if (client.ClientData.FuBenID != LuoLanFaZhenCopySceneManager.LuoLanFaZhenFubenID)
                {
                    return(TCPProcessCmdResults.RESULT_OK);
                }
                SingleLuoLanFaZhenFubenData fubenData = LuoLanFaZhenCopySceneManager.GetFubenData(client.ClientData.FuBenSeqID);
                if (null == fubenData)
                {
                    return(TCPProcessCmdResults.RESULT_OK);
                }
                FazhenMapData mapData = null;
                lock (fubenData.MapDatas)
                {
                    fubenData.MapDatas.TryGetValue(client.ClientData.CopyMapID, out mapData);
                    if (null == mapData)
                    {
                        return(TCPProcessCmdResults.RESULT_OK);
                    }
                }
                FazhenMapProtoData senddata = new FazhenMapProtoData();
                senddata.listTelegate = new List <FazhenTelegateProtoData>();
                senddata.SrcMapCode   = mapData.MapCode;
                lock (mapData.Telegates)
                {
                    List <int> listGateID = mapData.Telegates.Keys.ToList <int>();
                    if (null != listGateID)
                    {
                        foreach (int gateid in listGateID)
                        {
                            SingleFazhenTelegateData gatedata = mapData.Telegates[gateid];
                            if (null != gatedata)
                            {
                                FazhenTelegateProtoData gatedata_s = new FazhenTelegateProtoData();
                                gatedata_s.gateId = gateid;
                                if (gatedata.usedAlready || LuoLanFaZhenCopySceneManager.GM_OpenState == 1)
                                {
                                    gatedata_s.DestMapCode = gatedata.destMapCode;
                                }
                                else
                                {
                                    gatedata_s.DestMapCode = 0;
                                }
                                senddata.listTelegate.Add(gatedata_s);
                            }
                        }
                    }
                }
                byte[] bytes = DataHelper.ObjectToBytes <FazhenMapProtoData>(senddata);
                tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, bytes, 0, bytes.Length, 685);
                return(TCPProcessCmdResults.RESULT_DATA);
            }
            catch (Exception ex)
            {
                DataHelper.WriteFormatExceptionLog(ex, "ProcessFazhenTeleportCMD", false, false);
            }
            return(TCPProcessCmdResults.RESULT_FAILED);
        }
Exemple #4
0
        public static TCPProcessCmdResults OnTeleport(GameClient client, int teleportID, TCPOutPacketPool pool, out TCPOutPacket tcpOutPacket)
        {
            tcpOutPacket = null;
            TCPProcessCmdResults result;

            if (client.ClientData.FuBenID != LuoLanFaZhenCopySceneManager.LuoLanFaZhenFubenID || client.ClientData.FuBenSeqID <= 0)
            {
                result = TCPProcessCmdResults.RESULT_FAILED;
            }
            else
            {
                SingleLuoLanFaZhenFubenData fubenData = LuoLanFaZhenCopySceneManager.GetFubenData(client.ClientData.FuBenSeqID);
                if (null == fubenData)
                {
                    result = TCPProcessCmdResults.RESULT_FAILED;
                }
                else
                {
                    FazhenMapData            mapdata  = null;
                    SingleFazhenTelegateData teledata = null;
                    lock (fubenData.MapDatas)
                    {
                        if (!fubenData.MapDatas.TryGetValue(client.ClientData.CopyMapID, out mapdata) || null == mapdata)
                        {
                            return(TCPProcessCmdResults.RESULT_FAILED);
                        }
                    }
                    if (mapdata.MapCode != client.ClientData.MapCode || mapdata.CopyMapID != client.ClientData.CopyMapID)
                    {
                        result = TCPProcessCmdResults.RESULT_FAILED;
                    }
                    else
                    {
                        lock (mapdata.Telegates)
                        {
                            if (!mapdata.Telegates.TryGetValue(teleportID, out teledata) || null == teledata)
                            {
                                return(TCPProcessCmdResults.RESULT_FAILED);
                            }
                        }
                        if (teledata.destMapCode <= 0)
                        {
                            result = TCPProcessCmdResults.RESULT_FAILED;
                        }
                        else
                        {
                            bool TeleToSpecial = false;
                            if (teledata.SpecialDestMapCode > 0)
                            {
                                if (0 != fubenData.SpecailBossLeftNum)
                                {
                                    int rand = Global.GetRandomNumber(0, 100);
                                    if (rand < LuoLanFaZhenCopySceneManager.SpecialTeleRate)
                                    {
                                        TeleToSpecial = true;
                                    }
                                }
                            }
                            if (TeleToSpecial)
                            {
                                GameManager.ClientMgr.ChangeMap(TCPManager.getInstance().MySocketListener, TCPOutPacketPool.getInstance(), client, teleportID, teledata.SpecialDestMapCode, teledata.SpecialDestX, teledata.SpecialDestY, client.ClientData.RoleDirection, 123);
                            }
                            else
                            {
                                bool NeedSend = false;
                                lock (teledata)
                                {
                                    if (!teledata.usedAlready)
                                    {
                                        teledata.usedAlready = true;
                                        NeedSend             = true;
                                    }
                                }
                                if (NeedSend)
                                {
                                    FazhenMapProtoData senddata = new FazhenMapProtoData();
                                    senddata.listTelegate = new List <FazhenTelegateProtoData>();
                                    senddata.SrcMapCode   = mapdata.MapCode;
                                    FazhenTelegateProtoData gatedata_s = new FazhenTelegateProtoData();
                                    gatedata_s.gateId      = teledata.gateId;
                                    gatedata_s.DestMapCode = teledata.destMapCode;
                                    senddata.listTelegate.Add(gatedata_s);
                                    LuoLanFaZhenCopySceneManager.BroadMapData <FazhenMapProtoData>(685, senddata, mapdata.MapCode, client.ClientData.FuBenSeqID);
                                }
                                GameManager.ClientMgr.ChangeMap(TCPManager.getInstance().MySocketListener, TCPOutPacketPool.getInstance(), client, teleportID, teledata.destMapCode, teledata.destX, teledata.destY, client.ClientData.RoleDirection, 123);
                            }
                            result = TCPProcessCmdResults.RESULT_OK;
                        }
                    }
                }
            }
            return(result);
        }
Exemple #5
0
        //客户端请求罗兰法阵地图数据
        public static TCPProcessCmdResults ProcessFazhenTeleportCMD(TCPManager tcpMgr, TMSKSocket socket, TCPClientPool tcpClientPool, TCPOutPacketPool pool, int nID, byte[] data, int count, out TCPOutPacket tcpOutPacket)
        {
            tcpOutPacket = null;
            string cmdData = null;

            try
            {
                cmdData = new UTF8Encoding().GetString(data, 0, count);
            }
            catch (Exception) //解析错误
            {
                LogManager.WriteLog(LogTypes.Error, string.Format("解析指令字符串错误, CMD={0}, Client={1}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket)));
                return(TCPProcessCmdResults.RESULT_FAILED);
            }

            try
            {
                string[] fields = cmdData.Split(':');
                if (fields.Length != 2)
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("指令参数个数错误, CMD={0}, Client={1}, Recv={2}",
                                                                      (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket), fields.Length));
                    return(TCPProcessCmdResults.RESULT_FAILED);
                }

                int roleID = Convert.ToInt32(fields[0]);

                // 206发现这个字段解析异常
                int MapCode = 0;
                if (int.TryParse(fields[1], out MapCode) == false)
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("ProcessFazhenTeleportCMD, roleID={0}, MapCode={1}", roleID, fields[1]));
                    return(TCPProcessCmdResults.RESULT_OK);
                }

                GameClient client = GameManager.ClientMgr.FindClient(socket);
                if (null == client || client.ClientData.RoleID != roleID)
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("根据RoleID定位GameClient对象失败, CMD={0}, Client={1}, RoleID={2}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket), roleID));
                    return(TCPProcessCmdResults.RESULT_FAILED);
                }

                if (client.ClientData.MapCode != MapCode)
                {
                    return(TCPProcessCmdResults.RESULT_OK);
                }

                if (client.ClientData.FuBenID != LuoLanFaZhenFubenID)
                {
                    return(TCPProcessCmdResults.RESULT_OK);
                }

                SingleLuoLanFaZhenFubenData fubenData = GetFubenData(client.ClientData.FuBenSeqID);
                if (null == fubenData)
                {
                    return(TCPProcessCmdResults.RESULT_OK);
                }

                FazhenMapData mapData = null;
                lock (fubenData.MapDatas)
                {
                    fubenData.MapDatas.TryGetValue(client.ClientData.CopyMapID, out mapData);
                    if (null == mapData)
                    {
                        return(TCPProcessCmdResults.RESULT_OK);
                    }
                }

                //发送此地图内的传送门数据
                FazhenMapProtoData senddata = new FazhenMapProtoData();
                senddata.listTelegate = new List <FazhenTelegateProtoData>();
                senddata.SrcMapCode   = mapData.MapCode;

                //遍历此地图内所有传送门
                lock (mapData.Telegates)
                {
                    List <int> listGateID = mapData.Telegates.Keys.ToList();

                    if (null != listGateID)
                    {
                        foreach (var gateid in listGateID)
                        {
                            SingleFazhenTelegateData gatedata = mapData.Telegates[gateid];
                            if (null == gatedata)
                            {
                                continue;
                            }

                            FazhenTelegateProtoData gatedata_s = new FazhenTelegateProtoData();
                            gatedata_s.gateId = gateid;
                            if (gatedata.usedAlready || GM_OpenState == 1)
                            {
                                gatedata_s.DestMapCode = gatedata.destMapCode;
                            }
                            else
                            {
                                gatedata_s.DestMapCode = 0;
                            }

                            senddata.listTelegate.Add(gatedata_s);
                        }
                    }
                }

                //发送此地图内的传送门数据
                byte[] bytes = DataHelper.ObjectToBytes <FazhenMapProtoData>(senddata);
                tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, bytes, 0, bytes.Length, (int)TCPGameServerCmds.CMD_MAP_TELEPORT);
                return(TCPProcessCmdResults.RESULT_DATA);
            }
            catch (Exception ex)
            {
                DataHelper.WriteFormatExceptionLog(ex, "ProcessFazhenTeleportCMD", false);
            }

            return(TCPProcessCmdResults.RESULT_FAILED);
        }
Exemple #6
0
        //玩家使用传送门
        public static TCPProcessCmdResults OnTeleport(GameClient client, int teleportID, TCPOutPacketPool pool, out TCPOutPacket tcpOutPacket)
        {
            tcpOutPacket = null;

            if (client.ClientData.FuBenID != LuoLanFaZhenFubenID || client.ClientData.FuBenSeqID <= 0)
            {
                return(TCPProcessCmdResults.RESULT_FAILED);
            }

            SingleLuoLanFaZhenFubenData fubenData = GetFubenData(client.ClientData.FuBenSeqID);

            if (null == fubenData)
            {
                return(TCPProcessCmdResults.RESULT_FAILED);
            }

            FazhenMapData            mapdata  = null;
            SingleFazhenTelegateData teledata = null;

            lock (fubenData.MapDatas)
            {
                if (!fubenData.MapDatas.TryGetValue(client.ClientData.CopyMapID, out mapdata) || null == mapdata)
                {
                    return(TCPProcessCmdResults.RESULT_FAILED);
                }
            }

            if (mapdata.MapCode != client.ClientData.MapCode || mapdata.CopyMapID != client.ClientData.CopyMapID)
            {
                return(TCPProcessCmdResults.RESULT_FAILED);
            }

            lock (mapdata.Telegates)
            {
                //如果找不到这个传送门,说明这是个普通的传送点
                if (!mapdata.Telegates.TryGetValue(teleportID, out teledata) || null == teledata)
                {
                    return(TCPProcessCmdResults.RESULT_FAILED);
                }
            }

            if (teledata.destMapCode <= 0)
            {
                return(TCPProcessCmdResults.RESULT_FAILED);
            }

            //判断是否随机传到特殊地图
            bool TeleToSpecial = false;

            if (teledata.SpecialDestMapCode > 0)
            {
                //[bing] 有些人进入特殊地图时 该地图怪物已经被杀了 导致进入地图后又要返回 所以预先判断有无怪物 没怪物则不传送特殊地
                if (0 != fubenData.SpecailBossLeftNum)
                {
                    int rand = Global.GetRandomNumber(0, 100);
                    //是否随机传送到特殊地图
                    if (rand < SpecialTeleRate)
                    {
                        //传送到特殊地图
                        TeleToSpecial = true;
                    }
                }
            }

            if (TeleToSpecial)
            {
                //传送到特殊地图teledata.SpecialDestMapCode
                GameManager.ClientMgr.ChangeMap(TCPManager.getInstance().MySocketListener, TCPOutPacketPool.getInstance(), client, teleportID,
                                                teledata.SpecialDestMapCode, teledata.SpecialDestX, teledata.SpecialDestY, client.ClientData.RoleDirection,
                                                (int)TCPGameServerCmds.CMD_SPR_MAPCHANGE);
            }
            else   //传送到普通地图
            {
                //是否已经用过?
                bool NeedSend = false;
                lock (teledata)
                {
                    if (!teledata.usedAlready)
                    {
                        //没用过
                        teledata.usedAlready = true;
                        NeedSend             = true;
                    }
                }

                if (NeedSend)
                {
                    //通知副本内所有玩家传送门被用过后的数据
                    FazhenMapProtoData senddata = new FazhenMapProtoData();
                    senddata.listTelegate = new List <FazhenTelegateProtoData>();
                    senddata.SrcMapCode   = mapdata.MapCode;

                    FazhenTelegateProtoData gatedata_s = new FazhenTelegateProtoData();
                    gatedata_s.gateId      = teledata.gateId;
                    gatedata_s.DestMapCode = teledata.destMapCode;
                    senddata.listTelegate.Add(gatedata_s);

                    //发送此传送门数据给地图内所有玩家
                    BroadMapData <FazhenMapProtoData>((int)TCPGameServerCmds.CMD_MAP_TELEPORT, senddata, mapdata.MapCode, client.ClientData.FuBenSeqID);
                }

                //传送到普通地图
                GameManager.ClientMgr.ChangeMap(TCPManager.getInstance().MySocketListener, TCPOutPacketPool.getInstance(), client, teleportID,
                                                teledata.destMapCode, teledata.destX, teledata.destY, client.ClientData.RoleDirection,
                                                (int)TCPGameServerCmds.CMD_SPR_MAPCHANGE);
            }

            return(TCPProcessCmdResults.RESULT_OK);
        }