public void doMagic(bool playedToday) { if (Game1.currentLocation.isOutdoors || Game1.currentLocation.name.Equals("Greenhouse")) { GameLocation gls = Game1.currentLocation; List <Vector2> treetiles = new TerrainSelector <TerrainFeature>(t => (t is Tree || t is FruitTree || t is Grass || t is Bush)).keysIn(gls); for (int i = 0; i < treetiles.Count; i++) { if (gls.terrainFeatures[treetiles[i]] is Tree) { if (!playedToday) { Tree tree = gls.terrainFeatures[treetiles[i]] as Tree; tree.growthStage = (tree.growthStage < 4) ? tree.growthStage + 1 : tree.growthStage; gls.terrainFeatures[treetiles[i]] = tree; } (gls.terrainFeatures[treetiles[i]] as Tree).performUseAction(treetiles[i]); } if (gls.terrainFeatures[treetiles[i]] is FruitTree) { if (!playedToday) { FruitTree tree = (gls.terrainFeatures[treetiles[i]] as FruitTree); tree.growthStage = (tree.growthStage <= 4) ? tree.growthStage + 1 : tree.growthStage; tree.daysUntilMature = tree.daysUntilMature - 7; gls.terrainFeatures[treetiles[i]] = tree; } (gls.terrainFeatures[treetiles[i]] as FruitTree).performUseAction(treetiles[i]); } if (gls.terrainFeatures[treetiles[i]] is Grass) { if (!playedToday) { Grass grass = (gls.terrainFeatures[treetiles[i]] as Grass); grass.numberOfWeeds = Math.Min(grass.numberOfWeeds + Game1.random.Next(1, 4), 4); gls.terrainFeatures[treetiles[i]] = grass; } } (gls.terrainFeatures[treetiles[i]] as Grass).doCollisionAction(gls.terrainFeatures[treetiles[i]].getBoundingBox(treetiles[i]), 3, treetiles[i], Game1.player, Game1.currentLocation); if (gls.terrainFeatures[treetiles[i]] is Bush) { (gls.terrainFeatures[treetiles[i]] as Bush).performUseAction(treetiles[i]); } } priorRadius = Game1.player.magneticRadius; Game1.player.magneticRadius += 2000; PyUtils.setDelayedAction(8000, () => Game1.player.magneticRadius = priorRadius); } }
public static Dictionary <GameLocation, NotifyCollectionChangedEventHandler> whenAddedToLocation <T>(this TerrainSelector <T> t, Action <GameLocation, List <Vector2> > action, GameLocation l = null) where T : TerrainFeature { List <GameLocation> gls = new List <GameLocation>(); if (l == null) { gls = PyUtils.getAllLocationsAndBuidlings(); } else { gls.Add(l); } Action <GameLocation, NotifyCollectionChangedEventArgs> a = delegate(GameLocation location, NotifyCollectionChangedEventArgs e) { List <Vector2> keys = new List <Vector2>(); if (e.Action == NotifyCollectionChangedAction.Add) { foreach (Vector2 key in e.NewItems) { if (t.predicate(location.terrainFeatures[key])) { keys.Add(key); } } } action.Invoke(location, keys); }; Dictionary <GameLocation, NotifyCollectionChangedEventHandler> d = new Dictionary <GameLocation, NotifyCollectionChangedEventHandler>(); foreach (GameLocation gl in gls) { d.AddOrReplace(gl, (o, e) => a(gl, e)); } return(d.useAll(p => p.Key.terrainFeatures.CollectionChanged += p.Value)); }
// Update is called once per frame void FixedUpdate() { if (Input.GetKeyUp(markingKey)) { Debug.DrawLine(transform.position, transform.position + Vector3.down, Color.red, 2, false); RaycastHit2D hit = Physics2D.Raycast(transform.position, Vector2.down, maxMarkableDistance + 0.1f, LayerMask.NameToLayer("Ground")); if (hit.collider != null) { Vector2 markPosition = hit.collider.gameObject.transform.position; TerrainChunk tc = TerrainSelector.SelectSquare(new Vector2(markPosition.x - 1, markPosition.y), new Vector2(markPosition.x + 2, markPosition.y + 3)); if (selections.Count <= 0) { tc.MarkChunk(GetColour()); selections.Add(tc); } else if (selections.Count == 1) { if (tc.isMarked) { foreach (Markable mkble in tc.terrains) { TerrainChunk wasIn = SelectedTerrainWasIn(mkble); if (wasIn != null) { wasIn.UnMarkChunk(); selections.Remove(wasIn); } } } else { tc.MarkChunk(GetColour()); selections.Add(tc); } } else if (selections.Count == 2) { if (tc.isMarked) { foreach (Markable mkble in tc.terrains) { TerrainChunk wasIn = SelectedTerrainWasIn(mkble); if (wasIn != null) { wasIn.UnMarkChunk(); selections.Remove(wasIn); } } } else { selections [0].UnMarkChunk(); selections.RemoveAt(0); tc.MarkChunk(GetColour()); selections.Add(tc); } } } } if (Input.GetKeyUp(swapKey)) { Swap(); } }