Ejemplo n.º 1
0
        // Very similar to `ThingFilter:Allows`
        public bool Allows(Thing thing)
        {
            thing = thing.GetInnerIfMinified();
            // Check the thing is equal to `forThing`
            if (thing.def != forThing)
            {
                return(false);
            }
            // is it made from the correct stuff
            if (!stuffs.EnumerableNullOrEmpty() && !stuffs.Contains(thing.Stuff))
            {
                return(false);
            }
            // does it have the correct number of hit points
            if (!allowedHpRange.IncludesEpsilon(Mathf.Clamp01(thing.HitPoints / (float)thing.MaxHitPoints)))
            {
                return(false);
            }
            // does it fall within the quality range?
            if (allowedQualities != QualityRange.All && !allowedQualities.Includes(GetQuality(thing)))
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        private bool Allows(Thing t, ThingDef expectedDef, QualityRange qualityRange, FloatRange hpRange, ThingFilter filter)
        {
#if DEBUG || DEBUG_DO_UNTIL_X
            Log.Warning("StoredApparel.Allows Begin [" + t.Label + "]");
#endif
            if (t.def != expectedDef)
            {
#if DEBUG || DEBUG_DO_UNTIL_X
                Log.Warning("StoredApparel.Allows End Def Does Not Match [False]");
#endif
                return(false);
            }
#if DEBUG || DEBUG_DO_UNTIL_X
            Log.Message("    def uses HP: " + expectedDef.useHitPoints + " filter: " + hpRange.min + " " + hpRange.max);
#endif
            if (expectedDef.useHitPoints &&
                hpRange != null &&
                hpRange.min != 0f && hpRange.max != 100f)
            {
                float num = (float)t.HitPoints / (float)t.MaxHitPoints;
                num = GenMath.RoundedHundredth(num);
                if (!hpRange.IncludesEpsilon(Mathf.Clamp01(num)))
                {
#if DEBUG || DEBUG_DO_UNTIL_X
                    Log.Warning("StoredApparel.Allows End Hit Points [False - HP]");
#endif
                    return(false);
                }
            }
#if DEBUG || DEBUG_DO_UNTIL_X
            Log.Message("    def follows quality: " + t.def.FollowQualityThingFilter() + " filter quality levels: " + qualityRange.min + " " + qualityRange.max);
#endif
            if (qualityRange != null && qualityRange != QualityRange.All && t.def.FollowQualityThingFilter())
            {
                QualityCategory p;
                if (!t.TryGetQuality(out p))
                {
                    p = QualityCategory.Normal;
                }
                if (!qualityRange.Includes(p))
                {
#if DEBUG || DEBUG_DO_UNTIL_X
                    Log.Warning("StoredApparel.Allows End Quality [False - Quality]");
#endif
                    return(false);
                }
            }

            if (filter != null && !filter.Allows(t.Stuff))
            {
#if DEBUG || DEBUG_DO_UNTIL_X
                Log.Warning("StoredApparel.Allows End Quality [False - filters.Allows]");
#endif
                return(false);
            }
#if DEBUG || DEBUG_DO_UNTIL_X
            Log.Warning("    StoredApparel.Allows End [True]");
#endif
            return(true);
        }
Ejemplo n.º 3
0
        public static bool GetPawnTest(GetPawnParms parms, out Pawn pawn)
        {
            pawn = null;
            if (parms.mustHaveNoFaction && parms.mustHaveRoyalTitleInCurrentFaction)
            {
                return(false);
            }
            if (parms.canGeneratePawn && (parms.mustBeFactionLeader || parms.mustBePlayerPrisoner || parms.mustBeFreeColonist))
            {
                Log.Warning("QuestGen_GetPawn has incompatible flags set, when canGeneratePawn is true these flags cannot be set: mustBeFactionLeader, mustBePlayerPrisoner, mustBeFreeColonist");
                return(false);
            }
            IEnumerable <Pawn> source = ExistingUsablePawns(parms);

            if (source.Count() > 0)
            {
                pawn = source.RandomElement();
                return(true);
            }
            if (parms.canGeneratePawn)
            {
                if (!parms.mustHaveNoFaction && !TryFindFactionForPawnGeneration(parms, out var _))
                {
                    return(false);
                }
                FloatRange senRange = parms.seniorityRange;
                if (parms.mustHaveRoyalTitleInCurrentFaction && parms.requireResearchedBedroomFurnitureIfRoyal && !DefDatabase <RoyalTitleDef> .AllDefsListForReading.Any((RoyalTitleDef x) => (senRange.max <= 0f || senRange.IncludesEpsilon(x.seniority)) && PlayerHasResearchedBedroomRequirementsFor(x)))
                {
                    return(false);
                }
                return(true);
            }
            return(false);
        }
Ejemplo n.º 4
0
        private static Pawn GeneratePawn(GetPawnParms parms, Faction faction = null)
        {
            PawnKindDef result = parms.mustBeOfKind;

            if (faction == null && !parms.mustHaveNoFaction)
            {
                if (!TryFindFactionForPawnGeneration(parms, out faction))
                {
                    Log.Error("QuestNode_GetPawn tried generating pawn but couldn't find a proper faction for new pawn.");
                }
                else if (result == null)
                {
                    result = faction.RandomPawnKind();
                }
            }
            RoyalTitleDef fixedTitle;

            if (parms.mustHaveRoyalTitleInCurrentFaction)
            {
                FloatRange senRange = parms.seniorityRange;
                IEnumerable <RoyalTitleDef> source = DefDatabase <RoyalTitleDef> .AllDefsListForReading.Where((RoyalTitleDef t) => faction.def.RoyalTitlesAllInSeniorityOrderForReading.Contains(t) && (senRange.max <= 0f || senRange.IncludesEpsilon(t.seniority)));

                if (parms.requireResearchedBedroomFurnitureIfRoyal && source.Any((RoyalTitleDef x) => PlayerHasResearchedBedroomRequirementsFor(x)))
                {
                    source = source.Where((RoyalTitleDef x) => PlayerHasResearchedBedroomRequirementsFor(x));
                }
                fixedTitle = source.RandomElementByWeight((RoyalTitleDef t) => t.commonality);
                if (parms.mustBeOfKind == null && !DefDatabase <PawnKindDef> .AllDefsListForReading.Where((PawnKindDef k) => k.titleRequired != null && k.titleRequired == fixedTitle).TryRandomElement(out result))
                {
                    DefDatabase <PawnKindDef> .AllDefsListForReading.Where((PawnKindDef k) => k.titleSelectOne != null && k.titleSelectOne.Contains(fixedTitle)).TryRandomElement(out result);
                }
            }
            else
            {
                fixedTitle = null;
            }
            if (result == null)
            {
                result = DefDatabase <PawnKindDef> .AllDefsListForReading.Where((PawnKindDef kind) => kind.race.race.Humanlike).RandomElement();
            }
            Pawn pawn = PawnGenerator.GeneratePawn(new PawnGenerationRequest(result, faction, PawnGenerationContext.NonPlayer, -1, forceGenerateNewPawn: true, newborn: false, allowDead: false, allowDowned: false, canGeneratePawnRelations: true, mustBeCapableOfViolence: false, 1f, forceAddFreeWarmLayerIfNeeded: false, allowGay: true, allowFood: true, allowAddictions: true, inhabitant: false, certainlyBeenInCryptosleep: false, forceRedressWorldPawnIfFormerColonist: false, worldPawnFactionDoesntMatter: false, 0f, null, 1f, null, null, null, null, null, null, null, null, null, null, null, fixedTitle));

            Find.WorldPawns.PassToWorld(pawn);
            if (pawn.royalty != null && pawn.royalty.AllTitlesForReading.Any())
            {
                QuestPart_Hyperlinks questPart_Hyperlinks = new QuestPart_Hyperlinks();
                questPart_Hyperlinks.pawns.Add(pawn);
                QuestGen.quest.AddPart(questPart_Hyperlinks);
            }
            return(pawn);
        }
Ejemplo n.º 5
0
        protected override bool TestRunInt(Slate slate)
        {
            if (mustHaveNoFaction.GetValue(slate) && mustHaveRoyalTitleInCurrentFaction.GetValue(slate))
            {
                return(false);
            }
            if (canGeneratePawn.GetValue(slate) && (mustBeFactionLeader.GetValue(slate) || mustBeWorldPawn.GetValue(slate) || mustBePlayerPrisoner.GetValue(slate) || mustBeFreeColonist.GetValue(slate)))
            {
                Log.Warning("QuestNode_GetPawn has incompatible flags set, when canGeneratePawn is true these flags cannot be set: mustBeFactionLeader, mustBeWorldPawn, mustBePlayerPrisoner, mustBeFreeColonist");
                return(false);
            }
            if (slate.TryGet(storeAs.GetValue(slate), out Pawn var) && IsGoodPawn(var, slate))
            {
                return(true);
            }
            IEnumerable <Pawn> source = ExistingUsablePawns(slate);

            if (source.Count() > 0)
            {
                slate.Set(storeAs.GetValue(slate), source.RandomElement());
                return(true);
            }
            if (canGeneratePawn.GetValue(slate))
            {
                if (!mustHaveNoFaction.GetValue(slate) && !TryFindFactionForPawnGeneration(slate, out Faction _))
                {
                    return(false);
                }
                FloatRange senRange = seniorityRange.GetValue(slate);
                if (mustHaveRoyalTitleInCurrentFaction.GetValue(slate) && requireResearchedBedroomFurnitureIfRoyal.GetValue(slate) && !DefDatabase <RoyalTitleDef> .AllDefsListForReading.Any((RoyalTitleDef x) => (senRange.max <= 0f || senRange.IncludesEpsilon(x.seniority)) && PlayerHasResearchedBedroomRequirementsFor(x)))
                {
                    return(false);
                }
                return(true);
            }
            return(false);
        }
Ejemplo n.º 6
0
 public override bool Allows(Thing t)
 {
     return(allowedMarketValue.IncludesEpsilon(t.GetInnerIfMinified().MarketValue) && base.Allows(t));
 }
        protected override bool TestRunInt(Slate slate)
        {
            if (this.questGiver != null && this.storeAs.GetValue(slate) == "asker")
            {
                slate.Set <Pawn>(this.storeAs.GetValue(slate), this.questGiver, false);
                return(true);
            }
            if (this.mustHaveNoFaction.GetValue(slate) && this.mustHaveRoyalTitleInCurrentFaction.GetValue(slate))
            {
                return(false);
            }
            if (this.canGeneratePawn.GetValue(slate) && (this.mustBeFactionLeader.GetValue(slate) || this.mustBeWorldPawn.GetValue(slate) || this.mustBePlayerPrisoner.GetValue(slate) || this.mustBeFreeColonist.GetValue(slate)))
            {
                Log.Warning("QuestNode_GetPawn has incompatible flags set, when canGeneratePawn is true these flags cannot be set: mustBeFactionLeader, mustBeWorldPawn, mustBePlayerPrisoner, mustBeFreeColonist", false);
                return(false);
            }
            Pawn pawn;

            if (slate.TryGet <Pawn>(this.storeAs.GetValue(slate), out pawn, false) && this.IsGoodPawn(pawn, slate))
            {
                return(true);
            }
            IEnumerable <Pawn> source = this.ExistingUsablePawns(slate);

            if (source.Count <Pawn>() > 0)
            {
                slate.Set <Pawn>(this.storeAs.GetValue(slate), source.RandomElement <Pawn>(), false);
                return(true);
            }
            if (!this.canGeneratePawn.GetValue(slate))
            {
                return(false);
            }
            Faction faction;

            if (!this.mustHaveNoFaction.GetValue(slate) && !this.TryFindFactionForPawnGeneration(slate, out faction))
            {
                return(false);
            }
            FloatRange senRange = this.seniorityRange.GetValue(slate);

            return(!this.mustHaveRoyalTitleInCurrentFaction.GetValue(slate) || !this.requireResearchedBedroomFurnitureIfRoyal.GetValue(slate) || DefDatabase <RoyalTitleDef> .AllDefsListForReading.Any((RoyalTitleDef x) => (senRange.max <= 0f || senRange.IncludesEpsilon((float)x.seniority)) && this.PlayerHasResearchedBedroomRequirementsFor(x)));
        }