// Token: 0x06001566 RID: 5478 RVA: 0x0007D285 File Offset: 0x0007B485
        public Graphic SubGraphicFor(Thing thing)
        {
            CompAdvancedGraphic comp    = thing.TryGetComp <CompAdvancedGraphic>();
            CompQuality         quality = thing.TryGetComp <CompQuality>();
            CompArt             art     = thing.TryGetComp <CompArt>();

            if (comp != null)
            {
                //	Log.Message("SubGraphicFor "+ thing.Label + " found CompAdvancedGraphic int " + comp.gfxint);
                if (!comp.Props.onlyArtable || (art != null && art.Active))
                {
                    if (comp.Props.quality)
                    {
                        return(this.SubGraphicForQuality(thing, comp));
                    }
                    if (comp.Props.randomised)
                    {
                        return(this.SubGraphicRandomized(thing, comp));
                    }
                }
                if (!comp.Props.tagged.NullOrEmpty())
                {
                    Graphic sub = subGraphics.FirstOrDefault(x => x.path.Contains(comp.Props.tagged));
                    if (sub != null)
                    {
                        return(subGraphics.FirstOrDefault(x => x.path.Contains(comp.Props.tagged)));
                    }
                }
            }
            else
            {
                //	Log.Message("SubGraphicFor " + thing.Label + " Didnt find CompAdvancedGraphic");
            }
            return(this.subGraphics[0]);
        }
예제 #2
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.", false);
                }
                QualityCategory q = QualityUtility.GenerateQualityCreatedByPawn(worker, recipeDef.workSkill);
                compQuality.SetQuality(q, ArtGenerationContext.Colony);
                QualityUtility.SendCraftNotification(product, worker);
            }
            CompArt compArt = product.TryGetComp <CompArt>();

            if (compArt != null)
            {
                compArt.JustCreatedBy(worker);
                if (compQuality.Quality >= QualityCategory.Excellent)
                {
                    TaleRecorder.RecordTale(TaleDefOf.CraftedArt, new object[]
                    {
                        worker,
                        product
                    });
                }
            }
            if (product.def.Minifiable)
            {
                product = product.MakeMinified();
            }
            return(product);
        }
예제 #3
0
        // Token: 0x0600000B RID: 11 RVA: 0x000020E0 File Offset: 0x000002E0
        public void SetQuality(QualityCategory q, ArtGenerationContext source)
        {
            this.qualityInt = QualityCategory.Normal;
            CompArt compArt = this.parent.TryGetComp <CompArt>();

            compArt.InitializeArt(source);
        }
예제 #4
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);
        }
        private static Thing PostProcessProduct(Thing product, RecipeDef recipeDef, IRecipeProductWorker 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.GetSkillLevel(recipeDef.workSkill);
                QualityCategory qualityCategory = QualityUtility.GenerateQualityCreatedByPawn(level, false);
                compQuality.SetQuality(qualityCategory, ArtGenerationContext.Colony);
            }
            CompArt compArt = product.TryGetComp <CompArt>();

            if (compArt != null)
            {
                if (compQuality.Quality >= QualityCategory.Excellent)
                {
                    /*
                     * TaleRecorder.RecordTale(TaleDefOf.CraftedArt, new object[]
                     * {
                     *  product
                     * });
                     */
                }
            }
            if (product.def.Minifiable)
            {
                product = product.MakeMinified();
            }
            return(product);
        }
예제 #6
0
        // Token: 0x0600003D RID: 61 RVA: 0x0000347A File Offset: 0x0000167A
        protected override IEnumerable <Toil> MakeNewToils()
        {
            yield return(Toils_Goto.GotoThing(TargetIndex.B, PathEndMode.ClosestTouch));

            yield return(Toils_Haul.StartCarryThing(TargetIndex.B, false, false, false));

            yield return(Toils_Haul.CarryHauledThingToCell(TargetIndex.A));

            yield return(new Toil
            {
                initAction = delegate()
                {
                    Venue.rehearsing = true;
                    CompArt compArt = Art.TryGetComp <CompArt>();
                    CompQuality compQuality = Art.TryGetComp <CompQuality>();
                    if (compArt != null && compQuality != null)
                    {
                        Venue.artistName = compArt.AuthorName;
                        Venue.artTitle = compArt.Title;
                        Venue.artQuality = compQuality.Quality;
                    }
                    Art.Destroy(DestroyMode.Vanish);
                },
                defaultCompleteMode = ToilCompleteMode.Instant
            });

            yield break;
        }
