Example #1
0
 private void OnMenuChanged(object sender, MenuChangedEventArgs e)
 {
     if (!DeliveryEnabled())
     {
         return;
     }
     // remove old overlay
     if (this.CurrentOverlay != null)
     {
         this.CurrentOverlay?.Dispose();
         this.CurrentOverlay = null;
     }
     this.Monitor.Log("New menu: " + e.NewMenu?.GetType(), LogLevel.Trace);
     if (e.NewMenu is ItemGrabMenu igm && igm.context is Chest container)
     {
         DeliveryChest chest;
         if (!this.DeliveryChests.TryGetValue(container, out chest))
         {
             chest = new DeliveryChest(container);
             if (chest.Location == null)
             {
                 Monitor.Log($"Failed to find chest location.  Can't deliver to chest {container.Name}", LogLevel.Warn);
                 return;
             }
             DeliveryChests[container] = chest;
             Monitor.Log($"Creating DeliveryChest {chest.Location}", LogLevel.Trace);
         }
         this.Monitor.Log($"Applying DeliveryOverlay to {chest.Location}", LogLevel.Trace);
         this.Monitor.Log($"Send: {string.Join(", ", chest.DeliveryOptions.Send)} Receive: {string.Join(", ", chest.DeliveryOptions.Receive)}", LogLevel.Trace);
         this.CurrentOverlay = new DeliveryOverlay(this.Monitor, igm, chest, this.Helper, this.ModManifest.UniqueID, this.HostID);
     }
 }
Example #2
0
        private void Load(object sender, SaveLoadedEventArgs e)
        {
            CurrentOverlay = null;
            DeliveryChests = new Dictionary <Chest, DeliveryChest>();
            HostID         = 0;
            if (DeliveryEnabled() && Config.WaitForWizardShop)
            {
                Game1.addMailForTomorrow("DeliveryServiceWizardMail");
            }

            if (!Context.IsMainPlayer)
            {
                // Farmhands don't maintain state
                foreach (IMultiplayerPeer peer in this.Helper.Multiplayer.GetConnectedPlayers())
                {
                    if (peer.HasSmapi && peer.IsHost)
                    {
                        HostID = peer.PlayerID;
                        break;
                    }
                }
                return;
            }
            List <SaveDataModel> save = Helper.Data.ReadSaveData <List <SaveDataModel> >("delivery-service");

            if (save == null)
            {
                return;
            }
            foreach (SaveDataModel data in save)
            {
                DeliveryChest dchest = GetDeliveryChestFromMessage(data);
                if (dchest != null)
                {
                    int[] send    = new int[Enum.GetValues(typeof(DeliveryCategories)).Length];
                    int[] receive = new int[Enum.GetValues(typeof(DeliveryCategories)).Length];
                    foreach (DeliveryCategories cat in Enum.GetValues(typeof(DeliveryCategories)))
                    {
                        send[(int)cat]    = CheckCategoryEnabledInSave(cat, data.Send);
                        receive[(int)cat] = CheckCategoryEnabledInSave(cat, data.Receive);
                    }
                    dchest.DeliveryOptions.Set(send, receive, data.MatchColor);
                }
            }
        }