예제 #1
0
        private static void HandleAddExplorationQuests(GameSession session, PacketReader packet)
        {
            List <QuestStatus> list = new List <QuestStatus>();

            int listSize = packet.ReadInt();

            for (int i = 0; i < listSize; i++)
            {
                int questId = packet.ReadInt();
                if (session.Player.QuestList.Exists(x => x.Basic.Id == questId && x.Started))
                {
                    continue;
                }

                QuestMetadata metadata    = QuestMetadataStorage.GetMetadata(questId);
                QuestStatus   questStatus = new QuestStatus(session.Player, metadata)
                {
                    Started        = true,
                    StartTimestamp = DateTimeOffset.Now.ToUnixTimeSeconds()
                };
                list.Add(questStatus);
                session.Send(QuestPacket.AcceptQuest(questStatus.Basic.Id));
            }

            session.Player.QuestList.AddRange(list);
        }
예제 #2
0
    public override void Execute(GameCommandTrigger trigger)
    {
        int questId = trigger.Get <int>("id");

        if (questId == 0)
        {
            trigger.Session.SendNotice("Type an quest id.");
            return;
        }
        QuestMetadata quest = QuestMetadataStorage.GetMetadata(questId);

        if (quest == null)
        {
            trigger.Session.Send(NoticePacket.Notice($"Quest not found with id: {questId.ToString().Color(Color.Aquamarine)}.", NoticeType.Chat));
            return;
        }
        if (trigger.Session.Player.QuestData.ContainsKey(questId))
        {
            trigger.Session.Send(NoticePacket.Notice($"You already have quest: {questId.ToString().Color(Color.Aquamarine)}.", NoticeType.Chat));
            return;
        }

        trigger.Session.Player.QuestData.Add(questId, new(trigger.Session.Player, quest, QuestState.Started, TimeInfo.Now()));
        trigger.Session.Send(QuestPacket.AcceptQuest(questId));
    }
예제 #3
0
        public override void Handle(GameSession session, PacketReader packet) // TODO: Refactor when DB is implemented
        {
            QuestMode mode = (QuestMode)packet.ReadByte();

            switch (mode)
            {
            case QuestMode.AcceptQuest:
            {
                int questid  = packet.ReadInt();
                int objectid = packet.ReadInt();
                session.Send(QuestPacket.AcceptQuest(questid));
                break;
            }

            case QuestMode.CompleteQuest:
            {
                int questid  = packet.ReadInt();
                int objectid = packet.ReadInt();
                session.Send(QuestPacket.CompleteQuest(questid));
                QuestReward quest = QuestMetadataStorage.GetMetadata(questid).Reward;
                session.Player.Levels.GainExp(quest.Exp);
                session.Player.Wallet.Meso.Modify(quest.Money);
                break;
            }

            case QuestMode.ExplorationGoals:
                List <QuestMetadata> list = new List <QuestMetadata>();

                int listSize = packet.ReadInt();

                for (int i = 0; i < listSize; i++)
                {
                    list.Add(QuestMetadataStorage.GetMetadata(packet.ReadInt()));
                }

                session.Send(QuestPacket.SendQuests(list));
                break;

            case QuestMode.CompleteNavigator:
                int questId = packet.ReadInt();

                foreach (QuestRewardItem item in QuestMetadataStorage.GetMetadata(questId).RewardItem)
                {
                    InventoryController.Add(session, new Types.Item(item.Code), true);
                }

                session.Send(QuestPacket.CompleteQuest(questId));
                break;

            default:
                IPacketHandler <GameSession> .LogUnknownMode(mode);

                break;
            }
        }
예제 #4
0
        private static void HandleAcceptQuest(GameSession session, PacketReader packet)
        {
            int questId  = packet.ReadInt();
            int objectId = packet.ReadInt();

            QuestStatus quest = session.Player.QuestList.FirstOrDefault(x => x.Basic.QuestID == questId);

            if (quest == null)
            {
                return;
            }

            quest.Started = true;
            session.Send(QuestPacket.AcceptQuest(questId));
        }
