public static void SetTechshardPrices() { foreach (ResearchProjectDef rpd in researchDic.Keys.ToList()) { ThingDef shardDef = ShardMaker.ShardForProject(rpd); if (shardDef == null) { Log.Message("No techshard found for " + rpd.defName + " in SetTechshardPrices"); continue; } var comp = shardDef.GetCompProperties <CompProperties_Techshard>(); if (comp.project.techprintCount == 0 && !TechprintingSettings.printAllItems) { continue; } if (TechprintingSettings.profitableShards) { shardDef.SetStatBaseValue(StatDefOf.MarketValue, ShardMaker.SellValueOfOneShard(comp.project)); } else { shardDef.SetStatBaseValue(StatDefOf.MarketValue, 0.01f); } shardDef.SetStatBaseValue(StatDefOf.SellPriceFactor, 1f); } }
public override float GetValueUnfinalized(StatRequest req, bool applyPostProcess = true) { if (req.HasThing && Base.thingDic.ContainsKey(req.Thing.def)) { return(Mathf.RoundToInt(ShardMaker.CalcNumShardsFor(req.Thing) / req.Thing.stackCount)); } return(0); }
protected override void FinishedRemoving() { Thing shards = ShardMaker.MakeShards(base.Target); IntVec3 pos = base.Target.Position; Map map = base.Target.Map; base.Target.Destroy(DestroyMode.Vanish); GenPlace.TryPlaceThing(shards, pos, map, ThingPlaceMode.Near); this.pawn.records.Increment(RecordDefOf.ThingsDeconstructed); }
public static bool IsSingleAllowed(ThingDef td) { ResearchProjectDef rpd; if (!thingDic.TryGetValue(td, out rpd)) { Log.Error("IsSingleAllowed tried to get td not in dic"); } return(td.BaseMarketValue >= ShardMaker.RequiredValueForOneShard(rpd) || td.BaseMarketValue >= ShardMaker.forceSingleThreshold); }
public static float GetShardRatio(ResearchProjectDef shardProj, ResearchProjectDef appliedProj) { if (!Base.researchDic.ContainsKey(appliedProj)) { return(1f); } float shardValue = ShardMaker.RequiredValueForOneShard(shardProj); float appliedValue = ShardMaker.RequiredValueForOneShard(appliedProj); return(shardValue / appliedValue); }
public static IEnumerable <ThingDef> ImpliedTechshardDefs() { ResearchProjectHelper.AssociateAll(); foreach (ResearchProjectDef researchProjectDef in DefDatabase <ResearchProjectDef> .AllDefsListForReading) { bool unlocks = ResearchProjectHelper.ProjectUnlocksShardable(researchProjectDef); if (ShardMaker.ShardForProject(researchProjectDef) == null && (researchProjectDef.techprintCount > 0 || unlocks)) { ThingDef thingDef = new ThingDef(); thingDef.category = ThingCategory.Item; thingDef.thingClass = typeof(ThingWithComps); thingDef.thingCategories = new List <ThingCategoryDef>(); thingDef.thingCategories.Add(Base.DefOf.DTechshards); thingDef.useHitPoints = true; thingDef.selectable = true; thingDef.SetStatBaseValue(StatDefOf.MaxHitPoints, 100f); thingDef.SetStatBaseValue(StatDefOf.Flammability, 1f); thingDef.SetStatBaseValue(StatDefOf.MarketValue, 0.01f); thingDef.SetStatBaseValue(StatDefOf.Mass, 0.01f); thingDef.SetStatBaseValue(StatDefOf.SellPriceFactor, 1f); thingDef.altitudeLayer = AltitudeLayer.Item; thingDef.comps.Add(new CompProperties_Forbiddable()); thingDef.comps.Add(new CompProperties_Techshard { project = researchProjectDef }); thingDef.tickerType = TickerType.Never; thingDef.alwaysHaulable = true; thingDef.rotatable = false; thingDef.pathCost = 15; thingDef.drawGUIOverlay = true; thingDef.stackLimit = 100; thingDef.modContentPack = researchProjectDef.modContentPack; thingDef.description = "TechshardDesc".Translate(researchProjectDef.Named("PROJECT")) + "\n\n" + researchProjectDef.LabelCap + "\n\n" + researchProjectDef.description; thingDef.graphicData = new GraphicData(); thingDef.graphicData.texPath = "Things/Item/Special/Techshard"; thingDef.graphicData.graphicClass = typeof(Graphic_StackCount); thingDef.defName = "Techshard_" + researchProjectDef.defName; thingDef.label = "TechshardLabel".Translate(researchProjectDef.Named("PROJECT")); thingDef.smallVolume = true; thingDef.resourceReadoutPriority = ResourceCountPriority.Middle; Base.DefOf.DTechshards.childThingDefs.Add(thingDef); var giveShortHash = AccessTools.Method(typeof(ShortHashGiver), "GiveShortHash"); giveShortHash.Invoke(null, new object[] { thingDef, typeof(ThingDef) }); yield return(thingDef); } } yield break; }
public override bool CanPossiblyStoreInStockpile(Bill_Production bill, Zone_Stockpile stockpile) { foreach (ThingDef thingDef in bill.ingredientFilter.AllowedThingDefs) { ResearchProjectDef rpd; if (!Base.thingDic.TryGetValue(thingDef, out rpd)) { return(false); } ThingDef shardDef = ShardMaker.ShardForProject(rpd); if (!stockpile.GetStoreSettings().AllowedToAccept(shardDef)) { return(false); } } return(true); }
public static void RefundXP(ResearchProjectDef proj, Pawn applyingPawn, ResearchProjectDef shardType, int shardsApplied, float xpGained) { if (applyingPawn == null || !Base.researchDic.ContainsKey(shardType)) { return; } float xpRequired = proj.baseCost - proj.ProgressReal; if (xpRequired >= 0) { int shardRefund = shardsApplied - Mathf.RoundToInt((float)shardsApplied * (xpRequired / xpGained)); if (shardRefund > 0) { ThingDef techShardDef = ShardMaker.ShardForProject(shardType); Thing shards = ThingMaker.MakeThing(techShardDef); shards.stackCount = shardRefund; GenPlace.TryPlaceThing(shards, applyingPawn.Position, applyingPawn.Map, ThingPlaceMode.Near, null, null, default(Rot4)); } } }
public static void RefundUnlock(ResearchProjectDef proj, Pawn applyingPawn, int shardsApplied) { if (applyingPawn == null || !Base.researchDic.ContainsKey(proj)) { return; } int shardsRequired = proj.techprintCount - Current.Game.researchManager.GetTechprints(proj); if (shardsRequired > 0) { int shardRefund = shardsApplied - shardsRequired; if (shardRefund > 0) { ThingDef techShardDef = ShardMaker.ShardForProject(proj); Thing shards = ThingMaker.MakeThing(techShardDef); shards.stackCount = shardRefund; GenPlace.TryPlaceThing(shards, applyingPawn.Position, applyingPawn.Map, ThingPlaceMode.Near, null, null, default(Rot4)); } } }
public override string GetExplanationUnfinalized(StatRequest req, ToStringNumberSense numberSense) { if (!req.HasThing || !Base.thingDic.ContainsKey(req.Thing.def)) { return(""); } ResearchProjectDef rpd = Base.thingDic[req.Thing.def]; float baseVal = Mathf.RoundToInt(ShardMaker.GetAverageValue(req.Thing.def) / ShardMaker.RequiredValueForOneShard(rpd)); string s = "Base item yield: " + baseVal; if (TechprintingSettings.shardYieldRatio != 1f) { s += "\nShard yield multiplier (from settings): " + TechprintingSettings.shardYieldRatio.ToString("p1"); } QualityCategory q; if (req.Thing.TryGetQuality(out q)) { float rawValue = (float)ShardMaker.CalcNumShardsForRaw(req.Thing, rpd); float multiplier = rawValue / baseVal; s += "\nQuality and condition multiplier: " + multiplier.ToString("p1"); s += "\nAdjusted value: " + rawValue; if (rawValue > 100) { int maxShards; if (q == QualityCategory.Legendary || q == QualityCategory.Masterwork) { maxShards = TechprintingSettings.printAllItems ? Mathf.RoundToInt(Mathf.Max(rpd.techprintCount, 100)) : Mathf.RoundToInt(rpd.techprintCount); } else { maxShards = 100; } s += "\n\nMax shards for quality: " + maxShards; } } return(s); }
public static bool IsStackAllowed(ThingDef td, int size) { if (td.stackLimit < size) { return(false); } ResearchProjectDef rpd; if (!thingDic.TryGetValue(td, out rpd)) { Log.Error("IsSingleAllowed tried to get td not in dic"); } float shardValue = ShardMaker.RequiredValueForOneShard(rpd); return (((td.BaseMarketValue < shardValue) && (td.BaseMarketValue < ShardMaker.forceSingleThreshold) && (td.BaseMarketValue * size >= shardValue) ) || (td.BaseMarketValue * size < shardValue * 100)); // 1 item not allowed, but stack is OR stack is under 100 shards }
private static IEnumerable <Thing> Postfix(IEnumerable <Thing> values, bool __state, RecipeDef recipeDef, List <Thing> ingredients, Thing dominantIngredient, IBillGiver billGiver) { if (!__state) { foreach (var value in values) { yield return(value); } yield break; } if (ingredients.Count == 0) { Log.Error("techshard recipe finished with no ingredients"); } Thing ingredient = ingredients[0]; yield return(ShardMaker.MakeShards(ingredient)); yield break; }
public static void MakeThingDictionaries() { thingDic = new Dictionary <ThingDef, ResearchProjectDef>(); researchDic = new Dictionary <ResearchProjectDef, List <ThingDef> >(); foreach (RecipeDef recipe in DefDatabase <RecipeDef> .AllDefsListForReading) { ResearchProjectDef rpd = ThingDefHelper.GetBestRPDForRecipe(recipe); if (rpd != null && recipe.ProducedThingDef != null) { if (ShardMaker.ShardForProject(rpd) != null && (rpd.techprintCount > 0 || TechprintingSettings.printAllItems)) { ThingDef producedThing = recipe.ProducedThingDef; if (producedThing.GetCompProperties <CompProperties_Shardable>() == null) { producedThing.comps.Add(new CompProperties_Shardable()); } thingDic.SetOrAdd(producedThing, rpd); List <ThingDef> things; if (researchDic.TryGetValue(rpd, out things)) { things.Add(producedThing); } else { researchDic.Add(rpd, new List <ThingDef> { producedThing }); } } } } if (TechprintingSettings.shardBuildings) { foreach (ThingDef building in DefDatabase <ThingDef> .AllDefs.Where(x => x.category == ThingCategory.Building || x.building != null)) { if (thingDic.ContainsKey(building)) { continue; } ResearchProjectDef rpd = ThingDefHelper.GetBestRPDForBuilding(building); if (rpd != null) { if (ShardMaker.ShardForProject(rpd) != null && (rpd.techprintCount > 0 || TechprintingSettings.printAllItems)) { if (building.GetCompProperties <CompProperties_Shardable>() == null) { building.comps.Add(new CompProperties_Shardable()); } thingDic.SetOrAdd(building, rpd); List <ThingDef> things; if (researchDic.TryGetValue(rpd, out things)) { things.Add(building); } else { researchDic.Add(rpd, new List <ThingDef> { building }); } } } } } GearAssigner.HardAssign(ref thingDic, ref researchDic); GearAssigner.OverrideAssign(ref thingDic, ref researchDic); }