コード例 #1
0
        /// <summary>Go through all the copiers and look for one that can do the right copy.</summary>
        private SObject Copy(SObject obj)
        {
            foreach (IObjectCopier copier in this.copiers)
            {
                if (copier.CanCopy(obj))
                {
                    this.Monitor.Log($"{obj.GetType().Name} was copied by {copier.GetType().Name}.", LogLevel.Trace);
                    return(copier.Copy(obj));
                }
            }

            this.Monitor.Log($"{obj.GetType().Name} was not copied.", LogLevel.Trace);
            return(obj);
        }
コード例 #2
0
ファイル: ItemSubject.cs プロジェクト: mit4web/StardewMods
        /// <summary>Get unfinished bundles which require this item.</summary>
        /// <param name="item">The item for which to find bundles.</param>
        private IEnumerable <BundleModel> GetUnfinishedBundles(SObject item)
        {
            // no bundles for Joja members
            if (Game1.player.hasOrWillReceiveMail(Constant.MailLetters.JojaMember))
            {
                yield break;
            }

            // get community center
            CommunityCenter communityCenter = Game1.locations.OfType <CommunityCenter>().First();

            if (communityCenter.areAllAreasComplete())
            {
                yield break;
            }

            // get bundles
            if (item.GetType() == typeof(SObject) && !item.bigCraftable.Value) // avoid false positives with hats, furniture, etc
            {
                foreach (BundleModel bundle in this.GameHelper.GetBundleData())
                {
                    // ignore completed bundle
                    if (communityCenter.isBundleComplete(bundle.ID))
                    {
                        continue;
                    }

                    bool isMissing = this.GetIngredientsFromBundle(bundle, item).Any(p => this.IsIngredientNeeded(bundle, p));
                    if (isMissing)
                    {
                        yield return(bundle);
                    }
                }
            }
        }
コード例 #3
0
        private void process()
        {
            if (!Multiplayer.locations.ContainsKey(location))
            {
                return;
            }
            LocationCache loc = Multiplayer.locations[location];

            Vector2 pos = new Vector2(posX, posY);

            if (!loc.loc.objects.ContainsKey(pos))
            {
                return;
            }
            Object obj = loc.loc.objects[pos];

            if (obj.GetType() != typeof(Fence))
            {
                return;
            }
            Fence fence = (Fence)obj;

            loc.ignoreUpdates  = true;
            fence.gatePosition = gatePos;
            loc.getMonitor <Fence>().recheck(pos);
            loc.ignoreUpdates = false;
        }
コード例 #4
0
        private bool handleInventoryRightClick()
        {
            // If interacting empty-handed with a loaded bomb, detach the seed.
            if (seed != null && Game1.player.CursorSlotItem == null)
            {
                Game1.player.CursorSlotItem = detach();
                return(true);
            }

            // If holding an object, that object must be a seed.
            SObject newSeed = Game1.player.CursorSlotItem as SObject;

            if (newSeed?.GetType() != typeof(SObject) ||
                newSeed.Category != SObject.SeedsCategory)
            {
                return(false);
            }

            // The seed must be a wild or flower seed.
            Crop testCrop = new (newSeed.ParentSheetIndex, 0, 0);

            if (testCrop.whichForageCrop.Value == 0)
            {
                SObject harvest = new (testCrop.indexOfHarvest.Value, 1);
                if (harvest.Category != SObject.flowersCategory)
                {
                    return(false);
                }
            }

            // Attach the new seed and detach any old seed.
            SObject oldSeed = detach(playSound: false);

            Game1.player.CursorSlotItem = attach(newSeed);
            if (oldSeed != null)
            {
                if (Game1.player.CursorSlotItem?.canStackWith(oldSeed) ?? false)
                {
                    Game1.player.CursorSlotItem.Stack += oldSeed.Stack;
                }
                else if (Game1.player.CursorSlotItem != null)
                {
                    Game1.player.addItemToInventory(oldSeed);
                }
                else
                {
                    Game1.player.CursorSlotItem = oldSeed;
                }
            }
            return(true);
        }
コード例 #5
0
        public ObjectUpdatePacket(GameLocation loc, Vector2 pos)
            : this()
        {
            location = Multiplayer.getUniqueLocationName(loc);;
            posX     = pos.X;
            posY     = pos.Y;

            Object obj = loc.objects[pos];

            if (obj != null && obj.GetType() == typeof(TYPE))
            {
                str = Util.serialize <TYPE>(obj as TYPE);
            }
        }
