Ejemplo n.º 1
0
        private static void ApplyStatChangeVars(Heroine heroine, PregnancyData preg, Dictionary <string, ValData> vars)
        {
            if (vars.TryGetVarValue("PillUsed", out bool used) && used)
            {
                PregnancyGameController.ForceStopPregnancyDelayed(heroine);

                var freePill = _personalityHasPills.TryGetValue(heroine.personality, out var val) && val;
                if (!freePill)
                {
                    StoreApi.SetItemAmountBought(AfterpillStoreId, Mathf.Clamp(StoreApi.GetItemAmountBought(AfterpillStoreId) - 1, 0, 99));
                }
            }

            if (vars.TryGetVarValue <int>("FavorChange", out var favor))
            {
                heroine.favor = Mathf.Clamp(heroine.favor + favor, 0, 150);
            }

            if (vars.TryGetVarValue <int>("LewdChange", out var lewd))
            {
                heroine.lewdness = Mathf.Clamp(heroine.lewdness + lewd, 0, 100);
            }

            if (vars.TryGetVarValue <int>("MoneyChange", out var money))
            {
                Manager.Game.saveData.player.koikatsuPoint += money;
            }
        }
        private static void ApplyToAllDatas(Func <SaveData.CharaData, PregnancyData, bool> action)
        {
            void ApplyToDatas(SaveData.CharaData character)
            {
                var chafiles = character.GetRelatedChaFiles();

                if (chafiles == null)
                {
                    return;
                }
                foreach (var chaFile in chafiles)
                {
                    var data = ExtendedSave.GetExtendedDataById(chaFile, PregnancyPlugin.GUID);
                    var pd   = PregnancyData.Load(data) ?? new PregnancyData();
                    if (action(character, pd))
                    {
                        ExtendedSave.SetExtendedDataById(chaFile, PregnancyPlugin.GUID, pd.Save());
                    }
                }
            }

            foreach (var heroine in Game.Instance.HeroineList)
            {
                ApplyToDatas(heroine);
            }
            ApplyToDatas(Game.Instance.Player);

            // If controller exists then update its state so it gets any pregnancy week updates
            foreach (var controller in FindObjectsOfType <PregnancyCharaController>())
            {
                controller.ReadData();
            }
        }
Ejemplo n.º 3
0
        private static bool AddPregnancyWeek(PregnancyData pd)
        {
            if (pd == null || !pd.GameplayEnabled)
            {
                return(false);
            }

            if (pd.IsPregnant)
            {
                if (pd.Week < PregnancyData.LeaveSchoolWeek)
                {
                    // Advance through in-school at full configured speed
                    var weekChange = PregnancyPlugin.PregnancyProgressionSpeed.Value;
                    pd.Week = Mathf.Min(PregnancyData.LeaveSchoolWeek, pd.Week + weekChange);
                }
                else if (pd.Week < PregnancyData.ReturnToSchoolWeek)
                {
                    // Make sure at least one week is spent out of school
                    var weekChange = Mathf.Min(PregnancyData.ReturnToSchoolWeek - PregnancyData.LeaveSchoolWeek - 1, PregnancyPlugin.PregnancyProgressionSpeed.Value);
                    pd.Week = pd.Week + weekChange;
                }

                if (pd.Week >= PregnancyData.ReturnToSchoolWeek)
                {
                    pd.Week = 0;
                }
                // PregnancyPlugin.Logger.LogDebug($"Preg - pregnancy week is now {pd.Week}");
            }
            else if (pd.PregnancyCount > 0)
            {
                pd.WeeksSinceLastPregnancy++;
            }

            return(true);
        }
        private static void ApplyToAllDatas(Func<AgentData, PregnancyData, bool> action)
        {
            void ApplyToDatas(AgentData character)
                {
                    var chafiles = character.GetRelatedChaFiles();
                    if (chafiles == null) return;

                    foreach (var chaFile in chafiles)
                    {
                        var data = ExtendedSave.GetExtendedDataById(chaFile, PregnancyPlugin.GUID);
                        var pd = PregnancyData.Load(data) ?? new PregnancyData();
                        if (action(character, pd))
                            ExtendedSave.SetExtendedDataById(chaFile, PregnancyPlugin.GUID, pd.Save());
                    }
                }

                var heroineList = GetHeroineList();
                if (heroineList == null) return;

                foreach (var heroine in heroineList)
                {
                    ApplyToDatas(heroine);
                }
                // ApplyToDatas(Singleton<Map>.Instance.Player.AgentPartner.AgentData);  TODO find male AgentData, if we want to match what KK is now doing

                // If controller exists then update its state so it gets any pregnancy week updates
                foreach (var controller in FindObjectsOfType<PregnancyCharaController>())
                    controller.ReadData();
        }
