Esempio n. 1
0
            public bool HandleResponse(WorldObject invoker, int optionSelected, WorldObject associateOverride = null, WorldObject source = null)
            {
                WorldObject Associate;
                string      Expression = string.Empty;

                // Quick sanity check
                if (optionSelected < 0 || optionSelected > Options.Count)
                {
                    Log.Error("Option dialog response: invalid player selection {OptionSelected}, aborting", optionSelected);
                    return(false);
                }

                if (Sequence.Associate != null)
                {
                    Associate = Sequence.Associate;
                }
                else
                {
                    Associate = associateOverride;
                }
                // Note that client is 1-indexed for responses
                // If we have a JumpDialog, handle that first

                if (Options[optionSelected - 1].JumpDialog != null)
                {
                    // Use jump dialog first
                    Options[optionSelected - 1].JumpDialog.ShowTo(invoker as User, Associate as VisibleObject);
                    return(true);
                }

                // If the response is a sequence, start it
                if (Options[optionSelected - 1].overrideSequence != null)
                {
                    var sequence = Options[optionSelected - 1].overrideSequence;
                    if (invoker is User)
                    {
                        var user = invoker as User;
                        // We lazily set this because an option / dialog can be constructed in a variety of places
                        if (sequence.Associate == null)
                        {
                            Associate.RegisterDialogSequence(sequence);
                        }
                        user.DialogState.TransitionDialog(Associate as VisibleObject, Options[optionSelected - 1].overrideSequence);
                        sequence.ShowTo(user, Associate as VisibleObject);
                    }
                }

                // If the individual options don't have callbacks, use the dialog callback instead.
                if (Handler != null && Options[optionSelected - 1].CallbackFunction == null)
                {
                    Expression = Handler;
                }
                else if (Options[optionSelected - 1].CallbackFunction != null)
                {
                    Expression = Options[optionSelected - 1].CallbackFunction;
                }
                // Regardless of what handler we use, make sure the script can see the value.
                // We pass everything as string to not make UserData barf, as it can't handle dynamics.
                // For option dialogs we pass both the "number" selected, and the actual text of the button pressed.
                var script = GetScript(associateOverride);

                script.SetGlobalValue("player_selection", optionSelected.ToString());
                script.SetGlobalValue("player_response", Options[optionSelected - 1].OptionText);
                return(script.Execute(Expression, invoker, source));
            }