Exemple #1
0
        private static Thing PostProcessProduct(Thing product, RecipeDef recipeDef, Pawn worker)
        {
            CompQuality compQuality = product.TryGetComp <CompQuality>();

            if (compQuality != null)
            {
                if (recipeDef.workSkill == null)
                {
                    Log.Error(recipeDef + " needs workSkill because it creates a product with a quality.");
                }
                int             level           = worker.skills.GetSkill(recipeDef.workSkill).Level;
                QualityCategory qualityCategory = QualityUtility.RandomCreationQuality(level);
                if (worker.InspirationDef == InspirationDefOf.InspiredArt && (product.def.IsArt || (product.def.minifiedDef != null && product.def.minifiedDef.IsArt)))
                {
                    qualityCategory = qualityCategory.AddLevels(3);
                    worker.mindState.inspirationHandler.EndInspiration(InspirationDefOf.InspiredArt);
                }
                compQuality.SetQuality(qualityCategory, ArtGenerationContext.Colony);
            }
            CompArt compArt = product.TryGetComp <CompArt>();

            if (compArt != null)
            {
                compArt.JustCreatedBy(worker);
                if ((int)compQuality.Quality >= 6)
                {
                    TaleRecorder.RecordTale(TaleDefOf.CraftedArt, worker, product);
                }
            }
            if (product.def.Minifiable)
            {
                product = product.MakeMinified();
            }
            return(product);
        }
Exemple #2
0
        /// <summary>
        /// Try to generate a random treasure
        /// </summary>
        /// <returns></returns>
        private Thing TryGetTreasure()
        {
            Thing treasure = null;

            // find fitting treasure
            TreasureCollection foundTreasure = null;

            if (!def.treasureDefs.TryRandomElementByWeight <TreasureCollection>(f => f.Chance, out foundTreasure))
            {
                return(null);
            }

            // make treasure
            if (foundTreasure == null)
            {
                return(null);
            }

            treasure = ThingMaker.MakeThing(foundTreasure.TreasureDef, foundTreasure.StuffDef);

            // try adjust quality
            CompQuality treasureCQ = treasure.TryGetComp <CompQuality>();

            if (treasureCQ != null)
            {
                treasureCQ.SetQuality(QualityUtility.RandomCreationQuality(Rand.RangeInclusive(10, 20)), ArtGenerationContext.Outsider);
            }

            // adjust Stack to a random stack size
            if (foundTreasure.GiveStack && treasure.def.stackLimit > 1)
            {
                treasure.stackCount = Rand.RangeInclusive(1, treasure.def.stackLimit);
            }

            // adjust Hitpoints (60 to Max)
            if (treasure.stackCount == 1)
            {
                treasure.HitPoints = Rand.RangeInclusive((int)(treasure.MaxHitPoints * 0.6), treasure.MaxHitPoints);
            }

            return(treasure);
        }
Exemple #3
0
        public static void ScatterWeaponsWhere(CellRect within, int num, Map map, Predicate <ThingDef> validator)
        {
            List <ThingStuffPair> list = MapGenUtility.GetWeapons(validator);

            for (int i = 0; i < num; i++)
            {
                ThingStuffPair thingStuffPair = GenCollection.RandomElement <ThingStuffPair>(list);
                Thing          thing          = ThingMaker.MakeThing(thingStuffPair.thing, thingStuffPair.stuff);
                CompQuality    compQuality    = ThingCompUtility.TryGetComp <CompQuality>(thing);
                if (compQuality != null)
                {
                    compQuality.SetQuality(QualityUtility.RandomCreationQuality(12), 0);
                }
                IntVec3 intVec;
                if (thing != null && CellFinder.TryFindRandomCellInsideWith(within, (IntVec3 loc) => GenGrid.Standable(loc, map), out intVec))
                {
                    GenSpawn.Spawn(thing, intVec, map);
                }
            }
        }
Exemple #4
0
        private static Thing TryGetTreasure(ThingDef treasureDef, ThingDef stuffDef)
        {
            Thing treasure = null;

            // make treasure
            if (treasureDef == null)
            {
                return(null);
            }

            treasure = ThingMaker.MakeThing(treasureDef, stuffDef);

            // try adjust quality
            CompQuality treasureQuality = treasure.TryGetComp <CompQuality>();

            if (treasureQuality != null)
            {
                treasureQuality.SetQuality(QualityUtility.RandomCreationQuality(Rand.RangeInclusive(10, 18)), ArtGenerationContext.Outsider);
            }

            // adjust Stack to a random stack size
            if (treasure.def.stackLimit > 1)
            {
                if (treasure.def.stackLimit > 50)
                {
                    treasure.stackCount = Rand.RangeInclusive(1, 45);
                }
                else
                {
                    treasure.stackCount = Rand.RangeInclusive(1, treasure.def.stackLimit);
                }
            }

            // adjust Hitpoints (40% to 100%)
            if (treasure.stackCount == 1)
            {
                treasure.HitPoints = Rand.RangeInclusive((int)(treasure.MaxHitPoints * 0.4), treasure.MaxHitPoints);
            }

            return(treasure);
        }