예제 #1
0
        /// <summary>
        /// Try to set quest as completed (if player has this quest and all the requirements are satisfied).
        /// </summary>
        public static void ServerCompleteQuest(
            PlayerCharacterQuests characterQuests,
            IProtoQuest questToComplete,
            bool ignoreRequirements)
        {
            characterQuests.ServerClaimReward(questToComplete, ignoreRequirements);

            var handler = ServerCharacterQuestCompleted;

            if (handler is not null)
            {
                Api.SafeInvoke(() => handler.Invoke(characterQuests.Character, questToComplete));
            }

            // success! (no exceptions thrown)
            // adding dependant quests
            foreach (var otherQuest in AllQuests)
            {
                if (!otherQuest.Prerequisites.Contains(questToComplete) ||
                    !ServerArePrerequisitesSatisfied(otherQuest, characterQuests))
                {
                    continue;
                }

                characterQuests.ServerTryAddQuest(otherQuest, isUnlocked: true);
            }
        }
예제 #2
0
 public static void ServerInitCharacterQuests(PlayerCharacterQuests characterQuests)
 {
     // add all quests which don't have any prerequisites or which are already satisfied
     foreach (var protoQuest in AllQuests)
     {
         var isUnlocked = ServerArePrerequisitesSatisfied(protoQuest, characterQuests);
         characterQuests.ServerTryAddQuest(protoQuest, isUnlocked);
     }
 }
예제 #3
0
        private static bool ServerArePrerequisitesSatisfied(IProtoQuest quest, PlayerCharacterQuests characterQuests)
        {
            if (quest.Prerequisites.Count == 0)
            {
                return(true);
            }

            foreach (var requiredQuest in quest.Prerequisites)
            {
                if (!characterQuests.SharedHasCompletedQuest(requiredQuest))
                {
                    return(false);
                }
            }

            return(true);
        }
예제 #4
0
        /// <summary>
        /// Try to set quest as completed (if player has this quest and all the requirements are satisfied).
        /// </summary>
        public static void ServerCompleteQuest(
            PlayerCharacterQuests characterQuests,
            IProtoQuest questToComplete,
            bool ignoreRequirements)
        {
            characterQuests.ServerTryClaimReward(questToComplete, ignoreRequirements);

            // success! (no exceptions thrown)
            // adding dependant quests
            foreach (var otherQuest in AllQuests)
            {
                if (!otherQuest.Prerequisites.Contains(questToComplete) ||
                    !ServerArePrequisitesSatisfied(otherQuest, characterQuests))
                {
                    continue;
                }

                characterQuests.ServerTryAddQuest(otherQuest, isUnlocked: true);
            }
        }