Пример #1
0
        public void CreateMonster(ElementWarScene scene, int upWave)
        {
            CopyMap copyMap = scene.CopyMapInfo;
            GameMap gameMap = null;

            if (!GameManager.MapMgr.DictMaps.TryGetValue(scene.MapID, out gameMap))
            {
                LogManager.WriteLog(LogTypes.Error, string.Format("元素试炼报错 地图配置 ID = {0}", scene.MapID), null, true);
            }
            else
            {
                long nowTicket = TimeUtil.NOW();
                long nowSecond = nowTicket / 1000L;
                lock (scene)
                {
                    if (scene.MonsterWave >= scene.MonsterWaveTotal)
                    {
                        scene.SceneStatus = GameSceneStatuses.STATUS_END;
                    }
                    else
                    {
                        scene.IsMonsterFlag = 1;
                        int wave = scene.MonsterWave + upWave;
                        if (wave > scene.MonsterWaveTotal)
                        {
                            wave = scene.MonsterWaveTotal;
                        }
                        ElementWarMonsterConfigInfo waveConfig = this._runtimeData.GetOrderConfig(wave);
                        if (waveConfig == null)
                        {
                            LogManager.WriteLog(LogTypes.Error, string.Format("元素试炼报错 刷怪波次 = {0}", wave), null, true);
                        }
                        else
                        {
                            scene.MonsterCountCreate = waveConfig.MonsterCount;
                            scene.MonsterWave        = wave;
                            scene.CreateMonsterTime  = nowSecond;
                            for (int i = 0; i < waveConfig.MonsterCount; i++)
                            {
                                int monsterID = waveConfig.MonsterIDs[i % waveConfig.MonsterIDs.Count];
                                int gridX     = gameMap.CorrectWidthPointToGridPoint(waveConfig.X + Global.GetRandomNumber(-waveConfig.Radius, waveConfig.Radius)) / gameMap.MapGridWidth;
                                int gridY     = gameMap.CorrectHeightPointToGridPoint(waveConfig.Y + Global.GetRandomNumber(-waveConfig.Radius, waveConfig.Radius)) / gameMap.MapGridHeight;
                                int gridNum   = 0;
                                GameManager.MonsterZoneMgr.AddDynamicMonsters(scene.MapID, monsterID, scene.CopyMapInfo.CopyMapID, 1, gridX, gridY, gridNum, 0, SceneUIClasses.Normal, null, null);
                            }
                            scene.ScoreData.Wave         = waveConfig.OrderID;
                            scene.ScoreData.EndTime      = nowTicket + (long)(waveConfig.Up1 * 1000);
                            scene.ScoreData.MonsterCount = (long)waveConfig.MonsterCount;
                            GameManager.ClientMgr.BroadSpecialCopyMapMessage <ElementWarScoreData>(1014, scene.ScoreData, scene.CopyMapInfo);
                        }
                    }
                }
            }
        }
Пример #2
0
        public bool InitConfig()
        {
            bool   success  = true;
            string fileName = "";

            lock (this._runtimeData.Mutex)
            {
                try
                {
                    this._runtimeData.MonsterOrderConfigList.Clear();
                    fileName = Global.GameResPath("Config/YuanSuShiLian.xml");
                    XElement xml = CheckHelper.LoadXml(fileName, true);
                    if (null == xml)
                    {
                        return(false);
                    }
                    IEnumerable <XElement> nodes = xml.Elements();
                    foreach (XElement xmlItem in nodes)
                    {
                        if (xmlItem != null)
                        {
                            ElementWarMonsterConfigInfo config = new ElementWarMonsterConfigInfo();
                            config.OrderID      = Convert.ToInt32(Global.GetDefAttributeStr(xmlItem, "ID", "0"));
                            config.MonsterCount = Convert.ToInt32(Global.GetDefAttributeStr(xmlItem, "Num", "0"));
                            string[] ids = Global.GetDefAttributeStr(xmlItem, "MonstersID", "0,0,0").Split(new char[]
                            {
                                '|'
                            });
                            config.MonsterIDs = new List <int>();
                            foreach (string id in ids)
                            {
                                config.MonsterIDs.Add(int.Parse(id));
                            }
                            config.Up1    = Convert.ToInt32(Global.GetDefAttributeStr(xmlItem, "UpOne", "0"));
                            config.Up2    = Convert.ToInt32(Global.GetDefAttributeStr(xmlItem, "UpTwo", "0"));
                            config.Up3    = Convert.ToInt32(Global.GetDefAttributeStr(xmlItem, "UpThree", "0"));
                            config.Up4    = Convert.ToInt32(Global.GetDefAttributeStr(xmlItem, "UpFour", "0"));
                            config.X      = Convert.ToInt32(Global.GetDefAttributeStr(xmlItem, "X", "0"));
                            config.Y      = Convert.ToInt32(Global.GetDefAttributeStr(xmlItem, "Y", "0"));
                            config.Radius = Convert.ToInt32(Global.GetDefAttributeStr(xmlItem, "Radius", "0"));
                            this._runtimeData.MonsterOrderConfigList.Add(config.OrderID, config);
                        }
                    }
                    this._runtimeData.AwardLight          = GameManager.systemParamsList.GetParamValueIntArrayByName("YuanSuShiLianAward", ',');
                    this._runtimeData.YuanSuShiLianAward2 = GameManager.systemParamsList.GetParamValueIntArrayByName("YuanSuShiLianAward2", ',');
                }
                catch (Exception ex)
                {
                    success = false;
                    LogManager.WriteLog(LogTypes.Fatal, string.Format("加载xml配置文件:{0}, 失败。", fileName), ex, true);
                }
            }
            return(success);
        }
