Example #1
0
            public static void Listener(Pawn p, ref ThoughtState __result)
            {
                try
                {
                    if (!__result.Active)
                    {
                        return;
                    }

                    CompSurrogateOwner cso = p.TryGetComp <CompSurrogateOwner>();

                    Pawn otherPawn          = LovePartnerRelationUtility.ExistingMostLikedLovePartnerRel(p, false).otherPawn;
                    CompSurrogateOwner cso2 = null;
                    if (otherPawn != null)
                    {
                        cso2 = otherPawn.TryGetComp <CompSurrogateOwner>();
                    }

                    if (p.IsAndroidTier() || p.IsSurrogateAndroid() || (cso != null && cso.skyCloudHost != null) || (otherPawn != null && (otherPawn.IsAndroidTier() || otherPawn.IsSurrogateAndroid() || (cso2 != null && cso2.skyCloudHost != null))))
                    {
                        __result = false;
                    }
                }
                catch (Exception e)
                {
                    Log.Message("[ATTP] ThoughtWorker_WantToSleepWithSpouseOrLover.CurrentStateInternal " + e.Message + " " + e.StackTrace);
                }
            }
Example #2
0
        private static void ShowHeart(float x, float y, Pawn pawn)
        {
            Texture2D          iconFor;
            DirectPawnRelation directPawnRelation = LovePartnerRelationUtility.ExistingMostLikedLovePartnerRel(pawn, false);

            if (directPawnRelation == null)
            {
                iconFor = null;
            }

            else if (!directPawnRelation.otherPawn.IsColonist || directPawnRelation.otherPawn.IsWorldPawn() || !directPawnRelation.otherPawn.relations.everSeenByPlayer)
            {
                iconFor = null;
            }

            else if (pawn.ownership.OwnedBed != null && pawn.ownership.OwnedBed == directPawnRelation.otherPawn.ownership.OwnedBed)
            {
                iconFor = BondIcon;
            }

            else
            {
                iconFor = BondBrokenIcon;
            }

            if (iconFor)
            {
                Vector2 iconSize = new Vector2(iconFor.width, iconFor.height);
                Rect    drawRect = new Rect(x, y, iconSize.x, iconSize.y);
                TooltipHandler.TipRegion(drawRect, directPawnRelation.otherPawn.LabelCap);
                GUI.DrawTexture(drawRect, iconFor);
            }
        }
        private static bool ShowHeart(float x, float y, Pawn pawn)
        {
            Texture2D iconFor;

            if (pawn == null || !pawn.IsColonist)
            {
                return(false);
            }

            DirectPawnRelation directPawnRelation = LovePartnerRelationUtility.ExistingMostLikedLovePartnerRel(pawn, false);

            if (directPawnRelation == null || directPawnRelation.otherPawn == null)
            {
                iconFor = null;
            }

            else if (!directPawnRelation.otherPawn.IsColonist || directPawnRelation.otherPawn.IsWorldPawn() || !directPawnRelation.otherPawn.relations.everSeenByPlayer)
            {
                iconFor = null;
            }

            else if (pawn.ownership?.OwnedBed != null && pawn.ownership?.OwnedBed == directPawnRelation.otherPawn.ownership?.OwnedBed)
            {
                iconFor = Textures.BondIcon;
            }

            else
            {
                iconFor = Textures.BondBrokenIcon;
            }

            if (iconFor != null)
            {
                Vector2 iconSize = new Vector2(iconFor.width, iconFor.height) * resizeHeart;
                Rect    drawRect = new Rect(x, y, iconSize.x, iconSize.y);
                TooltipHandler.TipRegion(drawRect, directPawnRelation.otherPawn.LabelCap);

                if (iconFor == Textures.BondBrokenIcon) // if its a broken heart - allow them to click on the broken heart to assign the missing partner to the bed
                {
                    if (Widgets.ButtonImage(drawRect, iconFor, Color.white, Color.red, true))
                    {
                        if (pawn.ownership?.OwnedBed?.SleepingSlotsCount >= 2)
                        {
                            pawn.ownership.OwnedBed.GetComp <CompAssignableToPawn>().TryAssignPawn(directPawnRelation.otherPawn);
                            return(true);
                        }
                    }
                }
                else
                {
                    GUI.DrawTexture(drawRect, iconFor);
                }
            }
            return(false);
        }
