Esempio n. 1
0
        // 執行工作
        public async Task DoWork(CancellationToken stoppingToken)
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                _executionCount++;

                _logger.LogInformation(
                    "Scoped Processing Service is working. Count: {Count}", _executionCount);
                // 取得角色資料
                var myKirito = await _myService.GetMyKiritoFn();

                if (myKirito != null)
                {
                    // 轉生限制條件:滿十等或死亡
                    if (myKirito.Dead || AppSettings._defaultReIncarnationLevel > 0 &&
                        myKirito.Lv >= AppSettings._defaultReIncarnationLevel)
                    {
                        // 計算轉生屬性點數
                        var freePoints = CheckPoint(myKirito.Lv);
                        // 開始轉生
                        if (await _myService.ReIncarnation(freePoints))
                        {
                            _totalPoints += freePoints;
                        }
                    }
                    else
                    {
                        // 日常動作:汁妹之類的
                        if (await _myService.DoAction(AppSettings._defaultAct))
                        {
                            // PVP
                            if (AppSettings._defaultFight != FightEnum.None && DateTime.Now > _nextPvpTime)
                            {
                                if (await _myService.GetUserList(myKirito.Exp + AppSettings._pvpEXP))
                                {
                                    _nextPvpTime = _nextPvpTime.AddSeconds(Const.PvpTime);
                                }
                            }
                        }
                    }
                }

                // 定時執行
                int addTime;
                if (AppSettings._randTime > 0)
                {
                    addTime = Const.CheckTime + RandomCd.Next(1, AppSettings._randTime);
                }
                else
                {
                    addTime = Const.CheckTime;
                }
                Console.WriteLine($"屬性小計:{_totalPoints}, 下次戰鬥: {_nextPvpTime}, 等待 {addTime} 秒...");
                await Task.Delay(addTime * 1000, stoppingToken);
            }
        }
Esempio n. 2
0
            // 執行工作
            public async Task DoWork(CancellationToken stoppingToken)
            {
                while (!stoppingToken.IsCancellationRequested)
                {
                    _executionCount++;

                    _logger.LogInformation(
                        "Scoped Processing Service is working. Count: {Count}", _executionCount);
                    // 取得角色資料
                    var myKirito = await _myService.GetMyKiritoFn();

                    // Log角色資料
                    Console.WriteLine(JsonSerializer.Serialize(myKirito,
                                                               new JsonSerializerOptions {
                        WriteIndented = true
                    }));
                    // 轉生限制條件:滿十等或死亡
                    if (myKirito.Dead || myKirito.Lv >= 10)
                    {
                        // 計算轉生屬性點數
                        var freePoints = CheckPoint(myKirito.Lv);
                        // 開始轉生
                        var result = await _myService.ReIncarnation(freePoints);

                        // Log轉生結果
                        Console.WriteLine(result);
                    }
                    else
                    {
                        // 日常動作:汁妹之類的
                        var result = await _myService.DoAction(_defaultAct);

                        // Log動作結果
                        Console.WriteLine(result);
                        // PVP
                        if (DateTime.Now > _nextPvpTime)
                        {
                            result = await _myService.GetUserList(myKirito.Exp);

                            Console.WriteLine(result);
                        }
                        else
                        {
                            Console.WriteLine($"Next PVP time is {_nextPvpTime.ToShortTimeString()}");
                        }
                    }

                    Console.WriteLine($"獲得屬性小計:{_totalPoints}");
                    // 定時執行
                    await Task.Delay(CheckTime, stoppingToken);
                }
            }