示例#1
0
        public bool IsQuestRelease(mstQuest quest)
        {
            var relaseList = AssetManage.Database.mstQuestRelease.Where(r => r.questId == quest.id).ToList();

            foreach (var release in relaseList)
            {
                if (!CheckQuestRelease(release))
                {
                    return(false);
                }
            }
            return(true);
        }
示例#2
0
        protected void BattleSetup()
        {
            ReceiveAsync <BattleTask>(
                new Predicate <BattleTask>(task => task.action == GameAction.HOME || task.action == GameAction.ITEMUSE),
                async task =>
            {
                if (task.excuteType == ExcuteType.Expires)
                {
                    Log(task.id, GameAction.BATTLERESULT, "正在准备战斗超时重试");
                }
                else if (task.excuteType == ExcuteType.ErrorReStart)
                {
                    Log(task.id, GameAction.BATTLERESULT, "正在准备战斗错误重试");
                }
                if (task.serverApi == null && (task.excuteType == ExcuteType.ErrorReStart || task.excuteType == ExcuteType.Expires))
                {
                    task.action = GameAction.unknown;
                    Self.Tell(task, Sender);
                    return;
                }
                if (task.serverApi == null)
                {
                    task.serverApi = InitServerApi(task);
                }
                var serverApi = task.serverApi;
                var deckId    = task.deckId;

                if (string.IsNullOrEmpty(task.deckId) && serverApi.userDeck == null && !task.task_data.ContainsKey("deckId"))
                {
                    Log(task.id, GameAction.BATTLERESULT, "没有战斗编队信息, 战斗失败");
                    await taskResultActor.Ask(new TaskResult()
                    {
                        id         = task.id,
                        nextAction = GameAction.unknown,
                        state      = TaskState.GAME_ERROR,
                    });
                    await TaskErrorBack(task.id, GameAction.BATTLERESULT, serverApi.LastResponse, "serverApi.userDeck && task_data[deckId] IS NULL");
                    return;
                }

                await Context.ActorOf <CheckDeckActor>().Ask <bool>(task);

                Log(task.id, GameAction.BATTLERESULT, "正在准备战斗数据");
                if (string.IsNullOrEmpty(task.deckId))
                {
                    if (serverApi.userDeck != null)
                    {
                        deckId = serverApi.userDeck.First().id.ToString();
                        task.task_data["deckId"] = deckId;
                        Log(task.id, GameAction.BATTLERESULT, "没有设置战斗编队, 使用第一编队战斗");
                    }
                    else
                    {
                        deckId = task.task_data["deckId"];
                        Log(task.id, GameAction.BATTLERESULT, "从保存数据中读取战斗编队");
                    }
                }
                else
                {
                    deckId = serverApi.userDeck[int.Parse(task.deckId)].id.ToString();
                }
                var follower = GetFollower(serverApi, task.followerId);
                Log(task.id, GameAction.BATTLERESULT, follower.message);
                Log(task.id, GameAction.BATTLESETUP, serverApi.userGame.name + "  lv : " + serverApi.userGame.lv + "    " + "ap : " + serverApi.ApNum);
                bool hasQuest         = false;
                string questId        = null;
                int ap                = serverApi.ApNum;
                int minAp             = 10000000;
                mstQuest mstQuestData = null;
                var questList         = new QuestChecker()
                {
                    TimetampSecond = serverApi.TimetampSecond,
                    userQuest      = serverApi.userQuest
                }.GetUserQuestList();
                var activeQuestList = questList.Where(q => task.questIds.Contains(q.id)).OrderByDescending(q => q.actConsume).ToList();
                foreach (var questData in activeQuestList)
                {
                    mstQuestData   = questData;
                    hasQuest       = true;
                    var actConsume = questData.actConsume;
                    if (actConsume > ap)
                    {
                        minAp = actConsume < minAp ? actConsume : minAp;
                        continue;
                    }
                    questId = questData.id;
                    break;
                }

                ///剧情check
                if (!hasQuest && task.questIds.Contains("1000000"))
                {
                    foreach (var quest in questList)
                    {
                        if (quest.type != "1")
                        {
                            continue;
                        }
                        var spot = AssetManage.Database.mstSpot.FirstOrDefault(s => s.id == quest.spotId);
                        if (spot == null)
                        {
                            continue;
                        }
                        var war = AssetManage.Database.mstWar.FirstOrDefault(w => w.id == spot.warId && w.status == "0");
                        if (war == null)
                        {
                            continue;
                        }
                        hasQuest = true;
                        if (quest.actConsume < ap)
                        {
                            questId      = quest.id;
                            mstQuestData = quest;
                            break;
                        }
                        else
                        {
                            minAp = quest.actConsume < minAp ? quest.actConsume : minAp;
                        }
                    }
                    if (!hasQuest)
                    {
                        await Context.ActorOf <RoleChapteredActor>().Ask <bool>(task.role.id);
                        logger.Info(task.role.username + " 章节清除完成");
                    }
                }

                if (!hasQuest)
                {
                    if (serverApi.userQuest == null || serverApi.userQuest.Count < 3)
                    {
                        Log(task.id, GameAction.BATTLESETUP, "找不到匹配的副本。尝试重新获取");
                        await taskResultActor.Ask(new TaskResult()
                        {
                            id            = task.id,
                            nextAction    = GameAction.unknown,
                            state         = TaskState.STOP,
                            nextStartTime = DateTime.Now
                        });
                        Sender.Tell(true);
                        return;
                    }
                    var mstQuests = AssetManage.Database.mstQuest.Where(q => task.questIds.Contains(q.id)).ToList();
                    if (mstQuests.Any(q => AssetManage.Database.mstQuestRelease.Where(p => p.questId == q.id).Any(p => p.type == 13 || p.type == 11)))
                    {
                        Log(task.id, GameAction.BATTLESETUP, "找不到匹配的副本。等待一小时后启动");
                        await taskResultActor.Ask(new TaskResult()
                        {
                            id            = task.id,
                            nextAction    = GameAction.unknown,
                            state         = TaskState.STOP,
                            nextStartTime = DateTime.Now.AddHours(1)
                        });
                    }
                    else
                    {
                        Log(task.id, GameAction.BATTLESETUP, "找不到匹配的副本。任务结束");
                        await taskResultActor.Ask(new TaskResult()
                        {
                            id         = task.id,
                            nextAction = GameAction.unknown,
                            state      = TaskState.STOP,
                            enable     = false
                        });
                    }
                    Sender.Tell(false);
                    return;
                }

                if (string.IsNullOrEmpty(questId))
                {
                    var item = serverApi.userItem.Where(u => u.itemId == "100" || u.itemId == "102" || u.itemId == "101").FirstOrDefault();
                    if (item != null && item.num != 0 && task.useitem)
                    {
                        task.task_data["itemId"] = item.itemId;
                        task.task_data["num"]    = "1";
                        if (await Context.ActorOf <ItemUseActor>().Ask <bool>(task))
                        {
                            Log(task.id, GameAction.BATTLESETUP, "Ap不足,消耗了一个苹果,总共" + item.num + "个");
                            task.action = GameAction.ITEMUSE;
                            Self.Tell(task);
                            return;
                        }
                    }
                    var t = TimeSpan.FromMilliseconds((minAp - ap) * 300 * 1000);
                    Log(task.id, GameAction.BATTLESETUP, "Ap不足,等待 " + t.Hours + "小时" + t.Minutes + "分" + t.Seconds + "秒");
                    if (t.TotalMinutes > 10)
                    {
                        await taskResultActor.Ask(new TaskResult()
                        {
                            id         = task.id,
                            nextAction = GameAction.HOME,
                            state      = TaskState.RUNNING
                        });
                    }
                    else
                    {
                        await Task.Delay(t);
                    }
                    Sender.Tell(true);
                    return;
                }
                var count     = AssetManage.Database.mstQuestPhase.Where(p => p.questId == questId).Count();
                var userQuest = serverApi.userQuest.FirstOrDefault(u => u.questId == questId);
                if (count > 0 && userQuest != null && userQuest.questPhase < count)
                {
                    task.task_data["questPhase"] = (++userQuest.questPhase).ToString();
                }
                else
                {
                    task.task_data["questPhase"] = "1";
                }


                if (mstQuestData.type == "1")
                {
                    var npcFlower = AssetManage.Database.npcFollower.FirstOrDefault(f => f.questId == questId && f.questPhase == task.task_data["questPhase"]);
                    if (npcFlower != null)
                    {
                        follower.id    = npcFlower.id;
                        follower.index = 0;
                    }
                }

                task.task_data["questId"]       = questId;
                task.task_data["followerId"]    = follower.id;
                task.task_data["followerIndex"] = follower.index.ToString();
                task.task_data["deckId"]        = deckId;

                Log(task.id, GameAction.BATTLESETUP, "战斗准备开始,战斗副本: " + mstQuestData.name);
                var sleepTime = await Context.ActorOf <BattleSetupActor>().Ask <TimeSpan>(task);
                if (sleepTime.TotalMilliseconds == 0)
                {
                    Log(task.id, GameAction.BATTLESETUP, "战斗开始失败");
                    Sender.Tell(false);
                    return;
                }
                Log(task.id, GameAction.BATTLESETUP, "战斗开始成功,等待" + sleepTime.Minutes + "分" + sleepTime.Seconds + "秒");
                await Task.Delay(sleepTime);
                task.action = GameAction.BATTLESETUP;
                Self.Tell(task, Sender);
            });
        }
