コード例 #1
0
        public override void Entry(IModHelper helper)
        {
            ModHelper  = helper;
            ModMonitor = Monitor;
            //Unused MetaData information. Works in player inventory but not in chests. Besides who really care where an object is from anyways. Also doesn't work 100% like I intended since it only gets base mod object that this runs from, not extensions?

            //  StardewModdingAPI.Events.GraphicsEvents.OnPostRenderGuiEvent += Metadata.GameEvents_UpdateTick;
            //StardewModdingAPI.Events.ControlEvents.MouseChanged += ControlEvents_MouseChanged;
            string invPath   = Path.Combine(ModCore.ModHelper.DirectoryPath, "PlayerData", Game1.player.name, "PlayerInventory");
            string worldPath = Path.Combine(ModCore.ModHelper.DirectoryPath, Game1.player.name, "ObjectsInWorld");;
            string trashPath = Path.Combine(ModCore.ModHelper.DirectoryPath, "ModTrashFolder");
            string chestPath = Path.Combine(ModCore.ModHelper.DirectoryPath, "StorageContainers");

            SerializationManager = new SerializationManager(invPath, trashPath, worldPath, chestPath);

            StardewModdingAPI.Events.SaveEvents.AfterSave  += SaveEvents_AfterSave;
            StardewModdingAPI.Events.SaveEvents.BeforeSave += SaveEvents_BeforeSave;
            StardewModdingAPI.Events.SaveEvents.AfterLoad  += SaveEvents_AfterLoad;

            IlluminateFramework.Colors.initializeColors();
            ContentDirectory = Path.Combine(ModHelper.DirectoryPath, "Content");
            if (!Directory.Exists(ContentDirectory))
            {
                Directory.CreateDirectory(ContentDirectory);
            }
            UIUtilities.SpriteFonts.SpriteFont.initialize();
        }
コード例 #2
0
        private void SaveEvents_AfterLoad(object sender, EventArgs e)
        {
            Game1.game1.Disposed += Game1_Disposed;

            string basePath = Path.Combine(ModCore.ModHelper.DirectoryPath, "PlayerData", Game1.player.Name + "_" + Game1.player.uniqueMultiplayerID);

            string invPath   = Path.Combine(basePath, "PlayerInventory");
            string worldPath = Path.Combine(basePath, "ObjectsInWorld");
            string trashPath = Path.Combine(basePath, "ModTrashFolder");
            string chestPath = Path.Combine(basePath, "StorageContainers");

            SerializationManager = new SerializationManager(invPath, trashPath, worldPath, chestPath);
            SerializationManager.initializeDefaultSuportedTypes();

            SerializationManager.restoreAllModObjects(SerializationManager.trackedObjectList);

            List <long> playerIds = new List <long>();

            foreach (Farmer f in Game1.getOnlineFarmers())
            {
                if (f.uniqueMultiplayerID == Game1.player.uniqueMultiplayerID)
                {
                    continue;
                }
                playerIds.Add(f.uniqueMultiplayerID);
                ModMonitor.Log("Sending Message to peer ID: " + f.uniqueMultiplayerID.ToString());
            }
            //ModMonitor.Log("Send message to restore mod objects after load!");
            ModHelper.Multiplayer.SendMessage <string>(MultiplayerSupport.RestoreModObjects, MultiplayerSupport.RestoreModObjects, new string[] { ModManifest.UniqueID }, playerIds.ToArray());

            /*
             * List<KeyValuePair<Vector2, MultiTileComponent>> objs = new List<KeyValuePair<Vector2, MultiTileComponent>>();
             *
             * MultiTileComponent tile1 = new MultiTileComponent(0,"Tileobj1","A basic tile obj",new Texture2DExtended(ModCore.ModHelper,ModCore.Manifest ,Path.Combine("Content", "Graphics", "MultiTest", "Test1.png")));
             * MultiTileComponent tile2 = new MultiTileComponent(0,"Tileobj2", "A basic tile obj", new Texture2DExtended(ModCore.ModHelper, ModCore.Manifest, Path.Combine("Content", "Graphics", "MultiTest", "Test2.png")));
             * MultiTileComponent tile3 = new MultiTileComponent(0,"Tileobj3", "A basic tile obj", new Texture2DExtended(ModCore.ModHelper, ModCore.Manifest, Path.Combine("Content", "Graphics", "MultiTest", "Test3.png")));
             * objs.Add(new KeyValuePair<Vector2, MultiTileComponent>(new Vector2(0, 0), tile1));
             * objs.Add(new KeyValuePair<Vector2, MultiTileComponent>(new Vector2(1, 0), tile2));
             * objs.Add(new KeyValuePair<Vector2, MultiTileComponent>(new Vector2(2, 0), tile3));
             *
             * MultiTileObject collection= new MultiTileObject("MultiTest", "Trying to get multi object testing working", Vector2.Zero, new Texture2DExtended(ModCore.ModHelper, ModCore.Manifest, Path.Combine("Content", "Graphics", "MultiTest", "Test3.png")), objs, StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.LightColorsList.Purple), "MultiTest");
             *
             *
             * Game1.player.addItemToInventory(collection);
             */

            /*
             * CoreObject testTile = new CoreObject(new Texture2DExtended(ModCore.ModHelper,ModCore.Manifest, Path.Combine("Content", "Graphics", "MultiTest", "Test3.png")),3, Vector2.Zero,9);
             *
             * testTile.description = "Hello";
             * testTile.Name = "test";
             * testTile.displayName = "test";
             * Game1.player.addItemToInventory(testTile);
             */
        }
