Exemple #1
0
        internal static void CheckGates()
        {
            if (!(Game1.currentLocation is StardewValley.Locations.BuildableGameLocation))
            {
                return;
            }

            Point NewTile = Game1.player.getTileLocationPoint();

            if (OldTile == NewTile)
            {
                return;
            }

            Vector2[] newAdjTiles = Utility.getAdjacentTileLocationsArray(Game1.player.getTileLocation());
            var       tilesComing = newAdjTiles.Where(p => !OldAdjTiles.Contains(p));

            // Open coming gates
            GateList.AsParallel().Where(p => tilesComing.Contains(p.Key) &&
                                        (p.Value.gatePosition.Value == Fence.gateClosedPosition) &&
                                        p.Value.checkForAction(Game1.player, true))
            .ForAll((gate => gate.Value.gatePosition.Value = Fence.gateOpenedPosition));

            var tilesGoing = OldAdjTiles.Where(p => !newAdjTiles.Contains(p));

            // Close going gates
            var qlist = GateList.AsParallel().Where(p => tilesGoing.Contains(p.Key) &&
                                                    (p.Value.gatePosition.Value == Fence.gateOpenedPosition));

            if (qlist.Any())
            {
                qlist.ForAll((gate => gate.Value.gatePosition.Value = Fence.gateClosedPosition));
                Game1.playSound("doorClose");
            }

            OldAdjTiles = newAdjTiles;
        }