コード例 #6
0
        public FenceUpdatePacket(GameLocation loc, Vector2 pos)
            : this()
        {
            location = Multiplayer.getUniqueLocationName(loc);;
            posX     = pos.X;
            posY     = pos.Y;

            Object obj = loc.objects[pos];

            if (obj != null && obj.GetType() == typeof(Fence))
            {
                gatePos = (obj as Fence).gatePosition;
            }
        }
コード例 #7
0
        private bool IsRawCraftable(Object o)
        {
            if (!o.bigCraftable)
            {
                return(false);
            }
            var craftableID = o.ParentSheetIndex;

            Type type;

            if (_craftableTypeMap.TryGetValue(craftableID, out type))
            {
                return(o.GetType() != type);
            }

            DynamicTypeInfo dynamicTypeInfo;

            if (_dynamicCraftableTypeMap.TryGetValue(craftableID, out dynamicTypeInfo))
            {
                return(o.GetType() != dynamicTypeInfo.BaseType);
            }

            return(false);
        }
コード例 #8
0
ファイル: Light.cs プロジェクト: somnomania/smapi-mod-dump
 public override bool canBePlacedHere(GameLocation l, Vector2 tile)
 {
     if ((l is FarmHouse))
     {
         for (int i = 0; i < this.boundingBox.Width / Game1.tileSize; i++)
         {
             for (int j = 0; j < this.boundingBox.Height / Game1.tileSize; j++)
             {
                 Vector2 vector = tile * (float)Game1.tileSize + new Vector2((float)i, (float)j) * (float)Game1.tileSize;
                 vector.X += (float)(Game1.tileSize / 2);
                 vector.Y += (float)(Game1.tileSize / 2);
                 foreach (KeyValuePair <Vector2, StardewValley.Object> something in l.objects)
                 {
                     StardewValley.Object obj = something.Value;
                     if ((obj.GetType()).ToString().Contains("Light"))
                     {
                         Light current = (Light)obj;
                         if (current.Decoration_type == 11 && current.getBoundingBox(current.tileLocation).Contains((int)vector.X, (int)vector.Y) && current.heldObject == null && this.getTilesWide() == 1)
                         {
                             bool result = true;
                             return(result);
                         }
                         if ((current.Decoration_type != 12 || this.Decoration_type == 12) && current.getBoundingBox(current.tileLocation).Contains((int)vector.X, (int)vector.Y))
                         {
                             bool result = false;
                             return(result);
                         }
                     }
                 }
             }
         }
         return(base.canBePlacedHere(l, tile));
     }
     else
     {
         // Game1.showRedMessage("NOT FARMHOUSE");
         for (int i = 0; i < this.boundingBox.Width / Game1.tileSize; i++)
         {
             for (int j = 0; j < this.boundingBox.Height / Game1.tileSize; j++)
             {
                 Vector2 vector = tile * (float)Game1.tileSize + new Vector2((float)i, (float)j) * (float)Game1.tileSize;
                 vector.X += (float)(Game1.tileSize / 2);
                 vector.Y += (float)(Game1.tileSize / 2);
             }
         }
         return(Util.canBePlacedHere(this, l, tile));
     }
 }
コード例 #9
0
        private bool IsRawItem(Object o)
        {
            if (o.bigCraftable)
            {
                return(false);
            }
            var itemID = o.ParentSheetIndex;

            Type type;

            if (_itemTypeMap.TryGetValue(itemID, out type))
            {
                return(o.GetType() != type);
            }

            return(false);
        }
コード例 #10
0
        private bool handleInventoryRightClick()
        {
            // If interacting empty-handed with a loaded bomb, detach the seed.
            if (heldObject.Value != null &&
                Game1.player.CursorSlotItem == null)
            {
                Game1.player.CursorSlotItem = detach();
                return(true);
            }

            // If holding an object, that object must be a seed.
            SObject seed = Game1.player.CursorSlotItem as SObject;

            if (seed?.GetType() != typeof(SObject) ||
                seed.Category != SObject.SeedsCategory)
            {
                return(false);
            }

            // The seed must be a wild or flower seed.
            Crop testCrop = new Crop(seed.ParentSheetIndex, 0, 0);

            if (testCrop.whichForageCrop.Value == 0)
            {
                SObject harvest = new SObject(testCrop.indexOfHarvest.Value, 1);
                if (harvest.Category != SObject.flowersCategory)
                {
                    return(false);
                }
            }

            // Attach the new seed and detach any old seed.
            SObject oldSeed = null;

            if (heldObject.Value != null)
            {
                oldSeed = detach(false);
            }
            Game1.player.CursorSlotItem = attach(seed);
            if (oldSeed != null)
            {
                Game1.player.CursorSlotItem = oldSeed;
            }
            return(true);
        }
