Exemplo n.º 1
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            if (pawn != null && pawn.Map != null && pawn.health != null && pawn.health.hediffSet != null && pawn.health.hediffSet.HasHediff(TorannMagicDefOf.TM_ChiHD) && !pawn.Drafted)
            {
                if (pawn.InBed() || HealthAIUtility.ShouldSeekMedicalRest(pawn) || !(pawn.GetPosture() == PawnPosture.Standing))
                {
                    return(null);
                }
                Need_Joy curJoy = pawn.needs.joy;
                if (curJoy == null)
                {
                    return(null);
                }
                if (curJoy.CurLevel >= .8f)
                {
                    return(null);
                }
                CompAbilityUserMight comp = pawn.GetComp <CompAbilityUserMight>();
                if (comp != null)
                {
                    MightPower mightPower = comp.MightData.MightPowersM.FirstOrDefault <MightPower>((MightPower x) => x.abilityDef == TorannMagicDefOf.TM_Meditate);

                    if (mightPower == null)
                    {
                        return(null);
                    }

                    if (!mightPower.AutoCast)
                    {
                        return(null);
                    }

                    Hediff      hediff  = pawn.health.hediffSet.GetFirstHediffOfDef(TorannMagicDefOf.TM_ChiHD);
                    PawnAbility ability = pawn.GetComp <CompAbilityUserMight>().AbilityData.Powers.FirstOrDefault((PawnAbility x) => x.Def == TorannMagicDefOf.TM_Meditate);

                    if (ability.CooldownTicksLeft > 0 || hediff.Severity >= 70)
                    {
                        return(null);
                    }

                    Building_Bed building_Bed = pawn.ownership.OwnedBed;
                    if (building_Bed != null)
                    {
                        if (building_Bed.GetRoom() != null && !building_Bed.GetRoom().PsychologicallyOutdoors)
                        {
                            List <IntVec3> roomCells = building_Bed.GetRoom().Cells.ToList();
                            for (int i = 0; i < roomCells.Count; i++)
                            {
                                if (roomCells[i].IsValid && roomCells[i].Walkable(pawn.Map) && roomCells[i].GetFirstBuilding(pawn.Map) == null)
                                {
                                    return(new Job(TorannMagicDefOf.JobDriver_TM_Meditate, roomCells[i]));
                                }
                            }
                        }
                    }
                    return(new Job(TorannMagicDefOf.JobDriver_TM_Meditate, pawn.Position));
                }
            }
            return(null);
        }
Exemplo n.º 2
0
        public override bool StateCanOccur(Pawn pawn)
        {
            bool result;

            if (!base.StateCanOccur(pawn))
            {
                result = false;
            }
            else
            {
                Building_Bed ownedBed = pawn.ownership.OwnedBed;
                if (ownedBed == null || ownedBed.GetRoom(RegionType.Set_Passable) == null || ownedBed.GetRoom(RegionType.Set_Passable).PsychologicallyOutdoors)
                {
                    result = false;
                }
                else
                {
                    MentalStateWorker_BedroomTantrum.tmpThings.Clear();
                    TantrumMentalStateUtility.GetSmashableThingsIn(ownedBed.GetRoom(RegionType.Set_Passable), pawn, MentalStateWorker_BedroomTantrum.tmpThings, null, 0);
                    bool flag = MentalStateWorker_BedroomTantrum.tmpThings.Any <Thing>();
                    MentalStateWorker_BedroomTantrum.tmpThings.Clear();
                    result = flag;
                }
            }
            return(result);
        }
