Ejemplo n.º 1
0
        public static void LoadContentPacksCommand(string command = null, string[] args = null)
        {
            Dictionary <int, string> objects = DataLoader.Helper.Content.Load <Dictionary <int, string> >("Data\\ObjectInformation", ContentSource.GameContent);

            foreach (IContentPack contentPack in Helper.ContentPacks.GetOwned())
            {
                if (File.Exists(Path.Combine(contentPack.DirectoryPath, ClonersDataJson)))
                {
                    CustomCrystalariumModEntry.ModMonitor.Log($"Reading content pack: {contentPack.Manifest.Name} {contentPack.Manifest.Version} from {contentPack.DirectoryPath}");
                    List <CustomCloner> clonerData = contentPack.ReadJsonFile <List <CustomCloner> >(ClonersDataJson);
                    foreach (var cloner in clonerData)
                    {
                        if (String.IsNullOrEmpty(cloner.Name))
                        {
                            CustomCrystalariumModEntry.ModMonitor.Log($"The cloner name property can't be null or empty. This cloner will be ignored.", LogLevel.Warn);
                        }
                        if (cloner.Name == "Crystalarium")
                        {
                            cloner.CloningData.ToList().ForEach(d =>
                            {
                                int?id = GetId(d.Key, objects);
                                if (id.HasValue && !CrystalariumDataId.ContainsKey(id.Value))
                                {
                                    CrystalariumDataId[id.Value] = d.Value;
                                    CustomCrystalariumModEntry.ModMonitor.Log($"Adding crystalarium data for item '{d.Key}' from mod '{contentPack.Manifest.UniqueID}'.", LogLevel.Trace);
                                }
                            });
                        }
                        else
                        {
                            cloner.ModUniqueID = contentPack.Manifest.UniqueID;
                            if (ClonerController.GetCloner(cloner.Name) is CustomCloner currentCloner)
                            {
                                if (currentCloner.ModUniqueID != cloner.ModUniqueID)
                                {
                                    CustomCrystalariumModEntry.ModMonitor.Log($"Both mods '{currentCloner.ModUniqueID}' and '{cloner.ModUniqueID}' have data for  '{cloner.Name}'. You should report the problem to these mod's authors. Data from mod '{currentCloner.ModUniqueID}' will be used.", LogLevel.Warn);
                                    continue;
                                }
                            }
                            cloner.CloningData.ToList().ForEach(d =>
                            {
                                int?id = GetId(d.Key, objects);
                                if (id.HasValue)
                                {
                                    cloner.CloningDataId[id.Value] = d.Value;
                                }
                            });
                            ClonerController.SetCloner(cloner);
                        }
                    }
                }
                else
                {
                    CustomCrystalariumModEntry.ModMonitor.Log($"Ignoring content pack: {contentPack.Manifest.Name} {contentPack.Manifest.Version} from {contentPack.DirectoryPath}\nIt does not have an CaskData.json file.", LogLevel.Warn);
                }
            }
        }
Ejemplo n.º 2
0
 public static void CheckForAction_postfix(ref Object __instance, Object __state, bool justCheckingForActivity)
 {
     if (ClonerController.GetCloner(__instance.Name) is CustomCloner cloner && __instance.Name != "Crystalarium" && __state != null && !justCheckingForActivity)
     {
         __instance.MinutesUntilReady = ClonerController.GetMinutesUntilReady(cloner, __state) ?? __instance.MinutesUntilReady;
         if (__instance.MinutesUntilReady != 0)
         {
             __instance.heldObject.Value = (Object)__state.getOne();
             __instance.initializeLightSource(__instance.TileLocation, false);
         }
     }
 }
Ejemplo n.º 3
0
 public static bool PerformRemoveAction(ref Object __instance, ref Vector2 tileLocation)
 {
     if (__instance.Name == "Crystalarium")
     {
         if (DataLoader.ModConfig.GetObjectBackOnChange && !DataLoader.ModConfig.GetObjectBackImmediately)
         {
             if (__instance.heldObject.Value != null)
             {
                 Game1.createItemDebris(__instance.heldObject.Value.getOne(), tileLocation * 64f, (Game1.player.FacingDirection + 2) % 4, (GameLocation)null, -1);
             }
         }
     }
     else if (ClonerController.GetCloner(__instance.Name) is CustomCloner cloner)
     {
         if (DataLoader.ModConfig.OverrideContentPackGetObjectProperties ? DataLoader.ModConfig.GetObjectBackOnChange && !DataLoader.ModConfig.GetObjectBackImmediately : cloner.GetObjectBackOnChange && !cloner.GetObjectBackImmediately)
         {
             if (__instance.heldObject.Value != null)
             {
                 Game1.createItemDebris(__instance.heldObject.Value.getOne(), tileLocation * 64f, (Game1.player.FacingDirection + 2) % 4, (GameLocation)null, -1);
             }
         }
     }
     return(true);
 }