コード例 #11
0
        /// <summary>Get unfinished bundles which require this item.</summary>
        /// <param name="item">The item for which to find bundles.</param>
        private IEnumerable <BundleModel> GetUnfinishedBundles(SObject item)
        {
            // no bundles for Joja members
            if (Game1.player.hasOrWillReceiveMail(Constant.MailLetters.JojaMember))
            {
                yield break;
            }

            // get community center
            CommunityCenter communityCenter = Game1.locations.OfType <CommunityCenter>().First();

            if (communityCenter.areAllAreasComplete())
            {
                yield break;
            }

            // get bundles
            if (item.GetType() == typeof(SObject) && !item.bigCraftable.Value) // avoid false positives with hats, furniture, etc
            {
                foreach (BundleModel bundle in DataParser.GetBundles())
                {
                    // ignore completed bundle
                    if (communityCenter.isBundleComplete(bundle.ID))
                    {
                        continue;
                    }

                    // get ingredient
                    BundleIngredientModel ingredient = bundle.Ingredients.FirstOrDefault(p => p.ItemID == item.ParentSheetIndex && p.Quality <= (ItemQuality)item.Quality);
                    if (ingredient == null)
                    {
                        continue;
                    }

                    // yield if missing
                    if (!communityCenter.bundles[bundle.ID][ingredient.Index])
                    {
                        yield return(bundle);
                    }
                }
            }
        }
コード例 #12
0
 public static void DumpObject(string sName, SDVObject oObject)
 {
     if (oObject == null)
     {
         LogTrace("SDVObject " + sName, " is null");
     }
     else
     {
         LogTrace("SDVObject " + sName, "Dump");
         DumpObject("   Type", oObject.GetType().Name);
         DumpObject("   name", oObject.Name);
         DumpObject("   displayname", oObject.DisplayName);
         DumpObject("   category", oObject.category.Value);
         DumpObject("   parentindex", oObject.parentSheetIndex.Value);
         DumpObject("   description", oObject.getDescription());
         DumpObject("   contexttags value", oObject.GetContextTagList());
         DumpObject("   parentSheetIndex", oObject.parentSheetIndex.Value);
         DumpObject("   heldObject", oObject.heldObject.Value == null ? "Nothing" : oObject.heldObject.Value.displayName ?? oObject.heldObject.Value.name);
         DumpObject("   preservedParentSheetIndex", oObject.preservedParentSheetIndex);
     }
 }
