public static bool CheckDisabilityMotes(this HediffComp_Stain_Footprint h, bool myDebug = false)
        {
            IEnumerable <ThingDef> disabilityMoteIE = null;

            disabilityMoteIE = DefDatabase <ThingDef> .AllDefs.Where((ThingDef b) => b.defName.Contains(h.Props.missingPartMote_pattern));

            if (disabilityMoteIE.EnumerableNullOrEmpty())
            {
                Tools.Warn("Cant find missingPart_Mote: " + h.Props.missingPartMote_pattern, myDebug);
                return(false);
            }
            else
            {
                string missingPart = string.Empty;
                foreach (ThingDef moteDef in disabilityMoteIE)
                {
                    missingPart += moteDef + ", ";
                }

                Tools.Warn("Found missingPart_Mote: " + disabilityMoteIE.Count() + "; " + missingPart, myDebug);
            }

            // checking pegleg motes for each regular footprint in Props
            foreach (Footprint footprint in h.Props.footprint)
            {
                string guessDefName = string.Empty;
                guessDefName     = Regex.Replace(footprint.moteDef.defName, "_Footprint$", h.Props.peglegMote_pattern);
                disabilityMoteIE = DefDatabase <ThingDef> .AllDefs.Where((ThingDef b) => b.defName == guessDefName);

                if (disabilityMoteIE.EnumerableNullOrEmpty())
                {
                    Tools.Warn("no pegleg Mote found :" + guessDefName, myDebug);
                    return(false);
                }
                else
                {
                    Tools.Warn("found pegleg Mote: " + guessDefName, myDebug);
                }
            }

            // checking wooden foot motes for each regular footprint in Props
            foreach (Footprint footprint in h.Props.footprint)
            {
                string guessDefName = string.Empty;
                guessDefName     = Regex.Replace(footprint.moteDef.defName, "_Footprint$", h.Props.woodenfootMote_pattern);
                disabilityMoteIE = DefDatabase <ThingDef> .AllDefs.Where((ThingDef b) => b.defName == guessDefName);

                if (disabilityMoteIE.EnumerableNullOrEmpty())
                {
                    Tools.Warn("no pegleg Mote found :" + guessDefName, myDebug);
                    return(false);
                }
                else
                {
                    Tools.Warn("found woodenfoot Mote: " + guessDefName, myDebug);
                }
            }

            return(true);
        }
Exemple #2
0
        public static void TryPlaceFootprint(this HediffComp_Stain_Footprint h, bool debug = false)
        {
            bool trailLike = h.Props.trailLikeFootprint;

            Vector3 drawPos    = h.Pawn.Drawer.DrawPos;
            Vector3 normalized = (drawPos - h.lastFootprintPlacePos).normalized;
            float   rot        = normalized.AngleFlat();

            Tools.Warn("base rotation: " + rot, debug);

            ThingDef myMoteDef = h.moteFootprintDef;

            if (h.Props.disabilityFootprints && h.availableDisabilityMotes && h.HasDisability)
            {
                myMoteDef = h.lastFootprintRight ? h.moteRightFootprintDef : h.moteLeftFootprintDef;
            }

            if (h.HasRotation)
            {
                if (h.lastFootprintRight)
                {
                    rot += h.Props.rightFootRotation;
                    Tools.Warn("right foot additional rotation: " + h.Props.rightFootRotation + "=>rot:" + rot, debug);
                }
                else
                {
                    rot += h.Props.leftFootRotation;
                    Tools.Warn("left foot additional rotation: " + h.Props.leftFootRotation + "=>rot:" + rot, debug);
                }
            }

            float angle = 0;

            if (!trailLike)
            {
                angle = (!h.lastFootprintRight) ? -90 : 90;
            }

            Vector3 b      = normalized.RotatedBy(angle) * 0.17f * Mathf.Sqrt(h.Pawn.BodySize);
            Vector3 vector = drawPos + FootprintOffset + b;
            IntVec3 c      = vector.ToIntVec3();

            if (c.InBounds(h.myMap) && c.GetTerrain(h.myMap) != null)
            {
                PlaceFootprint(vector, h.myMap, rot, h.Props.randomScale.RandomInRange, myMoteDef);
            }

            h.lastFootprintPlacePos = drawPos;
            h.lastFootprintRight    = !h.lastFootprintRight;
        }
        public static ThingDef RegularMoteToDisabilityHediffMote(this HediffComp_Stain_Footprint hFP, Hediff h, ThingDef baseMoteDef, bool myDebug = false)
        {
            string baseHDef   = baseMoteDef.defName;
            string newDefName = string.Empty;

            IEnumerable <ThingDef> newMoteIE = null;

            if (h.def == HediffDefOf.MissingBodyPart)
            {
                if (h.Part.def == BodyPartDefOf.Leg)
                {
                    return(null);
                }

                newMoteIE = DefDatabase <ThingDef> .AllDefs.Where((ThingDef b) => b.label == "Mote" && b.defName.Contains(hFP.Props.missingPartMote_pattern));

                if (newMoteIE.EnumerableNullOrEmpty())
                {
                    Tools.Warn("RegularMoteToHediffMote - Did not find Mote_Human_MissingPart", myDebug);
                    return(baseMoteDef);
                }

                return(newMoteIE.RandomElement());
            }
            else if (h.def == HediffDefOf.PegLeg)
            {
                newDefName = Regex.Replace(baseHDef, "_Footprint$", hFP.Props.peglegMote_pattern);
            }
            else if (h.def == MyDefs.WoodenFootHediffDef)
            {
                newDefName = Regex.Replace(baseHDef, "_Footprint$", hFP.Props.woodenfootMote_pattern);
            }
            else
            {
                Tools.Warn("RegularMoteToHediffMote - empty hediff case - should not happen", myDebug);
                return(baseMoteDef);
            }

            newMoteIE = DefDatabase <ThingDef> .AllDefs.Where((ThingDef b) => b.label == "Mote" && b.defName == newDefName);

            if (newMoteIE.EnumerableNullOrEmpty())
            {
                Tools.Warn("RegularMoteToHediffMote - Did not find " + newDefName, myDebug);
                return(baseMoteDef);
            }
            return(newMoteIE.First());
        }