public static void SendCraftNotification(Thing thing, Pawn worker) { if (worker == null) { return; } CompQuality compQuality = thing.TryGetComp <CompQuality>(); if (compQuality == null) { return; } if (compQuality.Quality == QualityCategory.Masterwork) { Messages.Message("MessageCraftedMasterwork".Translate(new object[] { worker.LabelShort, thing.LabelShort }), thing, MessageTypeDefOf.PositiveEvent, true); } else if (compQuality.Quality == QualityCategory.Legendary) { Find.LetterStack.ReceiveLetter("LetterCraftedLegendaryLabel".Translate(), "LetterCraftedLegendaryMessage".Translate(new object[] { worker.LabelShort, thing.LabelShort }), LetterDefOf.PositiveEvent, thing, null, null); } }
public static TaleData_Thing GenerateRandom() { ThingDef thingDef = DefDatabase <ThingDef> .AllDefs.Where(delegate(ThingDef d) { bool arg_36_0; if (d.comps != null) { arg_36_0 = d.comps.Any((CompProperties cp) => cp.compClass == typeof(CompArt)); } else { arg_36_0 = false; } return(arg_36_0); }).RandomElement <ThingDef>(); ThingDef thingDef2 = GenStuff.RandomStuffFor(thingDef); Thing thing = ThingMaker.MakeThing(thingDef, thingDef2); ArtGenerationContext source = (Rand.Value >= 0.5f) ? ArtGenerationContext.Outsider : ArtGenerationContext.Colony; CompQuality compQuality = thing.TryGetComp <CompQuality>(); if (compQuality != null && compQuality.Quality < thing.TryGetComp <CompArt>().Props.minQualityForArtistic) { compQuality.SetQuality(thing.TryGetComp <CompArt>().Props.minQualityForArtistic, source); } thing.TryGetComp <CompArt>().InitializeArt(source); return(TaleData_Thing.GenerateFrom(thing)); }
public static void SendCraftNotification(Thing thing, Pawn worker) { if (worker == null) { return; } CompQuality compQuality = thing.TryGetComp <CompQuality>(); if (compQuality == null) { return; } CompArt compArt = thing.TryGetComp <CompArt>(); if (compArt == null) { if (compQuality.Quality == QualityCategory.Masterwork) { Find.LetterStack.ReceiveLetter("LetterCraftedMasterworkLabel".Translate(), "LetterCraftedMasterworkMessage".Translate(worker.LabelShort, thing.LabelShort, worker.Named("WORKER"), thing.Named("CRAFTED")), LetterDefOf.PositiveEvent, thing); } else if (compQuality.Quality == QualityCategory.Legendary) { Find.LetterStack.ReceiveLetter("LetterCraftedLegendaryLabel".Translate(), "LetterCraftedLegendaryMessage".Translate(worker.LabelShort, thing.LabelShort, worker.Named("WORKER"), thing.Named("CRAFTED")), LetterDefOf.PositiveEvent, thing); } } else if (compQuality.Quality == QualityCategory.Masterwork) { Find.LetterStack.ReceiveLetter("LetterCraftedMasterworkLabel".Translate(), "LetterCraftedMasterworkMessageArt".Translate(compArt.GenerateImageDescription(), worker.LabelShort, thing.LabelShort, worker.Named("WORKER"), thing.Named("CRAFTED")), LetterDefOf.PositiveEvent, thing); } else if (compQuality.Quality == QualityCategory.Legendary) { Find.LetterStack.ReceiveLetter("LetterCraftedLegendaryLabel".Translate(), "LetterCraftedLegendaryMessageArt".Translate(compArt.GenerateImageDescription(), worker.LabelShort, thing.LabelShort, worker.Named("WORKER"), thing.Named("CRAFTED")), LetterDefOf.PositiveEvent, thing); } }
public static void AssignQuality(Thing thing, QualityGenerator?qualityGenerator) { CompQuality compQuality = thing.TryGetComp <CompQuality>(); if (compQuality != null) { QualityCategory q = QualityUtility.GenerateQuality(qualityGenerator ?? QualityGenerator.BaseGen); compQuality.SetQuality(q, ArtGenerationContext.Outsider); } }
public static void AssignRandomBaseGenItemQuality(List <Thing> things) { for (int i = 0; i < things.Count; i++) { CompQuality compQuality = things[i].TryGetComp <CompQuality>(); if (compQuality != null) { compQuality.SetQuality(QualityUtility.RandomBaseGenItemQuality(), ArtGenerationContext.Outsider); } } }
public Thing MakeThing() { Thing result = ThingMaker.MakeThing(this.thing, this.stuff); CompQuality compQuality = result.TryGetComp <CompQuality>(); if (compQuality != null) { compQuality.SetQuality(this.Quality, ArtGenerationContext.Outsider); } return(result); }
public void CompleteConstruction(Pawn worker) { resourceContainer.ClearAndDestroyContents(); Map map = base.Map; Destroy(); if (this.GetStatValue(StatDefOf.WorkToBuild) > 150f && def.entityDefToBuild is ThingDef && ((ThingDef)def.entityDefToBuild).category == ThingCategory.Building) { SoundDefOf.Building_Complete.PlayOneShot(new TargetInfo(base.Position, map)); } ThingDef thingDef = def.entityDefToBuild as ThingDef; Thing thing = null; if (thingDef != null) { thing = ThingMaker.MakeThing(thingDef, base.Stuff); thing.SetFactionDirect(base.Faction); CompQuality compQuality = thing.TryGetComp <CompQuality>(); if (compQuality != null) { QualityCategory q = QualityUtility.GenerateQualityCreatedByPawn(worker, SkillDefOf.Construction); compQuality.SetQuality(q, ArtGenerationContext.Colony); QualityUtility.SendCraftNotification(thing, worker); } CompArt compArt = thing.TryGetComp <CompArt>(); if (compArt != null) { if (compQuality == null) { compArt.InitializeArt(ArtGenerationContext.Colony); } compArt.JustCreatedBy(worker); } thing.HitPoints = Mathf.CeilToInt((float)HitPoints / (float)base.MaxHitPoints * (float)thing.MaxHitPoints); GenSpawn.Spawn(thing, base.Position, map, base.Rotation, WipeMode.FullRefund); Building b; if ((b = thing as Building) != null) { worker.GetLord()?.AddBuilding(b); } } else { map.terrainGrid.SetTerrain(base.Position, (TerrainDef)def.entityDefToBuild); FilthMaker.RemoveAllFilth(base.Position, map); } worker.records.Increment(RecordDefOf.ThingsConstructed); if (thing != null && thing.GetStatValue(StatDefOf.WorkToBuild) >= 9500f) { TaleRecorder.RecordTale(TaleDefOf.CompletedLongConstructionProject, worker, thing.def); } }
public static bool TryGetQuality(this Thing t, out QualityCategory qc) { MinifiedThing minifiedThing = t as MinifiedThing; CompQuality compQuality = (minifiedThing == null) ? t.TryGetComp <CompQuality>() : minifiedThing.InnerThing.TryGetComp <CompQuality>(); if (compQuality == null) { qc = QualityCategory.Normal; return(false); } qc = compQuality.Quality; return(true); }
public static TaleData_Thing GenerateRandom() { ThingDef obj = DefDatabase <ThingDef> .AllDefs.Where((ThingDef d) => d.comps != null && d.comps.Any((CompProperties cp) => cp.compClass == typeof(CompArt))).RandomElement(); ThingDef thingDef = GenStuff.RandomStuffFor(obj); Thing thing = ThingMaker.MakeThing(obj, thingDef); ArtGenerationContext source = (Rand.Value < 0.5f) ? ArtGenerationContext.Colony : ArtGenerationContext.Outsider; CompQuality compQuality = thing.TryGetComp <CompQuality>(); if (compQuality != null && (int)compQuality.Quality < (int)thing.TryGetComp <CompArt>().Props.minQualityForArtistic) { compQuality.SetQuality(thing.TryGetComp <CompArt>().Props.minQualityForArtistic, source); } thing.TryGetComp <CompArt>().InitializeArt(source); return(GenerateFrom(thing)); }
public static TaleData_Thing GenerateRandom() { ThingDef thingDef = (from d in DefDatabase <ThingDef> .AllDefs where d.comps != null && d.comps.Any((CompProperties cp) => cp.compClass == typeof(CompArt)) select d).RandomElement(); ThingDef thingDef2 = GenStuff.RandomStuffFor(thingDef); Thing thing = ThingMaker.MakeThing(thingDef, thingDef2); ArtGenerationContext source = (ArtGenerationContext)((Rand.Value < 0.5) ? 1 : 0); CompQuality compQuality = thing.TryGetComp <CompQuality>(); if (compQuality != null && (int)compQuality.Quality < (int)thing.TryGetComp <CompArt>().Props.minQualityForArtistic) { compQuality.SetQuality(thing.TryGetComp <CompArt>().Props.minQualityForArtistic, source); } thing.TryGetComp <CompArt>().InitializeArt(source); return(TaleData_Thing.GenerateFrom(thing)); }
public static void SendCraftNotification(Thing thing, Pawn worker) { if (worker != null) { CompQuality compQuality = thing.TryGetComp <CompQuality>(); if (compQuality != null) { if (compQuality.Quality == QualityCategory.Masterwork) { Messages.Message("MessageCraftedMasterwork".Translate(worker.LabelShort, thing.LabelShort, worker.Named("WORKER"), thing.Named("CRAFTED")), thing, MessageTypeDefOf.PositiveEvent); } else if (compQuality.Quality == QualityCategory.Legendary) { Find.LetterStack.ReceiveLetter("LetterCraftedLegendaryLabel".Translate(), "LetterCraftedLegendaryMessage".Translate(worker.LabelShort, thing.LabelShort, worker.Named("WORKER"), thing.Named("CRAFTED")), LetterDefOf.PositiveEvent, thing); } } } }
private Thing GenerateReward(float value, TechLevel techLevel, Predicate <ThingDef> validator = null) { if (Rand.Chance(0.5f) && (validator == null || validator(ThingDefOf.Silver))) { Thing thing = ThingMaker.MakeThing(ThingDefOf.Silver, null); thing.stackCount = ThingUtility.RoundedResourceStackCount(Mathf.Max(GenMath.RoundRandom(value), 1)); return(thing); } ThingDef thingDef = default(ThingDef); if (Rand.Chance(0.35f) && (from x in ItemCollectionGeneratorUtility.allGeneratableItems where x.itemGeneratorTags != null && x.itemGeneratorTags.Contains(ItemCollectionGeneratorUtility.SpecialRewardTag) && (validator == null || validator(x)) && Mathf.Abs((float)(1.0 - x.BaseMarketValue / value)) <= 0.34999999403953552 select x).TryRandomElement <ThingDef>(out thingDef)) { Thing thing2 = ThingMaker.MakeThing(thingDef, GenStuff.RandomStuffFor(thingDef)); CompQuality compQuality = thing2.TryGetComp <CompQuality>(); if (compQuality != null) { compQuality.SetQuality(QualityUtility.RandomBaseGenItemQuality(), ArtGenerationContext.Outsider); } return(thing2); } if (Rand.Chance(0.13f)) { float minExpensiveMineableResourceMarketValue = ThingDefOf.Uranium.BaseMarketValue; ThingDef thingDef2 = default(ThingDef); if ((from x in ItemCollectionGenerator_Meteorite.mineables where x.building.isResourceRock && x.building.mineableThing.BaseMarketValue >= minExpensiveMineableResourceMarketValue && (validator == null || validator(x.building.mineableThing)) select x).TryRandomElement <ThingDef>(out thingDef2)) { float num = (float)(value * 0.89999997615814209); ThingDef mineableThing = thingDef2.building.mineableThing; Thing thing3 = ThingMaker.MakeThing(mineableThing, null); thing3.stackCount = Mathf.Max(GenMath.RoundRandom(num / mineableThing.BaseMarketValue), 1); return(thing3); } } Option option2 = (from option in ItemCollectionGeneratorUtility.allGeneratableItems.Select(delegate(ThingDef td) { if ((int)td.techLevel > (int)techLevel) { return(null); } if (td.itemGeneratorTags != null && td.itemGeneratorTags.Contains(ItemCollectionGeneratorUtility.SpecialRewardTag)) { return(null); } if (!td.IsWithinCategory(ThingCategoryDefOf.Apparel) && !td.IsWithinCategory(ThingCategoryDefOf.Weapons) && !td.IsWithinCategory(ThingCategoryDefOf.Art) && (td.building == null || !td.Minifiable) && (td.tradeTags == null || !td.tradeTags.Contains("Exotic"))) { return(null); } if (validator != null && !validator(td)) { return(null); } ThingDef stuff = null; if (td.MadeFromStuff && !GenStuff.TryRandomStuffByCommonalityFor(td, out stuff, techLevel)) { return(null); } Option option3 = new Option(); option3.thingDef = td; option3.quality = ((!td.HasComp(typeof(CompQuality))) ? QualityCategory.Normal : QualityUtility.RandomQuality()); option3.stuff = stuff; return(option3); }) where option != null select option).MinBy(delegate(Option option) { float value2 = StatDefOf.MarketValue.Worker.GetValue(StatRequest.For(option.thingDef, option.stuff, option.quality), true); return(Mathf.Abs(value - value2)); }); Thing thing4 = ThingMaker.MakeThing(option2.thingDef, option2.stuff); CompQuality compQuality2 = thing4.TryGetComp <CompQuality>(); if (compQuality2 != null) { compQuality2.SetQuality(option2.quality, ArtGenerationContext.Outsider); } return(thing4); }
public void CompleteConstruction(Pawn worker) { this.resourceContainer.ClearAndDestroyContents(DestroyMode.Vanish); Map map = base.Map; this.Destroy(DestroyMode.Vanish); if (this.GetStatValue(StatDefOf.WorkToBuild, true) > 150.0 && base.def.entityDefToBuild is ThingDef && ((ThingDef)base.def.entityDefToBuild).category == ThingCategory.Building) { SoundDefOf.BuildingComplete.PlayOneShot(new TargetInfo(base.Position, map, false)); } ThingDef thingDef = base.def.entityDefToBuild as ThingDef; Thing thing = null; if (thingDef != null) { thing = ThingMaker.MakeThing(thingDef, base.Stuff); thing.SetFactionDirect(base.Faction); CompQuality compQuality = thing.TryGetComp <CompQuality>(); if (compQuality != null) { int level = worker.skills.GetSkill(SkillDefOf.Construction).Level; compQuality.SetQuality(QualityUtility.RandomCreationQuality(level), ArtGenerationContext.Colony); } CompArt compArt = thing.TryGetComp <CompArt>(); if (compArt != null) { if (compQuality == null) { compArt.InitializeArt(ArtGenerationContext.Colony); } compArt.JustCreatedBy(worker); } thing.HitPoints = Mathf.CeilToInt((float)this.HitPoints / (float)base.MaxHitPoints * (float)thing.MaxHitPoints); GenSpawn.Spawn(thing, base.Position, map, base.Rotation, false); } else { map.terrainGrid.SetTerrain(base.Position, (TerrainDef)base.def.entityDefToBuild); FilthMaker.RemoveAllFilth(base.Position, map); } if (thingDef != null && (thingDef.passability == Traversability.Impassable || thingDef.Fillage == FillCategory.Full) && (thing == null || !(thing is Building_Door))) { foreach (IntVec3 item in GenAdj.CellsOccupiedBy(base.Position, base.Rotation, base.def.Size)) { foreach (Thing item2 in map.thingGrid.ThingsAt(item).ToList()) { if (item2 is Plant) { item2.Destroy(DestroyMode.KillFinalize); } else if (item2.def.category == ThingCategory.Item || item2 is Pawn) { GenPlace.TryMoveThing(item2, item2.Position, item2.Map); } } } } worker.records.Increment(RecordDefOf.ThingsConstructed); if (thing != null && thing.GetStatValue(StatDefOf.WorkToBuild, true) >= 10000.0) { TaleRecorder.RecordTale(TaleDefOf.CompletedLongConstructionProject, worker, thing.def); } }
// Token: 0x060000D7 RID: 215 RVA: 0x000066F8 File Offset: 0x000048F8 public void CompleteConstruction(Pawn worker) { Map map = base.Map; bool flag = this.GetStatValue(StatDefOf.WorkToBuild, true) > 150f && this.def.entityDefToBuild is ThingDef && ((ThingDef)this.def.entityDefToBuild).category == ThingCategory.Building; if (flag) { SoundDefOf.Building_Complete.PlayOneShot(new TargetInfo(base.Position, map, false)); } ThingDef thingDef = this.def.entityDefToBuild as ThingDef; Thing thing = null; bool flag2 = thingDef != null; if (flag2) { thing = ThingMaker.MakeThing(thingDef, base.Stuff); thing.SetFactionDirect(base.Faction); CompQuality compQuality = thing.TryGetComp <CompQuality>(); bool flag3 = compQuality != null; if (flag3) { int relevantSkillLevel = 1; compQuality.SetQuality(QualityUtility.GenerateQualityCreatedByPawn(relevantSkillLevel, false), ArtGenerationContext.Colony); } CompArt compArt = thing.TryGetComp <CompArt>(); bool flag4 = compArt != null; if (flag4) { bool flag5 = compQuality == null; if (flag5) { compArt.InitializeArt(ArtGenerationContext.Colony); } compArt.JustCreatedBy(worker); } thing.HitPoints = Mathf.CeilToInt((float)this.HitPoints / (float)base.MaxHitPoints * (float)thing.MaxHitPoints); GenSpawn.Spawn(thing, base.Position, map, base.Rotation, WipeMode.FullRefund, false); } else { map.terrainGrid.SetTerrain(base.Position, (TerrainDef)this.def.entityDefToBuild); FilthMaker.RemoveAllFilth(base.Position, map); } bool flag6 = thingDef != null && (thingDef.passability == Traversability.Impassable || thingDef.Fillage == FillCategory.Full) && (thing == null || !(thing is Building_Door)); if (flag6) { foreach (IntVec3 c in GenAdj.CellsOccupiedBy(base.Position, base.Rotation, this.def.Size)) { foreach (Thing thing2 in map.thingGrid.ThingsAt(c).ToList <Thing>()) { bool flag7 = thing2 is Plant; if (flag7) { thing2.Destroy(DestroyMode.KillFinalize); } else { bool flag8 = thing2.def.category == ThingCategory.Item || thing2 is Pawn; if (flag8) { GenPlace.TryPlaceThing(thing2, thing2.Position, thing2.Map, ThingPlaceMode.Near, null, null, default(Rot4)); } } } } } worker.records.Increment(RecordDefOf.ThingsConstructed); }