public Crawler(Vector2 position, CritterEntry data) : base(position, data) { this.sprite.loop = false; this.baseFrame = this.sprite.currentFrame; this.crawlSpeed = Game1.random.Next(200, 350); }
public void balanceSpawning() { int numBugs = AllPossibleHomesByBug.Keys.Count; double sumRarity = BugCatchingMod.AllBugs.Where(bug => AllPossibleHomesByBug.ContainsKey(bug.Id)).Aggregate(0.0, (acc, bug) => acc + (1f - bug.Rarity)); int nTotalBugs = (int)Math.Floor(numBugs * sumRarity); Log.info($"location has ({nTotalBugs}) total bugs with a sumRarity of ({sumRarity})"); foreach (KeyValuePair <string, List <Vector2> > kvp in AllPossibleHomesByBug) { CritterEntry critterEntry = CritterEntry.critters[kvp.Key]; List <Vector2> possibleSpawnLocations = new List <Vector2>(); possibleSpawnLocations = kvp.Value; int nCritterSpawned = (int)Math.Ceiling(critterEntry.BugModel.Rarity * nTotalBugs); Log.info($"({nCritterSpawned}) {critterEntry.BugModel.Name} will spawn"); if (possibleSpawnLocations.Count > 0) { for (int i = 0; i <= nCritterSpawned; i++) { Vector2 tile = possibleSpawnLocations.PopRandom(); Log.info($"Adding {critterEntry.BugModel.Name} at location {tile}"); CritterLocation critterLocation = new CritterLocation(critterEntry) { tilePosition = tile }; registerCritterHome(critterLocation); } } else { Log.error($"{critterEntry.BugModel.Name} lacks Suitable Housing"); } } }
public void buildAllPossibleHomes() { if (CritterHomes.Count > 0) { CritterHomes.Clear(); } LocalSeasonalCritters = BugCatchingMod.SeasonalCritters.Where(c => c.SpawnConditions.Locations.Contains(Location.Name)).ToList(); Log.info($"in Location {Location} there are ({LocalSeasonalCritters.Count}/{BugCatchingMod.SeasonalCritters.Count}) local seasonal critters"); foreach (CritterEntry critterEntry in LocalSeasonalCritters) { Log.info($"building AllHomes for {critterEntry.BugModel.Name}"); string critterId = CritterEntry.GetCritterIdFromRegistry(critterEntry); List <Vector2> possibleSpawnLocations = new List <Vector2>(); foreach (Attractor attractor in critterEntry.Attractors) { List <Vector2> attractorTiles = new List <Vector2>(); attractorTiles = attractor.getAttractorTilesAtLocation(Location); Log.info($"{attractorTiles.Count} here"); possibleSpawnLocations.AddRange(attractorTiles); } Log.info($"found ({possibleSpawnLocations.Count}) Suitable Homes for {critterEntry.BugModel.Name}"); AllPossibleHomesByBug.AddOrReplace(critterId, possibleSpawnLocations); } }
public CustomCritter(CritterEntry data) { this.data = data; this.flip = Game1.random.NextDouble() < 0.5; var tex = BugCatchingMod.instance.Helper.Content.Load <Texture2D>(data.BugModel.SpriteData.TextureAsset); var texStr = BugCatchingMod.instance.Helper.Content.GetActualAssetKey(data.BugModel.SpriteData.TextureAsset); this.baseFrame = data.BugModel.SpriteData.TileIndex; this.sprite = new AnimatedSprite(texStr, baseFrame, data.BugModel.SpriteData.FrameWidth, data.BugModel.SpriteData.FrameHeight); }
public Floater(CustomCritter critter) : base(critter.startingPosition) { this.data = critter.data; this.sprite = critter.sprite; this.position = critter.startingPosition; this.startingPosition = this.position; this.baseFrame = this.sprite.currentFrame; if (critter.data.Behavior.NumFrames == 4) { this.summerButterfly = true; } this.sprite.loop = false; }
public CritterLocation(CritterEntry critter) { this.CritterEntry = critter; if (CritterEntry.Behavior.DisturbableHome || CritterEntry.Classification.Equals("Digger")) { isDisturbableType = true; } if (CritterEntry.Classification == "Digger") { layerName = "Back"; } else { layerName = "Front"; } }
public void activateCritter(CritterLocation critterLocationEntry) { if (critterLocationEntry == null) { Log.error("cannot activate; null critterLocationEntry"); return; } CritterEntry critterEntry = CritterEntry.critters.Find(ce => ce.Value == critterLocationEntry.CritterEntry).Value; if (critterEntry == null) { Log.error("cannot activate; null critterEntry"); return; } Location.addCritter(critterEntry.makeCritter(critterLocationEntry.tilePosition)); CritterHomes.Remove(critterLocationEntry); }
public void LoadCritters(object sender, UpdateTickedEventArgs e) { BugNetData data = _helper.Data.ReadJsonFile <BugNetData>("Assets/critters.json"); int Id = -666; AllCritters = new List <CritterEntry>(); Dictionary <int, string> AssetData = new Dictionary <int, string>(); foreach (CritterEntry critter in data.AllCritters) { AllCritters.AddOrReplace(critter); CritterEntry.Register(critter); var bugModel = new BugModel(); bugModel = critter.BugModel; //is this V necessary ? bugModel.ParentSheetIndex = Id; AllBugs.AddOrReplace(bugModel); CustomObjectData.newObject(bugModel.FullId, bugModel.SpriteData.getTexture(), Color.White, bugModel.Name, bugModel.Description, bugModel.SpriteData.TileIndex, price: bugModel.Price, customType: typeof(Bug)); //AssetData[bugData.sdvId] = bugModel.QuickItemDataString; Monitor.Log("Added: " + bugModel.Name + " id " + bugModel.FullId.ToString()); Id--; } foreach (NetModel netModel in data.AllNets) { AllNets.AddOrReplace(netModel); //net.ParentSheetIndex = Id; CustomObjectData.newBigObject(netModel.FullId, netModel.getTexture(), Color.White, netModel.Name, netModel.Description, netModel.TileIndex, netModel.Name, false, 0, false, false, "Crafting -9", 0, -300, new CraftingData(netModel.Name, netModel.Recipe), typeof(BugNetTool)); Log.info($"adding {netModel.FullId} with recipe {netModel.Recipe}"); //CustomObjectData.newObject($"{netModel.FullId}.Tool", new BugNetTool(netModel).loadTexture(), Color.White, netModel.Name, netModel.Description, netModel.TileIndex, "", "Net", 1, -300, craftingData: new CraftingData($"{netModel.FullId}.Tool", netModel.Recipe), customType: typeof(BugNetTool)); } //_helper.Data.WriteJsonFile("data\\bugs.json", AssetData); _helper.Events.GameLoop.UpdateTicked -= LoadCritters; }
public static string GetCritterIdFromRegistry(CritterEntry entry) { return(critters.Where(c => c.Value == entry).Single().Key); }
public static void Register(CritterEntry entry) { critters.Add(entry.BugModel.Id, entry); }
public Bug(CritterEntry critterData) : this(critterData.BugModel) { }
public CustomCritter(Vector2 position, CritterEntry data) : this(data) { this.position = this.startingPosition = position; }