예제 #7
0
        protected void DoEffect()
        {
            Thing target = base.TargetA.Thing;
            Map   map    = target.Map;

            target.Destroy(DestroyMode.WillReplace);
            Thing       wall        = ThingMaker.MakeThing(ThingDef.Named("Engraved" + target.def.building.unsmoothedThing.defName), target.Stuff);
            CompQuality compQuality = wall.TryGetComp <CompQuality>();

            if (compQuality != null)
            {
                int             level           = this.pawn.skills.GetSkill(SkillDefOf.Artistic).Level;
                QualityCategory qualityCategory = QualityUtility.GenerateQualityCreatedByPawn(level, false);
                compQuality.SetQuality(qualityCategory, ArtGenerationContext.Colony);
            }
            CompArt compArt = wall.TryGetComp <CompArt>();

            if (compArt != null)
            {
                compArt.JustCreatedBy(this.pawn);
                if (compQuality.Quality >= QualityCategory.Excellent)
                {
                    TaleRecorder.RecordTale(TaleDefOf.CraftedArt, new object[]
                    {
                        this.pawn,
                        wall
                    });
                }
            }
            wall.SetFaction(this.pawn.Faction, null);
            GenSpawn.Spawn(wall, target.Position, map, target.Rotation, WipeMode.Vanish, false);
            map.designationManager.TryRemoveDesignation(target.Position, DesignationDefOf.EngraveWall);
        }
        // Token: 0x06000018 RID: 24 RVA: 0x0000322C File Offset: 0x0000142C
        private static Thing PostProcessProduct(Thing product, RecipeDef recipeDef, Pawn worker)
        {
            string[] array = new string[6];
            array[0] = "post processing: product ";
            int   num   = 1;
            Thing thing = product;

            array[num] = ((thing != null) ? thing.ToString() : null);
            array[2]   = " recipeDef ";
            array[3]   = ((recipeDef != null) ? recipeDef.ToString() : null);
            array[4]   = " worker ";
            array[5]   = ((worker != null) ? worker.ToString() : null);
            Log.Message(string.Concat(array), false);
            CompQuality compQuality = product.TryGetComp <CompQuality>();
            bool        flag        = compQuality != null;

            if (flag)
            {
                bool flag2 = recipeDef.workSkill == null;
                if (flag2)
                {
                    Log.Error(((recipeDef != null) ? recipeDef.ToString() : null) + " needs workSkill because it creates a product with a quality.", false);
                }
                int             relevantSkillLevel = 1;
                QualityCategory q     = QualityUtility.GenerateQualityCreatedByPawn(relevantSkillLevel, false);
                bool            flag3 = worker.InspirationDef == InspirationDefOf.Inspired_Creativity && (product.def.IsArt || (product.def.minifiedDef != null && product.def.minifiedDef.IsArt));
                if (flag3)
                {
                    int relevantSkillLevel2 = 4;
                    q = QualityUtility.GenerateQualityCreatedByPawn(relevantSkillLevel2, false);
                }
                compQuality.SetQuality(q, ArtGenerationContext.Colony);
            }
            CompArt compArt = product.TryGetComp <CompArt>();
            bool    flag4   = compArt != null;

            if (flag4)
            {
                compArt.JustCreatedBy(worker);
            }
            bool minifiable = product.def.Minifiable;

            if (minifiable)
            {
                product = product.MakeMinified();
            }
            string[] array2 = new string[6];
            array2[0] = "end post processing:product ";
            int   num2   = 1;
            Thing thing2 = product;

            array2[num2] = ((thing2 != null) ? thing2.ToString() : null);
            array2[2]    = " recipeDef ";
            array2[3]    = ((recipeDef != null) ? recipeDef.ToString() : null);
            array2[4]    = " worker ";
            array2[5]    = ((worker != null) ? worker.ToString() : null);
            Log.Message(string.Concat(array2), false);
            return(product);
        }
예제 #9
0
        public static void FillGraveThought(Building_Grave __instance, Pawn worker)
        {
            CompArt comp = __instance.GetComp <CompArt>();

            if (worker.needs.mood != null && comp != null)
            {
                worker.needs.mood.thoughts.memories.TryGainMemory(ThoughtDefOfPsychology.FilledGraveBleedingHeart);
            }
        }