コード例 #3
0
 public static bool addItemToInventoryAndCleanTrackedList(CoreObject I, Serialization.SerializationManager s)
 {
     if (Game1.player.isInventoryFull() == false)
     {
         Game1.player.addItemToInventoryBool(I, false);
         s.trackedObjectList.Remove(I);
         return(true);
     }
     else
     {
         Random random = new Random(129);
         int    i      = random.Next();
         i = i % 4;
         Vector2 v2 = new Vector2(Game1.player.getTileX() * Game1.tileSize, Game1.player.getTileY() * Game1.tileSize);
         Game1.createItemDebris(I, v2, i);
         return(false);
     }
 }
コード例 #4
0
        public static bool placementAction(CoreObject cObj, GameLocation location, int x, int y, Serialization.SerializationManager s, StardewValley.Farmer who = null, bool playSound = true)
        {
            Vector2 vector = new Vector2((float)(x / Game1.tileSize), (float)(y / Game1.tileSize));

            //  cObj.health = 10;
            if (who != null)
            {
                cObj.owner = who.uniqueMultiplayerID;
            }
            else
            {
                cObj.owner = Game1.player.uniqueMultiplayerID;
            }

            if (!cObj.bigCraftable && !(cObj is Furniture))
            {
                int num = cObj.ParentSheetIndex;
                if (num <= 298)
                {
                    if (num > 94)
                    {
                        bool result;
                        switch (num)
                        {
                        case 286:
                        {
                            using (List <TemporaryAnimatedSprite> .Enumerator enumerator = Game1.currentLocation.temporarySprites.GetEnumerator())
                            {
                                while (enumerator.MoveNext())
                                {
                                    if (enumerator.Current.position.Equals(vector * (float)Game1.tileSize))
                                    {
                                        result = false;
                                        return(result);
                                    }
                                }
                            }
                            int num2 = Game1.random.Next();
                            Game1.playSound("thudStep");
                            Game1.currentLocation.TemporarySprites.Add(new TemporaryAnimatedSprite(cObj.parentSheetIndex, 100f, 1, 24, vector * (float)Game1.tileSize, true, false, Game1.currentLocation, who)
                                {
                                    shakeIntensity          = 0.5f,
                                    shakeIntensityChange    = 0.002f,
                                    extraInfoForEndBehavior = num2,
                                    endFunction             = new TemporaryAnimatedSprite.endBehavior(Game1.currentLocation.removeTemporarySpritesWithID)
                                });
                            Game1.currentLocation.TemporarySprites.Add(new TemporaryAnimatedSprite(Game1.mouseCursors, new Microsoft.Xna.Framework.Rectangle(598, 1279, 3, 4), 53f, 5, 9, vector * (float)Game1.tileSize + new Vector2(5f, 3f) * (float)Game1.pixelZoom, true, false, (float)(y + 7) / 10000f, 0f, Color.Yellow, (float)Game1.pixelZoom, 0f, 0f, 0f, false)
                                {
                                    id = (float)num2
                                });
                            Game1.currentLocation.TemporarySprites.Add(new TemporaryAnimatedSprite(Game1.mouseCursors, new Microsoft.Xna.Framework.Rectangle(598, 1279, 3, 4), 53f, 5, 9, vector * (float)Game1.tileSize + new Vector2(5f, 3f) * (float)Game1.pixelZoom, true, true, (float)(y + 7) / 10000f, 0f, Color.Orange, (float)Game1.pixelZoom, 0f, 0f, 0f, false)
                                {
                                    delayBeforeAnimationStart = 100,
                                    id = (float)num2
                                });
                            Game1.currentLocation.TemporarySprites.Add(new TemporaryAnimatedSprite(Game1.mouseCursors, new Microsoft.Xna.Framework.Rectangle(598, 1279, 3, 4), 53f, 5, 9, vector * (float)Game1.tileSize + new Vector2(5f, 3f) * (float)Game1.pixelZoom, true, false, (float)(y + 7) / 10000f, 0f, Color.White, (float)Game1.pixelZoom * 0.75f, 0f, 0f, 0f, false)
                                {
                                    delayBeforeAnimationStart = 200,
                                    id = (float)num2
                                });
                            if (Game1.fuseSound != null && !Game1.fuseSound.IsPlaying)
                            {
                                Game1.fuseSound = Game1.soundBank.GetCue("fuse");
                                Game1.fuseSound.Play();
                            }
                            return(true);
                        }

                        case 287:
                        {
                            using (List <TemporaryAnimatedSprite> .Enumerator enumerator = Game1.currentLocation.temporarySprites.GetEnumerator())
                            {
                                while (enumerator.MoveNext())
                                {
                                    if (enumerator.Current.position.Equals(vector * (float)Game1.tileSize))
                                    {
                                        result = false;
                                        return(result);
                                    }
                                }
                            }
                            int num2 = Game1.random.Next();
                            Game1.playSound("thudStep");
                            Game1.currentLocation.TemporarySprites.Add(new TemporaryAnimatedSprite(cObj.parentSheetIndex, 100f, 1, 24, vector * (float)Game1.tileSize, true, false, Game1.currentLocation, who)
                                {
                                    shakeIntensity          = 0.5f,
                                    shakeIntensityChange    = 0.002f,
                                    extraInfoForEndBehavior = num2,
                                    endFunction             = new TemporaryAnimatedSprite.endBehavior(Game1.currentLocation.removeTemporarySpritesWithID)
                                });
                            Game1.currentLocation.TemporarySprites.Add(new TemporaryAnimatedSprite(Game1.mouseCursors, new Microsoft.Xna.Framework.Rectangle(598, 1279, 3, 4), 53f, 5, 9, vector * (float)Game1.tileSize, true, false, (float)(y + 7) / 10000f, 0f, Color.Yellow, (float)Game1.pixelZoom, 0f, 0f, 0f, false)
                                {
                                    id = (float)num2
                                });
                            Game1.currentLocation.TemporarySprites.Add(new TemporaryAnimatedSprite(Game1.mouseCursors, new Microsoft.Xna.Framework.Rectangle(598, 1279, 3, 4), 53f, 5, 9, vector * (float)Game1.tileSize, true, false, (float)(y + 7) / 10000f, 0f, Color.Orange, (float)Game1.pixelZoom, 0f, 0f, 0f, false)
                                {
                                    delayBeforeAnimationStart = 100,
                                    id = (float)num2
                                });
                            Game1.currentLocation.TemporarySprites.Add(new TemporaryAnimatedSprite(Game1.mouseCursors, new Microsoft.Xna.Framework.Rectangle(598, 1279, 3, 4), 53f, 5, 9, vector * (float)Game1.tileSize, true, false, (float)(y + 7) / 10000f, 0f, Color.White, (float)Game1.pixelZoom * 0.75f, 0f, 0f, 0f, false)
                                {
                                    delayBeforeAnimationStart = 200,
                                    id = (float)num2
                                });
                            if (Game1.fuseSound != null && !Game1.fuseSound.IsPlaying)
                            {
                                Game1.fuseSound = Game1.soundBank.GetCue("fuse");
                                Game1.fuseSound.Play();
                            }
                            return(true);
                        }

                        case 288:
                        {
                            using (List <TemporaryAnimatedSprite> .Enumerator enumerator = Game1.currentLocation.temporarySprites.GetEnumerator())
                            {
                                while (enumerator.MoveNext())
                                {
                                    if (enumerator.Current.position.Equals(vector * (float)Game1.tileSize))
                                    {
                                        result = false;
                                        return(result);
                                    }
                                }
                            }
                            int num2 = Game1.random.Next();
                            Game1.playSound("thudStep");
                            Game1.currentLocation.TemporarySprites.Add(new TemporaryAnimatedSprite(cObj.parentSheetIndex, 100f, 1, 24, vector * (float)Game1.tileSize, true, false, Game1.currentLocation, who)
                                {
                                    shakeIntensity          = 0.5f,
                                    shakeIntensityChange    = 0.002f,
                                    extraInfoForEndBehavior = num2,
                                    endFunction             = new TemporaryAnimatedSprite.endBehavior(Game1.currentLocation.removeTemporarySpritesWithID)
                                });
                            Game1.currentLocation.TemporarySprites.Add(new TemporaryAnimatedSprite(Game1.mouseCursors, new Microsoft.Xna.Framework.Rectangle(598, 1279, 3, 4), 53f, 5, 9, vector * (float)Game1.tileSize + new Vector2(5f, 0f) * (float)Game1.pixelZoom, true, false, (float)(y + 7) / 10000f, 0f, Color.Yellow, (float)Game1.pixelZoom, 0f, 0f, 0f, false)
                                {
                                    id = (float)num2
                                });
                            Game1.currentLocation.TemporarySprites.Add(new TemporaryAnimatedSprite(Game1.mouseCursors, new Microsoft.Xna.Framework.Rectangle(598, 1279, 3, 4), 53f, 5, 9, vector * (float)Game1.tileSize + new Vector2(5f, 0f) * (float)Game1.pixelZoom, true, true, (float)(y + 7) / 10000f, 0f, Color.Orange, (float)Game1.pixelZoom, 0f, 0f, 0f, false)
                                {
                                    delayBeforeAnimationStart = 100,
                                    id = (float)num2
                                });
                            Game1.currentLocation.TemporarySprites.Add(new TemporaryAnimatedSprite(Game1.mouseCursors, new Microsoft.Xna.Framework.Rectangle(598, 1279, 3, 4), 53f, 5, 9, vector * (float)Game1.tileSize + new Vector2(5f, 0f) * (float)Game1.pixelZoom, true, false, (float)(y + 7) / 10000f, 0f, Color.White, (float)Game1.pixelZoom * 0.75f, 0f, 0f, 0f, false)
                                {
                                    delayBeforeAnimationStart = 200,
                                    id = (float)num2
                                });
                            if (Game1.fuseSound != null && !Game1.fuseSound.IsPlaying)
                            {
                                Game1.fuseSound = Game1.soundBank.GetCue("fuse");
                                Game1.fuseSound.Play();
                            }
                            return(true);
                        }

                        default:
                            if (num != 297)
                            {
                                if (num != 298)
                                {
                                    goto IL_FD7;
                                }
                                if (location.objects.ContainsKey(vector))
                                {
                                    return(false);
                                }
                                location.objects.Add(vector, new Fence(vector, 5, false));
                                Game1.playSound("axe");
                                return(true);
                            }
                            else
                            {
                                if (location.objects.ContainsKey(vector) || location.terrainFeatures.ContainsKey(vector))
                                {
                                    return(false);
                                }
                                location.terrainFeatures.Add(vector, new Grass(1, 4));
                                Game1.playSound("dirtyHit");
                                return(true);
                            }
                            break;
                        }
                        return(result);
                    }
                    if (num != 93)
                    {
                        if (num == 94)
                        {
                            if (location.objects.ContainsKey(vector))
                            {
                                return(false);
                            }
                            new Torch(vector, 1, 94).placementAction(location, x, y, who);
                            return(true);
                        }
                    }
                    else
                    {
                        if (location.objects.ContainsKey(vector))
                        {
                            return(false);
                        }
                        Utility.removeLightSource((int)(cObj.tileLocation.X * 2000f + cObj.tileLocation.Y));
                        Utility.removeLightSource((int)Game1.player.uniqueMultiplayerID);
                        new Torch(vector, 1).placementAction(location, x, y, (who == null) ? Game1.player : who);
                        return(true);
                    }
                }
                else if (num <= 401)
                {
                    switch (num)
                    {
                    case 309:
                    case 310:
                    case 311:
                    {
                        bool flag = location.terrainFeatures.ContainsKey(vector) && location.terrainFeatures[vector] is HoeDirt && (location.terrainFeatures[vector] as HoeDirt).crop == null;
                        if (!flag && (location.objects.ContainsKey(vector) || location.terrainFeatures.ContainsKey(vector) || (!(location is Farm) && !location.name.Contains("Greenhouse"))))
                        {
                            Game1.showRedMessage("Invalid Position");
                            return(false);
                        }
                        string text = location.doesTileHaveProperty(x, y, "NoSpawn", "Back");
                        if ((text == null || (!text.Equals("Tree") && !text.Equals("All"))) && (flag || (location.isTileLocationOpen(new Location(x * Game1.tileSize, y * Game1.tileSize)) && !location.isTileOccupied(new Vector2((float)x, (float)y), "") && location.doesTileHaveProperty(x, y, "Water", "Back") == null)))
                        {
                            int which = 1;
                            num = cObj.parentSheetIndex;
                            if (num != 310)
                            {
                                if (num == 311)
                                {
                                    which = 3;
                                }
                            }
                            else
                            {
                                which = 2;
                            }
                            location.terrainFeatures.Remove(vector);
                            location.terrainFeatures.Add(vector, new Tree(which, 0));
                            Game1.playSound("dirtyHit");
                            return(true);
                        }
                        break;
                    }

                    default:
                        switch (num)
                        {
                        case 322:
                            if (location.objects.ContainsKey(vector))
                            {
                                return(false);
                            }
                            location.objects.Add(vector, new Fence(vector, 1, false));
                            Game1.playSound("axe");
                            return(true);

                        case 323:
                            if (location.objects.ContainsKey(vector))
                            {
                                return(false);
                            }
                            location.objects.Add(vector, new Fence(vector, 2, false));
                            Game1.playSound("stoneStep");
                            return(true);

                        case 324:
                            if (location.objects.ContainsKey(vector))
                            {
                                return(false);
                            }
                            location.objects.Add(vector, new Fence(vector, 3, false));
                            Game1.playSound("hammer");
                            return(true);

                        case 325:
                            if (location.objects.ContainsKey(vector))
                            {
                                return(false);
                            }
                            location.objects.Add(vector, new Fence(vector, 4, true));
                            Game1.playSound("axe");
                            return(true);

                        case 326:
                        case 327:
                        case 330:
                        case 332:
                            break;

                        case 328:
                            if (location.terrainFeatures.ContainsKey(vector))
                            {
                                return(false);
                            }
                            location.terrainFeatures.Add(vector, new Flooring(0));
                            Game1.playSound("axchop");
                            return(true);

                        case 329:
                            if (location.terrainFeatures.ContainsKey(vector))
                            {
                                return(false);
                            }
                            location.terrainFeatures.Add(vector, new Flooring(1));
                            Game1.playSound("thudStep");
                            return(true);

                        case 331:
                            if (location.terrainFeatures.ContainsKey(vector))
                            {
                                return(false);
                            }
                            location.terrainFeatures.Add(vector, new Flooring(2));
                            Game1.playSound("axchop");
                            return(true);

                        case 333:
                            if (location.terrainFeatures.ContainsKey(vector))
                            {
                                return(false);
                            }
                            location.terrainFeatures.Add(vector, new Flooring(3));
                            Game1.playSound("thudStep");
                            return(true);

                        default:
                            if (num == 401)
                            {
                                if (location.terrainFeatures.ContainsKey(vector))
                                {
                                    return(false);
                                }
                                location.terrainFeatures.Add(vector, new Flooring(4));
                                Game1.playSound("thudStep");
                                return(true);
                            }
                            break;
                        }
                        break;
                    }
                }
                else
                {
                    switch (num)
                    {
                    case 405:
                        if (location.terrainFeatures.ContainsKey(vector))
                        {
                            return(false);
                        }
                        location.terrainFeatures.Add(vector, new Flooring(6));
                        Game1.playSound("woodyStep");
                        return(true);

                    case 406:
                    case 408:
                    case 410:
                        break;

                    case 407:
                        if (location.terrainFeatures.ContainsKey(vector))
                        {
                            return(false);
                        }
                        location.terrainFeatures.Add(vector, new Flooring(5));
                        Game1.playSound("dirtyHit");
                        return(true);

                    case 409:
                        if (location.terrainFeatures.ContainsKey(vector))
                        {
                            return(false);
                        }
                        location.terrainFeatures.Add(vector, new Flooring(7));
                        Game1.playSound("stoneStep");
                        return(true);

                    case 411:
                        if (location.terrainFeatures.ContainsKey(vector))
                        {
                            return(false);
                        }
                        location.terrainFeatures.Add(vector, new Flooring(8));
                        Game1.playSound("stoneStep");
                        return(true);

                    default:
                        if (num != 415)
                        {
                            if (num == 710)
                            {
                                if (location.objects.ContainsKey(vector) || location.doesTileHaveProperty((int)vector.X, (int)vector.Y, "Water", "Back") == null)
                                {
                                    return(false);
                                }
                                new CrabPot(vector, 1).placementAction(location, x, y, who);
                                return(true);
                            }
                        }
                        else
                        {
                            if (location.terrainFeatures.ContainsKey(vector))
                            {
                                return(false);
                            }
                            location.terrainFeatures.Add(vector, new Flooring(9));
                            Game1.playSound("stoneStep");
                            return(true);
                        }
                        break;
                    }
                }
            }
            else
            {
                int num = cObj.ParentSheetIndex;
                if (num <= 130)
                {
                    if (num == 71)
                    {
                        if (location is MineShaft)
                        {
                            if ((location as MineShaft).mineLevel != 120 && (location as MineShaft).recursiveTryToCreateLadderDown(vector, "hoeHit", 16))
                            {
                                return(true);
                            }
                            Game1.showRedMessage("Unsuitable Location");
                        }
                        return(false);
                    }
                    if (num == 130)
                    {
                        if (location.objects.ContainsKey(vector) || Game1.currentLocation is MineShaft)
                        {
                            Game1.showRedMessage("Unsuitable Location");
                            return(false);
                        }
                        location.objects.Add(vector, new Chest(true)
                        {
                            shakeTimer = 50
                        });
                        Game1.playSound("axe");
                        return(true);
                    }
                }
                else
                {
                    switch (num)
                    {
                    case 143:
                    case 144:
                    case 145:
                    case 146:
                    case 147:
                    case 148:
                    case 149:
                    case 150:
                    case 151:
                        if (location.objects.ContainsKey(vector))
                        {
                            return(false);
                        }
                        new Torch(vector, cObj.parentSheetIndex, true)
                        {
                            shakeTimer = 25
                        }.placementAction(location, x, y, who);
                        return(true);

                    default:
                        if (num == 163)
                        {
                            location.objects.Add(vector, new Cask(vector));
                            Game1.playSound("hammer");
                        }
                        break;
                    }
                }
            }
IL_FD7:
            if (cObj.name.Equals("Tapper"))
            {
                if (location.terrainFeatures.ContainsKey(vector) && location.terrainFeatures[vector] is Tree && (location.terrainFeatures[vector] as Tree).growthStage >= 5 && !(location.terrainFeatures[vector] as Tree).stump && !location.objects.ContainsKey(vector))
                {
                    cObj.tileLocation = vector;
                    location.objects.Add(vector, cObj);
                    int treeType = (location.terrainFeatures[vector] as Tree).treeType;
                    (location.terrainFeatures[vector] as Tree).tapped = true;
                    switch (treeType)
                    {
                    case 1:
                        cObj.heldObject        = new StardewValley.Object(725, 1, false, -1, 0);
                        cObj.minutesUntilReady = 13000 - Game1.timeOfDay;
                        break;

                    case 2:
                        cObj.heldObject        = new StardewValley.Object(724, 1, false, -1, 0);
                        cObj.minutesUntilReady = 16000 - Game1.timeOfDay;
                        break;

                    case 3:
                        cObj.heldObject        = new StardewValley.Object(726, 1, false, -1, 0);
                        cObj.minutesUntilReady = 10000 - Game1.timeOfDay;
                        break;

                    case 7:
                        cObj.heldObject        = new StardewValley.Object(420, 1, false, -1, 0);
                        cObj.minutesUntilReady = 3000 - Game1.timeOfDay;
                        if (!Game1.currentSeason.Equals("fall"))
                        {
                            cObj.heldObject        = new StardewValley.Object(404, 1, false, -1, 0);
                            cObj.minutesUntilReady = 6000 - Game1.timeOfDay;
                        }
                        break;
                    }
                    Game1.playSound("axe");
                    return(true);
                }
                return(false);
            }
            else if (cObj.name.Contains("Sapling"))
            {
                Vector2 key = default(Vector2);
                for (int i = x / Game1.tileSize - 2; i <= x / Game1.tileSize + 2; i++)
                {
                    for (int j = y / Game1.tileSize - 2; j <= y / Game1.tileSize + 2; j++)
                    {
                        key.X = (float)i;
                        key.Y = (float)j;
                        if (location.terrainFeatures.ContainsKey(key) && (location.terrainFeatures[key] is Tree || location.terrainFeatures[key] is FruitTree))
                        {
                            Game1.showRedMessage("Too close to another tree");
                            return(false);
                        }
                    }
                }
                if (location.terrainFeatures.ContainsKey(vector))
                {
                    if (!(location.terrainFeatures[vector] is HoeDirt) || (location.terrainFeatures[vector] as HoeDirt).crop != null)
                    {
                        return(false);
                    }
                    location.terrainFeatures.Remove(vector);
                }
                if (location is Farm && (location.doesTileHaveProperty((int)vector.X, (int)vector.Y, "Diggable", "Back") != null || location.doesTileHavePropertyNoNull((int)vector.X, (int)vector.Y, "Type", "Back").Equals("Grass")))
                {
                    Game1.playSound("dirtyHit");
                    DelayedAction.playSoundAfterDelay("coin", 100);
                    location.terrainFeatures.Add(vector, new FruitTree(cObj.parentSheetIndex));
                    return(true);
                }
                Game1.showRedMessage("Can't be planted here.");
                return(false);
            }
            else
            {
                //Game1.showRedMessage("STEP 1");

                if (cObj.category == -74)
                {
                    return(true);
                }
                if (!cObj.performDropDownAction(who))
                {
                    CoreObject @object = (CoreObject)cObj.getOne();
                    @object.shakeTimer   = 50;
                    @object.tileLocation = vector;
                    @object.performDropDownAction(who);
                    if (location.objects.ContainsKey(vector))
                    {
                        if (location.objects[vector].ParentSheetIndex != cObj.parentSheetIndex)
                        {
                            Game1.createItemDebris(location.objects[vector], vector * (float)Game1.tileSize, Game1.random.Next(4));
                            location.objects[vector] = @object;
                        }
                    }

                    else
                    {
                        //   Game1.showRedMessage("STEP 2");
                        //ModCore.ModMonitor.Log(vector.ToString());

                        Vector2 newVec = new Vector2(vector.X, vector.Y);
                        // cObj.boundingBox.Inflate(32, 32);
                        location.objects.Add(newVec, cObj);
                    }
                    @object.initializeLightSource(vector);
                }
                if (playSound == true)
                {
                    Game1.playSound("woodyStep");
                }
                else
                {
                    ModCore.ModMonitor.Log("restoring item from file");
                }
                //Log.AsyncM("Placed and object");
                cObj.locationsName = location.name;
                s.trackedObjectList.Add(cObj);
                return(true);
            }
        }
コード例 #5
0
        /// <summary>
        /// Place a core object into a game location.
        /// </summary>
        /// <param name="cObj"></param>
        /// <param name="location"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="s"></param>
        /// <param name="who"></param>
        /// <param name="playSound"></param>
        /// <returns></returns>
        public static bool placementAction(CoreObject cObj, GameLocation location, int x, int y, Serialization.SerializationManager s, StardewValley.Farmer who = null, bool playSound = true)
        {
            Vector2 vector = new Vector2((float)(x / Game1.tileSize), (float)(y / Game1.tileSize));

            //  cObj.health = 10;
            if (who != null)
            {
                if (cObj == null)
                {
                    StardustCore.ModCore.ModMonitor.Log("WHY IS MY COMPONENT NULL???");
                }
                cObj.owner.Value = who.UniqueMultiplayerID;
            }
            else
            {
                cObj.owner.Value = Game1.player.UniqueMultiplayerID;
            }

            int num = cObj.ParentSheetIndex;

            if (num <= 130)
            {
                if (num == 71)
                {
                    if (location is MineShaft)
                    {
                        if ((location as MineShaft).mineLevel != 120 && (location as MineShaft).recursiveTryToCreateLadderDown(vector, "hoeHit", 16))
                        {
                            return(true);
                        }
                        Game1.showRedMessage("Unsuitable Location");
                    }
                    return(false);
                }
                if (num == 130)
                {
                    if (location.objects.ContainsKey(vector) || Game1.currentLocation is MineShaft)
                    {
                        Game1.showRedMessage("Unsuitable Location");
                        return(false);
                    }
                    location.objects.Add(vector, new Chest(true)
                    {
                        shakeTimer = 50
                    });
                    Game1.playSound("axe");
                    return(true);
                }
            }
            else
            {
                switch (num)
                {
                case 143:
                case 144:
                case 145:
                case 146:
                case 147:
                case 148:
                case 149:
                case 150:
                case 151:
                    if (location.objects.ContainsKey(vector))
                    {
                        return(false);
                    }
                    new Torch(vector, cObj.ParentSheetIndex, true)
                    {
                        shakeTimer = 25
                    }.placementAction(location, x, y, who);
                    return(true);

                default:
                    if (num == 163)
                    {
                        location.objects.Add(vector, new Cask(vector));
                        Game1.playSound("hammer");
                    }
                    break;
                }
            }

            if (cObj.name.Equals("Tapper"))
            {
                if (location.terrainFeatures.ContainsKey(vector) && location.terrainFeatures[vector] is Tree && (location.terrainFeatures[vector] as Tree).growthStage.Value >= 5 && !(location.terrainFeatures[vector] as Tree).stump.Value && !location.objects.ContainsKey(vector))
                {
                    cObj.TileLocation = vector;
                    location.objects.Add(vector, cObj);
                    int treeType = (location.terrainFeatures[vector] as Tree).treeType.Value;
                    (location.terrainFeatures[vector] as Tree).tapped.Value = true;
                    switch (treeType)
                    {
                    case 1:
                        cObj.heldObject.Value  = new StardewValley.Object(725, 1, false, -1, 0);
                        cObj.MinutesUntilReady = 13000 - Game1.timeOfDay;
                        break;

                    case 2:
                        cObj.heldObject.Value  = new StardewValley.Object(724, 1, false, -1, 0);
                        cObj.MinutesUntilReady = 16000 - Game1.timeOfDay;
                        break;

                    case 3:
                        cObj.heldObject.Value  = new StardewValley.Object(726, 1, false, -1, 0);
                        cObj.MinutesUntilReady = 10000 - Game1.timeOfDay;
                        break;

                    case 7:
                        cObj.heldObject.Value  = new StardewValley.Object(420, 1, false, -1, 0);
                        cObj.MinutesUntilReady = 3000 - Game1.timeOfDay;
                        if (!Game1.currentSeason.Equals("fall"))
                        {
                            cObj.heldObject.Value  = new StardewValley.Object(404, 1, false, -1, 0);
                            cObj.MinutesUntilReady = 6000 - Game1.timeOfDay;
                        }
                        break;
                    }
                    Game1.playSound("axe");
                    return(true);
                }
                return(false);
            }
            else if (cObj.name.Contains("Sapling"))
            {
                Vector2 key = default(Vector2);
                for (int i = x / Game1.tileSize - 2; i <= x / Game1.tileSize + 2; i++)
                {
                    for (int j = y / Game1.tileSize - 2; j <= y / Game1.tileSize + 2; j++)
                    {
                        key.X = (float)i;
                        key.Y = (float)j;
                        if (location.terrainFeatures.ContainsKey(key) && (location.terrainFeatures[key] is Tree || location.terrainFeatures[key] is FruitTree))
                        {
                            Game1.showRedMessage("Too close to another tree");
                            return(false);
                        }
                    }
                }
                if (location.terrainFeatures.ContainsKey(vector))
                {
                    if (!(location.terrainFeatures[vector] is HoeDirt) || (location.terrainFeatures[vector] as HoeDirt).crop != null)
                    {
                        return(false);
                    }
                    location.terrainFeatures.Remove(vector);
                }
                if (location is Farm && (location.doesTileHaveProperty((int)vector.X, (int)vector.Y, "Diggable", "Back") != null || location.doesTileHavePropertyNoNull((int)vector.X, (int)vector.Y, "Type", "Back").Equals("Grass")))
                {
                    Game1.playSound("dirtyHit");
                    DelayedAction.playSoundAfterDelay("coin", 100);
                    location.terrainFeatures.Add(vector, new FruitTree(cObj.ParentSheetIndex));
                    return(true);
                }
                Game1.showRedMessage("Can't be planted here.");
                return(false);
            }
            else
            {
                //Game1.showRedMessage("STEP 1");

                if (cObj.Category == -74)
                {
                    return(true);
                }
                if (!cObj.performDropDownAction(who))
                {
                    CoreObject @object = cObj;
                    @object.shakeTimer   = 50;
                    @object.TileLocation = vector;
                    @object.performDropDownAction(who);
                    if (location.objects.ContainsKey(vector))
                    {
                        if (location.objects[vector].ParentSheetIndex != cObj.ParentSheetIndex)
                        {
                            Game1.createItemDebris(location.objects[vector], vector * (float)Game1.tileSize, Game1.random.Next(4));
                            location.objects[vector] = @object;
                        }
                    }

                    else
                    {
                        //   Game1.showRedMessage("STEP 2");
                        //ModCore.ModMonitor.Log(vector.ToString());

                        Vector2 newVec = new Vector2(vector.X, vector.Y);
                        // cObj.boundingBox.Inflate(32, 32);
                        location.objects.Add(newVec, cObj);
                    }
                    @object.initializeLightSource(vector);
                }
                if (playSound == true)
                {
                    Game1.playSound("woodyStep");
                }
                else
                {
                    ModCore.ModMonitor.Log("restoring item from file");
                }
                //Log.AsyncM("Placed and object");
                cObj.locationsName = location.Name;
                s.trackedObjectList.Add(cObj);
                return(true);
            }
        }