public override void Execute()
        {
            BattleScheduler.CancelChar(this._site.CurrentCharId);

            this._site.Config.IsDungeonGuaji = false;
            CharacterConfigCache.SaveConfig(this._site.Config);

            Response.WriteAsync(JsonUtil.Serialize(new { }));
        }
        /// <summary>
        ///
        /// </summary>
        private void InternalStart()
        {
            try
            {
                int tryTimes = 0;

                while (!_token.IsCancellationRequested) //直到人工取消/出错之前一直运行
                {
                    int sleepTime = 0;

                    try
                    {
                        sleepTime = InternalBattle();


                        //判断一下是否人工取消
                        _token.ThrowIfCancellationRequested();
                    }
                    catch (OperationCanceledException) { } //人工取消
                    catch (Exception ex)
                    {
                        Logger.Error(string.Format("CharNo={0},Name={1},MapId={2},Error={3}", this._site.CurrentChar.AccountId, this._site.CurrentChar.Name, this._site.Config.CurrentMapId, ex.Message));
                        this.OnError(this._charId, ex.Message);

                        if (tryTimes < 10)
                        {
                            sleepTime = 10 * (tryTimes + 1) * 1000; //等10秒重试,而不是简单地退出
                            tryTimes++;
                        }
                        else
                        {
                            throw;
                        }
                    }

                    if (sleepTime > 0) //如果是手动取消,这里是0
                    {
                        //SpinWait.SpinUntil(() => _token.IsCancellationRequested, sleepTime);
                        Thread.Sleep(sleepTime);
                    }
                }
            }
            catch (ThreadAbortException) { } //IIS关闭,强行中止线程
            catch (Exception ex)
            {
                Logger.Error(string.Format("CharNo={0},Name={1},MapId={2},Error={3}", this._site.CurrentChar.AccountId, this._site.CurrentChar.Name, this._site.Config.CurrentMapId, ex.ToString()));
                this.OnError(this._charId, ex.Message);

                BattleScheduler.CancelChar(this._charId);
                this._site.Config.IsGuaji = false;
                CharacterConfigCache.SaveConfig(this._site.Config);
            }
        }
예제 #3
0
        public Character InitChar()
        {
            Character result = CharacterCache.TryGetValue(this.CurrentCharId, id =>
            {
                string path = string.Format("/foodie-api/gamepassport/getGameCharacter?charaId={0}", this.CurrentCharId);
                var c       = this.GetResult <Character>(path);
                return(c);
            });

            result.IsGuaji        = BattleScheduler.IsGuaji(result.Id);
            result.IsDungeonGuaji = BattleScheduler.IsDungeonGuaji(result.Id);
            return(result);
        }
        public override void Execute()
        {
            if (string.IsNullOrEmpty(this._site.Config.CurrentMapId))
            {
                this._site.Config.CurrentMapId = this._site.InitAllSingleMaps().FirstOrDefault().MapId;
            }

            BattleScheduler.AddChar(this._site);

            this._site.Config.IsGuaji = true;
            CharacterConfigCache.SaveConfig(this._site.Config);

            Response.WriteAsync(JsonUtil.Serialize(new { }));
        }
 public static void CancelDungeonGuaji(CharacterConfig cfg)
 {
     BattleScheduler.CancelChar(cfg.CharId);
     cfg.IsDungeonGuaji = false;
     SaveConfig(cfg);
 }
예제 #6
0
        public override void Execute()
        {
            var allMaps     = this._site.InitAllMaps();
            var dynamicList = CharacterDynamicCache.LoadAllDynamics();

            foreach (var cd in dynamicList)
            {
                foreach (var mi in cd.ItemList)
                {
                    var map = allMaps.FirstOrDefault(p => p.MapId == mi.Key);
                    if (map != null)
                    {
                        foreach (var item in mi.Value)
                        {
                            if (!map.ItemsVoList.ContainsKey(item.Key))
                            {
                                map.ItemsVoList[item.Key] = item.Value;
                            }
                        }
                    }
                }
            }

            var cfgList = CharacterConfigCache.LoadAllConfigs();

            foreach (var cfg in cfgList)
            {
                InfinityServerSite site = new InfinityServerSite(this._site.Uri, this.Request, this.Response);
                site.CurrentCharId = cfg.CharId;
                site.Config        = CharacterConfigCache.TryGetValue(cfg.CharId, CharacterConfigCache.LoadConfig);
                site.Dynamic       = CharacterDynamicCache.TryGetValue(cfg.CharId, CharacterDynamicCache.LoadDynamic);
                site.FilterConfig  = ItemFilterCache.TryGetValue(cfg.CharId, ItemFilterCache.LoadConfig);
                try
                {
                    site.InitChar();

                    var group = site.InitArmyGroup();

                    if (cfg.IsGuaji)
                    {
                        if (group == null)
                        {
                            BattleScheduler.AddChar(site);
                        }
                        else
                        {
                            site.Config.IsGuaji = false;
                            CharacterConfigCache.SaveConfig(site.Config);
                        }
                    }
                    if (cfg.IsDungeonGuaji)
                    {
                        if (group != null)
                        {
                            if (site.CheckIsGroupCaption())
                            {
                                BattleScheduler.AddChar(site, true);
                            }
                            else
                            {
                                site.Config.IsDungeonGuaji = false;
                                CharacterConfigCache.SaveConfig(site.Config);
                            }
                        }
                    }
                }
                catch { }
            }

            Response.WriteAsync(JsonUtil.Serialize(new { }));
        }