Exemplo n.º 1
0
 private void Events_CallingTileActionShops(object sender, PlatoTK.Events.ICallingTileActionEventArgs e)
 {
     if (e.Trigger == "MapTKShop" && e.Parameter.Length > 0)
     {
         OpenMapTKShop(e.Parameter[0]);
     }
 }
Exemplo n.º 2
0
 private void Events_CallingTileActionLua(object sender, PlatoTK.Events.ICallingTileActionEventArgs e)
 {
     if (e.Trigger == "L#")
     {
         CallLua(e);
         e.TakeOver(true);
     }
 }
Exemplo n.º 3
0
 private void Events_CallingTileActionReloadMap(object sender, PlatoTK.Events.ICallingTileActionEventArgs e)
 {
     if (e.Trigger == "ReloadMap")
     {
         Plato.Utilities.ReloadMap(e.Location);
         e.TakeOver(true);
     }
 }
Exemplo n.º 4
0
        private void Events_CallingTileActionDropIn(object sender, PlatoTK.Events.ICallingTileActionEventArgs e)
        {
            Farmer       who      = e.Caller ?? Game1.player;
            GameLocation location = e.Location ?? Game1.currentLocation;

            if (e.Trigger == "DropIn" &&
                (who?.IsLocalPlayer ?? false))
            {
                if (who.ActiveObject is StardewValley.Object o)
                {
                    Func <StardewValley.Object, bool> validate;

                    int stack = 1;

                    if (int.TryParse(e.Parameter[0], out int s))
                    {
                        stack = s;
                    }

                    if (e.Parameter[1] == "L#")
                    {
                        validate = (obj) => (bool)CallLua(e, obj, 2).Globals["result"];
                    }
                    else
                    {
                        validate = (obj) => e.Parameter[1] == obj.Name ||
                                   (int.TryParse(e.Parameter[1], out int index) && (index == obj.ParentSheetIndex || obj.Category == index));
                    }

                    if (who.ActiveObject.Stack >= stack && validate(o))
                    {
                        who.ActiveObject.Stack -= s;
                        if (who.ActiveObject.Stack <= 0)
                        {
                            who.removeItemFromInventory(who.ActiveObject);
                            who.ActiveObject = null;

                            if (e.Tile != null && e.Tile.Properties.TryGetValue("@DropIn_Success", out PropertyValue value))
                            {
                                location?.performAction(value.ToString(), who, new xTile.Dimensions.Location(e.Position.X, e.Position.Y));
                            }
                        }
                        else if (e.Tile != null && e.Tile.Properties.TryGetValue("@DropIn_Failure", out PropertyValue value))
                        {
                            location?.performAction(value.ToString(), who, new xTile.Dimensions.Location(e.Position.X, e.Position.Y));
                        }
                    }
                }
                else if (e.Tile != null && e.Tile.Properties.TryGetValue("@DropIn_Default", out PropertyValue value))
                {
                    (e.Location ?? Game1.currentLocation).performAction(value.ToString(), who, new xTile.Dimensions.Location(e.Position.X, e.Position.Y));
                }
            }
        }
Exemplo n.º 5
0
        private MoonSharp.Interpreter.Script CallLua(PlatoTK.Events.ICallingTileActionEventArgs e, StardewValley.Object input = null, int skipParams = 0)
        {
            string[] parameter = e.Parameter.Skip(skipParams).ToArray();
            string   codeId    = parameter[0];
            Tile     tile      = e.Tile;
            string   code;
            string   function = null;

            if (codeId == "this")
            {
                string propertyId = parameter[1];
                code = tile.Properties[$"@Lua_{propertyId}"].ToString();


                if (parameter.Length > 2)
                {
                    function = parameter[2].ToString();
                }
                else
                {
                    code     = $"function callthis(location,tile,layer) {code} end";
                    function = "callthis";
                }
            }
            else
            {
                code = Plato.ModHelper.Content.Load <Dictionary <string, string> >(LuaScriptRepository, ContentSource.GameContent)[codeId];
                if (parameter.Length > 1)
                {
                    function = parameter[1];
                }
            }
            Dictionary <string, object> inputDict = null;

            if (input != null)
            {
                inputDict = new Dictionary <string, object>()
                {
                    { "input", input }
                }
            }
            ;

            var lua = Plato.Lua.LoadLuaCode(code, inputDict);

            if (!string.IsNullOrEmpty(function))
            {
                lua.Call(lua.Globals[function], e.Location, Utility.PointToVector2(e.Position), e.Layer.Id, e);
            }

            return(lua);
        }
    }
Exemplo n.º 6
0
 private void Events_CallingTileActionFlag(object sender, PlatoTK.Events.ICallingTileActionEventArgs e)
 {
     if (Game1.MasterPlayer is Farmer who)
     {
         if (e.Trigger == "SetFlag" && !who.hasOrWillReceiveMail(e.Parameter[0]))
         {
             who.mailReceived.Add(e.Parameter[0]);
         }
         else if (e.Trigger == "UnsetFlag" && who.hasOrWillReceiveMail(e.Parameter[0]))
         {
             who.mailReceived.Remove(e.Parameter[0]);
         }
     }
 }