static void Postfix() { if (SeedDef.AddMissingSeeds()) { ResourceCounter.ResetDefs(); Log.Warning("SeedsPlease :: Don't rely on autogenerated seeds, share the generated xml for proper support"); } }
static void Postfix() { var report = new System.Text.StringBuilder(); if (SeedDef.AddMissingSeeds(report)) { ResourceCounter.ResetDefs(); Log.Warning("SeedsPlease :: Some Seeds were autogenerated." + " Don't rely on autogenerated seeds," + " share the generated xml for proper support.\n\n" + report); } }
static void AddMissingSeed(ThingDef thingDef) { string name = thingDef.defName; foreach (string prefix in SeedsPleaseMod.knownPrefixes) { name = name.Replace(prefix, ""); } name = name.CapitalizeFirst(); var template = ResourceBank.ThingDefOf.Seed_Psychoid; var seed = new SeedDef() { defName = "Seed_" + name, label = name.ToLower() + " seeds", plant = thingDef, harvest = thingDef.plant.harvestedThingDef, BaseMarketValue = AssignMarketValueFromHarvest(thingDef), stackLimit = template.stackLimit, seed = new SeedProperties() { harvestFactor = 1f, seedFactor = 1f, baseChance = 0.95f, extraChance = 0.15f }, tradeTags = template.tradeTags, thingCategories = template.thingCategories, soundDrop = template.soundDrop, soundInteract = template.soundInteract, statBases = template.statBases, graphicData = template.graphicData, description = template.description, thingClass = template.thingClass, pathCost = template.pathCost, rotatable = template.rotatable, drawGUIOverlay = template.drawGUIOverlay, alwaysHaulable = template.alwaysHaulable, comps = template.comps, altitudeLayer = template.altitudeLayer, selectable = template.selectable, useHitPoints = template.useHitPoints, resourceReadoutPriority = template.resourceReadoutPriority, category = template.category, uiIcon = template.uiIcon, uiIconColor = template.uiIconColor, }; seed.ResolveReferences(); thingDef.blueprintDef = seed; foreach (var category in seed.thingCategories) { category.childThingDefs.Add(seed); } DefDatabase <ThingDef> .Add(seed); DefDatabase <SeedDef> .Add(seed); var stringBuilder = new System.Text.StringBuilder(); stringBuilder.Append("SeedsPlease :: "); stringBuilder.Append(thingDef.defName); stringBuilder.Append(" ("); stringBuilder.Append(thingDef.modContentPack.IsCoreMod ? "Patched" : thingDef.modContentPack.Name); stringBuilder.Append(") is missing a SeedDef. Autogenerated as "); stringBuilder.AppendLine(seed.defName); stringBuilder.AppendLine(); var seedXml = new XElement("SeedsPlease.SeedDef", new XAttribute("ParentName", "SeedBase"), new XElement("defName", seed.defName), new XElement("label", seed.label), new XElement("plant", thingDef.defName)); stringBuilder.AppendLine(seedXml.ToString()); if (thingDef.plant.harvestedThingDef.IsStuff) { Log.Warning(stringBuilder.ToString()); return; } float yieldCount = Mathf.Max(Mathf.Round(thingDef.plant.harvestYield / 3f), 4f); var ingredient = new IngredientCount(); ingredient.filter.SetAllow(thingDef.plant.harvestedThingDef, true); ingredient.SetBaseCount(yieldCount); var recipe = new RecipeDef() { defName = "ExtractSeed_" + name, label = "extract " + name.ToLower() + " seeds", description = "Extract seeds from " + thingDef.plant.harvestedThingDef.defName.Replace("Raw", ""), ingredients = new List <IngredientCount>() { ingredient }, defaultIngredientFilter = ingredient.filter, fixedIngredientFilter = ingredient.filter, products = new List <ThingDefCountClass>() { new ThingDefCountClass() { thingDef = seed, count = 3 } }, researchPrerequisite = thingDef.researchPrerequisites?.FirstOrFallback(), workAmount = 600f, workSkill = SkillDefOf.Cooking, effectWorking = EffecterDefOf.Vomit, workSpeedStat = StatDefOf.EatingSpeed, jobString = "Extracting seeds.", }; DefDatabase <RecipeDef> .Add(recipe); ResourceBank.ThingDefOf.PlantProcessingTable.recipes.Add(recipe); var recipeXml = new XElement("RecipeDef", new XAttribute("ParentName", "ExtractSeed"), new XElement("defName", recipe.defName), new XElement("label", recipe.label), new XElement("description", recipe.description), new XElement("ingredients", new XElement("li", new XElement("filter", new XElement("thingDefs", new XElement("li", thingDef.plant.harvestedThingDef.defName))), new XElement("count", yieldCount))), new XElement("fixedIngredientFilter", new XElement("thingDefs", new XElement("li", thingDef.plant.harvestedThingDef.defName))), new XElement("products", new XElement(seed.defName, 3))); stringBuilder.AppendLine(); stringBuilder.AppendLine(recipeXml.ToString()); Log.Warning(stringBuilder.ToString()); }
private Toil HarvestSeedsToil() { Toil toil = new Toil(); toil.defaultCompleteMode = ToilCompleteMode.Never; toil.tickAction = delegate { Pawn actor = toil.actor; Plant plant = Plant; if (actor.skills != null) { actor.skills.Learn(SkillDefOf.Growing, xpPerTick); } workDone += actor.GetStatValue(StatDefOf.PlantWorkSpeed, true); if (workDone >= plant.def.plant.harvestWork) { if (plant.def.plant.harvestedThingDef != null) { if (actor.RaceProps.Humanlike && plant.def.plant.harvestFailable && Rand.Value < actor.GetStatValue(StatDefOf.HarvestFailChance, true)) { MoteMaker.ThrowText((actor.DrawPos + plant.DrawPos) / 2, actor.Map, "HarvestFailed".Translate(), 3.65f); } else { int plantYield = plant.YieldNow(); ThingDef harvestedThingDef; SeedDef seedDef = plant.def.blueprintDef as SeedDef; if (seedDef != null) { float parameter = Mathf.Max(Mathf.InverseLerp(plant.def.plant.harvestMinGrowth, 1.2f, plant.Growth), 1f); if (seedDef.seed.seedFactor > 0 && Rand.Value < seedDef.seed.baseChance * parameter) { int count; if (Rand.Value < seedDef.seed.extraChance) { count = 2; } else { count = 1; } Thing seeds = ThingMaker.MakeThing(seedDef, null); seeds.stackCount = Mathf.RoundToInt(seedDef.seed.seedFactor * count); GenPlace.TryPlaceThing(seeds, actor.Position, actor.Map, ThingPlaceMode.Near); } plantYield = Mathf.RoundToInt(plantYield * seedDef.seed.harvestFactor); harvestedThingDef = seedDef.harvest; } else { harvestedThingDef = plant.def.plant.harvestedThingDef; } if (plantYield > 0) { Thing thing = ThingMaker.MakeThing(harvestedThingDef, null); thing.stackCount = plantYield; if (actor.Faction != Faction.OfPlayer) { thing.SetForbidden(true, true); } GenPlace.TryPlaceThing(thing, actor.Position, actor.Map, ThingPlaceMode.Near, null); } actor.records.Increment(RecordDefOf.PlantsHarvested); } } plant.def.plant.soundHarvestFinish.PlayOneShot(actor); plant.PlantCollected(); workDone = 0; ReadyForNextToil(); return; } }; toil.FailOnDespawnedNullOrForbidden(TargetIndex.A); toil.WithEffect(EffecterDefOf.Harvest, TargetIndex.A); toil.WithProgressBar(TargetIndex.A, () => workDone / Plant.def.plant.harvestWork, true, -0.5f); toil.PlaySustainerOrSound(() => Plant.def.plant.soundHarvesting); return(toil); }