Esempio n. 1
0
 public void ConvertFromVanillaMap()
 {
     foreach (GameLocation location in Game1.locations)
     {
         foreach (KeyValuePair <Vector2, SObject> obj in location.Objects.Pairs.ToList())
         {
             if (obj.Value is Fence && obj.Value.modData.ContainsKey("ItemPipes"))
             {
                 if (obj.Value.modData["Type"] != null)
                 {
                     CustomObjectItem customObj = ItemFactory.CreateObject(obj.Key, obj.Value.modData["Type"]);
                     customObj.Load(obj.Value.modData);
                     location.objects.Remove(obj.Key);
                     location.objects.Add(obj.Key, customObj);
                 }
             }
             if (obj.Value is Chest && (obj.Value as Chest).items.Any(i => i is Fence))
             {
                 for (int i = 0; i < (obj.Value as Chest).items.Count; i++)
                 {
                     if ((obj.Value as Chest).items[i] is Fence && (obj.Value as Chest).items[i].modData.ContainsKey("ItemPipes"))
                     {
                         Fence            tempObj   = (Fence)(obj.Value as Chest).items[i];
                         CustomObjectItem customObj = ItemFactory.CreateItem(tempObj.modData["Type"]);
                         (obj.Value as Chest).items.RemoveAt(i);
                         (obj.Value as Chest).items.Insert(i, customObj);
                     }
                     else if ((obj.Value as Chest).items[i] is Axe && (obj.Value as Chest).items[i].modData.ContainsKey("ItemPipes"))
                     {
                         Axe            tempTool  = (Axe)(obj.Value as Chest).items[i];
                         CustomToolItem customObj = ItemFactory.CreateTool(tempTool.modData["Type"]);
                         (obj.Value as Chest).items.RemoveAt(i);
                         (obj.Value as Chest).items.Insert(i, customObj);
                     }
                 }
             }
             if (obj.Value is Chest)
             {
                 NetworkManager.AddObject(obj, location);
             }
         }
     }
 }
Esempio n. 2
0
        private void OnObjectListChanged(object sender, ObjectListChangedEventArgs e)
        {
            List <KeyValuePair <Vector2, StardewValley.Object> > addedObjects = e.Added.ToList();

            foreach (KeyValuePair <Vector2, StardewValley.Object> obj in addedObjects)
            {
                if (obj.Value is CustomObjectItem || obj.Value is Chest)
                {
                    NetworkManager.AddObject(obj, e.Location);
                    NetworkManager.UpdateLocationNetworks(Game1.currentLocation);
                }
            }

            List <KeyValuePair <Vector2, StardewValley.Object> > removedObjects = e.Removed.ToList();

            foreach (KeyValuePair <Vector2, StardewValley.Object> obj in removedObjects)
            {
                if (obj.Value is CustomObjectItem || obj.Value is Chest)
                {
                    NetworkManager.RemoveObject(obj, e.Location);
                    NetworkManager.UpdateLocationNetworks(Game1.currentLocation);
                }
            }
        }