예제 #10
0
        // Token: 0x06000004 RID: 4 RVA: 0x00002160 File Offset: 0x00000360
        private List <Thing> CreateLoot()
        {
            List <Thing> list = new List <Thing>();
            int          ItemCount;

            if (PropsResourceBox.spawnAll)
            {
                ItemCount = PropsResourceBox.possibleItems.Count;
            }
            else
            {
                ItemCount = Rand.RangeInclusive(PropsResourceBox.minItems, PropsResourceBox.maxItems);
            }
            for (int i = 0; i < ItemCount; i++)
            {
                ThingDef named = null;
                int      PerItemCount;
                int      j = 0;
                if (PropsResourceBox.PerItemCount != 0)
                {
                    PerItemCount = PropsResourceBox.PerItemCount;
                }
                else
                {
                    PerItemCount = Rand.RangeInclusive(PropsResourceBox.minPerItem, PropsResourceBox.maxPerItem);
                }
                if (!PropsResourceBox.possibleItems.NullOrEmpty())
                {
                    if (PropsResourceBox.spawnAll)
                    {
                        named = PropsResourceBox.possibleItems[i];
                    }
                    else
                    {
                        named = PropsResourceBox.possibleItems.RandomElement();
                    }
                }
                if (named != null)
                {
                    Thing thing = ThingMaker.MakeThing(named, GenStuff.RandomStuffFor(named));
                    thing.stackCount = PerItemCount;
                    CompQuality compQuality = ThingCompUtility.TryGetComp <CompQuality>(thing);
                    if (compQuality != null)
                    {
                        QualityCategory qualityCategory = QualityUtility.GenerateQualityCreatedByPawn(Rand.RangeInclusive(0, 19), false);
                        compQuality.SetQuality(qualityCategory, 0);
                    }
                    CompArt compArt = ThingCompUtility.TryGetComp <CompArt>(thing);
                    if (compArt != null)
                    {
                        compArt.InitializeArt(0);
                    }
                    list.Add(thing);
                }
            }
            return(list);
        }
        public static Thing ReplacedThing(ThingWithComps original)
        {
            bool actionRequired = original.GetType() != original.def.thingClass;

            if (actionRequired)
            {
                //    Log.Message("original.GetType("+ original.GetType()+ ") != original.def.thingClass("+ original.def.thingClass+")");
                bool act = original.def.modContentPack != null && original.def.modContentPack.Name.Contains("Adeptus Mechanicus");
                if (act)
                {
                    try
                    {
                        //    Log.Message("act");
                        //    Log.Warning(original.LabelCap + "'s ThingClass doesnt match its Defs ThingClass, trying to fix");
                        Thing thing = ThingMaker.MakeThing(original.def, original.Stuff);
                        thing.Position = original.Position;
                        CompQuality quality = original.TryGetCompFast <CompQuality>();
                        if (quality != null)
                        {
                            quality.parent = thing as ThingWithComps;
                        }
                        CompArt art = original.TryGetCompFast <CompArt>();
                        if (art != null)
                        {
                            art.parent = thing as ThingWithComps;
                        }
                        thing.thingIDNumber = original.thingIDNumber;
                        IThingHolder   holder     = original.ParentHolder;
                        CompEquippable equippable = original.TryGetCompFast <CompEquippable>();
                        if (equippable != null)
                        {
                            Thing user = equippable.VerbTracker.PrimaryVerb.Caster;
                            Pawn  p    = user as Pawn;
                            if (p != null)
                            {
                                p.equipment.Remove(original);
                                p.equipment.AddEquipment(thing as ThingWithComps);
                            }
                        }
                        else
                        if (holder != null)
                        {
                            holder.GetDirectlyHeldThings().Remove(original);
                            holder.GetDirectlyHeldThings().TryAdd(thing);
                        }
                        return(thing);
                    }
                    catch (Exception)
                    {
                        Log.Warning("Something went wrong trying to replace " + original.LabelCap + "'s ThingClass from " + original.GetType().Name + " to " + original.def.thingClass.Name);
                        return(original);
                    }
                }
            }
            return(original);
        }
예제 #12
0
        public void SetNature(NatureCategory ccor, ArtGenerationContext source)
        {
            this.ccint = ccor;
            CompArt compArt = this.parent.TryGetComp <CompArt>();

            if (compArt != null)
            {
                compArt.InitializeArt(source);
            }
        }
        public static void Postfix(Apparel apparel, BodyTypeDef bodyType, ref ApparelGraphicRecord rec)
        {
            if (apparel.def.apparel.wornGraphicPath.NullOrEmpty())
            {
                return;
            }
            CompAdvancedGraphic comp    = apparel.TryGetComp <CompAdvancedGraphic>();
            CompQuality         quality = apparel.TryGetComp <CompQuality>();
            CompArt             art     = apparel.TryGetComp <CompArt>();
            bool adv = comp != null;

            if (adv)
            {
                if (comp._graphic == null || comp._graphic.path.NullOrEmpty())
                {
                    bool flag = apparel.DefaultGraphic as Graphic_RandomRotated != null;
                    if (flag)
                    {
                        //	Log.Message(apparel.LabelShortCap + " as Graphic_RandomRotated");
                        Traverse traverse = Traverse.Create(apparel.DefaultGraphic);
                        Graphic_AdvancedSingle subGraphic = AG_Thing_get_DefaultGraphic_CompAdvancedGraphic_Patch.subgraphic.GetValue(apparel.DefaultGraphic) as Graphic_AdvancedSingle;
                        if (subGraphic != null)
                        {
                            //	Log.Message(apparel.LabelShortCap + " as Graphic_AdvancedSingle");
                            comp._graphic = subGraphic.SubGraphicFor(apparel);
                        }
                    }
                    else
                    {
                        comp._graphic = apparel.DefaultGraphic;
                        return;
                    }
                }
                string path   = apparel.def.apparel.wornGraphicPath;
                Shader shader = ShaderDatabase.Cutout;
                if (apparel.def.apparel.useWornGraphicMask)
                {
                    shader = ShaderDatabase.CutoutComplex;
                }
                if (apparel.def.apparel.LastLayer == ApparelLayerDefOf.Overhead || apparel.def.apparel.wornGraphicPath == BaseContent.PlaceholderImagePath)
                {
                    path = comp._graphic.path;
                }
                else
                {
                    path = comp._graphic.path + "_" + bodyType.defName;
                }
                Graphic graphic = GraphicDatabase.Get <Graphic_Multi>(path, shader, apparel.def.graphicData.drawSize, apparel.DrawColor, apparel.DrawColorTwo);
                rec = new ApparelGraphicRecord(graphic, apparel);
            }
            if (apparel.DrawColorTwo != Color.white)
            {
                rec.graphic = rec.graphic.GetColoredVersion(rec.graphic.Shader, apparel.DrawColor, apparel.DrawColorTwo);
            }
        }
