forked from ApryllForever/PolyamorySweetLove
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pregnancy.cs
256 lines (235 loc) · 11.7 KB
/
Pregnancy.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
using Microsoft.Xna.Framework;
using StardewModdingAPI;
using StardewValley;
using StardewValley.BellsAndWhistles;
using StardewValley.Characters;
using StardewValley.Events;
using StardewValley.Locations;
using StardewValley.Menus;
using System;
using System.Collections.Generic;
using System.Linq;
namespace PolyamorySweetLove
{
public partial class ModEntry
{
public static bool Utility_pickPersonalFarmEvent_Prefix(ref FarmEvent __result)
{
if (!Config.EnableMod)
return true;
SMonitor.Log("picking event");
if (Game1.weddingToday)
{
__result = null;
return false;
}
List<NPC> allSpouses = GetSpouses(Game1.player,true).Values.ToList();
ShuffleList(ref allSpouses);
foreach (NPC spouse in allSpouses)
{
if (spouse == null)
{
SMonitor.Log($"Utility_pickPersonalFarmEvent_Prefix spouse is null");
continue;
}
Farmer f = spouse.getSpouse();
Friendship friendship = f.friendshipData[spouse.Name];
if (friendship.DaysUntilBirthing <= 0 && friendship.NextBirthingDate != null)
{
lastPregnantSpouse = null;
lastBirthingSpouse = spouse;
__result = new BirthingEvent();
return false;
}
}
if (plannedParenthoodAPI is not null && plannedParenthoodAPI.GetPartnerTonight() is not null)
{
SMonitor.Log($"Handing farm sleep event off to Planned Parenthood");
return true;
}
lastBirthingSpouse = null;
lastPregnantSpouse = null;
foreach (NPC spouse in allSpouses)
{
if (spouse == null)
continue;
Farmer f = spouse.getSpouse();
if (!Config.RoommateRomance && f.friendshipData[spouse.Name].RoommateMarriage)
continue;
int heartsWithSpouse = f.getFriendshipHeartLevelForNPC(spouse.Name);
Friendship friendship = f.friendshipData[spouse.Name];
List<Child> kids = f.getChildren();
int maxChildren = Config.MaxChildren ;
FarmHouse fh = Utility.getHomeOfFarmer(f);
bool can = spouse.daysAfterLastBirth <= 0 && fh.cribStyle.Value > 0 && fh.upgradeLevel >= 2 && friendship.DaysUntilBirthing < 0 && heartsWithSpouse >= 10 && friendship.DaysMarried >= 7 && (kids.Count < maxChildren);
SMonitor.Log($"Checking ability to get pregnant: {spouse.Name} {can}:{(fh.cribStyle.Value > 0 ? $" no crib":"")}{(Utility.getHomeOfFarmer(f).upgradeLevel < 2 ? $" house level too low {Utility.getHomeOfFarmer(f).upgradeLevel}":"")}{(friendship.DaysMarried < 7 ? $", not married long enough {friendship.DaysMarried}":"")}{(friendship.DaysUntilBirthing >= 0 ? $", already pregnant (gives birth in: {friendship.DaysUntilBirthing})":"")}");
if (can && Game1.player.currentLocation == Game1.getLocationFromName(Game1.player.homeLocation.Value) && myRand.NextDouble() < 0.05)
{
SMonitor.Log("Requesting a baby!");
lastPregnantSpouse = spouse;
__result = new QuestionEvent(1);
return false;
}
}
return true;
}
public static NPC lastPregnantSpouse;
private static NPC lastBirthingSpouse;
public static bool QuestionEvent_setUp_Prefix(int ___whichQuestion, ref bool __result)
{
if(Config.EnableMod && ___whichQuestion == 1)
{
if (lastPregnantSpouse == null)
{
__result = true;
return false;
}
Response[] answers = new Response[]
{
new Response("Yes", Game1.content.LoadString("Strings\\Events:HaveBabyAnswer_Yes")),
new Response("Not", Game1.content.LoadString("Strings\\Events:HaveBabyAnswer_No"))
};
if (!lastPregnantSpouse.isAdoptionSpouse() || Config.GayPregnancies)
{
Game1.currentLocation.createQuestionDialogue(Game1.content.LoadString("Strings\\Events:HavePlayerBabyQuestion", lastPregnantSpouse.Name), answers, new GameLocation.afterQuestionBehavior(answerPregnancyQuestion), lastPregnantSpouse);
}
else
{
Game1.currentLocation.createQuestionDialogue(Game1.content.LoadString("Strings\\Events:HavePlayerBabyQuestion_Adoption", lastPregnantSpouse.Name), answers, new GameLocation.afterQuestionBehavior(answerPregnancyQuestion), lastPregnantSpouse);
}
Game1.messagePause = true;
__result = false;
return false;
}
return true;
}
public static bool BirthingEvent_tickUpdate_Prefix(GameTime time, BirthingEvent __instance, ref bool __result, ref int ___timer, string ___soundName, ref bool ___playedSound, string ___message, ref bool ___naming, bool ___getBabyName, bool ___isMale, string ___babyName)
{
if (!Config.EnableMod || !___getBabyName)
return true;
Game1.player.CanMove = false;
___timer += time.ElapsedGameTime.Milliseconds;
Game1.fadeToBlackAlpha = 1f;
if (!___naming)
{
Game1.activeClickableMenu = new NamingMenu(new NamingMenu.doneNamingBehavior(__instance.returnBabyName), Game1.content.LoadString(___isMale ? "Strings\\Events:BabyNamingTitle_Male" : "Strings\\Events:BabyNamingTitle_Female"), "");
___naming = true;
}
if (___babyName != null && ___babyName != "" && ___babyName.Length > 0)
{
double chance = (lastBirthingSpouse.Name.Equals("Maru") || lastBirthingSpouse.Name.Equals("Krobus")) ? 0.5 : 0.0;
chance += (Game1.player.hasDarkSkin() ? 0.5 : 0.0);
bool isDarkSkinned = new Random((int)Game1.uniqueIDForThisGame + (int)Game1.stats.DaysPlayed).NextDouble() < chance;
string newBabyName = ___babyName;
List<NPC> all_characters = Utility.getAllCharacters();
bool collision_found = false;
do
{
collision_found = false;
using (List<NPC>.Enumerator enumerator = all_characters.GetEnumerator())
{
while (enumerator.MoveNext())
{
if (enumerator.Current.Name.Equals(newBabyName))
{
newBabyName += " ";
collision_found = true;
break;
}
}
}
}
while (collision_found);
Child baby = new Child(newBabyName, ___isMale, isDarkSkinned, Game1.player)
{
Age = 0,
Position = new Vector2(16f, 4f) * 64f + new Vector2(0f + myRand.Next(-64, 48), -24f + myRand.Next(-24, 24)),
};
baby.modData["aedenthorn.FreeLove/OtherParent"] = lastBirthingSpouse.Name;
Utility.getHomeOfFarmer(Game1.player).characters.Add(baby);
Game1.playSound("smallSelect");
Game1.getCharacterFromName(lastBirthingSpouse.Name).daysAfterLastBirth = 5;
Game1.player.friendshipData[lastBirthingSpouse.Name].NextBirthingDate = null;
if (Game1.player.getChildrenCount() == 2)
{
Game1.getCharacterFromName(lastBirthingSpouse.Name).shouldSayMarriageDialogue.Value = true;
Game1.getCharacterFromName(lastBirthingSpouse.Name).currentMarriageDialogue.Insert(0, new MarriageDialogueReference("Data\\ExtraDialogue", "NewChild_SecondChild" + myRand.Next(1, 3), true, new string[0]));
Game1.getSteamAchievement("Achievement_FullHouse");
}
else if (lastBirthingSpouse.isAdoptionSpouse() && !Config.GayPregnancies)
{
Game1.getCharacterFromName(lastBirthingSpouse.Name).currentMarriageDialogue.Insert(0, new MarriageDialogueReference("Data\\ExtraDialogue", "NewChild_Adoption", true, new string[]
{
___babyName
}));
}
else
{
Game1.getCharacterFromName(lastBirthingSpouse.Name).currentMarriageDialogue.Insert(0, new MarriageDialogueReference("Data\\ExtraDialogue", "NewChild_FirstChild", true, new string[]
{
___babyName
}));
}
Game1.morningQueue.Enqueue(delegate
{
mp.globalChatInfoMessage("Baby", new string[]
{
Lexicon.capitalize(Game1.player.Name),
Game1.player.spouse,
Lexicon.getGenderedChildTerm(___isMale),
Lexicon.getPronoun(___isMale),
baby.displayName
});
});
if (Game1.keyboardDispatcher != null)
{
Game1.keyboardDispatcher.Subscriber = null;
}
Game1.player.Position = Utility.PointToVector2(Utility.getHomeOfFarmer(Game1.player).getBedSpot()) * 64f;
Game1.globalFadeToClear(null, 0.02f);
lastBirthingSpouse = null;
__result = true;
return false;
}
__result = false;
return false;
}
public static bool BirthingEvent_setUp_Prefix(ref bool ___isMale, ref string ___message, ref bool __result)
{
if (!Config.EnableMod)
return true;
if(lastBirthingSpouse == null)
{
__result = true;
return false;
}
NPC spouse = lastBirthingSpouse;
Game1.player.CanMove = false;
___isMale = myRand.NextDouble() > 0.5f;
if (spouse.isAdoptionSpouse())
{
___message = Game1.content.LoadString("Strings\\Events:BirthMessage_Adoption", Lexicon.getGenderedChildTerm(___isMale));
}
else if (spouse.Gender == Gender.Male)
{
___message = Game1.content.LoadString("Strings\\Events:BirthMessage_PlayerMother", Lexicon.getGenderedChildTerm(___isMale));
}
else
{
___message = Game1.content.LoadString("Strings\\Events:BirthMessage_SpouseMother", Lexicon.getGenderedChildTerm(___isMale), spouse.displayName);
}
__result = false;
return false;
}
public static void answerPregnancyQuestion(Farmer who, string answer)
{
if (answer == "Yes" && who is not null && lastPregnantSpouse is not null && who.friendshipData.ContainsKey(lastPregnantSpouse.Name))
{
WorldDate birthingDate = new WorldDate(Game1.Date);
birthingDate.TotalDays += 14;
who.friendshipData[lastPregnantSpouse.Name].NextBirthingDate = birthingDate;
lastPregnantSpouse.isAdoptionSpouse();
}
}
}
}