Exemplo n.º 1
0
        private void registerTileActions()
        {
            TileAction Game = new TileAction("Game", (action, location, tile, layer) =>
            {
                List <string> text = action.Split(' ').ToList();
                text.RemoveAt(0);
                action = String.Join(" ", text);
                return(location.performAction(action, Game1.player, new Location((int)tile.X, (int)tile.Y)));
            }).register();

            TileAction Lua = new TileAction("Lua", (action, location, tile, layer) =>
            {
                string[] a = action.Split(' ');
                if (a.Length > 2)
                {
                    if (a[1] == "this")
                    {
                        string id = location.Name + "." + layer + "." + tile.Y + tile.Y;
                        if (!PyLua.hasScript(id))
                        {
                            if (layer == "Map")
                            {
                                if (location.map.Properties.ContainsKey("Lua"))
                                {
                                    PyLua.loadScriptFromString(@"
                                function callthis(location,tile,layer)
                                " + location.map.Properties["Lua"].ToString() + @"
                                end", id);
                                }
                                else
                                {
                                    PyLua.loadScriptFromString("Luau.log(\"Error: Could not find Lua property on Map.\")", id);
                                }
                            }
                            else
                            {
                                if (location.doesTileHaveProperty((int)tile.X, (int)tile.Y, "Lua", layer) is string lua)
                                {
                                    PyLua.loadScriptFromString(@"
                                function callthis(location,tile,layer)
                                " + lua + @"
                                end", id);
                                }
                                else
                                {
                                    PyLua.loadScriptFromString("Luau.log(\"Error: Could not find Lua property on Tile.\")", id);
                                }
                            }
                        }
                        PyLua.callFunction(id, "callthis", new object[] { location, tile, layer });
                    }
                    else
                    {
                        PyLua.callFunction(a[1], a[2], new object[] { location, tile, layer });
                    }
                }
                return(true);
            }).register();
        }
Exemplo n.º 2
0
 public static bool luaAction(string action, GameLocation location, Vector2 tile, string layer)
 {
     string[] a = action.Split(' ');
     if (a.Length > 2)
     {
         PyLua.callFunction(a[1], a[2], new object[] { location, tile, layer });
     }
     return(true);
 }
Exemplo n.º 3
0
        public static bool luaAction(string action, GameLocation location, Vector2 tile, string layer)
        {
            string[] a = action.Split(' ');
            if (a.Length > 2)
            {
                if (a[2] == "this")
                {
                    string id = location.Name + "." + layer + "." + tile.Y + tile.Y;
                    if (!PyLua.hasScript(id))
                    {
                        if (layer == "Map")
                        {
                            if (location.map.Properties.ContainsKey("Lua"))
                            {
                                PyLua.loadScriptFromString(location.map.Properties["Lua"].ToString(), id);
                            }
                            else
                            {
                                PyLua.loadScriptFromString("Luau.log(\"Error: Could not find Lua property on Map.\")", id);
                            }
                        }
                        else
                        {
                            if (location.doesTileHaveProperty((int)tile.X, (int)tile.Y, "Lua", layer) is string lua)
                            {
                                PyLua.loadScriptFromString(lua, id);
                            }
                            else
                            {
                                PyLua.loadScriptFromString("Luau.log(\"Error: Could not find Lua property on Tile.\")", id);
                            }
                        }
                    }

                    PyLua.callFunction(id, a[2], new object[] { location, tile, layer });
                }
                else
                {
                    PyLua.callFunction(a[1], a[2], new object[] { location, tile, layer });
                }
            }
            return(true);
        }
Exemplo n.º 4
0
 public void doMagic(bool playedToday)
 {
     PyLua.loadScriptFromFile(Path.Combine(helper.DirectoryPath, "Assets", "luamagic.lua"), "luaMagic");
     PyLua.callFunction("luaMagic", "doMagic", playedToday);
 }
Exemplo n.º 5
0
        private void registerTileActions()
        {
            TileAction CC = new TileAction("CC", (action, location, tile, layer) =>
            {
                List <string> text = action.Split(' ').ToList();
                string key         = text[1];
                text.RemoveAt(0);
                text.RemoveAt(0);
                action = String.Join(" ", text);
                if (key == "cs")
                {
                    action += ";";
                }
                Helper.ConsoleCommands.Trigger(key, action.Split(' '));
                return(true);
            }).register();

            TileAction Game = new TileAction("Game", (action, location, tile, layer) =>
            {
                List <string> text = action.Split(' ').ToList();
                text.RemoveAt(0);
                action = String.Join(" ", text);
                return(location.performAction(action, Game1.player, new xTile.Dimensions.Location((int)tile.X, (int)tile.Y)));
            }).register();

            TileAction Lua = new TileAction("Lua", (action, location, tile, layer) =>
            {
                string[] a = action.Split(' ');
                if (a.Length > 2)
                {
                    if (a[1] == "this")
                    {
                        string id = location.Name + "." + layer + "." + tile.Y + tile.Y;
                        if (!PyLua.hasScript(id))
                        {
                            if (layer == "Map")
                            {
                                if (location.map.Properties.ContainsKey("Lua_" + a[2]))
                                {
                                    string script = @"
                                function callthis(location,tile,layer)
                                " + location.map.Properties["Lua_" + a[2]].ToString() + @"
                                end";

                                    PyLua.loadScriptFromString(script, id);
                                }
                            }
                            else
                            {
                                if (location.doesTileHaveProperty((int)tile.X, (int)tile.Y, "Lua_" + a[2], layer) is string lua)
                                {
                                    PyLua.loadScriptFromString(@"
                                function callthis(location,tile,layer)
                                " + lua + @"
                                end", id);
                                }
                            }
                        }

                        if (PyLua.hasScript(id))
                        {
                            PyLua.callFunction(id, "callthis", new object[] { location, tile, layer });
                        }
                    }
                    else
                    {
                        PyLua.callFunction(a[1], a[2], new object[] { location, tile, layer });
                    }
                }
                return(true);
            }).register();
        }