Exemplo n.º 1
0
 public static void checkDrawConditions(Map map)
 {
     foreach (Layer layer in map.Layers.Where(l => l.Properties.ContainsKey("DrawConditions")))
     {
         layer.Properties.AddOrReplace("DrawConditionsResult", PyUtils.checkEventConditions(layer.Properties["DrawConditions"], layer, Game1.currentLocation) ? "T" : "F");
     }
 }
Exemplo n.º 2
0
        private void harmonyFix()
        {
            HarmonyInstance instance = HarmonyInstance.Create("Platonymous.PyTK");

            OvSpritebatch.DrawFix1.init("SObject", PyUtils.getTypeSDV("Object"), new List <string>()
            {
                "draw", "drawInMenu", "drawWhenHeld", "drawAsProp"
            });
            instance.PatchAll(Assembly.GetExecutingAssembly());
        }
Exemplo n.º 3
0
 public static void adjustWarps(string name)
 {
     if (Game1.getLocationFromName(name) is GameLocation target)
     {
         foreach (var location in PyUtils.getWarpLocations(target))
         {
             PyUtils.adjustInboundWarps(location, target);
         }
     }
     else
     {
         Monitor.Log("Could not find Location: " + name);
     }
 }
Exemplo n.º 4
0
        private void harmonyFix()
        {
            HarmonyInstance instance = HarmonyInstance.Create("Platonymous.PyTK");

            PyUtils.initOverride("SObject", PyUtils.getTypeSDV("Object"), typeof(DrawFix1), new List <string>()
            {
                "draw", "drawInMenu", "drawWhenHeld", "drawAsProp"
            });
            PyUtils.initOverride("TemporaryAnimatedSprite", PyUtils.getTypeSDV("TemporaryAnimatedSprite"), typeof(DrawFix2), new List <string>()
            {
                "draw"
            });
            instance.PatchAll(Assembly.GetExecutingAssembly());
        }
Exemplo n.º 5
0
        private void Player_Warped(object sender, WarpedEventArgs e)
        {
            if (e.NewLocation.Map.Properties.ContainsKey("@WaterColor") && TMXColor.FromString(e.NewLocation.Map.Properties["@WaterColor"]) is TMXColor color)
            {
                e.NewLocation.waterColor.Value = new Color(color.R, color.G, color.B, color.A);
            }

            if (!e.IsLocalPlayer)
            {
                return;
            }

            e.NewLocation?.Map.enableMoreMapLayers();

            if (e.NewLocation is GameLocation g && g.map is Map m)
            {
                int forceX = Game1.player.getTileX();
                int forceY = Game1.player.getTileY();
                int forceF = Game1.player.FacingDirection;
                if (e.OldLocation is GameLocation og && m.Properties.ContainsKey("ForceEntry_" + og.Name))
                {
                    string[] pos = m.Properties["ForceEntry_" + og.Name].ToString().Split(' ');
                    if (pos.Length > 0 && pos[1] != "X")
                    {
                        int.TryParse(pos[0], out forceX);
                    }

                    if (pos.Length > 1 && pos[1] != "Y")
                    {
                        int.TryParse(pos[1], out forceY);
                    }

                    if (pos.Length > 2 && pos[2] != "F")
                    {
                        int.TryParse(pos[2], out forceF);
                    }

                    Game1.player.Position        = new Vector2(forceX, forceY);
                    Game1.player.FacingDirection = forceF;
                }

                if (m.Properties.ContainsKey("EntryAction"))
                {
                    TileAction.invokeCustomTileActions("EntryAction", g, Vector2.Zero, "Map");
                }

                PyUtils.checkDrawConditions(m);
            }
        }
