Example #1
0
 private DeliveryChest GetDeliveryChestFromMessage(SerializableChestLocation message)
 {
     foreach (GameLocation location in LocationHelper.GetAccessibleLocations())
     {
         if (location.NameOrUniqueName == message.Location)
         {
             Item item;
             if (message.isFridge)
             {
                 if (location is FarmHouse house && Game1.player.HouseUpgradeLevel > 0)
                 {
                     item = house.fridge.Value;
                 }
                 else
                 {
                     break;
                 }
             }
             else
             {
                 item = location.getObjectAtTile(message.X, message.Y);
             }
             if (item != null && item is Chest chest)
             {
                 DeliveryChest dchest;
                 if (DeliveryChests.TryGetValue(chest, out dchest))
                 {
                     return(dchest);
                 }
                 dchest = new DeliveryChest(chest);
                 DeliveryChests[chest] = dchest;
                 return(dchest);
             }
         }
     }
Example #2
0
 private void OnModMessageReceived(object sender, ModMessageReceivedEventArgs e)
 {
     //Monitor.Log($"Got message: {e.Type}", LogLevel.Debug);
     if (e.FromModID != this.ModManifest.UniqueID)
     {
         return;
     }
     if (e.Type == "UpdateDeliveryOptions")
     {
         SyncDataModel message = e.ReadAs <SyncDataModel>();
         DeliveryChest dchest  = GetDeliveryChestFromMessage(message);
         if (dchest != null)
         {
             //Monitor.Log($"Send:{string.Join(", ", message.DeliveryOptions.Send)}", LogLevel.Debug);
             dchest.DeliveryOptions.Set(message.DeliveryOptions);
             if (this.CurrentOverlay != null)
             {
                 this.CurrentOverlay.ResetEdit();
             }
         }
     }
     else if (e.Type == "RequestDeliveryOptions")
     {
         SerializableChestLocation message = e.ReadAs <SerializableChestLocation>();
         DeliveryChest             dchest  = GetDeliveryChestFromMessage(message);
         if (dchest != null)
         {
             Helper.Multiplayer.SendMessage(new SyncDataModel(dchest), "UpdateDeliveryOptions", modIDs: new[] { e.FromModID }, playerIDs: new[] { e.FromPlayerID });
         }
     }
 }