예제 #5
0
        private static void HandleAcceptQuest(GameSession session, PacketReader packet)
        {
            int questId  = packet.ReadInt();
            int objectId = packet.ReadInt();

            QuestStatus questStatus = session.Player.QuestList.FirstOrDefault(x => x.Basic.Id == questId);

            if (questStatus == null)
            {
                return;
            }

            questStatus.Started        = true;
            questStatus.StartTimestamp = DateTimeOffset.Now.ToUnixTimeSeconds();
            session.Send(QuestPacket.AcceptQuest(questId));
        }
예제 #6
0
    private static void HandleAcceptQuest(GameSession session, PacketReader packet)
    {
        int questId  = packet.ReadInt();
        int objectId = packet.ReadInt();

        if (!session.Player.QuestData.TryGetValue(questId, out QuestStatus questStatus))
        {
            return;
        }

        questStatus.State          = QuestState.Started;
        questStatus.StartTimestamp = TimeInfo.Now();
        DatabaseManager.Quests.Update(questStatus);
        session.Send(QuestPacket.AcceptQuest(questId));
        TrophyManager.OnAcceptQuest(session.Player, questId);
    }
예제 #7
0
    private static void HandleAddExplorationQuests(GameSession session, PacketReader packet)
    {
        int listSize = packet.ReadInt();

        for (int i = 0; i < listSize; i++)
        {
            int questId = packet.ReadInt();
            session.Player.QuestData.TryGetValue(questId, out QuestStatus questStatus);

            session.Send(QuestPacket.AcceptQuest(questId));
            if (questStatus is null)
            {
                QuestMetadata metadata = QuestMetadataStorage.GetMetadata(questId);
                session.Player.QuestData.Add(questId, new(session.Player, metadata, QuestState.Started, TimeInfo.Now()));
                continue;
            }

            questStatus.State = QuestState.Started;
            DatabaseManager.Quests.Update(questStatus);
        }
    }
예제 #8
0
    public override void Execute(GameCommandTrigger trigger)
    {
        int  questId    = trigger.Get <int>("id");
        bool forceStart = trigger.Get <bool>("force");

        if (questId == 0)
        {
            trigger.Session.SendNotice("Type an quest id.");
            return;
        }

        QuestMetadata quest = QuestMetadataStorage.GetMetadata(questId);

        if (quest == null)
        {
            trigger.Session.Send(NoticePacket.Notice($"Quest not found with id: {questId.ToString().Color(Color.Aquamarine)}.", NoticeType.Chat));
            return;
        }

        Player player = trigger.Session.Player;

        if (player.QuestData.TryGetValue(questId, out QuestStatus questStatus) && !forceStart)
        {
            trigger.Session.Send(NoticePacket.Notice(
                                     $"You already have quest: {questId.ToString().Color(Color.Aquamarine)}. \r\tUse '/startquest {questId} true' to start it again.",
                                     NoticeType.Chat));
            return;
        }

        if (questStatus is not null)
        {
            player.QuestData.Remove(questId, out _);
            DatabaseManager.Quests.Delete(questStatus.Uid);
        }

        questStatus = new(player.CharacterId, questId, QuestState.Started, TimeInfo.Now(), accepted : true);
        player.QuestData.Add(questId, questStatus);
        trigger.Session.Send(QuestPacket.AcceptQuest(questStatus));
    }
        public override void Execute(GameCommandTrigger trigger)
        {
            int questId = trigger.Get <int>("id");

            if (questId == 0)
            {
                trigger.Session.SendNotice("Type an quest id.");
                return;
            }
            QuestMetadata quest = QuestMetadataStorage.GetMetadata(questId);

            if (quest == null)
            {
                trigger.Session.Send(NoticePacket.Notice($"Quest not found with id: {questId.ToString().Color(Color.Aquamarine)}.", NoticeType.Chat));
                return;
            }
            if (trigger.Session.Player.QuestList.Any(x => x.Basic.Id == questId))
            {
                trigger.Session.Send(NoticePacket.Notice($"You already have quest: {questId.ToString().Color(Color.Aquamarine)}.", NoticeType.Chat));
                return;
            }
            trigger.Session.Player.QuestList.Add(new QuestStatus(trigger.Session.Player, quest, true, DateTimeOffset.Now.ToUnixTimeSeconds()));
            trigger.Session.Send(QuestPacket.AcceptQuest(questId));
        }