Exemplo n.º 6
0
        private void registerConsoleCommands()
        {
            CcLocations.clearSpace().register();
            CcSaveHandler.cleanup().register();
            CcSaveHandler.savecheck().register();
            CcTime.skip().register();
            CcLua.runScript().register();

            new ConsoleCommand("adjustWarps", "", (s, p) =>
            {
                PyUtils.adjustWarps(p[0]);
            }).register();

            new ConsoleCommand("rebuild_objects", "", (s, e) =>
            {
                SaveHandler.RebuildAll(Game1.currentLocation.objects, Game1.currentLocation);
                SaveHandler.RebuildAll(Game1.currentLocation.terrainFeatures, Game1.currentLocation);
            }).register();

            new ConsoleCommand("allready", "confirms all players for the current readydialogue", (s, p) =>
            {
                if (!(Game1.activeClickableMenu is ReadyCheckDialog))
                {
                    Monitor.Log("No open ready check.", LogLevel.Alert);
                }
                else
                {
                    OvGame.allready = true;
                }
            }).register();

            new ConsoleCommand("send", "sends a message to all players: send [address] [message]", (s, p) =>
            {
                if (p.Length < 2)
                {
                    Monitor.Log("Missing address or message.", LogLevel.Alert);
                }
                else
                {
                    string address      = p[0];
                    List <string> parts = new List <string>(p);
                    parts.Remove(p[0]);
                    string message = String.Join(" ", p);
                    PyNet.sendMessage(address, message);
                    Monitor.Log("OK", LogLevel.Info);
                }
            }).register();

            new ConsoleCommand("messages", "lists all new messages on a specified address: messages [address]", (s, p) =>
            {
                if (p.Length == 0)
                {
                    Monitor.Log("Missing address", LogLevel.Alert);
                }
                else
                {
                    List <MPMessage> messages = PyNet.getNewMessages(p[0]).ToList();
                    foreach (MPMessage msg in messages)
                    {
                        Monitor.Log($"From {msg.sender.Name} : {msg.message}", LogLevel.Info);
                    }

                    Monitor.Log("OK", LogLevel.Info);
                }
            }).register();

            new ConsoleCommand("getstamina", "lists the current stamina values of all players", (s, p) =>
            {
                Monitor.Log(Game1.player.Name + ": " + Game1.player.Stamina, LogLevel.Info);
                foreach (Farmer farmer in Game1.otherFarmers.Values)
                {
                    PyNet.sendRequestToFarmer <int>("PytK.StaminaRequest", -1, farmer, (getStamina) => Monitor.Log(farmer.Name + ": " + getStamina, LogLevel.Info));
                }
            }).register();

            new ConsoleCommand("setstamina", "changes the stamina of all or a specific player. use: setstamina [playername or all] [stamina]", (s, p) =>
            {
                if (p.Length < 2)
                {
                    Monitor.Log("Missing parameter", LogLevel.Alert);
                }

                Monitor.Log(Game1.player.Name + ": " + Game1.player.Stamina, LogLevel.Info);
                Farmer farmer = null;

                farmer = Game1.otherFarmers.Find(k => k.Value.Name.Equals(p[0])).Value;


                if (farmer == null)
                {
                    Monitor.Log("Couldn't find Farmer", LogLevel.Alert);
                    return;
                }

                int i = -1;
                int.TryParse(p[1], out i);

                PyNet.sendRequestToFarmer <int>("PytK.StaminaRequest", i, farmer, (setStamina) => Monitor.Log(farmer.Name + ": " + setStamina, LogLevel.Info));
            }).register();


            new ConsoleCommand("ping", "pings all other players", (s, p) =>
            {
                foreach (Farmer farmer in Game1.otherFarmers.Values)
                {
                    long t = Game1.currentGameTime.TotalGameTime.Milliseconds;
                    PyNet.sendRequestToFarmer <bool>("PytK.Ping", t, farmer, (ping) =>
                    {
                        long r = Game1.currentGameTime.TotalGameTime.Milliseconds;
                        if (ping)
                        {
                            Monitor.Log(farmer.Name + ": " + (r - t) + "ms", LogLevel.Info);
                        }
                        else
                        {
                            Monitor.Log(farmer.Name + ": No Answer", LogLevel.Error);
                        }
                    });
                }
            }).register();

            new ConsoleCommand("syncmap", "Syncs map of a specified location to all clients. Exp.: syncmap Farm, syncmap BusStop, syncmao Town", (s, p) =>
            {
                if (p.Length < 1)
                {
                    Monitor.Log("No Location specified. ");
                }

                PyNet.syncLocationMapToAll(p[0]);
            }).register();
        }