Exemplo n.º 3
0
        private static void ApplyBedThoughts(Pawn actor)
        {
            if (actor.needs.mood == null)
            {
                return;
            }

            var          memories     = actor.needs.mood.thoughts.memories;
            Building_Bed building_Bed = actor.CurrentBed();

            memories.RemoveMemoriesOfDef(ThoughtDefOf.SleptInBedroom);
            memories.RemoveMemoriesOfDef(ThoughtDefOf.SleptInBarracks);
            memories.RemoveMemoriesOfDef(ThoughtDefOf.SleptOutside);
            memories.RemoveMemoriesOfDef(ThoughtDefOf.SleptOnGround);
            memories.RemoveMemoriesOfDef(ThoughtDefOf.SleptInCold);
            memories.RemoveMemoriesOfDef(ThoughtDefOf.SleptInHeat);

            if (actor.GetRoom(RegionType.Set_Passable).PsychologicallyOutdoors)
            {
                memories.TryGainMemory(ThoughtDefOf.SleptOutside, null);
            }

            if (building_Bed == null || building_Bed.CostListAdjusted().Count == 0)
            {
                memories.TryGainMemory(ThoughtDefOf.SleptOnGround, null);
            }

            if (actor.AmbientTemperature < actor.def.GetStatValueAbstract(StatDefOf.ComfyTemperatureMin, null))
            {
                memories.TryGainMemory(ThoughtDefOf.SleptInCold, null);
            }

            if (actor.AmbientTemperature > actor.def.GetStatValueAbstract(StatDefOf.ComfyTemperatureMax, null))
            {
                memories.TryGainMemory(ThoughtDefOf.SleptInHeat, null);
            }

            if (building_Bed != null && building_Bed == actor.ownership.OwnedBed && !building_Bed.ForPrisoners && !actor.story.traits.HasTrait(TraitDefOf.Ascetic))
            {
                ThoughtDef thoughtDef = null;
                if (building_Bed.GetRoom(RegionType.Set_Passable).Role == RoomRoleDefOf.Bedroom)
                {
                    thoughtDef = ThoughtDefOf.SleptInBedroom;
                }
                else if (building_Bed.GetRoom(RegionType.Set_Passable).Role == RoomRoleDefOf.Barracks)
                {
                    thoughtDef = ThoughtDefOf.SleptInBarracks;
                }

                if (thoughtDef != null)
                {
                    int scoreStageIndex = RoomStatDefOf.Impressiveness.GetScoreStageIndex(building_Bed.GetRoom(RegionType.Set_Passable).GetStat(RoomStatDefOf.Impressiveness));
                    if (thoughtDef.stages[scoreStageIndex] != null)
                    {
                        memories.TryGainMemory(ThoughtMaker.MakeThought(thoughtDef, scoreStageIndex), null);
                    }
                }
            }
        }
Exemplo n.º 4
0
            public static bool Replacement(Pawn actor)
            {
                if (actor.needs.mood == null)
                {
                    return(false);
                }

                Building_Bed building_Bed = actor.CurrentBed();

                actor.needs.mood.thoughts.memories.RemoveMemoriesOfDef(ThoughtDefOf.SleptInBedroom);
                actor.needs.mood.thoughts.memories.RemoveMemoriesOfDef(ThoughtDefOf.SleptInBarracks);
                actor.needs.mood.thoughts.memories.RemoveMemoriesOfDef(ThoughtDefOf.SleptOutside);
                actor.needs.mood.thoughts.memories.RemoveMemoriesOfDef(ThoughtDefOf.SleptOnGround);
                actor.needs.mood.thoughts.memories.RemoveMemoriesOfDef(ThoughtDefOf.SleptInCold);
                actor.needs.mood.thoughts.memories.RemoveMemoriesOfDef(ThoughtDefOf.SleptInHeat);
                if (actor.GetRoom().PsychologicallyOutdoors)
                {
                    actor.needs.mood.thoughts.memories.TryGainMemory(ThoughtDefOf.SleptOutside);
                }
                if (building_Bed == null || building_Bed.CostListAdjusted().Count == 0)
                {
                    actor.needs.mood.thoughts.memories.TryGainMemory(ThoughtDefOf.SleptOnGround);
                }
                if (actor.AmbientTemperature < actor.def.GetStatValueAbstract(StatDefOf.ComfyTemperatureMin))
                {
                    actor.needs.mood.thoughts.memories.TryGainMemory(ThoughtDefOf.SleptInCold);
                }
                if (actor.AmbientTemperature > actor.def.GetStatValueAbstract(StatDefOf.ComfyTemperatureMax))
                {
                    actor.needs.mood.thoughts.memories.TryGainMemory(ThoughtDefOf.SleptInHeat);
                }
                if (building_Bed != null && AddedBedIsOwned(actor, building_Bed) && !building_Bed.ForPrisoners && !actor.story.traits.HasTrait(TraitDefOf.Ascetic))
                {
                    ThoughtDef thoughtDef = null;
                    // ADDED:
                    if (building_Bed.GetRoom().Role == BedUtility.roleDefGuestRoom)
                    {
                        thoughtDef = building_Bed.GetRoom().OnlyOneBed() ? ThoughtDefOf.SleptInBedroom : ThoughtDefOf.SleptInBarracks;
                    } ////
                    else if (building_Bed.GetRoom().Role == RoomRoleDefOf.Bedroom)
                    {
                        thoughtDef = ThoughtDefOf.SleptInBedroom;
                    }
                    else if (building_Bed.GetRoom().Role == RoomRoleDefOf.Barracks)
                    {
                        thoughtDef = ThoughtDefOf.SleptInBarracks;
                    }
                    if (thoughtDef != null)
                    {
                        int scoreStageIndex = RoomStatDefOf.Impressiveness.GetScoreStageIndex(building_Bed.GetRoom().GetStat(RoomStatDefOf.Impressiveness));
                        if (thoughtDef.stages[scoreStageIndex] != null)
                        {
                            actor.needs.mood.thoughts.memories.TryGainMemory(ThoughtMaker.MakeThought(thoughtDef, scoreStageIndex));
                        }
                    }
                }
                return(false);
            }