예제 #14
0
 public static IEnumerable <Thing> MakeProducts(this RecipeDef def, Order order, int cycles)
 {
     if (cycles <= 0)
     {
         Log.Error(string.Concat(new Object[] {
             "Order ",
             def.defName,
             " tried to make products using invalid number of cycles: ",
             cycles.ToString()
         }));
         yield break;
     }
     foreach (var current in def.products)
     {
         //Log.Message("Starting to make things");
         int count = current.count * cycles;
         while (count > 0)
         {
             if (count <= 0)
             {
                 break;
             }
             //Log.Message("Making things");
             Thing thing;
             if (current.thingDef.MadeFromStuff)
             {
                 ThingDef stuffDef = order.ShoppingList.AcquiredMats.Where((ListItem i) => i.thing.stuffProps != null).First().thing;
                 if (stuffDef == null)
                 {
                     Log.Error(string.Concat(new object[] {
                         "Order ",
                         order.Recipe.LabelCap,
                         " tried to produce a thing with stuff, but no ingredients had stuffprops!"
                     }));
                 }
                 thing = ThingMaker.MakeThing(current.thingDef, stuffDef);
             }
             else
             {
                 thing = ThingMaker.MakeThing(current.thingDef);
             }
             CompArt art = thing.TryGetComp <CompArt>();
             if (art != null)
             {
                 art.GenerateTaleRef(ArtGenerationSource.Colony);
             }
             int num = UnityEngine.Mathf.Min(count, thing.def.stackLimit);
             thing.stackCount = num;
             count           -= num;
             //TODO
             //Check to see if it has a quality level. If yes, then overrite it with the quality able to be produced by the line.
             yield return(thing);
         }
     }
 }
예제 #15
0
        public static void FillTab(ITab_Art __instance)
        {
            Thing thing = Find.Selector.SingleSelectedThing;

            if (thing is MinifiedThing minifiedThing)
            {
                thing = minifiedThing.InnerThing;
            }
            CompArt art = thing?.TryGetComp <CompArt>();

            Rect rect1 = new Rect(10f, 270f, 100f, 20f);

            if (Widgets.ButtonText(rect1, "Reroll"))
            {
                art.InitializeArt(ArtGenerationContext.Colony);
            }

            // The following are much more involved and cannot use the default behavior
            Rect rect2 = new Rect(110f, 270f, 120f, 20f);

            if (Widgets.ButtonText(rect2, "Reroll Specific"))
            {
                List <FloatMenuOption> options = new List <FloatMenuOption>();
                foreach (TaleDef taleDef in from def in DefDatabase <TaleDef> .AllDefs orderby def.defName select def)
                {
                    FloatMenuOption option = new FloatMenuOption(taleDef.defName, delegate
                    {
                        var tales    = Find.TaleManager.AllTalesListForReading.Where(it => it.def.defName == taleDef.defName);
                        var selected = tales.RandomElementByWeightWithFallback(it => it.InterestLevel + (1 / (1 + it.Uses)));
                        InitializeArt(art, selected);
                    });
                    options.Add(option);
                }
                Find.WindowStack.Add(new FloatMenu(options));
            }

            Rect rect3 = new Rect(230f, 270f, 120f, 20f);

            if (Widgets.ButtonText(rect3, "Reroll Colonist"))
            {
                List <FloatMenuOption> options = new List <FloatMenuOption>();
                foreach (Pawn pawn in from p in PawnsFinder.AllMapsCaravansAndTravelingTransportPods_Alive_Colonists orderby p.Name.ToStringShort select p)
                {
                    FloatMenuOption option = new FloatMenuOption(pawn.Name.ToStringShort, delegate
                    {
                        var tales    = Find.TaleManager.AllTalesListForReading.Where(it => it.Concerns(pawn));
                        var selected = tales.RandomElementByWeightWithFallback(it => it.InterestLevel + (1 / (1 + it.Uses)));
                        InitializeArt(art, selected);
                    });
                    options.Add(option);
                }
                Find.WindowStack.Add(new FloatMenu(options));
            }
        }
 internal static void _Notify_CorpseBuried(this Building_Grave _this, Pawn worker)
 {
     CompArt comp = _this.GetComp<CompArt>();
     if (comp != null && !comp.Active)
     {
         comp.JustCreatedBy(worker);
         comp.InitializeArt(_this.Corpse.InnerPawn);
         worker.needs.mood.thoughts.memories.TryGainMemoryThought(ThoughtDefOfPsychology.FilledGraveBleedingHeart);
     }
     _this.Map.mapDrawer.MapMeshDirty(_this.Position, MapMeshFlag.Buildings);
 }
        public static Thing ReplacedThing(ThingWithComps original)
        {
            Type oldType = original.GetType();
            Type newType = original.def.thingClass;

            try
            {
                //   if (AMAMod.Dev) Log.Warning(original.LabelCap + "'s ThingClass(" + oldType + ") doesnt match its Defs ThingClass(" + newType + "), trying to fix");
                Thing thing = ThingMaker.MakeThing(original.def, original.Stuff);
                thing.Position = original.Position;
                CompQuality quality = original.TryGetCompFast <CompQuality>();
                if (quality != null)
                {
                    quality.parent = thing as ThingWithComps;
                }
                CompArt art = original.TryGetCompFast <CompArt>();
                if (art != null)
                {
                    art.parent = thing as ThingWithComps;
                }
                thing.thingIDNumber = original.thingIDNumber;
                IThingHolder   holder     = original.ParentHolder;
                CompEquippable equippable = original.TryGetCompFast <CompEquippable>();
                if (equippable != null)
                {
                    Thing user = equippable.VerbTracker.PrimaryVerb.Caster;
                    Pawn  p    = user as Pawn;
                    if (p != null)
                    {
                        p.equipment.Remove(original);
                        p.equipment.AddEquipment(thing as ThingWithComps);
                    }
                }
                else
                if (holder != null)
                {
                    holder.GetDirectlyHeldThings().Remove(original);
                    holder.GetDirectlyHeldThings().TryAdd(thing);
                }
                if (AMAMod.Dev)
                {
                    Log.Message(original.LabelCap + "'s ThingClass(" + thing.GetType() + ") " + (thing.GetType() == newType ? "now matches" : "doesnt match") + "its Defs ThingClass(" + newType + ")");
                }
                return(thing);
            }
            catch (Exception)
            {
                Log.Warning("Something went wrong trying to replace " + original.LabelCap + "'s ThingClass from " + oldType.Name + " to " + newType.Name);
                return(original);
            }
        }
        static public bool Prefix(out TaggedString __result, CompArt __instance)
        {
            Thing t  = __instance.parent;
            var   ss = Current.Game.GetComponent <PRFGameComponent>().specialScupltures;

            if (ss == null)
            {
                return(true);
            }
            var s = ss.FirstOrDefault(x => x.currentInstances != null &&
                                      x.currentInstances.Contains(t));

            if (s == null)
            {
                return(true);
            }
            __result = new TaggedString(s.descKey.Translate());
            return(false); // skip vanilla
        }