Exemplo n.º 7
0
        private void registerCPTokens()
        {
            if (!Helper.ModRegistry.IsLoaded("Pathoschild.ContentPatcher"))
            {
                return;
            }

            IContentPatcherAPI api = Helper.ModRegistry.GetApi <IContentPatcherAPI>("Pathoschild.ContentPatcher");

            /*
             * api.RegisterToken(this.ModManifest, "LuaString", () =>
             * {
             *  foreach (string k in tokenStrings.Keys)
             *      if (tokenStrings[k] != PyUtils.getLuaString(k))
             *          return true;
             *
             *  return false;
             * }, () => Context.IsWorldReady, (s) =>
             * {
             *  tokenStrings.AddOrReplace(s, PyUtils.getLuaString(s));
             *  return new string[] { tokenStrings[s] };
             * }, true, true);*/

            api.RegisterToken(this.ModManifest, "Conditional", () =>
            {
                foreach (string k in tokenBoleans.Keys)
                {
                    if (tokenBoleans[k] != PyUtils.checkEventConditions(k.Split(new[] { " >: " }, StringSplitOptions.RemoveEmptyEntries)[0]))
                    {
                        return(true);
                    }
                }

                return(false);
            }, () => Context.IsWorldReady, (s) =>
            {
                string[] parts = s.Split(new [] { " >: " }, StringSplitOptions.RemoveEmptyEntries);

                if (parts.Length < 2)
                {
                    return(null);
                }

                tokenBoleans.AddOrReplace(s, PyUtils.checkEventConditions(parts[0]));
                return(new string[] { tokenBoleans[s] ? parts[1] : parts.Length < 3 ? null : parts[2] });
            }, true, true);

            api.RegisterToken(
                mod: this.ModManifest,
                name: "ObjectByName",
                updateContext: () =>
            {
                if (!PyTK.PyTKMod.UpdateCustomObjects)
                {
                    return(false);
                }

                UpdateCustomObjects = false;
                return(true);
            },
                isReady: () => Context.IsWorldReady,
                getValue: GetObjectByNameTokenValue,
                allowsInput: true,
                requiresInput: true
                );

            api.RegisterToken(
                mod: this.ModManifest,
                name: "LuaString",
                updateContext: () =>
            {
                if (!UpdateLuaTokens)
                {
                    return(false);
                }

                UpdateLuaTokens = false;
                return(true);
            },
                isReady: () => Context.IsWorldReady,
                getValue: GetLuaString,
                allowsInput: true,
                requiresInput: true
                );
        }