示例#3
0
        public BattleActor()
        {
            ReceiveAsync <BattleTask>(async task =>
            {
                if (!await Context.ActorOf <LoginActor>().Ask <bool>(task))
                {
                    Sender.Tell(false);
                    return;
                }
                if (!await Context.ActorOf <HomeActor>().Ask <bool>(task))
                {
                    Sender.Tell(false);
                    return;
                }

                var serverApi  = task.serverApi;
                var deckId     = string.IsNullOrEmpty(task.deckId) ? serverApi.userDeck.First().id : task.deckId.ToString();
                var followerId = string.IsNullOrEmpty(task.followerId) ? serverApi.userFollower.First().userId : task.followerId.ToString();

                System.Console.WriteLine("userId : " + serverApi.PlatfromInfos["userId"]);
                System.Console.WriteLine("name : " + serverApi.userGame.name);
                System.Console.WriteLine("lv : " + serverApi.userGame.lv);
                System.Console.WriteLine("ap : " + serverApi.ApNum);
                start:
                bool hasQuest         = false;
                string questId        = null;
                int ap                = serverApi.ApNum;
                int minAp             = 10000000;
                mstQuest mstQuestData = null;
                foreach (var item in serverApi.userQuest)
                {
                    if (task.questIds.Contains(item.questId))
                    {
                        var questData = AssetManage.Database.mstQuest.FirstOrDefault(q => q.id == item.questId);
                        if (questData != null)
                        {
                            mstQuestData   = questData;
                            hasQuest       = true;
                            var actConsume = int.Parse(questData.actConsume);;
                            if (actConsume > ap)
                            {
                                minAp = actConsume < minAp ? actConsume : minAp;
                                continue;
                            }
                            questId = item.questId;
                            break;
                        }
                    }
                }
                if (!hasQuest)
                {
                    System.Console.WriteLine("战斗任务找不到匹配的副本。自动禁用 ID:" + task.id);
                    await Context.ActorOf <DisableTaskAcotr>().Ask(task.id);
                    Sender.Tell(false);
                    return;
                }
                if (string.IsNullOrEmpty(questId))
                {
                    System.Console.WriteLine("Ap不够了");
                    var item = serverApi.userItem.Where(u => u.itemId == "100").FirstOrDefault();
                    if (item != null && item.num != "0" && task.useitem)
                    {
                        var itemuse = await serverApi.Itemuse(item.itemId, "1");
                        if (itemuse.code == 0)
                        {
                            System.Console.WriteLine("消耗了一个苹果,总共" + item.num + "个");
                            goto start;
                        }
                    }
                    var t = TimeSpan.FromMilliseconds((minAp - ap) * 300 * 1000);
                    System.Console.WriteLine("等待 " + t.Hours + "小时" + t.Minutes + "分" + t.Seconds + "秒");
                    await Task.Delay(t);
                }
                var setup = await serverApi.Battlesetup(deckId, followerId, questId);
                if (setup.code != 0)
                {
                    await TaskErrorAndBack(task.id, GameAction.BATTLESETUP, setup);
                    return;
                }

                var random   = new Random();
                var time     = random.Next((int)TimeSpan.FromMinutes(2).TotalMilliseconds, (int)TimeSpan.FromMinutes(3).TotalMilliseconds);
                var timespan = TimeSpan.FromMilliseconds(time);

                Context.ActorOf <SaveRoleDataActor>().Tell(new SaveActionDataTask()
                {
                    action      = GameAction.BATTLESETUP,
                    serverApi   = serverApi,
                    expiresTime = DateTime.Now.Add(timespan),
                    taskId      = task.id,
                    battleId    = setup.cache.replaced.battle[0].id
                });

                var color = System.Console.ForegroundColor;
                System.Console.ForegroundColor = ConsoleColor.DarkBlue;
                System.Console.WriteLine(mstQuestData.name);
                System.Console.WriteLine("战斗开始,等待" + timespan.Minutes + "分" + timespan.Seconds + "秒");
                System.Console.ForegroundColor = color;
                await Task.Delay(time);
                var count  = random.Next(20, 35);
                var action = new BattleresultActionItem[count];
                for (int i = 0; i < count; i++)
                {
                    action[i] = new BattleresultActionItem()
                    {
                        ty  = random.Next(1, 4),
                        uid = random.Next(1, 4)
                    };
                }
                var battresult = await serverApi.Battleresult(setup.cache.replaced.battle[0].id, action, new string[] { });
                if (battresult.code != 0)
                {
                    await TaskErrorAndBack(task.id, GameAction.BATTLERESULT, battresult);
                    return;
                }
                System.Console.WriteLine("战斗结束");
                await Task.Delay(10000);
                Context.ActorOf <SaveRoleDataActor>().Tell(task);
                Sender.Tell(true);
            });
        }