Пример #3
0
        /// <summary>
        /// 刷怪
        /// </summary>
        public void CreateMonster(ElementWarScene scene, int upWave)
        {
            CopyMap copyMap = scene.CopyMapInfo;
            ElementWarMonsterConfigInfo waveConfig = null;

            GameMap gameMap = null;

            if (!GameManager.MapMgr.DictMaps.TryGetValue(scene.MapID, out gameMap))
            {
                LogManager.WriteLog(LogTypes.Error, string.Format("元素试炼报错 地图配置 ID = {0}", scene.MapID));
                return;
            }

            long nowTicket = TimeUtil.NOW();
            long nowSecond = nowTicket / 1000;

            lock (scene)
            {
                if (scene.MonsterWave >= scene.MonsterWaveTotal)
                {
                    scene.SceneStatus = GameSceneStatuses.STATUS_END;
                    return;
                }

                //置刷怪标记
                scene.IsMonsterFlag = 1;

                int wave = scene.MonsterWave + upWave;
                if (wave > scene.MonsterWaveTotal)
                {
                    wave = scene.MonsterWaveTotal;
                }

                waveConfig = _runtimeData.GetOrderConfig(wave);
                if (waveConfig == null)
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("元素试炼报错 刷怪波次 = {0}", wave));
                    return;
                }

                scene.MonsterCountCreate = waveConfig.MonsterCount;
                scene.MonsterWave        = wave; // 递增刷怪波数
                scene.CreateMonsterTime  = nowSecond;

                int monsterID = 0;
                int gridX     = 0;
                int gridY     = 0;
                int gridNum   = 0;

                for (int i = 0; i < waveConfig.MonsterCount; i++)
                {
                    monsterID = waveConfig.MonsterIDs[i % waveConfig.MonsterIDs.Count];
                    gridX     = gameMap.CorrectWidthPointToGridPoint(waveConfig.X + Global.GetRandomNumber(-waveConfig.Radius, waveConfig.Radius)) / gameMap.MapGridWidth;
                    gridY     = gameMap.CorrectHeightPointToGridPoint(waveConfig.Y + Global.GetRandomNumber(-waveConfig.Radius, waveConfig.Radius)) / gameMap.MapGridHeight;
                    gridNum   = 0;

                    GameManager.MonsterZoneMgr.AddDynamicMonsters(scene.MapID, monsterID, scene.CopyMapInfo.CopyMapID, 1, gridX, gridY, gridNum);
                }

                scene.ScoreData.Wave         = waveConfig.OrderID;
                scene.ScoreData.EndTime      = nowTicket + waveConfig.Up1 * 1000;
                scene.ScoreData.MonsterCount = waveConfig.MonsterCount;

                GameManager.ClientMgr.BroadSpecialCopyMapMessage((int)TCPGameServerCmds.CMD_SPR_ELEMENT_WAR_SCORE_INFO, scene.ScoreData, scene.CopyMapInfo);
            }
        }