Exemplo n.º 8
0
        public override void Entry(IModHelper helper)
        {
            _instance = this;
            PostSerializer.Add(ModManifest, Rebuilder);
            PreSerializer.Add(ModManifest, Replacer);
            harmonyFix();

            FormatManager.Instance.RegisterMapFormat(new TMXTile.TMXFormat(Game1.tileSize / Game1.pixelZoom, Game1.tileSize / Game1.pixelZoom, Game1.pixelZoom, Game1.pixelZoom));

            initializeResponders();
            startResponder();
            registerConsoleCommands();
            CustomTVMod.load();
            PyLua.init();
            registerTileActions();
            registerEventPreconditions();
            SaveHandler.setUpEventHandlers();
            CustomObjectData.CODSyncer.start();
            ContentSync.ContentSyncHandler.initialize();

            helper.Events.GameLoop.DayStarted += (s, e) =>
            {
                if (ReInjectCustomObjects)
                {
                    ReInjectCustomObjects = false;
                    CustomObjectData.injector.Invalidate();
                    CustomObjectData.injectorBig.Invalidate();
                }
            };

            this.Helper.Events.Player.Warped                   += Player_Warped;
            this.Helper.Events.GameLoop.DayStarted             += OnDayStarted;
            this.Helper.Events.Multiplayer.PeerContextReceived += (s, e) =>
            {
                if (Game1.IsMasterGame && Game1.IsServer)
                {
                    if (CustomObjectData.collection.Values.Count > 0)
                    {
                        List <CODSync> list = new List <CODSync>();
                        foreach (CustomObjectData data in CustomObjectData.collection.Values)
                        {
                            list.Add(new CODSync(data.id, data.sdvId));
                        }

                        PyNet.sendDataToFarmer(CustomObjectData.CODSyncerName, new CODSyncMessage(list), e.Peer.PlayerID, SerializationType.JSON);
                    }

                    PyNet.sendDataToFarmer("PyTK.ModSavdDataReceiver", saveData, e.Peer.PlayerID, SerializationType.JSON);
                }
            };

            Helper.Events.Display.RenderingHud += (s, e) =>
            {
                if (Game1.displayHUD && Context.IsWorldReady)
                {
                    PyTK.PlatoUI.UIHelper.DrawHud(e.SpriteBatch, true);
                }
            };

            Helper.Events.Display.RenderedHud += (s, e) =>
            {
                if (Game1.displayHUD && Context.IsWorldReady)
                {
                    PyTK.PlatoUI.UIHelper.DrawHud(e.SpriteBatch, false);
                }
            };

            Helper.Events.Input.ButtonPressed += (s, e) =>
            {
                if (Game1.displayHUD && Context.IsWorldReady)
                {
                    if (e.Button == SButton.MouseLeft || e.Button == SButton.MouseRight)
                    {
                        PlatoUI.UIHelper.BaseHud.PerformClick(e.Cursor.ScreenPixels.toPoint(), e.Button == SButton.MouseRight, false, false);
                    }
                }
            };

            Helper.Events.Display.WindowResized += (s, e) =>
            {
                PlatoUI.UIElement.Viewportbase.UpdateBounds();
                PlatoUI.UIHelper.BaseHud.UpdateBounds();
            };

            Helper.Events.Multiplayer.ModMessageReceived += PyNet.Multiplayer_ModMessageReceived;
            helper.Events.GameLoop.Saving += (s, e) =>
            {
                if (Game1.IsMasterGame)
                {
                    try
                    {
                        helper.Data.WriteSaveData <PyTKSaveData>("PyTK.ModSaveData", saveData);
                    }
                    catch
                    {
                    }
                }
            };

            helper.Events.GameLoop.ReturnedToTitle += (s, e) =>
            {
                saveData = new PyTKSaveData();
            };

            helper.Events.GameLoop.SaveLoaded += (s, e) =>
            {
                if (Game1.IsMasterGame)
                {
                    try
                    {
                        saveData = helper.Data.ReadSaveData <PyTKSaveData>("PyTK.ModSaveData");
                    }
                    catch
                    {
                    }
                    if (saveData == null)
                    {
                        saveData = new PyTKSaveData();
                    }
                }
            };

            helper.Events.GameLoop.OneSecondUpdateTicked += (s, e) =>
            {
                if (Context.IsWorldReady && Game1.currentLocation is GameLocation location && location.Map is Map map)
                {
                    PyUtils.checkDrawConditions(map);
                }
            };


            helper.Events.GameLoop.GameLaunched += (s, e) =>
            {
                if (!Helper.ModRegistry.IsLoaded("spacechase0.GenericModConfigMenu"))
                {
                    return;
                }

                try
                {
                    registerCPTokens();
                }
                catch { }
            };

            helper.Events.GameLoop.DayStarted += (s, e) => UpdateLuaTokens = true;
        }
