2022-03-06 08:45:26 +00:00
|
|
|
|
using RimWorld;
|
|
|
|
|
using rjw;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Verse;
|
|
|
|
|
|
2022-03-20 14:15:55 +00:00
|
|
|
|
namespace RJWSexperience
|
2022-03-06 08:45:26 +00:00
|
|
|
|
{
|
|
|
|
|
public static class PawnExtensions
|
|
|
|
|
{
|
|
|
|
|
public static bool IsIncest(this Pawn pawn, Pawn otherpawn)
|
|
|
|
|
{
|
2022-06-12 07:09:55 +00:00
|
|
|
|
if (otherpawn == null)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
IEnumerable<PawnRelationDef> relations = pawn.GetRelations(otherpawn);
|
2023-04-21 15:19:37 +00:00
|
|
|
|
if (relations == null)
|
2022-06-12 07:09:55 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
foreach (PawnRelationDef relation in relations)
|
2022-03-06 08:45:26 +00:00
|
|
|
|
{
|
2022-06-12 07:09:55 +00:00
|
|
|
|
if (relation.incestOpinionOffset < 0)
|
|
|
|
|
return true;
|
2022-03-06 08:45:26 +00:00
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static float GetSexStat(this Pawn pawn)
|
|
|
|
|
{
|
|
|
|
|
if (xxx.is_human(pawn) && !pawn.Dead)
|
2023-04-17 11:34:35 +00:00
|
|
|
|
return pawn.GetStatValue(RsDefOf.Stat.SexAbility);
|
2022-06-12 07:09:55 +00:00
|
|
|
|
return 1.0f;
|
2022-03-06 08:45:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static T GetAdjacentBuilding<T>(this Pawn pawn) where T : Building
|
|
|
|
|
{
|
2022-06-12 07:09:55 +00:00
|
|
|
|
if (!pawn.Spawned)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
EdificeGrid edifice = pawn.Map.edificeGrid;
|
|
|
|
|
if (edifice[pawn.Position] is T building)
|
|
|
|
|
return building;
|
|
|
|
|
foreach (IntVec3 pos in GenAdjFast.AdjacentCells8Way(pawn.Position))
|
2022-03-06 08:45:26 +00:00
|
|
|
|
{
|
2022-06-12 07:09:55 +00:00
|
|
|
|
if (edifice[pos] is T adjBuilding)
|
|
|
|
|
return adjBuilding;
|
2022-03-06 08:45:26 +00:00
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-30 14:35:32 +00:00
|
|
|
|
public static IEnumerable<T> GetAdjacentBuildings<T>(this Pawn pawn) where T : Building
|
2022-05-07 16:05:27 +00:00
|
|
|
|
{
|
2022-04-30 14:35:32 +00:00
|
|
|
|
var results = new List<T>();
|
2022-06-12 07:09:55 +00:00
|
|
|
|
|
|
|
|
|
if (!pawn.Spawned)
|
|
|
|
|
return results;
|
|
|
|
|
|
|
|
|
|
EdificeGrid edifice = pawn.Map.edificeGrid;
|
|
|
|
|
if (edifice[pawn.Position] is T building)
|
|
|
|
|
results.Add(building);
|
|
|
|
|
foreach (IntVec3 pos in GenAdjFast.AdjacentCells8Way(pawn.Position))
|
2022-04-30 14:35:32 +00:00
|
|
|
|
{
|
2023-03-24 12:32:34 +00:00
|
|
|
|
if (pos.InBounds(pawn.Map) && edifice[pos] is T adjBuilding)
|
2022-06-12 07:09:55 +00:00
|
|
|
|
results.Add(adjBuilding);
|
2022-04-30 14:35:32 +00:00
|
|
|
|
}
|
|
|
|
|
return results;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-06 08:45:26 +00:00
|
|
|
|
/// <summary>
|
2023-04-21 15:19:37 +00:00
|
|
|
|
/// Check if the pawn is virgin
|
2022-03-06 08:45:26 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
public static bool IsVirgin(this Pawn pawn)
|
|
|
|
|
{
|
2023-04-21 15:19:37 +00:00
|
|
|
|
return pawn.records.GetValue(RsDefOf.Record.VaginalSexCount) == 0 ||
|
|
|
|
|
pawn.relations?.ChildrenCount > 0; // Male is a virgins unless he stick into vagina? Not sure it should work this way
|
2022-03-06 08:45:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2023-04-21 15:19:37 +00:00
|
|
|
|
/// Remove virginity if pawn is virgin and announce it
|
2022-03-06 08:45:26 +00:00
|
|
|
|
/// </summary>
|
2023-04-21 15:19:37 +00:00
|
|
|
|
public static void TryRemoveVirginity(this Pawn pawn, Pawn partner, SexProps props)
|
2022-03-06 08:45:26 +00:00
|
|
|
|
{
|
2022-06-18 05:27:03 +00:00
|
|
|
|
int? removedDegree = Virginity.TraitHandler.RemoveVirginTrait(pawn);
|
|
|
|
|
|
2023-04-21 15:19:37 +00:00
|
|
|
|
if (SexperienceMod.Settings.EnableSexHistory && pawn.IsVirgin())
|
2022-03-06 08:45:26 +00:00
|
|
|
|
{
|
2023-04-21 15:19:37 +00:00
|
|
|
|
pawn.TryGetComp<SexHistory.SexHistoryComp>()?.RecordFirst(partner);
|
2022-03-06 08:45:26 +00:00
|
|
|
|
}
|
2022-06-18 05:27:03 +00:00
|
|
|
|
|
2023-04-21 15:19:37 +00:00
|
|
|
|
if (removedDegree != null && removedDegree != Virginity.TraitDegree.FemaleAfterSurgery)
|
|
|
|
|
{
|
|
|
|
|
Messages.Message(Keyed.RS_LostVirgin(pawn.LabelShort, partner.LabelShort), MessageTypeDefOf.NeutralEvent, true);
|
2022-07-08 17:48:57 +00:00
|
|
|
|
RJWUtility.ThrowVirginHistoryEvent(pawn, partner, props, (int)removedDegree);
|
2023-04-21 15:19:37 +00:00
|
|
|
|
}
|
2022-03-06 08:45:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|