コード例 #13
0
 public override bool countsForDrawing(SObject adj)
 {
     if (adj is PipeItem && !(adj is ConnectorPipeItem))
     {
         return(true);
     }
     else if (adj is PipeItem && adj is ConnectorPipeItem)
     {
         if (adj.GetType().Equals(this.GetType()))
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }
コード例 #14
0
        public override bool placementAction(GameLocation location, int x, int y, StardewValley.Farmer who = null)
        {
            // Game1.showRedMessage("BALLS");
            return(true);

            if (location is FarmHouse)
            {
                Point            point = new Point(x / Game1.tileSize, y / Game1.tileSize);
                List <Rectangle> walls = FarmHouse.getWalls((location as FarmHouse).upgradeLevel);
                this.tileLocation = new Vector2((float)point.X, (float)point.Y);
                bool flag = false;
                if (this.Decoration_type == 6 || this.Decoration_type == 13 || this.parentSheetIndex == 1293)
                {
                    int  num   = (this.parentSheetIndex == 1293) ? 3 : 0;
                    bool flag2 = false;
                    foreach (Rectangle current in walls)
                    {
                        if ((this.Decoration_type == 6 || this.Decoration_type == 13 || num != 0) && current.Y + num == point.Y && current.Contains(point.X, point.Y - num))
                        {
                            flag2 = true;
                            break;
                        }
                    }
                    if (!flag2)
                    {
                        Game1.showRedMessage("Must be placed on wall");
                        return(false);
                    }
                    flag = true;
                }
                for (int i = point.X; i < point.X + this.getTilesWide(); i++)
                {
                    for (int j = point.Y; j < point.Y + this.getTilesHigh(); j++)
                    {
                        if (location.doesTileHaveProperty(i, j, "NoFurniture", "Back") != null)
                        {
                            Game1.showRedMessage("Furniture can't be placed here");
                            return(false);
                        }
                        if (!flag && Utility.pointInRectangles(walls, i, j))
                        {
                            Game1.showRedMessage("Can't place on wall");
                            return(false);
                        }
                        if (location.getTileIndexAt(i, j, "Buildings") != -1)
                        {
                            return(false);
                        }
                    }
                }
                this.boundingBox = new Rectangle(x / Game1.tileSize * Game1.tileSize, y / Game1.tileSize * Game1.tileSize, this.boundingBox.Width, this.boundingBox.Height);
                foreach (KeyValuePair <Vector2, StardewValley.Object> c in location.objects)
                {
                    StardewValley.Object ehh = c.Value;
                    if (((ehh.GetType()).ToString()).Contains("Spawner"))
                    {
                        Decoration current2 = (Decoration)ehh;
                        if (current2.Decoration_type == 11 && current2.heldObject == null && current2.getBoundingBox(current2.tileLocation).Intersects(this.boundingBox))
                        {
                            current2.performObjectDropInAction(this, false, (who == null) ? Game1.player : who);
                            bool result = true;
                            return(result);
                        }
                    }
                }
                foreach (StardewValley.Farmer current3 in location.getFarmers())
                {
                    if (current3.GetBoundingBox().Intersects(this.boundingBox))
                    {
                        Game1.showRedMessage("Can't place on top of a person.");
                        bool result = false;
                        return(result);
                    }
                }
                this.updateDrawPosition();
                //  Log.AsyncO(this.boundingBox);
                //   Log.AsyncO(x);
                //   Log.AsyncY(y);
                for (int i = 0; i <= this.boundingBox.X / Game1.tileSize; i++)
                {
                    Util.placementAction(this, location, x + 1, y, who);
                }
                for (int i = 0; i <= this.boundingBox.Y / Game1.tileSize; i++)
                {
                    Util.placementAction(this, location, x + 1, y, who);
                }
                return(true);
            }
            else
            {
                Point point = new Point(x / Game1.tileSize, y / Game1.tileSize);
                //  List<Rectangle> walls = FarmHouse.getWalls((location as FarmHouse).upgradeLevel);
                this.tileLocation = new Vector2((float)point.X, (float)point.Y);
                bool flag = false;
                if (this.Decoration_type == 6 || this.Decoration_type == 13 || this.parentSheetIndex == 1293)
                {
                    int  num   = (this.parentSheetIndex == 1293) ? 3 : 0;
                    bool flag2 = false;

                    /*
                     * foreach (Rectangle current in walls)
                     * {
                     *  if ((this.Decoration_type == 6 || this.Decoration_type == 13 || num != 0) && current.Y + num == point.Y && current.Contains(point.X, point.Y - num))
                     *  {
                     *      flag2 = true;
                     *      break;
                     *  }
                     * }
                     */
                    if (!flag2)
                    {
                        Game1.showRedMessage("Must be placed on wall");
                        return(false);
                    }
                    flag = true;
                }
                for (int i = point.X; i < point.X + this.getTilesWide(); i++)
                {
                    for (int j = point.Y; j < point.Y + this.getTilesHigh(); j++)
                    {
                        if (location.doesTileHaveProperty(i, j, "NoFurniture", "Back") != null)
                        {
                            Game1.showRedMessage("Furniture can't be placed here");
                            return(false);
                        }

                        /*
                         * if (!flag && Utility.pointInRectangles(walls, i, j))
                         * {
                         *  Game1.showRedMessage("Can't place on wall");
                         *  return false;
                         * }
                         */
                        if (location.getTileIndexAt(i, j, "Buildings") != -1)
                        {
                            return(false);
                        }
                    }
                }
                this.boundingBox = new Rectangle(x / Game1.tileSize * Game1.tileSize, y / Game1.tileSize * Game1.tileSize, this.boundingBox.Width, this.boundingBox.Height);

                /*
                 * foreach (Furniture current2 in (location as FarmHouse).furniture)
                 * {
                 *  if (current2.furniture_type == 11 && current2.heldObject == null && current2.getBoundingBox(current2.tileLocation).Intersects(this.boundingBox))
                 *  {
                 *      current2.performObjectDropInAction(this, false, (who == null) ? Game1.player : who);
                 *      bool result = true;
                 *      return result;
                 *  }
                 * }
                 */
                foreach (StardewValley.Farmer current3 in location.getFarmers())
                {
                    if (current3.GetBoundingBox().Intersects(this.boundingBox))
                    {
                        Game1.showRedMessage("Can't place on top of a person.");
                        bool result = false;
                        return(result);
                    }
                }
                this.updateDrawPosition();
                this.thisLocation = Game1.player.currentLocation;
                //  Log.AsyncC(x);
                //   Log.AsyncY(y);
                //   Log.AsyncY(this.drawPosition);
                return(Util.placementAction(this, location, x, y, who));
            }
        }
コード例 #15
0
        public static void clear(GameLocation location, Type[] types = null, int[] parentSheetIndices = null)
        {
            List <Vector2>             list  = new List <Vector2>();
            List <Vector2>             list2 = new List <Vector2>();
            List <LargeTerrainFeature> list3 = new List <LargeTerrainFeature>();

            foreach (Vector2 vector in location.terrainFeatures.Keys)
            {
                TerrainFeature terrainFeature = location.terrainFeatures[vector];
                bool           flag           = Generator.GeneratorOptions.ContainsKey("Crop") && Generator.GeneratorOptions["Crop"] && terrainFeature is HoeDirt;
                if (flag)
                {
                    (terrainFeature as HoeDirt).crop = null;
                }
                bool flag2 = types == null || types.Contains(terrainFeature.GetType()) || types.Contains(typeof(TerrainFeature));
                if (flag2)
                {
                    list.Add(vector);
                }
            }
            foreach (Vector2 vector2 in location.Objects.Keys)
            {
                SObject @object = location.objects[vector2];
                bool    flag3   = types == null || types.Contains(@object.GetType()) || (parentSheetIndices != null && parentSheetIndices.Contains(@object.ParentSheetIndex)) || types.Contains(typeof(SObject)) || (Generator.GeneratorOptions.ContainsKey("Forage") && Generator.GeneratorOptions["Forage"] && @object.isForage(location));
                if (flag3)
                {
                    list2.Add(vector2);
                }
            }
            foreach (LargeTerrainFeature largeTerrainFeature in location.largeTerrainFeatures)
            {
                bool flag4 = types == null || types.Contains(largeTerrainFeature.GetType());
                if (flag4)
                {
                    list3.Add(largeTerrainFeature);
                }
            }
            bool flag5 = location is Farm;

            if (flag5)
            {
                Farm farm = location as Farm;
                List <ResourceClump> list4 = new List <ResourceClump>();
                foreach (ResourceClump resourceClump in farm.resourceClumps)
                {
                    bool flag6 = types == null || types.Contains(resourceClump.GetType()) || (parentSheetIndices != null && parentSheetIndices.Contains(resourceClump.parentSheetIndex.Value));
                    if (flag6)
                    {
                        list4.Add(resourceClump);
                    }
                }
                foreach (ResourceClump resourceClump2 in list4)
                {
                    bool flag7 = farm.resourceClumps.Contains(resourceClump2);
                    if (flag7)
                    {
                        farm.resourceClumps.Remove(resourceClump2);
                    }
                }
            }
            bool flag8 = location is Woods;

            if (flag8)
            {
                Woods woods = location as Woods;
                List <ResourceClump> list5 = new List <ResourceClump>();
                foreach (ResourceClump resourceClump3 in woods.stumps)
                {
                    bool flag9 = types == null || types.Contains(resourceClump3.GetType()) || (parentSheetIndices != null && parentSheetIndices.Contains(resourceClump3.parentSheetIndex.Value));
                    if (flag9)
                    {
                        list5.Add(resourceClump3);
                    }
                }
                foreach (ResourceClump resourceClump4 in list5)
                {
                    bool flag10 = woods.stumps.Contains(resourceClump4);
                    if (flag10)
                    {
                        woods.stumps.Remove(resourceClump4);
                    }
                }
            }
            bool flag11 = location is Forest;

            if (flag11)
            {
                Forest forest = location as Forest;
                bool   flag12 = forest.log != null && parentSheetIndices != null && parentSheetIndices.Contains(forest.log.parentSheetIndex.Value);
                if (flag12)
                {
                    forest.log = null;
                }
            }
            foreach (Vector2 vector3 in list)
            {
                bool flag13 = location.terrainFeatures.ContainsKey(vector3);
                if (flag13)
                {
                    location.terrainFeatures.Remove(vector3);
                }
            }
            foreach (Vector2 vector4 in list2)
            {
                bool flag14 = location.objects.ContainsKey(vector4);
                if (flag14)
                {
                    location.objects.Remove(vector4);
                }
            }
            foreach (LargeTerrainFeature largeTerrainFeature2 in list3)
            {
                bool flag15 = location.largeTerrainFeatures.Contains(largeTerrainFeature2);
                if (flag15)
                {
                    location.largeTerrainFeatures.Remove(largeTerrainFeature2);
                }
            }
        }