Exemplo n.º 9
0
        private void registerEventPreconditions()
        {
            PyUtils.addEventPrecondition("hasmod", (key, values, location) =>
            {
                string mod  = values.Replace("hasmod ", "").Replace(" ", "");
                bool result = LuaUtils.hasMod(mod);
                return(result);
            });

            PyUtils.addEventPrecondition("switch", (key, values, location) =>
            {
                return(LuaUtils.switches(values.Replace("switch ", "")));
            });

            PyUtils.addEventPrecondition("npcxy", (key, values, location) =>
            {
                var v    = values.Split(' ');
                var name = v[0];

                if (v.Length == 1)
                {
                    return(Game1.getCharacterFromName(name) is NPC npcp && npcp.currentLocation == location);
                }

                var x = int.Parse(v[1]);

                if (v.Length == 2)
                {
                    return(Game1.getCharacterFromName(name) is NPC npcx && npcx.currentLocation == location && npcx.getTileX() == x);
                }

                var y = int.Parse(v[2]);
                return(Game1.getCharacterFromName(name) is NPC npc && npc.currentLocation == location && (x == -1 || npc.getTileX() == x) && (y == -1 || npc.getTileY() == y));
            });

            PyUtils.addEventPrecondition("items", (key, values, location) =>
            {
                var v             = values.Split(',');
                List <Item> items = new List <Item>(Game1.player.Items);
                foreach (string pair in v)
                {
                    var p     = pair.Split(':');
                    var name  = p[0];
                    var stack = p.Length == 1 ? 1 : int.Parse(p[1]);
                    int count = 0;

                    foreach (Item item in items)
                    {
                        if (item.Name == name)
                        {
                            count += item.Stack;
                        }

                        if (count >= stack)
                        {
                            return(true);
                        }
                    }
                }

                return(false);
            });

            PyUtils.addEventPrecondition("counter", (key, values, location) =>
            {
                var v = values.Split(' ');
                var c = LuaUtils.counters(v[0]);

                if (v.Length == 2)
                {
                    return(c == int.Parse(v[1]));
                }
                else
                {
                    return(PyUtils.calcBoolean("c " + values, new KeyValuePair <string, object>("c", c)));
                }
            });

            PyUtils.addEventPrecondition("LC", (key, values, location) =>
            {
                return(PyUtils.checkEventConditions(values.Replace("%div", "/"), location, location));
            });
        }
