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);
        }
Beispiel #2
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();
            }
        }