Exemplo n.º 5
0
        public override bool StateCanOccur(Pawn pawn)
        {
            if (!base.StateCanOccur(pawn))
            {
                return(false);
            }
            Building_Bed ownedBed = pawn.ownership.OwnedBed;

            if (ownedBed == null || ownedBed.GetRoom() == null || ownedBed.GetRoom().PsychologicallyOutdoors)
            {
                return(false);
            }
            return(true);
        }
        static void PostfixApplyBedThoughts(Pawn actor)
        {
            var memories = actor.needs?.mood?.thoughts?.memories;

            if (memories == null)
            {
                return;
            }


            //remove any morph sleeping thoughts
            foreach (ThoughtDef sleepingThought in MorphUtilities.AllMorphSleepingThoughts)
            {
                memories.RemoveMemoriesOfDef(sleepingThought);
            }


            var group = actor.def.GetMorphOfRace()?.@group;

            if (group == null)
            {
                return;
            }
            Building_Bed building_Bed    = null;
            int?         scoreStageIndex = null;


            if (group.bedroomThoughtReplacement != null && memories.GetFirstMemoryOfDef(ThoughtDefOf.SleptInBedroom) != null)
            {
                building_Bed    = actor.CurrentBed();
                scoreStageIndex =
                    RoomStatDefOf.Impressiveness.GetScoreStageIndex(building_Bed.GetRoom().GetStat(RoomStatDefOf.Impressiveness));
                memories.RemoveMemoriesOfDef(ThoughtDefOf.SleptInBedroom);
                var mem = ThoughtMaker.MakeThought(group.bedroomThoughtReplacement, scoreStageIndex.Value);
                memories.TryGainMemory(mem);
            }

            if (group.barrakThoughtReplacement != null && memories.GetFirstMemoryOfDef(ThoughtDefOf.SleptInBarracks) != null)
            {
                building_Bed    = building_Bed ?? actor.CurrentBed(); //only do this if it wasn't done previously
                scoreStageIndex = scoreStageIndex ??
                                  RoomStatDefOf.Impressiveness.GetScoreStageIndex(building_Bed.GetRoom().GetStat(RoomStatDefOf.Impressiveness));
                memories.RemoveMemoriesOfDef(ThoughtDefOf.SleptInBarracks);
                var mem = ThoughtMaker.MakeThought(group.barrakThoughtReplacement, scoreStageIndex.Value);
                memories.TryGainMemory(mem);
            }
        }
        protected override void GetPotentialTargets(List <Thing> outThings)
        {
            outThings.Clear();
            Building_Bed ownedBed = pawn.ownership.OwnedBed;

            if (ownedBed != null)
            {
                if (ownedBed.GetRoom() != null && !ownedBed.GetRoom().PsychologicallyOutdoors)
                {
                    TantrumMentalStateUtility.GetSmashableThingsIn(ownedBed.GetRoom(), pawn, outThings, GetCustomValidator());
                }
                else
                {
                    TantrumMentalStateUtility.GetSmashableThingsNear(pawn, ownedBed.Position, outThings, GetCustomValidator(), 0, 8);
                }
            }
        }
        protected override void GetPotentialTargets(List <Thing> outThings)
        {
            outThings.Clear();
            Building_Bed ownedBed = this.pawn.ownership.OwnedBed;

            if (ownedBed == null)
            {
                return;
            }
            if (ownedBed.GetRoom(RegionType.Set_Passable) != null && !ownedBed.GetRoom(RegionType.Set_Passable).PsychologicallyOutdoors)
            {
                TantrumMentalStateUtility.GetSmashableThingsIn(ownedBed.GetRoom(RegionType.Set_Passable), this.pawn, outThings, this.GetCustomValidator(), 0);
            }
            else
            {
                TantrumMentalStateUtility.GetSmashableThingsNear(this.pawn, ownedBed.Position, outThings, this.GetCustomValidator(), 0, 8);
            }
        }
        public static void ChangeMedicalStatus(Building_Bed __instance, ref bool value)
        {
            var room = __instance.GetRoom();

            if (room != null)
            {
                Main.Instance?.LabelPlacementHandler?.AddOrUpdateRoom(room);
            }
        }
        public static void Postfix(ref Building_Bed __instance)
        {
            var room = __instance.GetRoom();

            if (room != null)
            {
                Main.Instance?.LabelPlacementHandler?.AddOrUpdateRoom(room);
            }
        }