Exemplo n.º 10
0
        public override void Entry(IModHelper helper)
        {
            _instance = this;

            if (xTile.Format.FormatManager.Instance.GetMapFormatByExtension("tmx") is TMXFormat tmxf)
            {
                tmxf.DrawImageLayer = PyMaps.drawImageLayer;
            }

            Game1.mapDisplayDevice = new PyDisplayDevice(Game1.content, Game1.graphics.GraphicsDevice);

            helper.Events.Display.RenderingWorld += (s, e) =>
            {
                if (Game1.currentLocation is GameLocation location && location.Map is Map map && map.GetBackgroundColor() is TMXColor tmxColor)
                {
                    Game1.graphics.GraphicsDevice.Clear(tmxColor.toColor());
                }
            };

            PostSerializer.Add(ModManifest, Rebuilder);
            PreSerializer.Add(ModManifest, Replacer);

            harmonyFix();

            initializeResponders();
            startResponder();
            registerConsoleCommands();
            CustomTVMod.load();
            PyLua.init();
            registerTileActions();
            registerEventPreconditions();
            SaveHandler.setUpEventHandlers();
            CustomObjectData.CODSyncer.start();
            ContentSync.ContentSyncHandler.initialize();

            helper.Events.GameLoop.DayStarted += (s, e) =>
            {
                if (ReInjectCustomObjects)
                {
                    ReInjectCustomObjects = false;
                    CustomObjectData.injector?.Invalidate();
                    CustomObjectData.injectorBig?.Invalidate();
                }
            };

            this.Helper.Events.Player.Warped                   += Player_Warped;
            this.Helper.Events.GameLoop.DayStarted             += OnDayStarted;
            this.Helper.Events.Multiplayer.PeerContextReceived += (s, e) =>
            {
                if (Game1.IsMasterGame && Game1.IsServer)
                {
                    if (CustomObjectData.collection.Values.Count > 0)
                    {
                        List <CODSync> list = new List <CODSync>();
                        foreach (CustomObjectData data in CustomObjectData.collection.Values)
                        {
                            list.Add(new CODSync(data.id, data.sdvId));
                        }

                        PyNet.sendDataToFarmer(CustomObjectData.CODSyncerName, new CODSyncMessage(list), e.Peer.PlayerID, SerializationType.JSON);
                    }

                    PyNet.sendDataToFarmer("PyTK.ModSavdDataReceiver", saveData, e.Peer.PlayerID, SerializationType.JSON);
                }
            };

            Helper.Events.Display.RenderingHud += (s, e) =>
            {
                if (Game1.displayHUD && Context.IsWorldReady)
                {
                    PyTK.PlatoUI.UIHelper.DrawHud(e.SpriteBatch, true);
                }
            };

            Helper.Events.Display.RenderedHud += (s, e) =>
            {
                if (Game1.displayHUD && Context.IsWorldReady)
                {
                    PyTK.PlatoUI.UIHelper.DrawHud(e.SpriteBatch, false);
                }
            };

            Helper.Events.Input.ButtonPressed += (s, e) =>
            {
                if (Game1.displayHUD && Context.IsWorldReady)
                {
                    if (e.Button == SButton.MouseLeft || e.Button == SButton.MouseRight)
                    {
                        PlatoUI.UIHelper.BaseHud.PerformClick(e.Cursor.ScreenPixels.toPoint(), e.Button == SButton.MouseRight, false, false);
                    }
                }
            };

            Helper.Events.Display.WindowResized += (s, e) =>
            {
                PlatoUI.UIElement.Viewportbase.UpdateBounds();
                PlatoUI.UIHelper.BaseHud.UpdateBounds();
            };

            Helper.Events.Multiplayer.ModMessageReceived += PyNet.Multiplayer_ModMessageReceived;
            helper.Events.GameLoop.Saving += (s, e) =>
            {
                if (Game1.IsMasterGame)
                {
                    try
                    {
                        helper.Data.WriteSaveData <PyTKSaveData>("PyTK.ModSaveData", saveData);
                    }
                    catch
                    {
                    }
                }
            };

            helper.Events.GameLoop.ReturnedToTitle += (s, e) =>
            {
                saveData = new PyTKSaveData();
            };

            helper.Events.GameLoop.SaveLoaded += (s, e) =>
            {
                CustomTVMod.reloadStrings();

                if (Game1.IsMasterGame)
                {
                    try
                    {
                        saveData = helper.Data.ReadSaveData <PyTKSaveData>("PyTK.ModSaveData");
                    }
                    catch
                    {
                    }
                    if (saveData == null)
                    {
                        saveData = new PyTKSaveData();
                    }
                }
            };

            helper.Events.GameLoop.OneSecondUpdateTicked += (s, e) =>
            {
                if (Context.IsWorldReady && Game1.currentLocation is GameLocation location && location.Map is Map map)
                {
                    PyUtils.checkDrawConditions(map);
                }
            };

            helper.Events.GameLoop.DayStarted += (s, e) =>
            {
                if (Game1.currentLocation is GameLocation loc)
                {
                    UpdateLuaTokens = true;
                }
            };

            helper.Events.GameLoop.UpdateTicked += (s, e) => AnimatedTexture2D.ticked = e.Ticks;
        }