예제 #19
0
        public override Job TryGiveJob(Pawn pawn)
        {
            bool allowedOutside = JoyUtility.EnjoyableOutsideNow(pawn, null);
            Job  result;

            try
            {
                JoyGiver_CuddlePlushie.candidates.AddRange(pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.Art).Where(delegate(Thing thing)
                {
                    if (thing.Faction != Faction.OfPlayer || thing.IsForbidden(pawn) || (!allowedOutside && !thing.Position.Roofed(thing.Map)) || !pawn.CanReserveAndReach(thing, PathEndMode.Touch, Danger.None, 1, -1, null, false) || !thing.IsPoliticallyProper(pawn))
                    {
                        return(false);
                    }
                    CompArt compArt = thing.TryGetComp <CompArt>();
                    if (compArt == null)
                    {
                        Log.Error("No CompArt on thing being considered for viewing: " + thing, false);
                        return(false);
                    }
                    //if (thing.def.defName != "Plushie")
                    if (thing.def.defName.StartsWith("Plushie") == false)
                    {
                        return(false);
                    }
                    Room room = thing.GetRoom(RegionType.Set_Passable);
                    return(room != null && ((room.Role != RoomRoleDefOf.Bedroom && room.Role != RoomRoleDefOf.Barracks && room.Role != RoomRoleDefOf.PrisonCell && room.Role != RoomRoleDefOf.PrisonBarracks && room.Role != RoomRoleDefOf.Hospital) || (pawn.ownership != null && pawn.ownership.OwnedRoom != null && pawn.ownership.OwnedRoom == room)));
                }));
                Thing t;
                if (!JoyGiver_CuddlePlushie.candidates.TryRandomElementByWeight((Thing target) => Math.Max(target.GetStatValue(StatDefOf.Beauty, true), 0.5f), out t))
                {
                    result = null;
                }
                else
                {
                    result = JobMaker.MakeJob(this.def.jobDef, t);
                }
            }
            finally
            {
                JoyGiver_CuddlePlushie.candidates.Clear();
            }
            return(result);
        }
