/// <summary>
        /// Handles the event raised after items are changed or removed from the Farmer's inventory
        /// </summary>
        /// <param name="sender">The sender of the InventoryChanged event</param>
        /// <param name="args">Event arguments for the InventoryChanged event</param>
        public void OnInventoryChanged(object sender, InventoryChangedEventArgs args)
        {
            // Short circuit if the pockey money hasn't increased
            if (Game1.player.Money <= PersistantFarmerData.PocketMoney)
            {
                return;
            }

            // Calculate all money gained from removed items or items that decreased their stack size
            int totalNewMoney = 0;

            totalNewMoney += ItemValueUtil.CalculateItemCollectionValue(args.Removed, false);
            totalNewMoney += ItemValueUtil.CalculateItemCollectionValue(args.QuantityChanged.Where(i => i.NewSize < i.OldSize), true);

            // Short circuit if the items removed don't have a value
            if (totalNewMoney == 0)
            {
                return;
            }

            // Get the share each player will receive
            int moneyPerPlayer = MoneySplitUtil.GetPerPlayerShare(totalNewMoney);

            // Correct the local player's money because they earned everyone's share
            MoneySplitUtil.CorrectLocalPlayer(totalNewMoney, moneyPerPlayer);

            // Tell all the other farmers to update their money too
            MoneyMessenger moneyMessenger = new MoneyMessenger();

            moneyMessenger.SendWalletNotification(moneyPerPlayer);
        }
Beispiel #2
0
        /// <summary>
        /// Calculates the shipping bin money before the day begins to end and
        /// sends the split share of that value after this function but before the day begins to end
        /// </summary>
        /// <param name="sender">The sender of the DayEndingEvent event</param>
        /// <param name="args">Event arguments for the DayEndingEvent event</param>
        public void OnDayEndingHandler(object sender, DayEndingEventArgs args)
        {
            EqualMoneyMod.Logger.Log($"DayEnding | {Game1.player.Name} has {Game1.player.Money} money");

            // Calculate all money that will be earned from the shipping bin
            PersistantFarmerData.ShippingBinMoney = ItemValueUtil.CalculateItemCollectionValue(Game1.player.personalShippingBin);
            PersistantFarmerData.ShareToSend      = MoneySplitUtil.GetPerPlayerShare(PersistantFarmerData.ShippingBinMoney);

            // Only send a notification if money has been earned
            if (PersistantFarmerData.ShareToSend != 0)
            {
                MoneyMessenger moneyMessenger = new MoneyMessenger();
                moneyMessenger.SendShippingBinNotification(PersistantFarmerData.ShareToSend);
            }
        }