Ejemplo n.º 1
0
 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);
 }
Ejemplo n.º 2
0
        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");
                }
            }
        }
Ejemplo n.º 3
0
        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);
            }
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
 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;
 }
Ejemplo n.º 6
0
 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";
     }
 }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        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;
        }
Ejemplo n.º 9
0
 public static string GetCritterIdFromRegistry(CritterEntry entry)
 {
     return(critters.Where(c => c.Value == entry).Single().Key);
 }
Ejemplo n.º 10
0
 public static void Register(CritterEntry entry)
 {
     critters.Add(entry.BugModel.Id, entry);
 }
Ejemplo n.º 11
0
 public Bug(CritterEntry critterData)
     : this(critterData.BugModel)
 {
 }
Ejemplo n.º 12
0
 public CustomCritter(Vector2 position, CritterEntry data)
     : this(data)
 {
     this.position = this.startingPosition = position;
 }