/// <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); } }