private List <Neighbor> gatherNeighbors(GameLocation loc, Vector2 tilePos) { List <Neighbor> results = _neighbors; results.Clear(); TerrainFeature feature = null; Flooring flooring = null; NetVector2Dictionary <TerrainFeature, NetRef <TerrainFeature> > terrainFeatures = loc.terrainFeatures; NeighborLoc[] offsets = _offsets; for (int k = 0; k < offsets.Length; k++) { NeighborLoc item = offsets[k]; Vector2 tile = tilePos + item.Offset; if (loc.map != null && !loc.isTileOnMap(tile)) { Neighbor j = new Neighbor(null, item.Direction, item.InvDirection); results.Add(j); } else if (terrainFeatures.TryGetValue(tile, out feature) && feature != null) { flooring = feature as Flooring; if (flooring != null && flooring.whichFloor == whichFloor) { Neighbor i = new Neighbor(flooring, item.Direction, item.InvDirection); results.Add(i); } } } return(results); }
public override void seasonUpdate(string season, bool onLoad = false) { // Hide the terrain features from the seasonal update so that grass // is not removed in winter. NetVector2Dictionary <TerrainFeature, NetRef <TerrainFeature> > hold = new NetVector2Dictionary <TerrainFeature, NetRef <TerrainFeature> > (); hold.MoveFrom(terrainFeatures); base.seasonUpdate(season, onLoad); terrainFeatures.MoveFrom(hold); // Handle the terrain features separately, preserving the grass. for (int num = terrainFeatures.Count() - 1; num >= 0; --num) { TerrainFeature tf = terrainFeatures.Values.ElementAt(num); if (tf is Grass) { tf.loadSprite(); } else if (tf.seasonUpdate(onLoad)) { terrainFeatures.Remove(terrainFeatures.Keys.ElementAt(num)); } } }
private List <Neighbor> gatherNeighbors(GameLocation loc, Vector2 tilePos) { List <Neighbor> results = _neighbors; results.Clear(); TerrainFeature feature = null; HoeDirt dirt = null; NetVector2Dictionary <TerrainFeature, NetRef <TerrainFeature> > terrainFeatures = loc.terrainFeatures; NeighborLoc[] offsets = _offsets; for (int j = 0; j < offsets.Length; j++) { NeighborLoc item = offsets[j]; Vector2 tile = tilePos + item.Offset; if (terrainFeatures.TryGetValue(tile, out feature) && feature != null) { dirt = feature as HoeDirt; if (dirt != null && dirt.state.Value != 2) { Neighbor i = new Neighbor(dirt, item.Direction, item.InvDirection); results.Add(i); } } } return(results); }
private List <Neighbor> gatherNeighbors(GameLocation loc, Vector2 tilePos) { List <Neighbor> results = _neighbors; results.Clear(); TerrainFeature feature = null; Flooring flooring2 = null; NetVector2Dictionary <TerrainFeature, NetRef <TerrainFeature> > terrainFeatures = loc.terrainFeatures; NeighborLoc[] offsets = _offsets; for (int j = 0; j < offsets.Length; j++) { NeighborLoc item = offsets[j]; Vector2 tile = tilePos + item.Offset; if (terrainFeatures.TryGetValue(tile, out feature) && feature != null) { flooring2 = (feature as Flooring); if (flooring2 != null && flooring2.whichFloor == whichFloor) { Neighbor i = new Neighbor(flooring2, item.Direction, item.InvDirection); results.Add(i); } } } return(results); }
public static void ReplaceWith <T, TField>(this NetVector2Dictionary <T, TField> collection, NetVector2Dictionary <T, TField> source) where TField : NetField <T, TField>, new() { collection.Clear(); foreach (var kvp in source.Pairs) { collection.Add(kvp.Key, kvp.Value); } }
private static void FindAllInstances(object value, List <string> propNames, HashSet <object> exploredObjects, Dictionary <object, List <object> > found, object parent) { if (value == null || exploredObjects.Contains(value)) { return; } exploredObjects.Add(value); IDictionary dict = value as IDictionary; IList list = value as IList; ICollection col = value as ICollection; OverlaidDictionary ovd = value as OverlaidDictionary; NetObjectList <Item> noli = value as NetObjectList <Item>; NetCollection <Building> netBuildings = value as NetCollection <Building>; NetCollection <Furniture> netFurniture = value as NetCollection <Furniture>; NetArray <SObject, NetRef <SObject> > netObjectArray = value as NetArray <SObject, NetRef <SObject> >; NetVector2Dictionary <TerrainFeature, NetRef <TerrainFeature> > terrain = value as NetVector2Dictionary <TerrainFeature, NetRef <TerrainFeature> >; if (dict != null) { foreach (object item in dict.Keys) { if (dict[item] != null) { FindAllInstances(dict[item], propNames, exploredObjects, found, new KeyValuePair <IDictionary, object>(dict, item)); } } } else if (list != null) { foreach (object item in list) { FindAllInstances(item, propNames, exploredObjects, found, list); } } else if (col != null) { foreach (object item in col) { FindAllInstances(item, propNames, exploredObjects, found, col); } } else if (ovd != null) { foreach (Vector2 item in ovd.Keys) { if (ovd[item] != null) { FindAllInstances(ovd[item], propNames, exploredObjects, found, new KeyValuePair <OverlaidDictionary, object>(ovd, item)); } FindAllInstances(item, propNames, exploredObjects, found, ovd); } } else if (noli != null) { foreach (object item in noli) { FindAllInstances(item, propNames, exploredObjects, found, noli); } } else if (netBuildings != null) { foreach (object item in netBuildings) { FindAllInstances(item, propNames, exploredObjects, found, netBuildings); } } else if (netFurniture != null) { foreach (object item in netFurniture) { FindAllInstances(item, propNames, exploredObjects, found, netFurniture); } } else if (netObjectArray != null) { foreach (SObject item in netObjectArray.Where(no => no != null)) { FindAllInstances(item, propNames, exploredObjects, found, netObjectArray); } } else if (terrain != null) { var fd = terrain.FieldDict; foreach (var item in terrain.Keys.Where(v => terrain[v] != null && terrain[v] is ISaveElement || getDataString(terrain[v]).StartsWith(newPrefix))) { FindAllInstances(fd[item], propNames, exploredObjects, found, new KeyValuePair <IDictionary, object>(fd, item)); } } else { if (found.ContainsKey(parent)) { found[parent].Add(value); } else { found.Add(parent, new List <object>() { value }); } Type type = value.GetType(); FieldInfo[] fields; if (fieldInfoChache.ContainsKey(type)) { fields = fieldInfoChache[type]; } else { fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); fieldInfoChache.Add(type, fields); } foreach (FieldInfo field in fields.Where(f => propNames.Contains(f.Name))) { object propertyValue = field.GetValue(value); if (propertyValue != null && propertyValue.GetType() is Type ty && ty.IsClass) { FindAllInstances(propertyValue, propNames, exploredObjects, found, new KeyValuePair <FieldInfo, object>(field, value)); } } } }
public override void DayUpdate(int dayOfMonth) { { // skip Farm.dayUpdate, call BuildableGameLocation.dayUpdate and anything further // up the chain of inheritance. // Don't try this at home, kids, this is ultimate example of how NOT to do things. // thanks to https://stackoverflow.com/a/32562464 for this ugly workaround. var ptr = typeof(BuildableGameLocation).GetMethod("DayUpdate").MethodHandle.GetFunctionPointer(); var grandparentDayUpdate = (Action <int>)Activator.CreateInstance(typeof(Action <int>), this, ptr); grandparentDayUpdate(dayOfMonth); } for (int index = this.animals.Count() - 1; index >= 0; --index) { this.animals.Pairs.ElementAt <KeyValuePair <long, FarmAnimal> >(index).Value.dayUpdate((GameLocation)this); } /*if (Game1.whichFarm == 4 && !Game1.player.mailReceived.Contains("henchmanGone")) * { * Game1.spawnMonstersAtNight = true; * }*/ this.lastItemShipped = null; for (int index = this.characters.Count - 1; index >= 0; --index) { if (this.characters[index] is JunimoHarvester) { this.characters.RemoveAt(index); } } for (int index = this.characters.Count - 1; index >= 0; --index) { if (this.characters[index] is Monster && (this.characters[index] as Monster).wildernessFarmMonster) { this.characters.RemoveAt(index); } } if (this.characters.Count > 5) { int num = 0; for (int index = this.characters.Count - 1; index >= 0; --index) { if (this.characters[index] is GreenSlime && Game1.random.NextDouble() < 0.035) { this.characters.RemoveAt(index); ++num; } } if (num > 0) { Game1.showGlobalMessage(Game1.content.LoadString(num == 1 ? "Strings\\Locations:Farm_1SlimeEscaped" : "Strings\\Locations:Farm_NSlimesEscaped", (object)num)); } } // stuff for handling specific Game1.whichFarm (hardwood stump/geode spawning) - ommited, doesn't concern expansion ICollection <Vector2> source = (ICollection <Vector2>) new List <Vector2>(this.terrainFeatures.Keys); for (int index = source.Count - 1; index >= 0; --index) { if (this.terrainFeatures[source.ElementAt <Vector2>(index)] is HoeDirt && (this.terrainFeatures[source.ElementAt <Vector2>(index)] as HoeDirt).crop == null && Game1.random.NextDouble() <= 0.1) { this.terrainFeatures.Remove(source.ElementAt <Vector2>(index)); } } if (this.terrainFeatures.Count() > 0 && Game1.currentSeason.Equals("fall") && (Game1.dayOfMonth > 1 && Game1.random.NextDouble() < 0.05)) { for (int index = 0; index < 10; ++index) { TerrainFeature terrainFeature = this.terrainFeatures.Pairs.ElementAt <KeyValuePair <Vector2, TerrainFeature> >(Game1.random.Next(this.terrainFeatures.Count())).Value; if (terrainFeature is Tree && (int)((NetFieldBase <int, NetInt>)(terrainFeature as Tree).growthStage) >= 5 && !(bool)((NetFieldBase <bool, NetBool>)(terrainFeature as Tree).tapped)) { (terrainFeature as Tree).treeType.Value = 7; (terrainFeature as Tree).loadSprite(); break; } } } if (this.framework.config.enableCrows) { this.addCrows(); } if (!Game1.currentSeason.Equals("winter")) { spawnWeedsAndStones(Game1.currentSeason.Equals("summer") ? 30 : 20, false, true); } spawnWeeds(false); if (dayOfMonth == 1) { for (int index = this.terrainFeatures.Count() - 1; index >= 0; --index) { KeyValuePair <Vector2, TerrainFeature> keyValuePair = this.terrainFeatures.Pairs.ElementAt <KeyValuePair <Vector2, TerrainFeature> >(index); if (keyValuePair.Value is HoeDirt) { keyValuePair = this.terrainFeatures.Pairs.ElementAt <KeyValuePair <Vector2, TerrainFeature> >(index); if ((keyValuePair.Value as HoeDirt).crop == null && Game1.random.NextDouble() < 0.8) { NetVector2Dictionary <TerrainFeature, NetRef <TerrainFeature> > terrainFeatures = this.terrainFeatures; keyValuePair = this.terrainFeatures.Pairs.ElementAt <KeyValuePair <Vector2, TerrainFeature> >(index); Vector2 key = keyValuePair.Key; terrainFeatures.Remove(key); } } } spawnWeedsAndStones(20, false, false); if (Game1.currentSeason.Equals("spring") && Game1.stats.DaysPlayed > 1U) { spawnWeedsAndStones(40, false, false); spawnWeedsAndStones(40, true, false); for (int index = 0; index < 15; ++index) { int xTile = Game1.random.Next(this.map.DisplayWidth / 64); int yTile = Game1.random.Next(this.map.DisplayHeight / 64); Vector2 vector2 = new Vector2((float)xTile, (float)yTile); Object @object; this.objects.TryGetValue(vector2, out @object); if (@object == null && this.doesTileHaveProperty(xTile, yTile, "Diggable", "Back") != null && (this.isTileLocationOpen(new Location(xTile * 64, yTile * 64)) && !this.isTileOccupied(vector2, "")) && this.doesTileHaveProperty(xTile, yTile, "Water", "Back") == null) { this.terrainFeatures.Add(vector2, (TerrainFeature) new Grass(1, 4)); } } this.growWeedGrass(40); } } base.growWeedGrass(1); }