/// <summary> /// Add a mail to the game. /// </summary> /// <param name="modId">The ID of the mod which wants to add the mail.</param> /// <param name="mailId">The ID of the mail.</param> /// <param name="arrivalDay">The day of arrival of the mail.</param> /// <exception cref="ArgumentException"> /// The specified <paramref name="modId"/> is <c>null</c>, does not contain at least one /// non-whitespace character or contains an invalid character sequence -or- /// the specified <paramref name="mailId"/> is <c>null</c>, does not contain at least one /// non-whitespace character or contains an invalid character sequence -or- /// a mail with the specified <paramref name="mailId"/> provided by the mod with the specified <paramref name="modId"/> /// for the specified <paramref name="arrivalDay"/> already exists. /// </exception> /// <exception cref="ArgumentNullException">The specified <paramref name="arrivalDay"/> is <c>null</c>.</exception> public void Add(string modId, string mailId, SDate arrivalDay) { if (string.IsNullOrWhiteSpace(modId) || modId.Contains(MAIL_ID_PREFIX)) { throw new ArgumentException($"The mod ID \"{modId}\" has to contain at least one non-whitespace character and cannot " + $"contain the string {MAIL_ID_PREFIX}", nameof(modId)); } if (string.IsNullOrWhiteSpace(mailId) || mailId.Contains(MAIL_ID_PREFIX)) { throw new ArgumentException($"The mail ID \"{mailId}\" has to contain at least one non-whitespace character and cannot " + $"contain the string {MAIL_ID_PREFIX}", nameof(mailId)); } if (arrivalDay == null) { throw new ArgumentNullException(nameof(arrivalDay)); } // Components for the internal mail ID: MOD_ID + user ID + Arrival Day. // // Multiple mods can add mails with the same IDs for the same day, so in order to have // a straightforward relation between mail and the mod which added it, we need to add the mod ID // to the internal mail ID. // // We also add the arrival day to the internal mail ID because for each mod, mails with the // same ID for different arrival days can be added.The user cannot, however, have multiple mails // with the same ID for the same day for the same mod. int absoluteArrivalDay = arrivalDay.DaysSinceStart; string internalMailId = MAIL_ID_PREFIX + modId + mailId + absoluteArrivalDay + MAIL_ID_SUFFIX; if (this.registeredMailsMetaData.ContainsKey(internalMailId)) { throw new ArgumentException($"A mail with the specified ID \"{mailId}\" for the given mod \"{modId}\" for the " + $"specified arrival day \"{arrivalDay}\" already exists!"); } this.registeredMailsMetaData[internalMailId] = new MailMetaData(modId, mailId, absoluteArrivalDay); this.registeredMailsForDay.AddToList(absoluteArrivalDay, internalMailId); if (arrivalDay.Equals(SDate.Now())) { Game1.mailbox.Add(internalMailId); mailAssetEditor.RequestAssetCacheRefresh(); monitor.Log($"Added mail \"{mailId}\" to the player's mailbox."); } }