RJW-Sexperience/Source/RJWSexperience/ExtensionMethods/PawnExtensions.cs

81 lines
2.2 KiB
C#

using RimWorld;
using rjw;
using System.Collections.Generic;
using Verse;
namespace RJWSexperience
{
public static class PawnExtensions
{
public static bool IsIncest(this Pawn pawn, Pawn otherpawn)
{
if (otherpawn == null)
return false;
IEnumerable<PawnRelationDef> relations = pawn.GetRelations(otherpawn);
if (relations == null)
return false;
foreach (PawnRelationDef relation in relations)
{
if (relation.incestOpinionOffset < 0)
return true;
}
return false;
}
public static float GetSexStat(this Pawn pawn)
{
if (xxx.is_human(pawn) && !pawn.Dead)
return pawn.GetStatValue(RsDefOf.Stat.SexAbility);
return 1.0f;
}
public static T GetAdjacentBuilding<T>(this Pawn pawn) where T : Building => GetAdjacentBuildings<T>(pawn).FirstOrFallback();
public static IEnumerable<T> GetAdjacentBuildings<T>(this Pawn pawn) where T : Building
{
if (!pawn.Spawned)
yield break;
EdificeGrid edifice = pawn.Map.edificeGrid;
if (edifice[pawn.Position] is T building)
yield return building;
foreach (IntVec3 pos in GenAdjFast.AdjacentCells8Way(pawn.Position))
{
if (pos.InBounds(pawn.Map) && edifice[pos] is T adjBuilding)
yield return adjBuilding;
}
}
/// <summary>
/// Check if the pawn is virgin
/// </summary>
public static bool IsVirgin(this Pawn pawn)
{
return pawn.records.GetValue(RsDefOf.Record.VaginalSexCount) == 0 &&
(pawn.relations?.ChildrenCount ?? 0) < 1; // Male is a virgins unless he stick into vagina? Not sure it should work this way
}
/// <summary>
/// Remove virginity if pawn is virgin and announce it
/// </summary>
public static void TryRemoveVirginity(this Pawn pawn, Pawn partner, SexProps props)
{
int? removedDegree = Virginity.TraitHandler.RemoveVirginTrait(pawn);
if (SexperienceMod.Settings.EnableSexHistory && pawn.IsVirgin())
{
pawn.TryGetComp<SexHistory.SexHistoryComp>()?.RecordFirst(partner);
}
if (removedDegree != null && removedDegree != Virginity.TraitDegree.FemaleAfterSurgery)
{
Messages.Message(Keyed.RS_LostVirgin(pawn.LabelShort, partner.LabelShort), MessageTypeDefOf.NeutralEvent, true);
RJWUtility.ThrowVirginHistoryEvent(pawn, partner, props, (int)removedDegree);
}
}
}
}