Esempio n. 1
0
        protected override List <HediffWishInfo> PrimeHediffInfo()
        {
            List <HediffWishInfo> primeWishInfos = base.PrimeHediffInfo();
            List <RecipeDef>      recipes        = Def.CachedRecipeDef;

            List <HediffWishInfo> sortedWishInfos = new List <HediffWishInfo>();

            List <Hediff> hediffsMissingPart = new List <Hediff>();
            List <Hediff> hediffPartAdded    = new List <Hediff>();

            List <BodyPartRecord> allParts           = pawn.RaceProps.body.AllParts;
            List <BodyPartRecord> missingPartRecords = new List <BodyPartRecord>();
            List <BodyPartRecord> havingPartRecords  = new List <BodyPartRecord>();

            // find hediff for missingPartHediffs & hediffPartAdded
            List <Hediff> hediffs = pawn.health.hediffSet.hediffs;

            for (int i = 0; i < hediffs.Count; i++)
            {
                if (hediffs[i] is Hediff_MissingPart)
                {
                    hediffsMissingPart.Add(hediffs[i]);
                }
                else if (hediffs[i] is Hediff_AddedPart)
                {
                    hediffPartAdded.Add(hediffs[i]);
                }
            }
            // missingPartRecords : add the most upward missing part record
            for (int i = 0; i < hediffsMissingPart.Count; i++)
            {
                for (int j = 0; j < hediffsMissingPart.Count; j++)
                {
                    if (hediffsMissingPart[i].Part.parent == hediffsMissingPart[j].Part)
                    {
                        break;
                    }
                    if (j == hediffsMissingPart.Count - 1)
                    {
                        missingPartRecords.Add(hediffsMissingPart[i].Part);
                    }
                }
            }
            // missingPartRecords : remove missing part record if that part is missing du to an added part
            for (int i = 0; i < hediffPartAdded.Count; i++)
            {
                for (int j = missingPartRecords.Count - 1; j >= 0; j--)
                {
                    if (HediffWish_Utility.AllParentPartRecordRecursive(missingPartRecords[j]).Contains(hediffPartAdded[i].Part))
                    {
                        missingPartRecords.RemoveAt(j);
                    }
                }
            }
            // missingPartRecords : add all missing child part
            int count = missingPartRecords.Count;

            for (int i = 0; i < count; i++)
            {
                missingPartRecords.AddRange(HediffWish_Utility.AllChildPartRecordRecursive(missingPartRecords[i]));
            }
            // havingPartRecords : add all part that not in missingPartRecords
            havingPartRecords = allParts.Where(part => !missingPartRecords.Contains(part)).ToList();

            bool shouldContinue;

            for (int h = 0; h < allParts.Count; h++)
            {
                for (int i = 0; i < recipes.Count; i++)
                {
                    if (!recipes[i].appliedOnFixedBodyParts.Contains(allParts[h].def))
                    {
                        continue;
                    }
                    shouldContinue = false;
                    // check if recipe is usable (pawn have the parent of recipe body part)
                    if (!havingPartRecords.Contains(allParts[h]) &&
                        !havingPartRecords.Contains(allParts[h].parent))
                    {
                        continue;
                    }

                    //Case natural body part recipe
                    if (recipes[i].addsHediff == null)
                    {
                        //NonNaturalBodyPartCase
                        if (!Def.shouldBeMissingBodyPart)
                        {
                            for (int j = 0; j < hediffPartAdded.Count; j++)
                            {
                                if (allParts[h] == hediffPartAdded[j].Part && (!Def.shouldBeAnUpgrade || 1 > hediffPartAdded[j].def.addedPartProps.partEfficiency))
                                {
                                    SetUpData(null, hediffPartAdded[j].def, allParts[h]);
                                    shouldContinue = true;
                                    break;
                                }
                            }
                            if (shouldContinue)
                            {
                                continue;
                            }
                        }
                        //MissingBodyPartCase;
                        for (int j = 0; j < missingPartRecords.Count; j++)
                        {
                            if (!HediffWish_Utility.AllParentPartRecordRecursive(missingPartRecords[j], true).Contains(allParts[h]))
                            {
                                continue;
                            }
                            SetUpData(null, hediffsMissingPart.Where(hed => hed.Part == missingPartRecords[j]).First().def, allParts[h]);
                            break;
                        }
                        // NaturalBodyPartCase (no need since it would be the same as recipe)
                    }
                    // Case non natural body part recipe
                    else
                    {
                        for (int j = 0; j < primeWishInfos.Count; j++)
                        {
                            if (recipes[i].addsHediff != primeWishInfos[j].def)
                            {
                                continue;
                            }

                            // MissingBodyPartCase
                            for (int k = 0; k < missingPartRecords.Count; k++)
                            {
                                if (!HediffWish_Utility.AllParentPartRecordRecursive(missingPartRecords[k], true).Contains(allParts[h]))
                                {
                                    continue;
                                }
                                //hediffsMissingPart.Where(hed => hed.Part == missingPartRecords[k]).First().def
                                SetUpData(recipes[i].addsHediff, null, allParts[h], sortedWishInfos.Count);
                                sortedWishInfos.Add(primeWishInfos[j]);
                                shouldContinue = true;
                                break;
                            }
                            if (shouldContinue)
                            {
                                break;
                            }

                            if (!Def.shouldBeMissingBodyPart)
                            {
                                // NonNaturalBodyPartCase
                                for (int k = 0; k < hediffPartAdded.Count; k++)
                                {
                                    if (allParts[h] == hediffPartAdded[k].Part && (!Def.shouldBeAnUpgrade || recipes[i].addsHediff.addedPartProps.partEfficiency > hediffPartAdded[k].def.addedPartProps.partEfficiency))
                                    {
                                        // hediffPartAdded[k].def
                                        SetUpData(recipes[i].addsHediff, null, allParts[h], sortedWishInfos.Count);
                                        sortedWishInfos.Add(primeWishInfos[j]);
                                        shouldContinue = true;
                                        break;
                                    }
                                }
                                if (shouldContinue)
                                {
                                    break;
                                }

                                // NaturalBodyPartCase (last possible case so no need to check)
                                if (Def.canReplaceNaturalPart && (!Def.shouldBeAnUpgrade || recipes[i].addsHediff.addedPartProps.betterThanNatural))
                                {
                                    SetUpData(recipes[i].addsHediff, null, allParts[h], sortedWishInfos.Count);
                                    sortedWishInfos.Add(primeWishInfos[j]);
                                }
                            }
                        }
                    }
                }
            }
            if (Def.hediffInfos != null)
            {
                sortedWishInfos.AddRange(Def.hediffInfos);
            }
            return(sortedWishInfos);
        }