Ejemplo n.º 4
0
        public static bool PerformObjectDropInAction(ref Object __instance, ref Item dropInItem, ref bool probe, ref Farmer who, ref bool __result)
        {
            if (dropInItem is Object object1)
            {
                if (!(__instance.heldObject.Value != null && !__instance.Name.Equals("Recycling Machine") &&
                      !__instance.Name.Equals("Crystalarium") && !ClonerController.HasCloner(__instance.Name) || object1 != null && (bool)(object1.bigCraftable.Value)))
                {
                    if (__instance.Name.Equals("Crystalarium") || ClonerController.HasCloner(__instance.Name))
                    {
                        if ((__instance.heldObject.Value == null || __instance.heldObject.Value.ParentSheetIndex != object1.ParentSheetIndex) &&
                            (__instance.heldObject.Value == null || __instance.MinutesUntilReady > 0))
                        {
                            int minutesUntilReady = 0;

                            Item currentObject = __instance.heldObject.Value;

                            if (__instance.Name.Equals("Crystalarium"))
                            {
                                if (DataLoader.CrystalariumDataId.ContainsKey(object1.ParentSheetIndex))
                                {
                                    minutesUntilReady = DataLoader.CrystalariumDataId[object1.ParentSheetIndex];
                                }
                                else if (DataLoader.CrystalariumDataId.ContainsKey(object1.Category))
                                {
                                    minutesUntilReady = DataLoader.CrystalariumDataId[object1.Category];
                                }
                                else if ((object1.Category == -2 || object1.Category == -12) && object1.ParentSheetIndex != 74)
                                {
                                    minutesUntilReady = DataLoader.Helper.Reflection.GetMethod(__instance, "getMinutesForCrystalarium").Invoke <int>(object1.ParentSheetIndex);
                                }
                                else
                                {
                                    return(true);
                                }
                            }
                            else if (ClonerController.GetCloner(__instance.Name) is CustomCloner cloner)
                            {
                                if (cloner.UsePfmForInput)
                                {
                                    return(true);
                                }
                                var clonerMinutes = ClonerController.GetMinutesUntilReady(cloner, object1);
                                if (clonerMinutes.HasValue)
                                {
                                    minutesUntilReady = clonerMinutes.Value;
                                }
                                else
                                {
                                    return(true);
                                }
                            }
                            if (__instance.bigCraftable.Value && !probe &&
                                (object1 != null && __instance.heldObject.Value == null))
                            {
                                __instance.scale.X = 5f;
                            }
                            __instance.heldObject.Value = (Object)object1.getOne();
                            if (!probe)
                            {
                                who.currentLocation.playSound("select");
                                __instance.MinutesUntilReady = minutesUntilReady;
                                if (__instance.Name.Equals("Crystalarium") || DataLoader.ModConfig.OverrideContentPackGetObjectProperties ? DataLoader.ModConfig.GetObjectBackImmediately : ClonerController.GetCloner(__instance.Name).GetObjectBackImmediately)
                                {
                                    __instance.MinutesUntilReady = 0;
                                    __instance.minutesElapsed(0, who.currentLocation);
                                }
                                else if (currentObject != null && (__instance.Name.Equals("Crystalarium") || DataLoader.ModConfig.OverrideContentPackGetObjectProperties ? DataLoader.ModConfig.GetObjectBackOnChange : ClonerController.GetCloner(__instance.Name).GetObjectBackOnChange))
                                {
                                    who.addItemByMenuIfNecessary(currentObject.getOne());
                                }
                                __instance.initializeLightSource(__instance.TileLocation, false);
                            }
                            __result = true;
                            return(false);
                        }
                    }
                }
            }
            return(true);
        }