예제 #20
0
        static bool SendCraftNotification(Thing thing, Pawn worker)
        {
            if (worker == null)
            {
                return(false);
            }
            CompQuality compQuality = thing.TryGetComp <CompQuality>();

            if (compQuality == null)
            {
                return(false);
            }
            CompArt compArt = thing.TryGetComp <CompArt>();

            if (compArt == null || thing is Building_Grave)
            {
                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, null, null, null, null);
                    return(false);
                }
                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, null, null, null, null);
                    return(false);
                }
            }
            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, null, null, null, null);
                    return(false);
                }
                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, null, null, null, null);
                }
            }
            return(false);
        }
        protected override void FillTab()
        {
            Rect rect  = new Rect(0f, 0f, this.size.x, this.size.y).ContractedBy(20f);
            Rect rect2 = rect;

            Text.Font = GameFont.Medium;
            CompArt compArt = (CompArt)this.selectedCompArtGetter.Invoke(this, null);

            Widgets.Label(rect2, compArt.Title);
            if (ITab_Art_Alternate.cachedImageSource != compArt || ITab_Art_Alternate.cachedTaleRef != compArt.TaleRef)
            {
                ITab_Art_Alternate.cachedImageDescription = compArt.ImageDescription();
                ITab_Art_Alternate.cachedImageSource      = compArt;
                ITab_Art_Alternate.cachedTaleRef          = compArt.TaleRef;
            }
            Rect rect3 = rect;

            rect3.yMin += 35f;
            Text.Font   = GameFont.Small;
            Widgets.Label(rect3, ITab_Art_Alternate.cachedImageDescription);
        }
예제 #22
0
        public static void InitializeArt(this CompArt art, string author, string title, string bakedTaleData)
        {
            // Debug.Message("Initializing custom art");
            var prop = art.GetType().GetField("taleRef", System.Reflection.BindingFlags.NonPublic
                                              | System.Reflection.BindingFlags.Instance);

            // Debug.Message("Got prop");
            prop.SetValue(art, new BakedTaleReference(bakedTaleData));
            // Debug.Message("Set value");

            var titleProp = art.GetType().GetField("titleInt", System.Reflection.BindingFlags.NonPublic
                                                   | System.Reflection.BindingFlags.Instance);

            //Debug.Message("Got title prop");
            titleProp.SetValue(art, title);

            var authProp = art.GetType().GetField("authorNameInt", System.Reflection.BindingFlags.NonPublic
                                                  | System.Reflection.BindingFlags.Instance);

            //Debug.Message("Got author prop");
            authProp.SetValue(art, author);
        }
예제 #23
0
        // Token: 0x06001566 RID: 5478 RVA: 0x0007D285 File Offset: 0x0007B485
        public Graphic SubGraphicFor(Thing thing)
        {
            CompAdvancedGraphic advancedGraphic = thing.TryGetComp <CompAdvancedGraphic>();
            CompQuality         quality         = thing.TryGetComp <CompQuality>();
            CompArt             art             = thing.TryGetComp <CompArt>();

            if (advancedGraphic != null)
            {
                if (!advancedGraphic.Props.onlyArtable || (art != null && art.Active))
                {
                    if (advancedGraphic.Props.quality)
                    {
                        return(this.SubGraphicForQuality(thing, advancedGraphic));
                    }
                    if (advancedGraphic.Props.randomised)
                    {
                        return(this.SubGraphicRandomized(thing, advancedGraphic));
                    }
                }
            }
            return(this.subGraphics[0]);
        }
예제 #24
0
        /// <summary>
        /// A reimplementation of CompArt.InitializeArt() for specific tales.
        /// </summary>
        private static void InitializeArt(CompArt comp, Tale tale)
        {
            if (comp.TaleRef != null)
            {
                comp.TaleRef.ReferenceDestroyed();
            }
            TaleReference taleRef;

            if (tale == null)
            {
                taleRef = TaleReference.Taleless;
            }
            else
            {
                tale.Notify_NewlyUsed();
                taleRef = new TaleReference(tale);
            }
            var traverse = Traverse.Create(comp);

            traverse.Field("taleRef").SetValue(taleRef);
            traverse.Field("titleInt").SetValue(new TaggedString(traverse.Method("GenerateTitle").GetValue <string>()));
        }
예제 #25
0
        // Token: 0x06000004 RID: 4 RVA: 0x00002160 File Offset: 0x00000360
        private List <Thing> CreateLoot()
        {
            List <Thing> list = new List <Thing>();
            int          ItemCount;

            if (PropsResourceBox.spawnAll)
            {
                ItemCount = PropsResourceBox.possibleItems.Count;
            }
            else
            {
                Rand.PushState();
                ItemCount = Rand.RangeInclusive(PropsResourceBox.minItems, PropsResourceBox.maxItems);
                Rand.PopState();
            }
            for (int i = 0; i < ItemCount; i++)
            {
                ThingDef named = null;
                int      PerItemCount;
                if (PropsResourceBox.PerItemCount != -1)
                {
                    PerItemCount = PropsResourceBox.PerItemCount;
                }
                else
                {
                    if (PropsResourceBox.randomCount)
                    {
                        Rand.PushState();
                        PerItemCount = Rand.RangeInclusive(PropsResourceBox.minPerItem, PropsResourceBox.maxPerItem);
                        Rand.PopState();
                    }
                    else
                    {
                        PerItemCount = PropsResourceBox.possibleItems[i].count;
                    }
                }
                if (!PropsResourceBox.possibleItems.NullOrEmpty())
                {
                    if (PropsResourceBox.spawnAll)
                    {
                        named = PropsResourceBox.possibleItems[i].thingDef;
                    }
                    else
                    {
                        Rand.PushState();
                        int element = Rand.RangeInclusive(0, PropsResourceBox.possibleItems.Count - 1);
                        Rand.PopState();
                        named = PropsResourceBox.possibleItems[element].thingDef;
                    }
                }
                if (named != null)
                {
                    Thing thing = ThingMaker.MakeThing(named, GenStuff.RandomStuffFor(named));
                    thing.stackCount = PerItemCount;
                    CompQuality compQuality = ThingCompUtility.TryGetComp <CompQuality>(thing);
                    if (compQuality != null)
                    {
                        QualityCategory qualityCategory = this.Quality;
                        compQuality.SetQuality(qualityCategory, 0);
                    }
                    CompArt compArt = ThingCompUtility.TryGetComp <CompArt>(thing);
                    if (compArt != null)
                    {
                        compArt.InitializeArt(0);
                    }
                    list.Add(thing);
                }
            }
            return(list);
        }