Пример #4
0
        /// <summary>
        /// 心跳处理
        /// </summary>
        public void TimerProc()
        {
            long nowTicks = TimeUtil.NOW();

            if (nowTicks < _nextHeartBeatTicks)
            {
                return;
            }

            _nextHeartBeatTicks = nowTicks + 1020; //1020毫秒执行一次

            long nowSecond = nowTicks / 1000;

            foreach (ElementWarScene scene in _sceneDict.Values)
            {
                lock (_mutex)
                {
                    int nID     = scene.FuBenSeqId;
                    int nCopyID = scene.CopyID;
                    int nMapID  = scene.MapID;

                    if (nID < 0 || nCopyID < 0 || nMapID < 0)
                    {
                        continue;
                    }

                    CopyMap copyMap = scene.CopyMapInfo;

                    if (scene.SceneStatus == GameSceneStatuses.STATUS_NULL)             // 如果处于空状态 -- 是否要切换到准备状态
                    {
                        scene.PrepareTime = nowSecond;
                        scene.BeginTime   = nowSecond + _runtimeData.PrepareSecs;
                        scene.SceneStatus = GameSceneStatuses.STATUS_PREPARE;

                        scene.StateTimeData.GameType = (int)_gameType;
                        scene.StateTimeData.State    = (int)scene.SceneStatus;
                        scene.StateTimeData.EndTicks = nowTicks + _runtimeData.PrepareSecs * 1000;//scene.BeginTime;
                        GameManager.ClientMgr.BroadSpecialCopyMapMessage((int)TCPGameServerCmds.CMD_SPR_NOTIFY_TIME_STATE, scene.StateTimeData, scene.CopyMapInfo);
                    }
                    else if (scene.SceneStatus == GameSceneStatuses.STATUS_PREPARE)     // 场景战斗状态切换
                    {
                        if (nowSecond >= (scene.BeginTime))
                        {
                            scene.SceneStatus = GameSceneStatuses.STATUS_BEGIN;
                            scene.EndTime     = nowSecond + _runtimeData.FightingSecs;

                            scene.StateTimeData.GameType = (int)_gameType;
                            scene.StateTimeData.State    = (int)scene.SceneStatus;
                            scene.StateTimeData.EndTicks = nowTicks + _runtimeData.FightingSecs * 1000;//scene.EndTime;
                            GameManager.ClientMgr.BroadSpecialCopyMapMessage((int)TCPGameServerCmds.CMD_SPR_NOTIFY_TIME_STATE, scene.StateTimeData, scene.CopyMapInfo);

                            //放开光幕
                            //copyMap.AddGuangMuEvent(1, 0);
                            //GameManager.ClientMgr.BroadSpecialMapAIEvent(copyMap.MapCode, copyMap.CopyMapID, 1, 0);
                        }
                    }
                    else if (scene.SceneStatus == GameSceneStatuses.STATUS_BEGIN)       // 战斗开始
                    {
                        if (nowSecond >= scene.EndTime)
                        {
                            scene.SceneStatus = GameSceneStatuses.STATUS_END;
                            continue;
                        }

                        //检查怪物
                        bool bNeedCreateMonster = false;
                        int  upWave             = 0;
                        lock (scene)
                        {
                            ElementWarMonsterConfigInfo configInfo = _runtimeData.GetOrderConfig(scene.MonsterWave);
                            if (configInfo == null)
                            {
                                scene.MonsterWaveOld = 1;
                                scene.MonsterWave    = 0;
                                scene.SceneStatus    = GameSceneStatuses.STATUS_END;
                                continue;
                            }
                            //检查超时
                            if (scene.CreateMonsterTime > 0 && nowSecond - scene.CreateMonsterTime >= configInfo.Up1)
                            {
                                scene.MonsterWave = 0;
                                scene.SceneStatus = GameSceneStatuses.STATUS_END;
                                continue;
                            }

                            if (scene.CreateMonsterTime > 0 && scene.IsMonsterFlag == 0 && scene.ScoreData.MonsterCount <= 0)
                            {
                                if (scene.MonsterWave < scene.MonsterWaveTotal)
                                {
                                    bNeedCreateMonster = true;
                                    if (nowSecond - scene.CreateMonsterTime <= configInfo.Up4)
                                    {
                                        upWave = 4;
                                    }
                                    else if (nowSecond - scene.CreateMonsterTime <= configInfo.Up3)
                                    {
                                        upWave = 3;
                                    }
                                    else if (nowSecond - scene.CreateMonsterTime <= configInfo.Up2)
                                    {
                                        upWave = 2;
                                    }
                                    else if (nowSecond - scene.CreateMonsterTime < configInfo.Up1)
                                    {
                                        upWave = 1;
                                    }
                                }
                                else
                                {
                                    scene.MonsterWaveOld = scene.MonsterWave;
                                    scene.MonsterWave    = 0;
                                    scene.SceneStatus    = GameSceneStatuses.STATUS_END;
                                    continue;
                                }
                            }

                            if (scene.CreateMonsterTime <= 0)
                            {
                                bNeedCreateMonster = true;
                            }

                            if (bNeedCreateMonster)
                            {
                                CreateMonster(scene, upWave);
                            }
                        }
                    }
                    else if (scene.SceneStatus == GameSceneStatuses.STATUS_END)
                    {
                        GiveAwards(scene);

                        //结算奖励
                        scene.SceneStatus = GameSceneStatuses.STATUS_AWARD;
                        scene.EndTime     = nowSecond;
                        scene.LeaveTime   = scene.EndTime + _runtimeData.ClearRolesSecs;

                        //  ElementWarClient.getInstance().GameFuBenChangeState(scene.GameId, GameFuBenState.End, DateTime.Now);

                        scene.StateTimeData.GameType = (int)_gameType;
                        scene.StateTimeData.State    = (int)GameSceneStatuses.STATUS_END;
                        scene.StateTimeData.EndTicks = nowTicks + _runtimeData.ClearRolesSecs * 1000;//scene.LeaveTime;
                        GameManager.ClientMgr.BroadSpecialCopyMapMessage((int)TCPGameServerCmds.CMD_SPR_NOTIFY_TIME_STATE, scene.StateTimeData, scene.CopyMapInfo);
                    }
                    else if (scene.SceneStatus == GameSceneStatuses.STATUS_AWARD)         // 战斗结束
                    {
                        if (nowSecond >= scene.LeaveTime)
                        {
                            copyMap.SetRemoveTicks(scene.LeaveTime);
                            scene.SceneStatus = GameSceneStatuses.STATUS_CLEAR;

                            try
                            {
                                List <GameClient> objsList = copyMap.GetClientsList();
                                if (objsList != null && objsList.Count > 0)
                                {
                                    for (int n = 0; n < objsList.Count; ++n)
                                    {
                                        GameClient c = objsList[n];
                                        if (c != null)
                                        {
                                            KuaFuManager.getInstance().GotoLastMap(c);
                                        }
                                    }
                                }
                            }
                            catch (System.Exception ex)
                            {
                                DataHelper.WriteExceptionLogEx(ex, "【元素试炼】清场调度异常");
                            }
                        }
                    }
                }
            }

            return;
        }