Exemplo n.º 11
0
        public override bool StateCanOccur(Pawn pawn)
        {
            if (!base.StateCanOccur(pawn))
            {
                return(false);
            }
            Building_Bed ownedBed = pawn.ownership.OwnedBed;

            if (ownedBed == null || ownedBed.GetRoom() == null || ownedBed.GetRoom().PsychologicallyOutdoors)
            {
                return(false);
            }
            tmpThings.Clear();
            TantrumMentalStateUtility.GetSmashableThingsIn(ownedBed.GetRoom(), pawn, tmpThings);
            bool result = tmpThings.Any();

            tmpThings.Clear();
            return(result);
        }
        // Token: 0x06003C32 RID: 15410 RVA: 0x001C591C File Offset: 0x001C3D1C
        public override bool StateCanOccur(Pawn pawn)
        {
            if (!base.StateCanOccur(pawn))
            {
                return(false);
            }
            Building_Bed ownedBed = pawn.ownership.OwnedBed;

            return(ownedBed != null && ownedBed.GetRoom(RegionType.Set_Passable) != null && !ownedBed.GetRoom(RegionType.Set_Passable).PsychologicallyOutdoors);
        }
Exemplo n.º 13
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);
        }
            private static IEnumerable <Gizmo> Process(Building_Bed __instance, IEnumerable <Gizmo> __result)
            {
                var isPrisonCell = __instance.GetRoom()?.isPrisonCell == true;

                if (!__instance.ForPrisoners && !__instance.Medical && __instance.def.building.bed_humanlike && !isPrisonCell)
                {
                    yield return
                        (new Command_Toggle
                    {
                        defaultLabel = "CommandBedSetAsGuestLabel".Translate(),
                        defaultDesc = "CommandBedSetAsGuestDesc".Translate(),
                        icon = ContentFinder <Texture2D> .Get("UI/Commands/AsGuest"),
                        isActive = __instance.IsGuestBed,
                        toggleAction = () => Building_GuestBed.Swap(__instance),
                        hotKey = KeyBindingDefOf.Misc4,
                        disabled = __instance.GetComp <CompAssignableToPawn_Bed>() == null,
                        disabledReason = "This bed type is not assignable to pawns."
                    });
                }
                foreach (var gizmo in __result)
                {
                    yield return(gizmo);
                }
            }