Example #4
0
        protected override ThoughtState CurrentStateInternal(Pawn p)
        {
            DirectPawnRelation directPawnRelation = LovePartnerRelationUtility.ExistingMostLikedLovePartnerRel(p, false);

            if (directPawnRelation == null)
            {
                return(false);
            }
            if (!directPawnRelation.otherPawn.IsColonist || directPawnRelation.otherPawn.IsWorldPawn() || !directPawnRelation.otherPawn.relations.everSeenByPlayer)
            {
                return(false);
            }
            if (p.relations.OpinionOf(directPawnRelation.otherPawn) <= 0)
            {
                return(false);
            }

            Building_Bed bed = p.ownership.OwnedBed;

            if (bed != null)
            {
                Room bedRoom = bed.GetRoom(RegionType.Set_Passable);
                if (bedRoom != null)
                {
                    if (bedRoom.Role == RoomRoleDefOf.Barracks || bedRoom.Role == RoomRoleDefOf.Bedroom)
                    {
                        List <Thing> containedAndAdjacentThings = bedRoom.ContainedAndAdjacentThings;
                        for (int i = 0; i < containedAndAdjacentThings.Count; i++)
                        {
                            Thing        thing    = containedAndAdjacentThings[i];
                            Building_Bed otherBed = thing as Building_Bed;
                            if (otherBed != null)
                            {
                                for (int j = 0; j < otherBed.owners.Count; j++)
                                {
                                    Pawn owner = otherBed.owners[j];
                                    if (owner == directPawnRelation.otherPawn)
                                    {
                                        return(false);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(true);
        }
Example #5
0
        private static bool ShowHeart(float x, float y, Pawn pawn)
        {
            Texture2D iconFor;

            if (pawn == null || !pawn.IsColonist)
            {
                return(false);
            }

            DirectPawnRelation directPawnRelation = LovePartnerRelationUtility.ExistingMostLikedLovePartnerRel(pawn, false);

            if (directPawnRelation == null || directPawnRelation.otherPawn == null)
            {
                iconFor = null;
            }

            else if (!directPawnRelation.otherPawn.IsColonist || directPawnRelation.otherPawn.IsWorldPawn() || !directPawnRelation.otherPawn.relations.everSeenByPlayer)
            {
                iconFor = null;
            }

            else if (pawn.ownership?.OwnedBed != null && pawn.ownership?.OwnedBed == directPawnRelation.otherPawn.ownership?.OwnedBed)
            {
                iconFor = Textures.BondIcon;
            }

            else
            {
                iconFor = Textures.BondBrokenIcon;
            }

            if (iconFor != null)
            {
                Vector2 iconSize = new Vector2(iconFor.width, iconFor.height) * resizeHeart;
                Rect    drawRect = new Rect(x, y, iconSize.x, iconSize.y);
                TooltipHandler.TipRegion(drawRect, directPawnRelation.otherPawn.LabelCap);
                GUI.DrawTexture(drawRect, iconFor);

                if (iconFor == Textures.BondBrokenIcon && Mouse.IsOver(drawRect) && Input.GetMouseButtonDown(0))
                {
                    if (pawn.ownership?.OwnedBed?.SleepingSlotsCount >= 2)
                    {
                        pawn.ownership.OwnedBed.GetComp <CompAssignableToPawn>().TryAssignPawn(directPawnRelation.otherPawn);
                        return(true);
                    }
                }
            }
            return(false);
        }
        public static void CurrentStateInternal(ref ThoughtState __result, Pawn p)
        {
            DirectPawnRelation directPawnRelation = LovePartnerRelationUtility.ExistingMostLikedLovePartnerRel(p, false);
            bool multiplePartners = (from r in p.relations.PotentiallyRelatedPawns
                                     where LovePartnerRelationUtility.LovePartnerRelationExists(p, r)
                                     select r).Count() > 1;
            bool partnerBedInRoom = (from t in p.ownership.OwnedBed.GetRoom().ContainedBeds
                                     where t.AssignedPawns.Contains(directPawnRelation.otherPawn)
                                     select t).Count() > 0;

            if (directPawnRelation != null && p.ownership.OwnedBed != null && p.story.traits.HasTrait(TraitDefOfPsychology.Polygamous) && multiplePartners && partnerBedInRoom)
            {
                __result = false;
            }
        }
        public static Building_AIPawnRechargeStation FindRechargeStationFor(AIPawn sleeper, AIPawn traveler, bool sleeperWillBePrisoner, bool checkSocialProperness, bool forceCheckMedBed = false)
        {
            Predicate <Thing> bedValidator = (Thing t) =>
            {
                Building_AIPawnRechargeStation foundRechargeStation = t as Building_AIPawnRechargeStation;
                if (foundRechargeStation == null)
                {
                    return(false);
                }

                if (!traveler.CanReserveAndReach(t, PathEndMode.OnCell, Danger.Some, foundRechargeStation.SleepingSlotsCount))
                {
                    return(false);
                }

                if (!foundRechargeStation.AnyUnoccupiedSleepingSlot && (!sleeper.InBed() || sleeper.CurrentBed() != foundRechargeStation))
                {
                    foreach (Pawn owner in foundRechargeStation.owners)
                    {
                        if (owner as AIPawn != null)
                        {
                            return(false);
                        }
                    }
                }

                if (sleeperWillBePrisoner)
                {
                    if (!foundRechargeStation.ForPrisoners)
                    {
                        return(false);
                    }

                    if (!foundRechargeStation.Position.IsInPrisonCell(sleeper.Map))
                    {
                        return(false);
                    }
                }
                else
                {
                    if (foundRechargeStation.Faction != traveler.Faction)
                    {
                        return(false);
                    }

                    if (foundRechargeStation.ForPrisoners)
                    {
                        return(false);
                    }
                }


                if (foundRechargeStation.Medical)
                {
                    if (!HealthAIUtility.ShouldEverReceiveMedicalCare(sleeper))
                    {
                        return(false);
                    }
                    if (!HealthAIUtility.ShouldSeekMedicalRest(sleeper))
                    {
                        return(false);
                    }
                    if (!foundRechargeStation.AnyUnoccupiedSleepingSlot && (!sleeper.InBed() || sleeper.CurrentBed() != foundRechargeStation))
                    {
                        return(false);
                    }
                }
                else if (foundRechargeStation.owners.Any <Pawn>() && !foundRechargeStation.owners.Contains(sleeper))
                {
                    // The pawn in the recharge station is not an AIPawn. UnassignPawn!
                    foreach (Pawn owner in foundRechargeStation.owners)
                    {
                        if (owner as AIPawn == null)
                        {
                            if (foundRechargeStation.owners.Find((Pawn x) => LovePartnerRelationUtility.LovePartnerRelationExists(sleeper, x)) == null)
                            {
                                foundRechargeStation.TryUnassignPawn(owner);
                                break;
                            }
                        }
                    }
                    // Now recheck if there is a free place
                    if (!foundRechargeStation.AnyUnownedSleepingSlot)
                    {
                        return(false);
                    }
                }

                return((!checkSocialProperness || foundRechargeStation.IsSociallyProper(sleeper, sleeperWillBePrisoner, false)) && !foundRechargeStation.IsForbidden(traveler) && !foundRechargeStation.IsBurning());
            };

            if (sleeper.ownership != null && sleeper.ownership.OwnedBed != null && bedValidator(sleeper.ownership.OwnedBed))
            {
                Building_AIPawnRechargeStation rStation = sleeper.ownership.OwnedBed as Building_AIPawnRechargeStation;

                if (rStation != null)
                {
                    return(rStation);
                }
                else
                {
                    sleeper.ownership.UnclaimBed();
                }
            }

            DirectPawnRelation directPawnRelation = LovePartnerRelationUtility.ExistingMostLikedLovePartnerRel(sleeper, false);

            if (directPawnRelation != null)
            {
                Building_AIPawnRechargeStation ownedBed = directPawnRelation.otherPawn.ownership.OwnedBed as Building_AIPawnRechargeStation;
                if (ownedBed != null && bedValidator(ownedBed))
                {
                    return(ownedBed);
                }
            }
            for (int j = 0; j < RestUtility.AllBedDefBestToWorst.Count; j++)
            {
                ThingDef thingDef = RestUtility.AllBedDefBestToWorst[j];
                if (RestUtility.CanUseBedEver(sleeper, thingDef))
                {
                    Predicate <Thing> validator = (Thing b) => bedValidator(b) && (b as Building_AIPawnRechargeStation != null) && !((Building_AIPawnRechargeStation)b).Medical;
                    Building_AIPawnRechargeStation building_Bed2 = GenClosest.ClosestThingReachable(sleeper.Position, sleeper.Map, ThingRequest.ForDef(thingDef), PathEndMode.OnCell, TraverseParms.For(traveler, Danger.Deadly, TraverseMode.ByPawn, false), 9999f, validator, null, 0, -1, false)
                                                                   as Building_AIPawnRechargeStation;
                    if (building_Bed2 != null)
                    {
                        if (sleeper.ownership != null)
                        {
                            sleeper.ownership.UnclaimBed();
                        }
                        return(building_Bed2);
                    }
                }
            }
            return(null);
        }