Ejemplo n.º 5
0
        public void ReadData()
        {
            var data = GetExtendedData();

            Data = PregnancyData.Load(data) ?? new PregnancyData();

            // PregnancyPlugin.Logger.LogDebug($"Preg - ReadData week {Data.Week} {ChaControl.name}");
        }
Ejemplo n.º 6
0
        private static void RunIntroEvent(Heroine heroine, PregnancyData preg, bool isPillEvent)
        {
            var loadedEvt = GetEvent(heroine, preg, isPillEvent);

            if (loadedEvt == null)
            {
                PregnancyPlugin.Logger.LogError("Unexpected null GetEvent result");
                return;
            }

            // Init needed first since the custom event starts empty
            var evt = EventApi.CreateNewEvent(setPlayerParam: true);

            heroine.SetADVParam(evt);
            var freePill = _personalityHasPills.TryGetValue(heroine.personality, out var val) && val;

            evt.Add(Program.Transfer.VAR("bool", "PillForFree", freePill.ToString(CultureInfo.InvariantCulture)));
            evt.Add(Program.Transfer.VAR("bool", "PlayerHasPill", (StoreApi.GetItemAmountBought(AfterpillStoreId) >= 1).ToString(CultureInfo.InvariantCulture)));
            // Give favor by default, gets overriden if the event specifies any other value
            evt.Add(Program.Transfer.VAR("int", "FavorChange", "30"));

            evt.AddRange(loadedEvt);

            var scene = TalkScene.instance;

            scene.StartADV(evt, scene.cancellation.Token)
            .ContinueWith(() => Program.ADVProcessingCheck(scene.cancellation.Token))
            .ContinueWith(() =>
            {
                PregnancyGameController.ApplyToAllDatas((chara, data) =>
                {
                    if (chara == heroine)
                    {
                        if (isPillEvent)
                        {
                            data.CanAskForAfterpill = false;
                        }
                        else
                        {
                            data.CanTellAboutPregnancy = false;
                        }
                        return(true);
                    }
                    return(false);
                });

                var vars = ActionScene.instance.AdvScene.Scenario.Vars;
                ApplyStatChangeVars(heroine, preg, vars);

                // Fix mouth getting permanently locked by the events
                heroine.chaCtrl.ChangeMouthFixed(false);
            })
            .Forget();
        }
            private static void GetMenstruationOverridePrefix()
            {
                if (_lastHeroine != null)
                {
                    // Get a schedule directly this way since the controller is not spawned in class roster
                    var schedule = _lastHeroine.GetRelatedChaFiles()
                                   .Select(c => PregnancyData.Load(ExtendedSave.GetExtendedDataById(c, GUID))?.MenstruationSchedule ?? MenstruationSchedule.Default)
                                   .FirstOrDefault(x => x != MenstruationSchedule.Default);

                    _menstruationsBackup = HFlag.menstruations;
                    HFlag.menstruations  = PregnancyCharaController.GetMenstruationsArr(schedule);
                }
            }
Ejemplo n.º 8
0
            private static bool CanGetSpawned(AgentActor heroine)
            {
                var isOnLeave = heroine.GetRelatedChaFiles()
                                .Any(c =>
                {
                    var pd = PregnancyData.Load(ExtendedSave.GetExtendedDataById(heroine.ChaControl.chaFile, GUID));
                    if (pd == null)
                    {
                        return(false);
                    }
                    return(pd.GameplayEnabled && pd.Week >= PregnancyData.LeaveSchoolWeek);
                });

                return(!isOnLeave);
            }
        /// <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));
        }
Ejemplo n.º 10
0
        public void ReadData()
        {
            var data = GetExtendedData();

            Data = PregnancyData.Load(data) ?? new PregnancyData();

            if (!CanGetDangerousDays())
            {
                // Force the girl to always be on the safe day, happens every day after day of conception
                var heroine = ChaControl.GetHeroine();
                if (heroine != null)
                {
                    HFlag.SetMenstruation(heroine, HFlag.MenstruationType.安全日);
                }
            }
        }
        public void ReadData()
        {
            var data = GetExtendedData();

            Data = PregnancyData.Load(data) ?? new PregnancyData();

            // PregnancyPlugin.Logger.LogDebug($"Preg - ReadData week {Data.Week} {ChaControl.name}");

#if KK
            if (!CanGetDangerousDays())
            {
                // Force the girl to always be on the safe day, happens every day after day of conception
                var heroine = ChaControl.GetHeroine();
                if (heroine != null)
                {
                    HFlag.SetMenstruation(heroine, HFlag.MenstruationType.安全日);
                }
            }
#endif
        }
Ejemplo n.º 12
0
        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);
        }