Exemplo n.º 15
0
        public static bool Prefix(object __instance, Pawn actor)
        {
            bool result;

            if (actor.needs.mood == null)
            {
                result = false;
            }
            else if (actor.CurrentBed() == null)
            {
                result = true;
            }
            else
            {
                //Log.Message("ApplyBedThoughts is relevant for " + actor);
                Building_Bed bed = new Building_Bed();
                bed = actor.CurrentBed();
                bool hospitalityIsGuest = false;
                if (isHospitalityLoaded)
                {
                    //Correcting for Hospitality 1.0.25
                    hospitalityIsGuest = AddedBedIsOwned(__instance, actor, bed);
                    //
                }
                actor.needs.mood.thoughts.memories.RemoveMemoriesOfDef(ThoughtDefOf.SleptInBedroom);
                actor.needs.mood.thoughts.memories.RemoveMemoriesOfDef(ThoughtDefOf.SleptInBarracks);
                actor.needs.mood.thoughts.memories.RemoveMemoriesOfDef(ThoughtDefOf.SleptOutside);
                actor.needs.mood.thoughts.memories.RemoveMemoriesOfDef(ThoughtDefOf.SleptOnGround);
                actor.needs.mood.thoughts.memories.RemoveMemoriesOfDef(ThoughtDefOf.SleptInCold);
                actor.needs.mood.thoughts.memories.RemoveMemoriesOfDef(ThoughtDefOf.SleptInHeat);
                if (actor.GetRoom(RegionType.Set_Passable).PsychologicallyOutdoors)
                {
                    actor.needs.mood.thoughts.memories.TryGainMemory(ThoughtDefOf.SleptOutside, null);
                }
                if (bed == null || bed.CostListAdjusted().Count == 0)
                {
                    actor.needs.mood.thoughts.memories.TryGainMemory(ThoughtDefOf.SleptOnGround, null);
                }
                //taking bed insulation into consideration:
                //Log.Message("bedStats: cold = " + bed.GetStatValue(BedInsulationCold.Bed_Insulation_Cold, true)+", heat ="+ bed.GetStatValue(BedInsulationHeat.Bed_Insulation_Heat));
                float minTempInBed = actor.def.GetStatValueAbstract(StatDefOf.ComfyTemperatureMin, null) - bed.GetStatValue(BedInsulationCold.Bed_Insulation_Cold, true);
                float maxTempInBed = actor.def.GetStatValueAbstract(StatDefOf.ComfyTemperatureMax, null) + bed.GetStatValue(BedInsulationHeat.Bed_Insulation_Heat, true);
                if (actor.AmbientTemperature < minTempInBed)
                {
                    actor.needs.mood.thoughts.memories.TryGainMemory(ThoughtDefOf.SleptInCold, null);
                    //Log.Message("Temperature is " + actor.AmbientTemperature + " and bed insulation is " + minTempInBed + ",  so " + actor + " gains cold memory");
                }
                if (actor.AmbientTemperature > maxTempInBed)
                {
                    actor.needs.mood.thoughts.memories.TryGainMemory(ThoughtDefOf.SleptInHeat, null);
                    //Log.Message("Temperature is " + actor.AmbientTemperature + " and bed insulation is " + maxTempInBed + ",  so " + actor + " gains heat memory");
                }
                //adapted for hospitality:
                if (bed != null && (hospitalityIsGuest || bed == actor.ownership.OwnedBed) && !bed.ForPrisoners && !actor.story.traits.HasTrait(TraitDefOf.Ascetic))
                {
                    ThoughtDef thoughtDef = null;
                    Room       room       = bed.GetRoom();

                    //Correcting for Hospitality 1.0.25
                    if (hospitalityIsGuest)
                    {
                        bool hospitalityOnlyOneBed = room.ContainedBeds.Count() == 1;
                        if (room.Role == DefDatabase <RoomRoleDef> .GetNamed("GuestRoom", true))// easier to replicate GuestUtility.roleDefGuestRoom than reflecting it!
                        {
                            thoughtDef = hospitalityOnlyOneBed ? ThoughtDefOf.SleptInBedroom : ThoughtDefOf.SleptInBarracks;
                        }
                    }
                    else if (room.Role == RoomRoleDefOf.Bedroom)
                    {
                        thoughtDef = ThoughtDefOf.SleptInBedroom;
                    }
                    else if (room.Role == RoomRoleDefOf.Barracks)
                    {
                        thoughtDef = ThoughtDefOf.SleptInBarracks;
                    }
                    if (thoughtDef != null)
                    {
                        int scoreStageIndex = RoomStatDefOf.Impressiveness.GetScoreStageIndex(bed.GetRoom(RegionType.Set_Passable).GetStat(RoomStatDefOf.Impressiveness));
                        if (thoughtDef.stages[scoreStageIndex] != null)
                        {
                            actor.needs.mood.thoughts.memories.TryGainMemory(ThoughtMaker.MakeThought(thoughtDef, scoreStageIndex), null);
                        }
                    }
                }
                result = false;
            }
            return(result);
        }