Ejemplo n.º 1
0
        private void MainPageResponses(int responseID)
        {
            var player    = GetPC();
            var playerID  = GetGlobalID(player);
            var entity    = PlayerRepo.Get(playerID);
            var response  = GetResponseByID("MainPage", responseID);
            var classType = (ClassType)response.Data;

            var data = new JobChanged(player, entity.CurrentJob, classType);

            Publish.CustomEvent(player, JobEventPrefix.OnJobChanged, data);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Completes a quest for a player. If a reward is selected, that reward will be given to the player.
        /// Otherwise, all rewards configured for this quest will be given to the player.
        /// </summary>
        /// <param name="player">The player completing the quest.</param>
        /// <param name="questSource">The source of the quest completion</param>
        /// <param name="selectedReward">The reward selected by the player</param>
        internal void Complete(NWGameObject player, NWGameObject questSource, IQuestReward selectedReward)
        {
            if (!GetIsPlayer(player))
            {
                return;
            }
            if (!CanComplete(player))
            {
                return;
            }

            var playerID = GetGlobalID(player);
            var pcState  = QuestProgressRepo.Get(playerID, QuestID);

            // Mark player as being on the last state of the quest.
            pcState.CurrentState = GetStates().Count();
            pcState.TimesCompleted++;

            // No selected reward, simply give all available rewards to the player.
            if (selectedReward == null)
            {
                foreach (var reward in Rewards)
                {
                    reward.GiveReward(player);
                }
            }
            // There is a selected reward. Give that reward and any rewards which are not selectable to the player.
            else
            {
                // Non-selectable rewards (gold, GP, etc) are granted to the player.
                foreach (var reward in Rewards.Where(x => !x.IsSelectable))
                {
                    reward.GiveReward(player);
                }

                selectedReward.GiveReward(player);
            }

            QuestProgressRepo.Set(playerID, pcState);

            foreach (var action in _onCompleteActions)
            {
                action.Invoke(player, questSource);
            }

            SendMessageToPC(player, "Quest '" + Name + "' complete!");
            RemoveJournalQuestEntry(JournalTag, player, false);

            Publish.CustomEvent(player, QuestEventPrefix.OnQuestAdvanced, new QuestCompleted(player, QuestID));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Accepts a quest using the configured settings.
        /// </summary>
        /// <param name="player">The player accepting the quest.</param>
        /// <param name="questSource">The source of the quest giver</param>
        internal void Accept(NWGameObject player, NWGameObject questSource)
        {
            if (!GetIsPlayer(player))
            {
                return;
            }

            if (!CanAccept(player))
            {
                return;
            }

            var playerID = GetGlobalID(player);

            // By this point, it's assumed the player will accept the quest.
            var status = QuestProgressRepo.Get(playerID, QuestID);

            // Retrieve the first quest state for this quest.
            status.CurrentState = 1;
            status.QuestID      = QuestID;

            // Insert or update player's quest status.
            QuestProgressRepo.Set(playerID, status);

            var state = GetState(1);

            foreach (var objective in state.GetObjectives())
            {
                objective.Initialize(player, QuestID);
            }

            // Add the journal entry to the player.
            AddJournalQuestEntry(JournalTag, 1, player, false);

            // Notify them that they've accepted a quest.
            SendMessageToPC(player, "Quest '" + Name + "' accepted. Refer to your journal for more information on this quest.");

            // Run any quest-specific code.
            foreach (var action in _onAcceptActions)
            {
                action.Invoke(player, questSource);
            }

            // Notify to subscribers that a quest has just been accepted.
            Publish.CustomEvent(player, QuestEventPrefix.OnQuestAccepted, new QuestAccepted(player, QuestID));
        }
Ejemplo n.º 4
0
        public void RunMigration(NWGameObject player)
        {
            var playerID = GetGlobalID(player);
            var entity   = PlayerRepo.Get(playerID);
            var job      = GetClassByPosition(ClassPosition.First, player);

            entity.Name       = GetName(player);
            entity.CurrentJob = job;
            PlayerRepo.Set(entity);

            InitializeJobs(playerID);
            InitializeSkills(player);
            InitializeSavingThrows(player);
            RemoveNWNSpells(player);

            // Treat this initialization as a job change and a level-up.
            Publish.CustomEvent(player, JobEventPrefix.OnJobChanged, new JobChanged(player, job, job));
            Publish.CustomEvent(player, JobEventPrefix.OnLeveledUp, new LeveledUp(player));
        }
Ejemplo n.º 5
0
        public static void Main()
        {
            var data        = Script.GetScriptData <JobXPGained>();
            var player      = data.Creature;
            var playerID    = GetGlobalID(player);
            var jobType     = GetClassByPosition(ClassPosition.First, player);
            var levelBefore = GetLevelByPosition(ClassPosition.First, player);

            // Auto-level the NWN class.
            // These changes get adjusted as part of our auto-level process.
            LevelUpHenchman(player, jobType);
            var levelAfter = GetLevelByPosition(ClassPosition.First, player);
            var job        = JobRepo.Get(playerID, jobType);

            job.Level = levelAfter;
            job.XP    = GetXP(player);
            JobRepo.Set(playerID, jobType, job);

            if (levelBefore != levelAfter)
            {
                Publish.CustomEvent(player, JobEventPrefix.OnLeveledUp, new LeveledUp(player));
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Advances the player to the next quest state.
        /// </summary>
        /// <param name="player">The player advancing to the next quest state</param>
        /// <param name="questSource">The source of quest advancement</param>
        internal void Advance(NWGameObject player, NWGameObject questSource)
        {
            if (!GetIsPlayer(player))
            {
                return;
            }

            // Retrieve the player's current quest state.
            var playerID    = GetGlobalID(player);
            var questStatus = QuestProgressRepo.Get(playerID, QuestID);

            // Can't find a state? Notify the player they haven't accepted the quest.
            if (questStatus.CurrentState <= 0)
            {
                SendMessageToPC(player, "You have not accepted this quest yet.");
                return;
            }

            // If this quest has already been completed, exit early.
            // This is used in case a module builder incorrectly configures a quest.
            // We don't want to risk giving duplicate rewards.
            if (questStatus.TimesCompleted > 0 && !IsRepeatable)
            {
                return;
            }

            var currentState = GetState(questStatus.CurrentState);
            var lastState    = GetStates().Last();

            // If this is the last state, the assumption is that it's time to complete the quest.
            if (currentState == lastState)
            {
                RequestRewardSelectionFromPC(player, questSource);
            }
            else
            {
                // Progress player's quest status to the next state.
                questStatus.CurrentState++;
                var nextState = GetState(questStatus.CurrentState);

                // Update the player's journal
                AddJournalQuestEntry(JournalTag, questStatus.CurrentState, player, false);

                // Notify the player they've progressed.
                SendMessageToPC(player, "Objective for quest '" + Name + "' complete! Check your journal for information on the next objective.");

                // Submit all of these changes to the cache/DB.
                QuestProgressRepo.Set(playerID, questStatus);

                // Create any extended data entries for the next state of the quest.
                foreach (var objective in nextState.GetObjectives())
                {
                    objective.Initialize(player, QuestID);
                }

                // Run any quest-specific code.
                foreach (var action in _onAdvanceActions)
                {
                    action.Invoke(player, questSource, questStatus.CurrentState);
                }

                // Notify to subscribers that the player has advanced to the next state of the quest.
                Publish.CustomEvent(player, QuestEventPrefix.OnQuestAdvanced, new QuestAdvanced(player, QuestID, questStatus.CurrentState));
            }
        }