Beispiel #1
0
        private void QuestAccept(CommandArgs args)
        {
            var parameters = args.Parameters;
            var player     = args.Player;

            if (parameters.Count < 2)
            {
                player.SendErrorMessage($"Syntax: {Commands.Specifier}quest accept <name>.");
                return;
            }

            var session = GetSession(player);

            if (session.CurrentQuest != null)
            {
                player.SendErrorMessage("You are already in a quest. Either abort it or complete it.");
                return;
            }

            var availableQuests = session.UnlockedQuestNames.Where(n => QuestLoader.Contains(n))
                                  .Select(n => QuestLoader[n])
                                  .Where(session.CanAcceptQuest)
                                  .ToList();

            var inputName = string.Join(" ", parameters.Skip(1));
            var questInfo = availableQuests.FirstOrDefault(q => q.FriendlyName.Equals(inputName, StringComparison.OrdinalIgnoreCase) || q.Name == inputName);

            if (questInfo == null)
            {
                player.SendErrorMessage($"Invalid quest name '{inputName}'.");
                return;
            }

            var path = Path.Combine("quests", questInfo.ScriptPath ?? $"{questInfo.Name}.boo");

            if (!File.Exists(path))
            {
                player.SendErrorMessage($"Quest '{questInfo.FriendlyName}' is corrupted.");
                CustomQuestsPlugin.Instance.LogPrint($"Failed to start quest '{questInfo.Name}'. Script file not found at '{path}'.", TraceLevel.Error);
                QuestLoader.InvalidQuests.Add(questInfo.Name);
                return;
            }

            var concurrentParties = _parties.Values.Select(p => GetSession(p.Leader))
                                    .Count(s => s.CurrentQuestName == inputName);

            if (concurrentParties >= questInfo.MaxConcurrentParties)
            {
                player.SendErrorMessage($"There are too many parties currently performing the quest '{questInfo.FriendlyName}'.");
                return;
            }

            var party = session.Party;

            if (party != null)
            {
                if (party.Leader.Player != player)
                {
                    player.SendErrorMessage("Only the party leader can accept a quest.");
                    return;
                }
                if (party.Select(GetSession).Any(s => !s.UnlockedQuestNames.Contains(questInfo.Name) &&
                                                 !s.CompletedQuestNames.Contains(questInfo.Name)) ||
                    party.Select(GetSession).Any(s => !s.CanAcceptQuest(questInfo)))
                {
                    player.SendErrorMessage($"Not everyone can start the quest '{questInfo.FriendlyName}'.");
                    return;
                }
                if (party.Count < questInfo.MinPartySize)
                {
                    player.SendErrorMessage($"Quest requires a larger party size of {questInfo.MinPartySize}.");
                    return;
                }
                if (party.Count > questInfo.MaxPartySize)
                {
                    player.SendErrorMessage($"Quest requires a smaller party size of {questInfo.MaxPartySize}.");
                    return;
                }

                try
                {
                    player.SendSuccessMessage($"Starting quest '{questInfo.FriendlyName}'!");
                    //session.LoadQuest(questInfo);
                    session.LoadQuest(questInfo);

                    foreach (var player2 in party.Where(p => p.Player != player))
                    {
                        player2.SendSuccessMessage($"Starting quest '{questInfo.FriendlyName}'!");
                        var session2 = GetSession(player2);
                        //session2.QuestStatusManager.Clear();
                        session2.CurrentQuest = session.CurrentQuest;
                    }
                }
                catch (Exception ex)
                {
                    player.SendErrorMessage($"Quest '{questInfo.FriendlyName}' is corrupted.");
                    CustomQuestsPlugin.Instance.LogPrint(ex.ToString(), TraceLevel.Error);
                    CustomQuestsPlugin.Instance.LogPrint(ex.InnerException?.ToString());
                }
            }
            else
            {
                if (questInfo.MinPartySize > 1)
                {
                    player.SendErrorMessage($"Quest requires a party size of {questInfo.MinPartySize}.");
                    return;
                }

                try
                {
                    player.SendSuccessMessage($"Starting quest '{questInfo.FriendlyName}'!");
                    //session.LoadQuest(questInfo);
                    session.LoadQuest(questInfo);
                }
                catch (Exception ex)
                {
                    player.SendErrorMessage($"Quest '{questInfo.FriendlyName}' is corrupted.");
                    CustomQuestsPlugin.Instance.LogPrint(ex.ToString(), TraceLevel.Error);
                    CustomQuestsPlugin.Instance.LogPrint(ex.InnerException?.ToString());
                }
            }
        }