private void UpdateMails()
        {
            foreach (var mail in Mails)
            {
                if (mail.AddresseeID != Game1.player.UniqueMultiplayerID)
                {
                    continue;
                }

                string letterID         = $"{nameof(MailPersistenceFramework)}_{mail.ModUniqueID}_{mail.ID}";
                var    letter           = MailDao.FindLetter(letterID);
                var    isExistingLetter = letter is not null;
                if (letter is not null && mail.Title is null)
                {
                    MailDao.RemoveLetter(letter);
                }

                string?mailTitle = mail.Title;
                foreach (var @override in Overrides)
                {
                    @override.Title?.Invoke(
                        mail.ModUniqueID, mail.ID,
                        mailTitle,
                        v =>
                    {
                        if (mailTitle is null && v is not null)
                        {
                            throw new InvalidOperationException("Cannot add a title to a mail that didn't start with a title to begin with.");
                        }
                        mailTitle = v;
                    }
Beispiel #2
0
        public static bool CreateMailOrder(Farmer recipient, int daysToWait, List <Item> packagedItems)
        {
            try
            {
                // Check if packagedItems contains Joja Prime item
                int jojaPrimeID = JojaItems.GetJojaPrimeMembershipID();
                if (packagedItems.Any(i => i.ParentSheetIndex == jojaPrimeID))
                {
                    // Remove Joja Prime from the store
                    JojaResources.RemoveFromJojaOnlineStock(packagedItems.First(i => i.ParentSheetIndex == jojaPrimeID));

                    // Now send out mail with JojaPrimeShipping id
                    SendMail(recipient, "JojaPrimeShippingInfo", $"Valued Member,^^Thank you for purchasing Joja Prime. You are now able to use free next day delivery on Joja Online.^^We look forward to your continued business.^^- Joja Co.");

                    // Add JojaPrimeShipping mailID to the player's received mail so the flags recognize the membership has been purchased
                    // Otherwise the player will not have the membership until they read the mail the next day
                    Game1.MasterPlayer.mailReceived.Add("JojaPrimeShipping");

                    // Set the hasPrimeShipping to true manually, as it otherwise wouldn't update until the next day
                    JojaSite.SetPrimeShippingStatus(true);

                    // Remove Joja Prime from the list of shipped items, as we actually don't want to ship it
                    packagedItems = packagedItems.Where(i => i.ParentSheetIndex != jojaPrimeID).ToList();

                    // Skip rest of logic of there are no more items to ship due to removing Joja Prime
                    if (packagedItems.Count == 0)
                    {
                        return(true);
                    }
                }

                // Determine order number
                int orderNumber = 0;
                while (MailDao.FindLetter($"JojaMailOrder[#{orderNumber}]") != null || recipient.mailReceived.Contains($"JojaMailOrder[#{orderNumber}]") || IsOrderNumberScheduled(recipient, orderNumber))
                {
                    orderNumber++;
                }
                string mailOrderID = $"JojaMailOrder[#{orderNumber}]";

                // Generate mail message
                string message = $"Valued Customer,^^Thank you for using Joja Online. Your items for order #{orderNumber:0000} are packaged below.^^We look forward to your continued business.^^- Joja Co.";

                if (JojaSite.GetMembershipStatus() || JojaSite.GetPrimeShippingStatus())
                {
                    message = $"Valued Member,^^Thank you for using Joja Online. Your items for order #{orderNumber:0000} are packaged below.^^We look forward to your continued business.^^- Joja Co.";
                }

                // Determine the deliveryDate
                int deliveryDate = daysToWait + Game1.dayOfMonth > 28 ? daysToWait : daysToWait + Game1.dayOfMonth;

                // Need to save this mail data if it can't be delivered before shutdown
                recipient.mailForTomorrow.Add($"{mailOrderID}[{message}][{deliveryDate}][{String.Join(", ", packagedItems.Select(i => $"[{i.Name}, {i.category}, {i.parentSheetIndex}, {i.Stack}]"))}]");

                monitor.Log($"JojaMail order [#{orderNumber}] created with delivery date of [{deliveryDate}] {String.Join(", ", packagedItems.Select(i => $"[{i.Name}, {i.category}, {i.parentSheetIndex}, {i.Stack}]"))}!", LogLevel.Debug);
            }
            catch (Exception ex)
            {
                return(false);
            }

            return(true);
        }