Ejemplo n.º 1
0
        public override void receiveLeftClick(int x, int y, bool playSound = true)
        {
            base.receiveLeftClick(x, y, playSound);
            lastTick = Game1.ticks;

            if (Game1.activeClickableMenu == null)
            {
                return;
            }

            if (isCheckingOut)
            {
                if (cancelButton.containsPoint(x, y))
                {
                    isCheckingOut = false;
                    Game1.playSound("cancel");
                }
                else if (nextDayShippingButton.containsPoint(x, y))
                {
                    isNextDayShipping = true;
                    Game1.playSound("select");
                }
                else if (twoDayShippingButton.containsPoint(x, y))
                {
                    isNextDayShipping = false;
                    Game1.playSound("select");
                }
                else if (purchaseButton.containsPoint(x, y))
                {
                    if (canAffordOrder)
                    {
                        // Close this menu
                        base.exitThisMenu();

                        // Create mail order
                        if (JojaMail.CreateMailOrder(Game1.player, isNextDayShipping ? 1 : 2, itemsInCart.Keys.Select(i => i as Item).ToList()))
                        {
                            this.monitor.Log("Order placed via JojaMail!", LogLevel.Debug);

                            // Display order success dialog
                            if (isNextDayShipping)
                            {
                                Game1.player.Money        = Game1.player.Money - (itemsInCart.Keys.Sum(i => i.Stack * itemsInCart[i][0]) + (itemsInCart.Keys.Sum(i => i.Stack * itemsInCart[i][0]) / nextDayShippingFee));
                                Game1.activeClickableMenu = new DialogueBox("Your order has been placed! ^It will arrive tomorrow.");
                            }
                            else
                            {
                                Game1.player.Money        = Game1.player.Money - itemsInCart.Keys.Sum(i => i.Stack * itemsInCart[i][0]);
                                Game1.activeClickableMenu = new DialogueBox("Your order has been placed! ^It will arrive in 2 days.");
                            }

                            Game1.playSound("moneyDial");
                            Game1.dayTimeMoneyBox.moneyShakeTimer = 1000;
                        }
                        else
                        {
                            this.monitor.Log("Issue ordering items, failed to dispatch JojaMail!", LogLevel.Error);

                            // Display order error dialog
                            Game1.activeClickableMenu = new DialogueBox($"Order failed to place! Please try again later.");
                        }
                    }
                    else
                    {
                        // Shake money bag
                        Game1.dayTimeMoneyBox.moneyShakeTimer = 2000;
                        Game1.playSound("cancel");
                    }
                }

                return;
            }

            if (this.scrollBar.containsPoint(x, y))
            {
                this.scrolling = true;
            }
            else if (randomSaleButton.containsPoint(x, y))
            {
                // Move the forSaleButtons until the randomSaleItem is displayed
                for (this.currentItemIndex = 0; this.currentItemIndex < Math.Max(0, this.forSale.Count - buttonScrollingOffset); currentItemIndex++)
                {
                    bool matchedItem = false;

                    for (int i = 0; i < this.forSaleButtons.Count; i++)
                    {
                        int index = (this.currentItemIndex * 2) + i;

                        if (this.forSale[index] == randomSaleItem)
                        {
                            matchedItem = true;
                            break;
                        }
                    }

                    if (matchedItem)
                    {
                        break;
                    }
                }

                this.setScrollBarToCurrentIndex();
                this.updateSaleButtonNeighbors();
            }
            else if ((checkoutButton.containsPoint(x, y) || cartQuantity.containsPoint(x, y)) && itemsInCart.Count > 0)
            {
                this.monitor.Log("Starting checkout...");
                isCheckingOut = true;
            }
            else
            {
                for (int i = 0; i < this.forSaleButtons.Count; i++)
                {
                    if ((this.currentItemIndex * 2) + i >= this.forSale.Count || !this.forSaleButtons[i].containsPoint(x, y))
                    {
                        continue;
                    }

                    int index = (this.currentItemIndex * 2) + i;
                    if (this.forSale[index] != null)
                    {
                        // Skip if we're at max for the cart size
                        if (itemsInCart.Count >= maxUniqueCartItems && !itemsInCart.ContainsKey(this.forSale[index]))
                        {
                            continue;
                        }

                        // DEBUG: monitor.Log($"{index} | {this.forSale[index].Name}");
                        int toBuy = (!Game1.oldKBState.IsKeyDown(Keys.LeftShift)) ? 1 : 5;
                        toBuy = Math.Min(toBuy, this.forSale[index].maximumStackSize());

                        // Skip if we're trying to buy more then what we can in a stack via mail
                        if (itemsInCart.ContainsKey(this.forSale[index]) && (itemsInCart[this.forSale[index]][1] >= this.forSale[index].maximumStackSize() || itemsInCart[this.forSale[index]][1] + toBuy > this.forSale[index].maximumStackSize()))
                        {
                            continue;
                        }

                        if (this.tryToPurchaseItem(this.forSale[index], toBuy, x, y, index))
                        {
                            DelayedAction.playSoundAfterDelay("coin", 100);
                        }
                        else
                        {
                            Game1.dayTimeMoneyBox.moneyShakeTimer = 1000;
                            Game1.playSound("cancel");
                        }
                    }

                    this.updateSaleButtonNeighbors();
                    this.setScrollBarToCurrentIndex();
                    return;
                }
            }
        }
Ejemplo n.º 2
0
 private void OnSaved(object sender, SavedEventArgs e)
 {
     JojaMail.ProcessPlayerMailbox();
     this.Monitor.Log($"Processed player's mailbox to check for any scheduled JojaMail orders.");
 }