private static bool TryPlayCustomTopicAdvHook(TalkScene scene) { var topic = scene.topics[scene.selectTopic]; var topicNo = topic.No; _customTopics.TryGetValue(topicNo, out var topicInfo); if (topicInfo != null) { KoikatuAPI.Logger.LogDebug("Handling custom topic No=" + topicNo); var script = topicInfo.ScriptGetter(scene, topicNo, scene.targetHeroine.personality, scene.isNPC); if (script != null) { KoikatuAPI.Logger.LogDebug("Playing ADV scene for the topic"); scene.StartADV(script, CancellationToken.None).GetAwaiter().GetResult(); //todo handle cancelling var vars = ActionScene.initialized ? ActionScene.instance.AdvScene.Scenario.Vars : SceneParameter.advScene.Scenario.Vars; var result = topicInfo.ResultGetter(scene, topicNo, scene.targetHeroine.personality, scene.isNPC, vars); scene.m_CVInfo = result ?? new ChangeValueTopicInfo(); } return(true); } return(false); }
/// <summary> /// Start a new ADV event inside of a TalkScene (same as stock game events when talking). /// The target heroine is automatically added to the heroine list, and their vars are set at the very start. /// Warning: You have to have a Close command or the scene will softlock after reaching the end! /// </summary> /// <param name="talkScene">Currently opened talk scene</param> /// <param name="commands">List of commands for the event</param> /// <param name="endTalkScene">If true, end the talk scene after this event finishes.</param> /// <param name="decreaseTalkTime">Should the talk time bar decrease after the event. If the bar runs out then the talk scene will end.</param> public static IEnumerator StartTextSceneEvent(TalkScene talkScene, IEnumerable <Program.Transfer> commands, bool decreaseTalkTime, bool endTalkScene = false) { if (commands == null) { throw new ArgumentNullException(nameof(commands)); } if (talkScene == null || !talkScene.isActive) { throw new ArgumentNullException(nameof(talkScene), "Has to be ran inside of a TalkScene"); } if (talkScene.targetHeroine == null) { throw new ArgumentNullException(nameof(talkScene.targetHeroine), "Heroine in TalkScene is null somehow?"); } var token = talkScene.cancellation.Token; token.ThrowIfCancellationRequested(); var list = commands.ToList(); // Auto load all parameters of the TalkScene heroine list.Insert(0, Program.Transfer.Create(true, Command.CharaChange, "-2", "true")); talkScene.canvas.enabled = false; talkScene.raycast.enabled = false; yield return(talkScene.StartADV(list, token).ToCoroutine(UnityEngine.Debug.LogException)); if (decreaseTalkTime) { GameAssist.Instance.DecreaseTalkTime(talkScene.targetHeroine, 1); if (talkScene.targetHeroine.talkTime <= 0) { endTalkScene = true; } } if (endTalkScene) { yield return(talkScene.TalkEnd(token).ToCoroutine(UnityEngine.Debug.LogException)); } talkScene.LeaveAloneCancel(); talkScene.lstColDisposable.ForEach(x => x.End()); talkScene.TouchCancel(); if (talkScene.transVoice != null) { Voice.Stop(talkScene.transVoice); talkScene.transVoice = null; } if (!token.IsCancellationRequested) { talkScene.OnClickMain(-1); } if (!endTalkScene) { yield return(talkScene.CommandWait(token).ToCoroutine(UnityEngine.Debug.LogException)); } }