Exemplo n.º 11
0
        public static Item getItem(string type, int index = -1, string name = "none")
        {
            Item item = null;

            if (type == "Object")
            {
                if (index != -1)
                {
                    item = new StardewValley.Object(index, 1);
                }
                else if (name != "none")
                {
                    item = new StardewValley.Object(Game1.objectInformation.getIndexByName(name), 1);
                }
            }
            else if (type == "BigObject")
            {
                if (index != -1)
                {
                    item = new StardewValley.Object(Vector2.Zero, index);
                }
                else if (name != "none")
                {
                    item = new StardewValley.Object(Vector2.Zero, Game1.bigCraftablesInformation.getIndexByName(name));
                }
            }
            else if (type == "Ring")
            {
                if (index != -1)
                {
                    item = new Ring(index);
                }
                else if (name != "none")
                {
                    item = new Ring(Game1.objectInformation.getIndexByName(name));
                }
            }
            else if (type == "Hat")
            {
                if (index != -1)
                {
                    item = new Hat(index);
                }
                else if (name != "none")
                {
                    item = new Hat(Helper.Content.Load <Dictionary <int, string> >(@"Data/hats", ContentSource.GameContent).getIndexByName(name));
                }
            }
            else if (type == "Boots")
            {
                if (index != -1)
                {
                    item = new Boots(index);
                }
                else if (name != "none")
                {
                    item = new Boots(Helper.Content.Load <Dictionary <int, string> >(@"Data/Boots", ContentSource.GameContent).getIndexByName(name));
                }
            }
            else if (type == "TV")
            {
                if (index != -1)
                {
                    item = new StardewValley.Objects.TV(index, Vector2.Zero);
                }
                else if (name != "none")
                {
                    item = new TV(Helper.Content.Load <Dictionary <int, string> >(@"Data/Furniture", ContentSource.GameContent).getIndexByName(name), Vector2.Zero);
                }
            }
            else if (type == "IndoorPot")
            {
                item = new StardewValley.Objects.IndoorPot(Vector2.Zero);
            }
            else if (type == "CrabPot")
            {
                item = new StardewValley.Objects.CrabPot(Vector2.Zero);
            }
            else if (type == "Chest")
            {
                item = new StardewValley.Objects.Chest(true);
            }
            else if (type == "Cask")
            {
                item = new StardewValley.Objects.Cask(Vector2.Zero);
            }
            else if (type == "Cask")
            {
                item = new StardewValley.Objects.Cask(Vector2.Zero);
            }
            else if (type == "Furniture")
            {
                if (index != -1)
                {
                    item = new StardewValley.Objects.Furniture(index, Vector2.Zero);
                }
                else if (name != "none")
                {
                    item = new Furniture(Helper.Content.Load <Dictionary <int, string> >(@"Data/Furniture", ContentSource.GameContent).getIndexByName(name), Vector2.Zero);
                }
            }
            else if (type == "Sign")
            {
                item = new StardewValley.Objects.Sign(Vector2.Zero, index);
            }
            else if (type == "Wallpaper")
            {
                item = new StardewValley.Objects.Wallpaper(Math.Abs(index), false);
            }
            else if (type == "Floors")
            {
                item = new StardewValley.Objects.Wallpaper(Math.Abs(index), true);
            }
            else if (type == "MeleeWeapon")
            {
                if (index != -1)
                {
                    item = new MeleeWeapon(index);
                }
                else if (name != "none")
                {
                    item = new MeleeWeapon(Helper.Content.Load <Dictionary <int, string> >(@"Data/weapons", ContentSource.GameContent).getIndexByName(name));
                }
            }
            else if (type == "CustomObject" && PyTK.CustomElementHandler.CustomObjectData.collection.ContainsKey(name))
            {
                item = PyTK.CustomElementHandler.CustomObjectData.collection[name].getObject();
            }
            else if (type == "SDVType")
            {
                try
                {
                    if (index == -1)
                    {
                        item = Activator.CreateInstance(PyUtils.getTypeSDV(name)) is Item i ? i : null;
                    }
                    else
                    {
                        item = Activator.CreateInstance(PyUtils.getTypeSDV(name), index) is Item i ? i : null;
                    }
                }
                catch (Exception ex)
                {
                    Monitor.Log(ex.Message + ":" + ex.StackTrace, LogLevel.Error);
                    Monitor.Log("Couldn't load item SDVType: " + name);
                }
            }
            else if (type == "ByType")
            {
                try
                {
                    if (index == -1)
                    {
                        item = Activator.CreateInstance(Type.GetType(name)) is Item i ? i : null;
                    }
                    else
                    {
                        item = Activator.CreateInstance(Type.GetType(name), index) is Item i ? i : null;
                    }
                }
                catch (Exception ex)
                {
                    Monitor.Log(ex.Message + ":" + ex.StackTrace, LogLevel.Error);
                    Monitor.Log("Couldn't load item ByType: " + name);
                }
            }

            return(item);
        }
