2021-07-27 14:28:31 +00:00
using System ;
using System.Collections.Generic ;
using System.Linq ;
using System.Text ;
using System.Threading.Tasks ;
using HarmonyLib ;
using rjw ;
using RimWorld ;
using Verse ;
2021-08-06 17:19:42 +00:00
using UnityEngine ;
2021-07-27 14:28:31 +00:00
namespace RJWSexperience
{
public static class RJWUtility
{
public static float GetSexStat ( this Pawn pawn )
{
2021-08-06 17:19:42 +00:00
if ( xxx . is_human ( pawn ) & & ! pawn . Dead )
2021-07-27 14:28:31 +00:00
{
return pawn . GetStatValue ( xxx . sex_stat ) ;
}
else return 1.0f ;
}
public static HistoryEvent TaggedEvent ( this HistoryEventDef def , Pawn pawn , string tag , Pawn partner )
{
return new HistoryEvent ( def , pawn . Named ( HistoryEventArgsNames . Doer ) , tag . Named ( HistoryEventArgsNamesCustom . Tag ) , partner . Named ( HistoryEventArgsNamesCustom . Partner ) ) ;
}
2021-08-06 17:19:42 +00:00
public static Faction GetFactionUsingPrecept ( this Pawn baby , out Ideo ideo )
{
Faction playerfaction = Find . FactionManager . OfPlayer ;
Ideo mainideo = playerfaction . ideos . PrimaryIdeo ;
if ( mainideo ! = null )
{
if ( mainideo . HasPrecept ( VariousDefOf . BabyFaction_AlwaysFather ) )
{
Pawn parent = baby . GetFather ( ) ;
if ( parent = = null ) baby . GetMother ( ) ;
ideo = parent . Ideo ;
return parent . Faction ;
}
else if ( mainideo . HasPrecept ( VariousDefOf . BabyFaction_AlwaysColony ) )
{
ideo = mainideo ;
return playerfaction ;
}
}
Pawn mother = baby . GetMother ( ) ;
2021-08-13 15:23:12 +00:00
ideo = mother ? . Ideo ;
return mother ? . Faction ? ? baby . Faction ;
2021-08-06 17:19:42 +00:00
}
2021-07-27 14:28:31 +00:00
}
[HarmonyPatch(typeof(JobDriver_Sex), "Orgasm")]
public static class RJW_Patch_Orgasm
{
public static void Postfix ( JobDriver_Sex __instance )
{
if ( __instance . sexType ! = xxx . rjwSextype . Masturbation & & ! ( __instance is JobDriver_Masturbate ) )
{
if ( __instance . isRape )
{
__instance . pawn ? . skills ? . Learn ( VariousDefOf . SexSkill , 0.05f , true ) ;
}
else
{
__instance . pawn ? . skills ? . Learn ( VariousDefOf . SexSkill , 0.35f , true ) ;
}
}
}
}
[HarmonyPatch(typeof(WhoringHelper), "WhoreAbilityAdjustmentMin")]
public static class RJW_Patch_WhoreAbilityAdjustmentMin
{
public static void Postfix ( Pawn whore , ref float __result )
{
__result * = whore . GetSexStat ( ) ;
}
}
[HarmonyPatch(typeof(WhoringHelper), "WhoreAbilityAdjustmentMax")]
public static class RJW_Patch_WhoreAbilityAdjustmentMax
{
public static void Postfix ( Pawn whore , ref float __result )
{
__result * = whore . GetSexStat ( ) ;
}
}
[HarmonyPatch(typeof(SexUtility), "SatisfyPersonal")]
2021-08-13 15:23:12 +00:00
public static class RJW_Patch_SatisfyPersonal
2021-07-27 14:28:31 +00:00
{
2021-08-13 15:23:12 +00:00
private const float base_sat_per_fuck = 0.4f ;
2021-07-27 14:28:31 +00:00
public static void Prefix ( Pawn pawn , Pawn partner , xxx . rjwSextype sextype , bool violent , bool pawn_is_raping , ref float satisfaction )
{
satisfaction * = partner . GetSexStat ( ) ;
}
public static void Postfix ( Pawn pawn , Pawn partner , xxx . rjwSextype sextype , bool violent , bool pawn_is_raping , float satisfaction )
{
float? lust = pawn . records ? . GetValue ( VariousDefOf . Lust ) ;
if ( lust ! = null )
{
2021-08-13 15:23:12 +00:00
if ( sextype ! = xxx . rjwSextype . Masturbation | | partner ! = null ) pawn . records . AddTo ( VariousDefOf . Lust , Mathf . Clamp ( ( satisfaction - base_sat_per_fuck ) * LustIncrementFactor ( lust ? ? 0 ) , - 0.5f , 0.5f ) ) ; // If the sex is satisfactory, lust grows up. Declines at the opposite.
else pawn . records . AddTo ( VariousDefOf . Lust , Mathf . Clamp ( satisfaction * satisfaction * LustIncrementFactor ( lust ? ? 0 ) , 0 , 0.5f ) ) ; // Masturbation always increases lust.
2021-07-27 14:28:31 +00:00
}
2021-08-13 15:23:12 +00:00
if ( sextype = = xxx . rjwSextype . Masturbation | | partner = = null )
{
Building_CumBucket cumbucket = ( Building_CumBucket ) pawn . GetAdjacentBuilding < Building_CumBucket > ( ) ;
if ( cumbucket ! = null )
{
cumbucket . AddCum ( pawn . GetCumVolume ( ) ) ;
}
}
2021-07-27 14:28:31 +00:00
}
2021-08-06 17:19:42 +00:00
public static float LustIncrementFactor ( float lust )
{
return Mathf . Exp ( - Mathf . Pow ( lust / Configurations . LustLimit , 2 ) ) ;
}
2021-07-27 14:28:31 +00:00
}
[HarmonyPatch(typeof(xxx), "TransferNutrition")]
public static class RJW_Patch_TransferNutrition
{
public static void Postfix ( Pawn pawn , Pawn partner , xxx . rjwSextype sextype )
{
Pawn receiver = null ;
if ( Genital_Helper . has_penis_fertile ( pawn ) ) receiver = partner ;
else if ( Genital_Helper . has_penis_fertile ( partner ) ) receiver = pawn ;
if ( receiver ! = null & & (
sextype = = xxx . rjwSextype . Oral | |
sextype = = xxx . rjwSextype . Fellatio | |
sextype = = xxx . rjwSextype . Sixtynine ) )
{
2021-08-13 15:23:12 +00:00
receiver . CumDrugEffect ( ) ;
2021-07-27 14:28:31 +00:00
}
}
}
[HarmonyPatch(typeof(Nymph_Generator), "set_skills")]
public static class RJW_Patch_Nymph_set_skills
{
public static void Postfix ( Pawn pawn )
{
SkillRecord sexskill = pawn . skills . GetSkill ( VariousDefOf . SexSkill ) ;
if ( sexskill ! = null )
{
sexskill . passion = Passion . Major ;
sexskill . Level = ( int ) Utility . RandGaussianLike ( 7f , 20.99f ) ;
sexskill . xpSinceLastLevel = sexskill . XpRequiredForLevelUp * Rand . Range ( 0.10f , 0.90f ) ;
}
}
}
}