Ejemplo n.º 13
0
        private static List <Program.Transfer> GetEvent(Heroine heroine, PregnancyData data, bool isPill)
        {
            var personalityNo = _personalityHasPills.ContainsKey(heroine.personality) ? heroine.personality : 99;

            var evtName = $"c{personalityNo:D2}_";

            if (isPill)
            {
                evtName += "AS_";
            }
            else if (data.PregnancyCount <= 1)
            {
                evtName += "PREG_";
            }
            else
            {
                evtName += "XPREG_";
            }

            var pattern = evtName + @"[\w\d ]+.csv$";

            var containingAssembly = typeof(CustomEventsFeature).Assembly;
            var evtResourceName    = containingAssembly.GetManifestResourceNames().SingleOrDefault(fname => Regex.IsMatch(fname, pattern));

            if (evtResourceName == null)
            {
                throw new IOException($"Pattern {pattern} did not match any resources inside assembly {containingAssembly}");
            }

            using (var resourceStream = containingAssembly.GetManifestResourceStream(evtResourceName))
                using (var reader = new StreamReader(resourceStream ?? throw new InvalidOperationException($"{evtResourceName} not found in assembly {containingAssembly}")))
                {
                    var lines     = reader.ReadToEnd().Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                    var paramList = CsvHelper.ReadFomCsv(lines);
                    return(paramList.Select(x => new Program.Transfer(x)).ToList());
                }
        }
Ejemplo n.º 14
0
        public void ReadData()
        {
            var heroine = KoikatuAPI.GetCurrentGameMode() == GameMode.MainGame ? ChaControl.GetHeroine() : null;

            if (heroine?.charFile != null)
            {
                Data = heroine.charFile.GetPregnancyData() ?? new PregnancyData();
            }
            else
            {
                Data = PregnancyData.Load(GetExtendedData()) ?? new PregnancyData();
            }

            // PregnancyPlugin.Logger.LogDebug($"Preg - ReadData week {Data.Week} {ChaControl.name}");

            if (!CanGetDangerousDays())
            {
                // Force the girl to always be on the safe day, happens every day after day of conception
                if (heroine != null)
                {
                    HFlag.SetMenstruation(heroine, HFlag.MenstruationType.安全日);
                }
            }
        }
        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);
        }
 public static HeroineStatus GetHeroineStatus(this SaveData.CharaData chara, PregnancyData pregData = null) => GetCharaStatus(chara, pregData);
        public static HeroineStatus GetCharaStatus(this SaveData.CharaData chara, PregnancyData pregData = null)
        {
            if (chara is SaveData.Heroine heroine)
            {
                if (pregData == null)
                {
                    pregData = heroine.GetPregnancyData();
                }

                // Check if she wants to tell
                if (heroine.intimacy >= 80 ||
                    heroine.hCount >= 5 ||
                    heroine.parameter.attribute.bitch && heroine.favor > 50 ||
                    (heroine.isGirlfriend || heroine.favor >= 90) &&
                    (!heroine.isVirgin || heroine.hCount >= 2 || heroine.intimacy >= 40))
                {
                    var pregnancyWeek = pregData.Week;
                    if (pregnancyWeek > 0)
                    {
                        if (pregnancyWeek >= PregnancyData.LeaveSchoolWeek)
                        {
                            return(HeroineStatus.OnLeave);
                        }
                        if (PregnancyPlugin.ShowPregnancyIconEarly.Value)
                        {
                            return(HeroineStatus.Pregnant);
                        }
                        // Different personalities notice at different times
                        if (_earlyDetectPersonalities.Contains(heroine.personality))
                        {
                            if (pregnancyWeek > 1)
                            {
                                return(HeroineStatus.Pregnant);
                            }
                        }
                        else if (_lateDetectPersonalities.Contains(heroine.personality))
                        {
                            if (pregnancyWeek > 11)
                            {
                                return(HeroineStatus.Pregnant);
                            }
                        }
                        else
                        {
                            if (pregnancyWeek > 5)
                            {
                                return(HeroineStatus.Pregnant);
                            }
                        }
                    }

                    return(HFlag.GetMenstruation(heroine.MenstruationDay) == HFlag.MenstruationType.安全日
                            ? HeroineStatus.Safe
                            : HeroineStatus.Risky);
                }
            }
            else if (chara is SaveData.Player player)
            {
                if (pregData == null)
                {
                    pregData = player.GetPregnancyData();
                }
                return(pregData.IsPregnant ? HeroineStatus.Pregnant : HeroineStatus.Safe);
            }
            return(HeroineStatus.Unknown);
        }
Ejemplo n.º 18
0
 public PregnancyCharaController()
 {
     Data        = new PregnancyData();
     _boneEffect = new PregnancyBoneEffect(this);
 }