Пример #5
0
        public void TimerProc()
        {
            long nowTicks = TimeUtil.NOW();

            if (nowTicks >= ElementWarManager._nextHeartBeatTicks)
            {
                ElementWarManager._nextHeartBeatTicks = nowTicks + 1020L;
                long nowSecond = nowTicks / 1000L;
                foreach (ElementWarScene scene in this._sceneDict.Values)
                {
                    lock (ElementWarManager._mutex)
                    {
                        int nID     = scene.FuBenSeqId;
                        int nCopyID = scene.CopyID;
                        int nMapID  = scene.MapID;
                        if (nID >= 0 && nCopyID >= 0 && nMapID >= 0)
                        {
                            CopyMap copyMap = scene.CopyMapInfo;
                            if (scene.SceneStatus == GameSceneStatuses.STATUS_NULL)
                            {
                                scene.PrepareTime            = nowSecond;
                                scene.BeginTime              = nowSecond + (long)this._runtimeData.PrepareSecs;
                                scene.SceneStatus            = GameSceneStatuses.STATUS_PREPARE;
                                scene.StateTimeData.GameType = 4;
                                scene.StateTimeData.State    = (int)scene.SceneStatus;
                                scene.StateTimeData.EndTicks = nowTicks + (long)(this._runtimeData.PrepareSecs * 1000);
                                GameManager.ClientMgr.BroadSpecialCopyMapMessage <GameSceneStateTimeData>(827, scene.StateTimeData, scene.CopyMapInfo);
                            }
                            else if (scene.SceneStatus == GameSceneStatuses.STATUS_PREPARE)
                            {
                                if (nowSecond >= scene.BeginTime)
                                {
                                    scene.SceneStatus            = GameSceneStatuses.STATUS_BEGIN;
                                    scene.EndTime                = nowSecond + (long)this._runtimeData.FightingSecs;
                                    scene.StateTimeData.GameType = 4;
                                    scene.StateTimeData.State    = (int)scene.SceneStatus;
                                    scene.StateTimeData.EndTicks = nowTicks + (long)(this._runtimeData.FightingSecs * 1000);
                                    GameManager.ClientMgr.BroadSpecialCopyMapMessage <GameSceneStateTimeData>(827, scene.StateTimeData, scene.CopyMapInfo);
                                }
                            }
                            else if (scene.SceneStatus == GameSceneStatuses.STATUS_BEGIN)
                            {
                                if (nowSecond >= scene.EndTime)
                                {
                                    scene.SceneStatus = GameSceneStatuses.STATUS_END;
                                }
                                else
                                {
                                    bool bNeedCreateMonster = false;
                                    int  upWave             = 0;
                                    lock (scene)
                                    {
                                        ElementWarMonsterConfigInfo configInfo = this._runtimeData.GetOrderConfig(scene.MonsterWave);
                                        if (configInfo == null)
                                        {
                                            scene.MonsterWaveOld = 1;
                                            scene.MonsterWave    = 0;
                                            scene.SceneStatus    = GameSceneStatuses.STATUS_END;
                                        }
                                        else if (scene.CreateMonsterTime > 0L && nowSecond - scene.CreateMonsterTime >= (long)configInfo.Up1)
                                        {
                                            scene.MonsterWave = 0;
                                            scene.SceneStatus = GameSceneStatuses.STATUS_END;
                                        }
                                        else
                                        {
                                            if (scene.CreateMonsterTime > 0L && scene.IsMonsterFlag == 0 && scene.ScoreData.MonsterCount <= 0L)
                                            {
                                                if (scene.MonsterWave >= scene.MonsterWaveTotal)
                                                {
                                                    scene.MonsterWaveOld = scene.MonsterWave;
                                                    scene.MonsterWave    = 0;
                                                    scene.SceneStatus    = GameSceneStatuses.STATUS_END;
                                                    continue;
                                                }
                                                bNeedCreateMonster = true;
                                                if (nowSecond - scene.CreateMonsterTime <= (long)configInfo.Up4)
                                                {
                                                    upWave = 4;
                                                }
                                                else if (nowSecond - scene.CreateMonsterTime <= (long)configInfo.Up3)
                                                {
                                                    upWave = 3;
                                                }
                                                else if (nowSecond - scene.CreateMonsterTime <= (long)configInfo.Up2)
                                                {
                                                    upWave = 2;
                                                }
                                                else if (nowSecond - scene.CreateMonsterTime < (long)configInfo.Up1)
                                                {
                                                    upWave = 1;
                                                }
                                            }
                                            if (scene.CreateMonsterTime <= 0L)
                                            {
                                                bNeedCreateMonster = true;
                                            }
                                            if (bNeedCreateMonster)
                                            {
                                                this.CreateMonster(scene, upWave);
                                            }
                                        }
                                    }
                                }
                            }
                            else if (scene.SceneStatus == GameSceneStatuses.STATUS_END)
                            {
                                this.GiveAwards(scene);
                                scene.SceneStatus            = GameSceneStatuses.STATUS_AWARD;
                                scene.EndTime                = nowSecond;
                                scene.LeaveTime              = scene.EndTime + (long)this._runtimeData.ClearRolesSecs;
                                scene.StateTimeData.GameType = 4;
                                scene.StateTimeData.State    = 3;
                                scene.StateTimeData.EndTicks = nowTicks + (long)(this._runtimeData.ClearRolesSecs * 1000);
                                GameManager.ClientMgr.BroadSpecialCopyMapMessage <GameSceneStateTimeData>(827, scene.StateTimeData, scene.CopyMapInfo);
                            }
                            else if (scene.SceneStatus == GameSceneStatuses.STATUS_AWARD)
                            {
                                if (nowSecond >= scene.LeaveTime)
                                {
                                    copyMap.SetRemoveTicks(scene.LeaveTime);
                                    scene.SceneStatus = GameSceneStatuses.STATUS_CLEAR;
                                    try
                                    {
                                        List <GameClient> objsList = copyMap.GetClientsList();
                                        if (objsList != null && objsList.Count > 0)
                                        {
                                            for (int i = 0; i < objsList.Count; i++)
                                            {
                                                GameClient c = objsList[i];
                                                if (c != null)
                                                {
                                                    KuaFuManager.getInstance().GotoLastMap(c);
                                                }
                                            }
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        DataHelper.WriteExceptionLogEx(ex, "【元素试炼】清场调度异常");
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }