コード例 #1
0
        public override void drawInMenu(SpriteBatch spriteBatch, Vector2 location, float scaleSize, float transparency, float layerDepth, bool drawStackNumber)
        {
            if (Game1.player.items.Contains(this))
            {
                this.inList    = Game1.player.items;
                this.index     = Game1.player.items.FindIndex(x => x == this);
                this.inventory = true;
            }
            else
            {
                inventory = false;
                Dictionary <Vector2, StardewValley.Object> allObjects = Game1.currentLocation.objects;
                Vector2     check     = new Vector2(0, 0);
                Vector2     pPosition = new Vector2(Game1.player.getTileX(), Game1.player.getTileX());
                LinkedChest newChest  = new LinkedChest(true);

                for (float i = -1; i <= 1.0; i++)
                {
                    for (float j = -1; j <= 1.0; j++)
                    {
                        check = (new Vector2(i, j) + pPosition);
                        if (allObjects.ContainsKey(check) && allObjects[check] is Chest && (allObjects[check] as Chest).items.Contains(this))
                        {
                            this.inList = (allObjects[check] as Chest).items;
                            this.index  = this.inList.FindIndex(x => x == this);
                            if (allObjects[check] is LinkedChest)
                            {
                                this.linkedJunimo.targetChest = (LinkedChest)null;
                                this.removeObject();
                            }
                            else
                            {
                                this.tileLocation = allObjects[check].tileLocation;
                            }
                            break;
                        }
                    }
                }
            }

            base.drawInMenu(spriteBatch, location, scaleSize, transparency, layerDepth, drawStackNumber);
            if (this.objectID > 0)
            {
                this.quality = 2;
                float num = this.quality < 4 ? 0.0f : (float)((Math.Cos((double)Game1.currentGameTime.TotalGameTime.Milliseconds * Math.PI / 512.0) + 1.0) * 0.0500000007450581);
                spriteBatch.Draw(Game1.mouseCursors, location + new Vector2(12f, (float)(Game1.tileSize - 12) + num), new Microsoft.Xna.Framework.Rectangle?(this.quality < 4 ? new Microsoft.Xna.Framework.Rectangle(338 + (this.quality - 1) * 8, 400, 8, 8) : new Microsoft.Xna.Framework.Rectangle(346, 392, 8, 8)), this.playerChoiceColor * transparency, 0.0f, new Vector2(4f, 4f), (float)(3.0 * (double)scaleSize * (1.0 + (double)num)), SpriteEffects.None, layerDepth);
            }
        }
コード例 #2
0
        public void checkForChest()
        {
            if (this.targetChest == null && !this.onTracks)
            {
                Dictionary <Vector2, StardewValley.Object> allObjects = this.location.objects;
                Vector2     check     = new Vector2(0, 0);
                Vector2     pPosition = new Vector2(this.tileLocation.X, this.tileLocation.Y);
                LinkedChest newChest  = new LinkedChest(true);

                for (float i = -1; i <= 1.0; i++)
                {
                    if (this.targetChest != null)
                    {
                        break;
                    }
                    for (float j = -1; j <= 1.0; j++)
                    {
                        check = (new Vector2(i, j) + pPosition);
                        if (allObjects.ContainsKey(check) && allObjects[check] is Chest && (allObjects[check] as Chest).isEmpty() && !(allObjects[check] is LinkedChest))
                        {
                            newChest.items = (allObjects[check] as Chest).items;
                            allObjects.Remove(check);
                            allObjects.Add(check, newChest);
                            newChest.linkedJunimo      = this;
                            newChest.tileLocation      = check;
                            newChest.playerChoiceColor = this.color;
                            newChest.objectID          = LoadData.objectlist.Count();
                            this.targetChest           = newChest;
                            LoadData.objectlist.Add(newChest);
                            break;
                        }
                    }
                }
            }
            else if (this.targetChest != null)
            {
                this.targetChest.playerChoiceColor = this.color;
            }
        }
コード例 #3
0
ファイル: loadData.cs プロジェクト: sapid/Stardew-Valley-Mods
        public void LoadFromString(string savestring)
        {
            string[]    savedata = Regex.Split(savestring, "--");
            List <Item> itemList = new List <Item>();
            SerializableDictionary <Vector2, StardewValley.Object> objects = new SerializableDictionary <Vector2, StardewValley.Object>();

            for (int i = 1; i < savedata.Length; i++)
            {
                string[] entry = Regex.Split(savedata[i], ";;;");
                int      row   = (int)Math.Floor(craftables[2] / 24.0);
                int      col   = craftables[2] % 24;
                if (entry[0] == "Tracks")
                {
                    if (Game1.getLocationFromName(entry[1]).terrainFeatures.ContainsKey(new Vector2(int.Parse(entry[4]), int.Parse(entry[5]))))
                    {
                        Game1.getLocationFromName(entry[1]).terrainFeatures.Remove(new Vector2(int.Parse(entry[4]), int.Parse(entry[5])));
                    }
                    RailroadTrack rt = new RailroadTrack(row, col);
                    Game1.getLocationFromName(entry[1]).terrainFeatures.Add(new Vector2(int.Parse(entry[4]), int.Parse(entry[5])), rt);
                    LoadData.terrainFeatureList.Add(rt);
                    continue;
                }

                if (entry[3] != "-1")
                {
                    if (entry[1] == "Inventory")
                    {
                        itemList = Game1.player.items;
                    }
                    else if (entry[2] == "-1")
                    {
                        itemList = (Game1.getLocationFromName(entry[1]).objects[new Vector2(int.Parse(entry[4]), int.Parse(entry[4]))] as Chest).items;
                    }
                    else
                    {
                        itemList = ((Game1.getLocationFromName(entry[1]) as BuildableGameLocation).buildings[int.Parse(entry[2])].indoors.objects[new Vector2(int.Parse(entry[4]), int.Parse(entry[5]))] as Chest).items;
                    }

                    Item slot = itemList[int.Parse(entry[3])];

                    if (entry[0] == "CraftedTracks")
                    {
                        itemList[int.Parse(entry[3])] = new StardewValley.Object(craftables[0], slot.Stack);
                    }
                    else if (entry[0] == "CraftedJunimo")
                    {
                        itemList[int.Parse(entry[3])] = new StardewValley.Object(craftables[1], slot.Stack);
                    }
                    if (entry[0] == "LinkedChest")
                    {
                        LinkedChest newLinkedChest = new LinkedChest(Game1.getLocationFromName(entry[1]), true, true);
                        newLinkedChest.inList            = (slot as Chest).items;
                        newLinkedChest.index             = int.Parse(entry[3]);
                        newLinkedChest.location          = Game1.getLocationFromName(entry[1]);
                        newLinkedChest.building          = int.Parse(entry[2]);
                        newLinkedChest.tileLocation      = new Vector2(int.Parse(entry[4]), int.Parse(entry[5]));
                        newLinkedChest.playerChoiceColor = (slot as Chest).playerChoiceColor;
                        Item[] items = new Item[(slot as Chest).items.Count];
                        (slot as Chest).items.CopyTo(items);
                        newLinkedChest.items    = new List <Item>(items);
                        newLinkedChest.objectID = int.Parse(entry[6]);
                        if (int.Parse(entry[6]) > 0)
                        {
                            int findJunimo = objectlist.FindIndex(x => x is JunimoHelper && (x as JunimoHelper).objectID == int.Parse(entry[6]));
                            if (findJunimo >= 0)
                            {
                                newLinkedChest.linkedJunimo             = (JunimoHelper)objectlist[findJunimo];
                                newLinkedChest.linkedJunimo.targetChest = newLinkedChest;
                            }
                        }
                        itemList[int.Parse(entry[3])] = newLinkedChest;
                        objectlist.Add(newLinkedChest);
                    }
                }
                else
                {
                    if (entry[2] == "-1")
                    {
                        objects = Game1.getLocationFromName(entry[1]).objects;
                    }
                    else
                    {
                        objects = (Game1.getLocationFromName(entry[1]) as BuildableGameLocation).buildings[int.Parse(entry[2])].indoors.objects;
                    }

                    Chest slot = (Chest)objects[new Vector2(int.Parse(entry[4]), int.Parse(entry[5]))];

                    if (entry[0] == "LinkedChest")
                    {
                        LinkedChest newLinkedChest = new LinkedChest(Game1.getLocationFromName(entry[1]), false, true);
                        newLinkedChest.inventory = false;
                        newLinkedChest.index     = -1;
                        newLinkedChest.location  = Game1.getLocationFromName(entry[1]);
                        newLinkedChest.building  = int.Parse(entry[2]);
                        if (newLinkedChest.building > 0)
                        {
                            newLinkedChest.location = (Game1.getLocationFromName(entry[1]) as BuildableGameLocation).buildings[newLinkedChest.building].indoors;
                            newLinkedChest.bgl      = (BuildableGameLocation)Game1.getLocationFromName(entry[1]);
                        }

                        newLinkedChest.tileLocation      = new Vector2(int.Parse(entry[4]), int.Parse(entry[5]));
                        newLinkedChest.playerChoiceColor = (slot as Chest).playerChoiceColor;
                        Item[] items = new Item[(slot as Chest).items.Count];
                        (slot as Chest).items.CopyTo(items);
                        newLinkedChest.items    = new List <Item>(items);
                        newLinkedChest.objectID = int.Parse(entry[6]);
                        if (int.Parse(entry[6]) > 0)
                        {
                            int findJunimo = objectlist.FindIndex(x => x is JunimoHelper && (x as JunimoHelper).objectID == int.Parse(entry[6]));
                            if (findJunimo >= 0)
                            {
                                newLinkedChest.linkedJunimo             = (JunimoHelper)objectlist[findJunimo];
                                newLinkedChest.linkedJunimo.targetChest = newLinkedChest;
                            }
                        }
                        objects[new Vector2(int.Parse(entry[4]), int.Parse(entry[5]))] = newLinkedChest;
                        objectlist.Add(newLinkedChest);
                    }
                    else if (entry[0] == "JunimoHelper")
                    {
                        JunimoHelper newJunimo = new JunimoHelper(Game1.getLocationFromName(entry[1]), new Vector2(int.Parse(entry[4]), int.Parse(entry[5])), craftables[3], false);
                        newJunimo.color = (slot as Chest).playerChoiceColor;
                        newJunimo.index = -1;
                        if (entry.Length > 7)
                        {
                            newJunimo.direction = int.Parse(entry[7]);
                        }
                        newJunimo.location = Game1.getLocationFromName(entry[1]);
                        newJunimo.building = int.Parse(entry[2]);
                        if (newJunimo.building > 0)
                        {
                            newJunimo.location = (Game1.getLocationFromName(entry[1]) as BuildableGameLocation).buildings[newJunimo.building].indoors;
                            newJunimo.bgl      = (BuildableGameLocation)Game1.getLocationFromName(entry[1]);
                        }

                        newJunimo.tileLocation = new Vector2(int.Parse(entry[4]), int.Parse(entry[5]));
                        Item[] items = new Item[(slot as Chest).items.Count];
                        (slot as Chest).items.CopyTo(items);
                        newJunimo.itemChest.items = new List <Item>(items);
                        newJunimo.objectID        = int.Parse(entry[6]);

                        if (int.Parse(entry[6]) > 0)
                        {
                            int findChest = objectlist.FindIndex(x => x is LinkedChest && (x as LinkedChest).objectID == int.Parse(entry[6]));
                            if (findChest >= 0)
                            {
                                newJunimo.targetChest = (LinkedChest)objectlist[findChest];
                                newJunimo.targetChest.linkedJunimo = newJunimo;
                            }
                        }
                        objects[new Vector2(int.Parse(entry[4]), int.Parse(entry[5]))] = newJunimo;
                        objectlist.Add(newJunimo);
                    }
                }
            }
        }
コード例 #4
0
        private void transform()
        {
            GameLocation gl = Game1.currentLocation;

            List <Vector2> vl  = new List <Vector2>();
            List <Vector2> vl2 = new List <Vector2>();
            List <Vector2> vl3 = new List <Vector2>();
            List <Vector2> vl4 = new List <Vector2>();

            Dictionary <Vector2, StardewValley.Object> allObjects = gl.objects;

            List <Vector2> sVectors  = new List <Vector2>();
            Vector2        check     = new Vector2(0, 0);
            Vector2        pPosition = new Vector2(Game1.player.getTileLocation().X, Game1.player.getTileLocation().Y);

            for (float i = -3; i <= 3.0; i++)
            {
                for (float j = -3; j <= 3.0; j++)
                {
                    check = (new Vector2(i, j) + pPosition);
                    if (allObjects.ContainsKey(check) && allObjects[check].name == "Tracks")
                    {
                        vl.Add(check);
                    }
                    if (allObjects.ContainsKey(check) && allObjects[check].name == "Junimo Helper")
                    {
                        vl2.Add(check);
                    }

                    if (allObjects.ContainsKey(check) && allObjects[check] is Chest && (allObjects[check] as Chest).items.Count == 1 && !(allObjects[check] is LinkedChest) && (allObjects[check] as Chest).items.FindIndex(x => (x is StardewValley.Object) && x.Name == "Junimo Helper") >= 0)
                    {
                        vl4.Add(check);
                    }


                    if (allObjects.ContainsKey(check) && allObjects[check] is JunimoHelper)
                    {
                        if ((allObjects[check] as JunimoHelper).targetChest == null)
                        {
                            vl3.Add(check);
                        }
                    }
                }
            }


            for (int i = 0; i < vl4.Count; i++)
            {
                LinkedChest newChest = new LinkedChest(true);
                (allObjects[vl4[i]] as Chest).items.RemoveAt(0);
                allObjects.Remove(vl4[i]);
                allObjects.Add(vl4[i], newChest);
                newChest.tileLocation = vl4[i];
                newChest.linkedJunimo = null;
                newChest.objectID     = -1;
                LoadData.objectlist.Add(newChest);
                Game1.activeClickableMenu.exitThisMenu();
            }

            for (int i = 0; i < vl.Count; i++)
            {
                int row = (int)Math.Floor(this.textureOriginTracks / 24.0);
                int col = this.textureOriginTracks % 24;


                if (!gl.terrainFeatures.ContainsKey(vl[i]) && Game1.currentLocation.name == "Farm")
                {
                    TerrainFeature t = new RailroadTrack(row, col);
                    gl.terrainFeatures.Add(vl[i], t);
                    LoadData.terrainFeatureList.Add(t);
                }
                else
                {
                    Game1.player.addItemToInventory(gl.objects[vl[i]]);
                }
                gl.objects.Remove(vl[i]);
            }


            for (int i = 0; i < vl2.Count; i++)
            {
                gl.objects.Remove(vl2[i]);
                JunimoHelper junimo = new JunimoHelper(vl2[i], this.textureOriginHelper, false);
                gl.objects.Add(vl2[i], junimo);

                LoadData.objectlist.Add(junimo);
            }
            for (int i = 0; i < vl3.Count; i++)
            {
                (gl.objects[vl3[i]] as JunimoHelper).checkForChest();
            }
        }