Esempio n. 2
0
        protected override float GetChance(Pawn pawn, float chance)
        {
            float baseChance = base.GetChance(pawn, chance);

            if (baseChance == 0)
            {
                return(0);
            }
            // not sure if should check for canReplaceNaturalPart in this condition
            if (!shouldBeMissingBodyPart && !replaceToNaturalPart && !shouldBeAnUpgrade && canReplaceNaturalPart)
            {
                return(baseChance);
            }
            int count = 0;
            List <BodyPartRecord> findPart = new List <BodyPartRecord>();
            List <Hediff>         miss     = pawn.health.hediffSet.hediffs.FindAll(hediff => hediff is Hediff_MissingPart);
            List <Hediff>         added    = pawn.health.hediffSet.hediffs.FindAll(hediff => hediff is Hediff_AddedPart);
            BodyPartRecord        partDef;

            for (int i = 0; i < miss.Count; i++)
            {
                for (int j = 0; j < miss.Count; j++)
                {
                    if (miss[i].Part.parent == miss[j].Part)
                    {
                        break;
                    }
                    if (j == miss.Count - 1 && (added.Find(hed => hed.Part == miss[i].Part || hed.Part == miss[i].Part.parent) == null))
                    {
                        for (int k = 0; k < CachedRecipeDef.Count; k++)
                        {
                            partDef = HediffWish_Utility.AllParentPartRecordRecursive(miss[i].Part, true).Find(part => CachedRecipeDef[k].appliedOnFixedBodyParts.Contains(part.def));
                            if (partDef != null && !findPart.Contains(partDef))
                            {
                                findPart.Add(partDef);
                                count++;
                                break;
                            }
                        }
                    }
                }
            }
            if (shouldBeMissingBodyPart)
            {
                if (count < amountNeeded)
                {
                    return(0);
                }
                return(baseChance);
            }
            added = pawn.health.hediffSet.hediffs.FindAll(hediff => hediff is Hediff_AddedPart);
            for (int i = 0; i < added.Count; i++)
            {
                if (findPart.Contains(added[i].Part))
                {
                    continue;
                }
                for (int j = 0; j < CachedRecipeDef.Count; j++)
                {
                    if (CachedRecipeDef[j].appliedOnFixedBodyParts.Contains(added[i].Part.def))
                    {
                        if (replaceToNaturalPart)
                        {
                            if (shouldBeAnUpgrade && added[i].def.addedPartProps.betterThanNatural)
                            {
                                continue;
                            }
                            findPart.Add(added[i].Part);
                            count++;
                            break;
                        }
                        else if (shouldBeAnUpgrade &&
                                 (CachedRecipeDef[j].addsHediff != null && CachedRecipeDef[j].addsHediff.addedPartProps.partEfficiency > added[i].def.addedPartProps.partEfficiency) ||
                                 (CachedRecipeDef[j].addsHediff == null && 1 > added[i].def.addedPartProps.partEfficiency))
                        {
                            findPart.Add(added[i].Part);
                            count++;
                            break;
                        }
                    }
                }
            }
            if (!canReplaceNaturalPart)
            {
                if (count < amountNeeded)
                {
                    return(0);
                }
                return(baseChance);
            }
            List <BodyPartRecord> naturalPart = new List <BodyPartRecord>(pawn.RaceProps.body.AllParts);
            List <BodyPartRecord> parts;

            for (int i = 0; i < miss.Count; i++)
            {
                parts = HediffWish_Utility.AllParentPartRecordRecursive(miss[i].Part, true);
                for (int j = 0; j < parts.Count; j++) /* if(naturalPart.Contains(parts[j]))*/ naturalPart {
Esempio n. 3
0
        protected override bool DidGetRidAtIndex(int index, List <Hediff> matchingHediffDef)
        {
            if (!base.DidGetRidAtIndex(index, matchingHediffDef))
            {
                return(false);
            }
            int matchAtIndex = ridIndex.IndexOf(index);

            if (matchAtIndex < 0)
            {
                return(false);
            }
            if (matchingHediffDef.Find(hed => hed.Part == affectedPart[matchAtIndex]) == null ||
                (hediffToGetRid[index] == HediffDefOf.MissingBodyPart &&
                 pawn.health.hediffSet.hediffs.Find(hed => hed is Hediff_AddedPart && HediffWish_Utility.AllParentPartRecordRecursive(affectedPart[matchAtIndex], true).Contains(hed.Part)) != null))
            {
                return(true);
            }

            return(false);
        }