예제 #1
0
        public UserSettings(Dictionary <string, string> args)
            : base(args)
        {
            try
            {
                _configurationSettings = UtilBuildConfigurationSettings();
                _persistData           = new PersistedData(this.GetType().Name, _configurationSettings);
                _userChangeRequest     = new ConfigurationChangeRequest(_configurationSettings);

                // If we've yet to capture the user's original settings, do so now...
                // We need to do this 'up front' because the "UserOriginal" configuration will
                // also be captured as a preset.
                _originalConfiguration = _persistData.OriginalConfiguration;
                _presetChangeRequests  = UtilBuildPresetChangeRequests(_configurationSettings,
                                                                       _originalConfiguration);

                // QuestRequirement* attributes are explained here...
                //    http://www.thebuddyforum.com/mediawiki/index.php?title=Honorbuddy_Programming_Cookbook:_QuestId_for_Custom_Behaviors
                // ...and also used for IsDone processing.
                bool?tmpDebugShowChangesApplied;

                tmpDebugShowChangesApplied = GetAttributeAsNullable <bool>("DebugShowChangesApplied", false, null, null);
                DebugShowDetails           = GetAttributeAsNullable <bool>("DebugShowDetails", false, null, null) ?? false;
                DebugShowDiff            = GetAttributeAsNullable <bool>("DebugShowDiff", false, null, null) ?? false;
                PresetName               = GetAttributeAs <string>("Preset", false, new ConstrainTo.SpecificValues <string>(_presetChangeRequests.Keys.ToArray()), null) ?? "";
                QuestId                  = GetAttributeAsNullable <int>("QuestId", false, ConstrainAs.QuestId(this), null) ?? 0;
                QuestRequirementComplete = GetAttributeAsNullable <QuestCompleteRequirement>("QuestCompleteRequirement", false, null, null) ?? QuestCompleteRequirement.NotComplete;
                QuestRequirementInLog    = GetAttributeAsNullable <QuestInLogRequirement>("QuestInLogRequirement", false, null, null) ?? QuestInLogRequirement.InLog;
                IsStopBot                = GetAttributeAsNullable <bool>("StopBot", false, null, null) ?? false;

                _userChangeRequest.GetChangesFromAttributes(this);

                // Transfer any 'debug' requests made by the user into our persistent copy --
                if (tmpDebugShowChangesApplied.HasValue)
                {
                    _persistData.DebugShowChangesApplied = tmpDebugShowChangesApplied.Value;
                }
            }

            catch (Exception except)
            {
                // Maintenance problems occur for a number of reasons.  The primary two are...
                // * Changes were made to the behavior, and boundary conditions weren't properly tested.
                // * The Honorbuddy core was changed, and the behavior wasn't adjusted for the new changes.
                // In any case, we pinpoint the source of the problem area here, and hopefully it
                // can be quickly resolved.
                LogMessage("error", "BEHAVIOR MAINTENANCE PROBLEM: " + except.Message
                           + "\nFROM HERE:\n"
                           + except.StackTrace + "\n");
                IsAttributeProblem = true;
            }
        }
예제 #2
0
        // Builds a change request from the settings captured by this snapshot...
        // We only place entries that don't agree with the snapshot's value into the change request.
        public ConfigurationChangeRequest MakeChangeRequest()
        {
            ConfigurationChangeRequest changeRequest = new ConfigurationChangeRequest(_recognizedAttributes);
            var changedDescs = (from kvp in _configSnapshot
                                where !kvp.Key.Value.Equals(kvp.Value)
                                select kvp);

            foreach (KeyValuePair <ConfigDescriptor, object> kvp in changedDescs)
            {
                changeRequest.Add(kvp.Key.Name, kvp.Value);
            }

            return(changeRequest);
        }