Exemplo n.º 12
0
        public override void Entry(IModHelper helper)
        {
            _helper  = helper;
            _monitor = Monitor;

            harmonyFix();

            // Monitor.Log("Harmony Patching failed", LogLevel.Error);

            FormatManager.Instance.RegisterMapFormat(new NewTiledTmxFormat());

            SaveHandler.BeforeRebuilding += (a, b) => CustomObjectData.collection.useAll(k => k.Value.sdvId = k.Value.getNewSDVId());
            initializeResponders();
            startResponder();
            registerConsoleCommands();
            CustomTVMod.load();
            PyLua.init();
            registerTileActions();
            registerEventPreconditions();
            SaveHandler.setUpEventHandlers();
            CustomObjectData.CODSyncer.start();
            ContentSync.ContentSyncHandler.initialize();
            this.Helper.Events.Player.Warped                   += Player_Warped;
            this.Helper.Events.GameLoop.DayStarted             += OnDayStarted;
            this.Helper.Events.Multiplayer.PeerContextReceived += (s, e) =>
            {
                if (Game1.IsMasterGame && Game1.IsServer)
                {
                    if (CustomObjectData.collection.Values.Count > 0)
                    {
                        List <CODSync> list = new List <CODSync>();
                        foreach (CustomObjectData data in CustomObjectData.collection.Values)
                        {
                            list.Add(new CODSync(data.id, data.sdvId));
                        }

                        PyNet.sendDataToFarmer(CustomObjectData.CODSyncerName, new CODSyncMessage(list), e.Peer.PlayerID, SerializationType.JSON);
                    }

                    PyNet.sendDataToFarmer("PyTK.ModSavdDataReceiver", saveData, e.Peer.PlayerID, SerializationType.JSON);
                }
            };

            Helper.Events.Display.RenderingHud += (s, e) =>
            {
                if (Game1.displayHUD && Context.IsWorldReady)
                {
                    PyTK.PlatoUI.UIHelper.DrawHud(e.SpriteBatch, true);
                }
            };

            Helper.Events.Display.RenderedHud += (s, e) =>
            {
                if (Game1.displayHUD && Context.IsWorldReady)
                {
                    PyTK.PlatoUI.UIHelper.DrawHud(e.SpriteBatch, false);
                }
            };

            Helper.Events.Input.ButtonPressed += (s, e) =>
            {
                if (Game1.displayHUD && Context.IsWorldReady)
                {
                    if (e.Button == SButton.MouseLeft || e.Button == SButton.MouseRight)
                    {
                        PlatoUI.UIHelper.BaseHud.PerformClick(e.Cursor.ScreenPixels.toPoint(), e.Button == SButton.MouseRight, false, false);
                    }
                }
            };

            Helper.Events.Display.WindowResized += (s, e) =>
            {
                PlatoUI.UIElement.Viewportbase.UpdateBounds();
                PlatoUI.UIHelper.BaseHud.UpdateBounds();
            };

            Helper.Events.Multiplayer.ModMessageReceived += PyNet.Multiplayer_ModMessageReceived;
            helper.Events.GameLoop.Saving += (s, e) =>
            {
                if (Game1.IsMasterGame)
                {
                    try
                    {
                        helper.Data.WriteSaveData <PyTKSaveData>("PyTK.ModSaveData", saveData);
                    }
                    catch
                    {
                    }
                }
            };

            helper.Events.GameLoop.ReturnedToTitle += (s, e) =>
            {
                saveData = new PyTKSaveData();
            };

            helper.Events.GameLoop.SaveLoaded += (s, e) =>
            {
                if (Game1.IsMasterGame)
                {
                    try
                    {
                        saveData = helper.Data.ReadSaveData <PyTKSaveData>("PyTK.ModSaveData");
                    }
                    catch
                    {
                    }
                    if (saveData == null)
                    {
                        saveData = new PyTKSaveData();
                    }
                }
            };

            helper.Events.GameLoop.OneSecondUpdateTicked += (s, e) =>
            {
                if (Context.IsWorldReady && Game1.currentLocation is GameLocation location && location.Map is Map map)
                {
                    PyUtils.checkDrawConditions(map);
                }
            };
        }