コード例 #1
0
        public static bool Prefix(StardewValley.Object __instance, GameLocation location, int x, int y, Farmer who, ref bool __result)
        {
            if (!__instance.bigCraftable.Value)
            {
                return(true);
            }
            var entry = Mod.entries.SingleOrDefault(cle => cle.Name == __instance.Name);

            if (entry == null)
            {
                return(true);
            }

            string placementSound = "hammer";

            Vector2 baseIndex = new Vector2(x / 64, y / 64);

            __instance.setHealth(10);
            if (who != null)
            {
                __instance.owner.Value = who.UniqueMultiplayerID;
            }
            else
            {
                __instance.owner.Value = Game1.player.UniqueMultiplayerID;
            }

            for (int ix = 0; ix < entry.Width; ++ix)
            {
                for (int iy = 0; iy < entry.Length; ++iy)
                {
                    Vector2 index = baseIndex + new Vector2(ix, iy);
                    if (location.objects.ContainsKey(index))
                    {
                        __result = false;
                        return(false);
                    }
                }
            }

            for (int ix = 0; ix < entry.Width; ++ix)
            {
                for (int iy = 0; iy < entry.Length; ++iy)
                {
                    int     iOffset = ix + (entry.Length - 1 - iy) * entry.Width;
                    Vector2 index   = baseIndex + new Vector2(ix, iy);
                    var     obj     = new StardewValley.Object(index, __instance.ParentSheetIndex);
                    obj.SetBiggerIndex(iOffset);
                    location.objects.Add(index, obj);
                }
            }

            location.playSound(placementSound);

            __result = true;
            return(false);
        }