/// <summary>
 /// When overridden in the derived class, sets the values read from the Read method.
 /// </summary>
 /// <param name="conditional">The conditional.</param>
 /// <param name="not">The Not value.</param>
 /// <param name="parameters">The parameters.</param>
 protected override void SetReadValues(NPCChatConditionalBase conditional, bool not,
                                       NPCChatConditionalParameter[] parameters)
 {
     _conditional = conditional;
     _not = not;
     _parameters = parameters;
 }
        /// <summary>
        /// Tries the set one of the Parameters.
        /// </summary>
        /// <param name="index">The index.</param>
        /// <param name="value">The value.</param>
        /// <returns>True if set successfully; otherwise false.</returns>
        public bool TrySetParameter(int index, NPCChatConditionalParameter value)
        {
            if (index < 0)
                return false;
            if (index >= _parameters.Count)
                return false;
            if (value == null)
                return false;

            _parameters[index] = value;

            if (Changed != null)
                Changed.Raise(this, EventArgs.Empty);

            return true;
        }
        /// <summary>
        /// When overridden in the derived class, sets the values read from the Read method.
        /// </summary>
        /// <param name="conditional">The conditional.</param>
        /// <param name="not">The Not value.</param>
        /// <param name="parameters">The parameters.</param>
        protected override void SetReadValues(NPCChatConditionalBase conditional, bool not,
                                              NPCChatConditionalParameter[] parameters)
        {
            _conditional = conditional;
            _not = not;
            _parameters.Clear();
            _parameters.AddRange(parameters);

            if (Changed != null)
                Changed.Raise(this, EventArgs.Empty);
        }
        /// <summary>
        /// Sets the Conditional.
        /// </summary>
        /// <param name="conditional">The new <see cref="NPCChatConditionalBase"/>.</param>
        /// <exception cref="ArgumentNullException"><paramref name="conditional" /> is <c>null</c>.</exception>
        public void SetConditional(NPCChatConditionalBase conditional)
        {
            if (conditional == null)
                throw new ArgumentNullException("conditional");

            if (_conditional == conditional)
                return;

            // Set the new conditional
            _conditional = conditional;

            // Re-create all the parameters to the appropriate type for the new conditional
            var newParameters = new NPCChatConditionalParameter[Conditional.ParameterCount];

            for (var i = 0; i < Conditional.ParameterCount; i++)
            {
                var neededType = Conditional.GetParameter(i);
                if (i < _parameters.Count && _parameters[i].ValueType == neededType)
                {
                    // The type matches the old type, so just reuse it
                    newParameters[i] = _parameters[i];
                }
                else
                {
                    // Different type or out of range, so make a new one
                    newParameters[i] = NPCChatConditionalParameter.CreateParameter(neededType);
                }
            }

            // Set the new parameters
            _parameters.Clear();
            _parameters.AddRange(newParameters);

            if (Changed != null)
                Changed.Raise(this, EventArgs.Empty);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Writes the <see cref="NPCChatConditionalParameter"/> to the given <see cref="IValueWriter"/>.
 /// </summary>
 /// <param name="p">The <see cref="NPCChatConditionalParameter"/>.</param>
 /// <param name="writer">The <see cref="IValueWriter"/> to write to.</param>
 public static void Write(NPCChatConditionalParameter p, IValueWriter writer)
 {
     writer.Write("ValueType", (byte)p.ValueType);
     p.WriteValue(writer, "Value");
 }
Ejemplo n.º 6
0
 /// <summary>
 /// When overridden in the derived class, performs the actual conditional evaluation.
 /// </summary>
 /// <param name="user">The User.</param>
 /// <param name="npc">The NPC.</param>
 /// <param name="parameters">The parameters to use. </param>
 /// <returns>True if the conditional returns true for the given <paramref name="user"/>,
 /// <paramref name="npc"/>, and <paramref name="parameters"/>; otherwise false.</returns>
 protected abstract bool DoEvaluate(object user, object npc, NPCChatConditionalParameter[] parameters);
 /// <summary>
 /// When overridden in the derived class, sets the values read from the Read method.
 /// </summary>
 /// <param name="conditional">The conditional.</param>
 /// <param name="not">The Not value.</param>
 /// <param name="parameters">The parameters.</param>
 protected abstract void SetReadValues(NPCChatConditionalBase conditional, bool not,
                                       NPCChatConditionalParameter[] parameters);
Ejemplo n.º 8
0
            /// <summary>
            /// Initializes a new instance of the <see cref="ParameterListItem"/> class.
            /// </summary>
            /// <param name="parameter">The <see cref="NPCChatConditionalParameter"/>.</param>
            /// <exception cref="ArgumentNullException"><paramref name="parameter" /> is <c>null</c>.</exception>
            public ParameterListItem(NPCChatConditionalParameter parameter)
            {
                if (parameter == null)
                    throw new ArgumentNullException("parameter");

                _parameter = parameter;
            }
Ejemplo n.º 9
0
 /// <summary>
 /// Writes the <see cref="NPCChatConditionalParameter"/> to the given <see cref="IValueWriter"/>.
 /// </summary>
 /// <param name="p">The <see cref="NPCChatConditionalParameter"/>.</param>
 /// <param name="writer">The <see cref="IValueWriter"/> to write to.</param>
 public static void Write(NPCChatConditionalParameter p, IValueWriter writer)
 {
     writer.Write("ValueType", (byte)p.ValueType);
     p.WriteValue(writer, "Value");
 }