예제 #10
0
    private static void HandleAddExplorationQuests(GameSession session, PacketReader packet)
    {
        int listSize = packet.ReadInt();

        for (int i = 0; i < listSize; i++)
        {
            int questId = packet.ReadInt();
            session.Player.QuestData.TryGetValue(questId, out QuestStatus questStatus);

            if (questStatus is null)
            {
                questStatus = new(session.Player.CharacterId, questId, QuestState.Started, TimeInfo.Now(), accepted : true);
                session.Player.QuestData.Add(questId, questStatus);
                session.Send(QuestPacket.AcceptQuest(questStatus));
                continue;
            }

            questStatus.State          = QuestState.Started;
            questStatus.StartTimestamp = TimeInfo.Now();
            questStatus.Accepted       = true;
            DatabaseManager.Quests.Update(questStatus);
            session.Send(QuestPacket.AcceptQuest(questStatus));
        }
    }
예제 #11
0
    public override void Execute(GameCommandTrigger trigger)
    {
        int questId = trigger.Get <int>("id");

        if (questId == 0)
        {
            trigger.Session.SendNotice("Please type an quest id");
            return;
        }

        if (!QuestMetadataStorage.IsValid(questId))
        {
            trigger.Session.Send(NoticePacket.Notice($"Quest not found with id: {questId.ToString().Color(Color.Aquamarine)}.", NoticeType.Chat));
            return;
        }

        Player player = trigger.Session.Player;

        if (!player.QuestData.TryGetValue(questId, out QuestStatus questStatus))
        {
            questStatus = new(player.CharacterId, questId);
            player.QuestData.Add(questId, questStatus);
        }

        if (questStatus.State is QuestState.None)
        {
            questStatus.Accepted       = true;
            questStatus.State          = QuestState.Started;
            questStatus.StartTimestamp = TimeInfo.Now();
            trigger.Session.Send(QuestPacket.AcceptQuest(questStatus));

            trigger.Session.Send(NoticePacket.Notice($"Quest {questId} started. Do it again to complete.", NoticeType.Chat));
            return;
        }

        questStatus.State = QuestState.Completed;
        questStatus.AmountCompleted++;
        questStatus.Condition.ForEach(x =>
        {
            x.Completed = true;
            x.Current   = x.Goal;
        });
        questStatus.StartTimestamp    = TimeInfo.Now();
        questStatus.CompleteTimestamp = TimeInfo.Now();
        player.Levels.GainExp(questStatus.Reward.Exp);
        player.Wallet.Meso.Modify(questStatus.Reward.Money);

        foreach (QuestRewardItem reward in questStatus.RewardItems)
        {
            Item newItem = new(id : reward.Code, amount : reward.Count, rarity : reward.Rank);
            if (newItem.RecommendJobs.Contains(player.Job) || newItem.RecommendJobs.Contains(0))
            {
                player.Inventory.AddItem(trigger.Session, newItem, true);
            }
        }

        DatabaseManager.Quests.Update(questStatus);
        trigger.Session.Send(QuestPacket.CompleteQuest(questId, true));

        // Add next quest
        IEnumerable <KeyValuePair <int, QuestMetadata> > questList =
            QuestMetadataStorage.GetAllQuests().Where(x => x.Value.Require.RequiredQuests.Contains(questId));

        foreach ((int id, QuestMetadata quest) in questList)
        {
            if (player.QuestData.ContainsKey(id))
            {
                continue;
            }

            player.QuestData.Add(id, new(player.CharacterId, quest));
        }
    }