-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from ManlyMarco/kks-preg
KKS preggers port
- Loading branch information
Showing
58 changed files
with
2,840 additions
and
1,344 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
using System; | ||
using System.Reflection; | ||
using ExtensibleSaveFormat; | ||
|
||
namespace KK_Pregnancy | ||
{ | ||
public sealed class PregnancyData | ||
{ | ||
public static readonly float DefaultFertility = 0.3f; | ||
|
||
/// <summary> | ||
/// Week at which pegnancy reaches max level and the character leaves school | ||
/// </summary> | ||
public static readonly int LeaveSchoolWeek = 41; | ||
|
||
/// <summary> | ||
/// Week at which pegracy ends and the character returns to school | ||
/// </summary> | ||
public static readonly int ReturnToSchoolWeek = LeaveSchoolWeek + 7; | ||
|
||
#region Names of these are important, used as dictionary keys | ||
|
||
/// <summary> | ||
/// The character is harder to get pregananant. | ||
/// </summary> | ||
public float Fertility = 0.3f; | ||
|
||
/// <summary> | ||
/// Should any gameplay code be executed for this character. | ||
/// If false the current pregancy week doesn't change and the character can't get pegnant. | ||
/// </summary> | ||
public bool GameplayEnabled = true; | ||
|
||
public MenstruationSchedule MenstruationSchedule = MenstruationSchedule.Default; | ||
|
||
/// <summary> | ||
/// The first day that menstraion started in AI | ||
/// </summary> | ||
public int MenstrationStartDay = -1; | ||
|
||
/// <summary> | ||
/// If 0 or negative, the character is not pregant. | ||
/// If between 0 and <see cref="LeaveSchoolWeek"/> the character is pregant and the belly is proportionately sized. | ||
/// If equal or above <see cref="LeaveSchoolWeek"/> the character is on a maternal leave until <see cref="ReturnToSchoolWeek"/>. | ||
/// </summary> | ||
public int Week; | ||
|
||
/// <summary> | ||
/// How many times the character was pergant, including the current one. | ||
/// </summary> | ||
public int PregnancyCount; | ||
|
||
public int WeeksSinceLastPregnancy; | ||
|
||
/// <summary> | ||
/// Always have milk, even if not pergenant | ||
/// </summary> | ||
public bool AlwaysLactates; | ||
|
||
#endregion | ||
|
||
#region Save/Load | ||
|
||
private static readonly PregnancyData _default = new PregnancyData(); | ||
private static readonly FieldInfo[] _serializedFields = typeof(PregnancyData).GetFields(BindingFlags.Public | BindingFlags.Instance); | ||
|
||
public static PregnancyData Load(PluginData data) | ||
{ | ||
if (data?.data == null) return null; | ||
|
||
var result = new PregnancyData(); | ||
foreach (var fieldInfo in _serializedFields) | ||
{ | ||
if (data.data.TryGetValue(fieldInfo.Name, out var val)) | ||
{ | ||
try | ||
{ | ||
if (fieldInfo.FieldType.IsEnum) val = (int)val; | ||
fieldInfo.SetValue(result, val); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine(ex); | ||
} | ||
} | ||
} | ||
|
||
if (result.IsPregnant) | ||
{ | ||
result.WeeksSinceLastPregnancy = 0; | ||
if (result.PregnancyCount == 0) result.PregnancyCount = 1; | ||
} | ||
|
||
return result; | ||
} | ||
|
||
public PluginData Save() | ||
{ | ||
var result = new PluginData { version = 1 }; | ||
foreach (var fieldInfo in _serializedFields) | ||
{ | ||
var value = fieldInfo.GetValue(this); | ||
// Check if any value is different than default, if not then don't save any data | ||
var defaultValue = fieldInfo.GetValue(_default); | ||
if (!Equals(defaultValue, value)) | ||
result.data.Add(fieldInfo.Name, value); | ||
} | ||
|
||
return result.data.Count > 0 ? result : null; | ||
} | ||
|
||
#endregion | ||
|
||
// If week is 0 the character is not peregenent | ||
public bool IsPregnant => Week > 0; | ||
|
||
public void StartPregnancy() | ||
{ | ||
if (GameplayEnabled && !IsPregnant) | ||
{ | ||
Week = 1; | ||
PregnancyCount++; | ||
WeeksSinceLastPregnancy = 0; | ||
} | ||
} | ||
|
||
public void StartMenstration(int currentDay) | ||
{ | ||
if (!IsPregnant) | ||
{ | ||
MenstrationStartDay = currentDay; | ||
} | ||
} | ||
|
||
public void StopMenstration() | ||
{ | ||
MenstrationStartDay = -1; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using ExtensibleSaveFormat; | ||
using KKAPI.MainGame; | ||
using AIChara; | ||
using AIProject; | ||
using AIProject.SaveData; | ||
using AIProject.Definitions; | ||
|
||
namespace KK_Pregnancy | ||
{ | ||
public static class PregnancyDataUtils | ||
{ | ||
private static readonly int[] _earlyDetectPersonalities = { 00, 11, 12, 13, 19, 24, 31, 33 }; | ||
private static readonly int[] _lateDetectPersonalities = { 03, 05, 08, 20, 25, 26, 37 }; | ||
|
||
/// <param name="c">ChaFile to test</param> | ||
///// <param name="afterWasDiscovered">The girl knows about it / tested it</param> | ||
public static PregnancyData GetPregnancyData(this ChaFileControl c) | ||
{ | ||
if (c == null) return null; | ||
|
||
var d = ExtendedSave.GetExtendedDataById(c, PregnancyPlugin.GUID); | ||
if (d == null) return null; | ||
|
||
return PregnancyData.Load(d); | ||
} | ||
|
||
public static PregnancyData GetPregnancyData(this AgentData heroine) | ||
{ | ||
if (heroine == null) return new PregnancyData(); | ||
|
||
// Figure out which data to take if there are multiple | ||
// probably not necessary? null check should be enough? | ||
return heroine.GetRelatedChaFiles() | ||
.Select(GetPregnancyData) | ||
.Where(x => x != null) | ||
.OrderByDescending(x => x.PregnancyCount) | ||
.ThenByDescending(x => x.WeeksSinceLastPregnancy) | ||
.ThenByDescending(x => x.Week) | ||
.ThenByDescending(x => x.GameplayEnabled) | ||
.FirstOrDefault() ?? new PregnancyData(); | ||
} | ||
|
||
public static HeroineStatus GetHeroineStatus(this AgentData heroine, PregnancyData pregData = null) | ||
{ | ||
if (heroine == null) return HeroineStatus.Unknown; | ||
if (pregData == null) pregData = heroine.GetPregnancyData(); | ||
|
||
var chaControl = heroine.GetNPC()?.ChaControl; | ||
if (chaControl == null) return HeroineStatus.Unknown; | ||
|
||
// Check if she wants to tell | ||
if (heroine.SickState.ID == AIProject.Definitions.Sickness.GoodHealthID && !heroine.IsWet && | ||
(chaControl.fileGameInfo.phase > 2 | ||
|| heroine.StatsTable[(int)Status.Type.Mood] > 95 | ||
|| heroine.StatsTable[(int)Status.Type.Immoral] > 95 | ||
|| heroine.StatsTable[(int)Status.Type.Motivation] > 140)) | ||
{ | ||
|
||
var pregnancyWeek = pregData.Week; | ||
if (pregnancyWeek > 0) | ||
{ | ||
if (PregnancyPlugin.ShowPregnancyIconEarly.Value) return HeroineStatus.Pregnant; | ||
// Different personalities notice at different times | ||
if (_earlyDetectPersonalities.Contains(chaControl.fileParam.personality)) | ||
{ | ||
if (pregnancyWeek > 1) return HeroineStatus.Pregnant; | ||
} | ||
else if (_lateDetectPersonalities.Contains(chaControl.fileParam.personality)) | ||
{ | ||
if (pregnancyWeek > 11) return HeroineStatus.Pregnant; | ||
} | ||
else | ||
{ | ||
if (pregnancyWeek > 5) return HeroineStatus.Pregnant; | ||
} | ||
} | ||
|
||
var pregCharCtrl = chaControl.GetComponent<PregnancyCharaController>(); | ||
return !pregCharCtrl.isDangerousDay | ||
? HeroineStatus.Safe | ||
: HeroineStatus.Risky; | ||
} | ||
|
||
return HeroineStatus.Unknown; | ||
|
||
} | ||
} | ||
} |
Oops, something went wrong.