예제 #26
0
        private void EncodeThing(Thing thing, XmlWriter writer)
        {
            if (thing is Corpse)
            {
                EncodeCorpse((Corpse)thing, writer);
                return;
            }
            else if (thing is Pawn)
            {
                EncodePawn((Pawn)thing, writer);
                return;
            }

            //Use only buildings and items. Ignoring pawns, trees, filth and so on
            if (thing.def.category == ThingCategory.Building || thing.def.category == ThingCategory.Item)
            {
                if (thing.def.building != null && thing.def.building.isNaturalRock)
                {
                    return;                                                                 //ignoring natural rocks too
                }
                Type CompTextClass = Type.GetType("SaM.CompText, Signs_and_Memorials");


                if (thing.HitPoints > thing.MaxHitPoints * 0.9f)
                {
                    maxHPItemsCount++;
                }
                itemsCount++;

                writer.WriteStartElement("item");
                writer.WriteAttributeString("def", thing.def.defName);

                if (thing.Stuff != null)
                {
                    writer.WriteAttributeString("stuffDef", thing.Stuff.defName);
                }

                if (thing.stackCount > 1)
                {
                    writer.WriteAttributeString("stackCount", thing.stackCount.ToString());
                }

                if (thing.Rotation != null)
                {
                    writer.WriteAttributeString("rot", thing.Rotation.AsByte.ToString());
                }

                CompArt a = thing.TryGetComp <CompArt>();
                if (a != null && a.Active)
                {
                    writer.WriteAttributeString("artAuthor", a.AuthorName);
                    writer.WriteAttributeString("artTitle", a.Title);
                    writer.WriteAttributeString("artDescription", a.GenerateImageDescription());
                }

                ThingWithComps thingWithComps = thing as ThingWithComps;
                if (thingWithComps != null && CompTextClass != null)
                {
                    Object textComp = null;
                    for (int i = 0; i < thingWithComps.AllComps.Count; i++)
                    {
                        var val = thingWithComps.AllComps[i];
                        if (val.GetType() == CompTextClass)
                        {
                            textComp = val;
                        }
                    }
                    if (textComp != null)
                    {
                        string text = (string)(textComp?.GetType()?.GetField("text")?.GetValue(textComp));
                        if (text != null)
                        {
                            writer.WriteAttributeString("text", text);
                        }
                    }
                }

                if (thing.def.passability == Traversability.Impassable || thing.def.fillPercent > 0.99)
                {
                    writer.WriteAttributeString("actsAsWall", "1");
                }

                if (thing.def.IsDoor)
                {
                    writer.WriteAttributeString("isDoor", "1");
                }

                if (thing is IThingHolder)
                {
                    ThingOwner innerThingsOwner = ((IThingHolder)thing).GetDirectlyHeldThings();
                    foreach (Thing t in innerThingsOwner)
                    {
                        EncodeThing(t, writer);
                    }
                }
                writer.WriteEndElement();
            }
        }
예제 #27
0
        // Token: 0x060000EF RID: 239 RVA: 0x00008640 File Offset: 0x00006840
        public static bool CompleteConstruction_Prefix(Frame __instance, Pawn worker)
        {
            bool flag = !worker.RaceProps.Humanlike;
            bool result;

            if (flag)
            {
                Thing thing = __instance.holdingOwner.Take(__instance);
                __instance.resourceContainer.ClearAndDestroyContents(DestroyMode.Vanish);
                Map map = worker.Map;
                __instance.Destroy(DestroyMode.Vanish);
                bool flag2 = __instance.GetStatValue(StatDefOf.WorkToBuild, true) > 150f && __instance.def.entityDefToBuild is ThingDef && ((ThingDef)__instance.def.entityDefToBuild).category == ThingCategory.Building;
                if (flag2)
                {
                    SoundDefOf.Building_Complete.PlayOneShot(new TargetInfo(thing.Position, map, false));
                }
                ThingDef thingDef = __instance.def.entityDefToBuild as ThingDef;
                Thing    thing2   = null;
                bool     flag3    = thingDef != null;
                if (flag3)
                {
                    thing2 = ThingMaker.MakeThing(thingDef, thing.Stuff);
                    thing2.SetFactionDirect(thing.Faction);
                    CompQuality compQuality = thing2.TryGetComp <CompQuality>();
                    bool        flag4       = compQuality != null;
                    if (flag4)
                    {
                        int             relevantSkillLevel = 1;
                        QualityCategory q = QualityUtility.GenerateQualityCreatedByPawn(relevantSkillLevel, false);
                        compQuality.SetQuality(q, ArtGenerationContext.Colony);
                        QualityUtility.SendCraftNotification(thing2, worker);
                    }
                    CompArt compArt = thing2.TryGetComp <CompArt>();
                    bool    flag5   = compArt != null;
                    if (flag5)
                    {
                        bool flag6 = compQuality == null;
                        if (flag6)
                        {
                            compArt.InitializeArt(ArtGenerationContext.Colony);
                        }
                        compArt.JustCreatedBy(worker);
                    }
                    thing2.HitPoints = Mathf.CeilToInt((float)__instance.HitPoints / (float)thing.MaxHitPoints * (float)thing2.MaxHitPoints);
                    GenSpawn.Spawn(thing2, thing.Position, worker.Map, thing.Rotation, WipeMode.Vanish, false);
                }
                else
                {
                    map.terrainGrid.SetTerrain(thing.Position, (TerrainDef)__instance.def.entityDefToBuild);
                    FilthMaker.RemoveAllFilth(thing.Position, map);
                }
                worker.records.Increment(RecordDefOf.ThingsConstructed);
                bool flag7 = thing2 != null && thing2.GetStatValue(StatDefOf.WorkToBuild, true) >= 9500f;
                if (flag7)
                {
                    TaleRecorder.RecordTale(TaleDefOf.CompletedLongConstructionProject, new object[]
                    {
                        worker,
                        thing2.def
                    });
                }
                result = false;
            }
            else
            {
                result = true;
            }
            return(result);
        }
        private List <Thing> CreateLoot()
        {
            Dictionary <string, float> lootEntries = new Dictionary <string, float>();

            string[] arr       = GenMagic.Magic(LootTable).Split('|');
            int      setsMin   = int.Parse(arr[0]);
            int      setsMax   = int.Parse(arr[1]);
            int      setsCount = GenMagic.GetRealCount(parent, Rand.RangeInclusive(setsMin, Rand.RangeInclusive(setsMin, setsMax)));

            //Log.Message("min: " + setsMin + ", max: " + setsMax + ", final: " + setsCount);
            for (int i = 2, iLen = arr.Length; i < iLen; i++)
            {
                string str = arr[i];
                int    pos = str.FirstIndexOf(c => c == ';');
                lootEntries.Add(str.Substring(pos + 1), float.Parse(str.Substring(0, pos)));
                //Log.Message("key : " + str.Substring(pos + 1) + ", val: " + float.Parse(str.Substring(0, pos)));
            }
            List <Thing> lootList = new List <Thing>();

            for (int i = 0; i < setsCount; i++)
            {
                string chosenSet = lootEntries.RandomElementByWeight(kvp => kvp.Value * kvp.Value).Key;
                //Log.Message("chosen set: " + chosenSet);
                arr = chosenSet.Split(';');
                for (int j = 0, jLen = arr.Length; j < jLen; j++)
                {
                    string[] inner = arr[j].Split(',');
                    int      min   = (inner.Length <= 1) ? 1 : int.Parse(inner[1]);
                    int      max   = (inner.Length <= 2) ? min : int.Parse(inner[2]);
                    if (inner.Length >= 4)
                    {
                        max = Rand.RangeInclusive(max, int.Parse(inner[3]));
                    }
                    ThingDef def = DefDatabase <ThingDef> .GetNamed(inner[0]);

                    //Log.Message("def: " + def.defName + ", min: " + min + ", max: " + max);
                    if (def != null)
                    {
                        int countToDo = Rand.RangeInclusive(min, max);
                        while (countToDo > 0)
                        {
                            int count = Math.Min(countToDo, def.stackLimit);
                            countToDo -= count;
                            Thing thing = ThingMaker.MakeThing(def, GenStuff.RandomStuffFor(def));
                            thing.stackCount = count;
                            //Log.Message("thing: " + thing + ", stuff: " + thing.Stuff + ", count: " + count);
                            CompQuality compQuality = thing.TryGetComp <CompQuality>();
                            if (compQuality != null)
                            {
                                QualityCategory q = QualityUtility.GenerateQualityCreatedByPawn(Rand.RangeInclusive(0, 19), false);
                                compQuality.SetQuality(q, ArtGenerationContext.Outsider);
                            }
                            CompArt compArt = thing.TryGetComp <CompArt>();
                            if (compArt != null)
                            {
                                compArt.InitializeArt(ArtGenerationContext.Outsider);
                            }
                            lootList.Add(thing);
                        }
                    }
                }
            }
            return(lootList);
        }
 public override void SpawnSetup(Map map, bool bla)
 {
     base.SpawnSetup(map, bla);
     artComp = GetComp <CompArt>();
     ResolveOwner();
 }