DialogueManager.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. using System;
  2. using System.Collections.Generic;
  3. using Common.Utility.CombatEvent;
  4. using Core.Event.Event;
  5. using Excel2Json;
  6. using Fort23.Core;
  7. using Fort23.Mono;
  8. using Fort23.UTool;
  9. using GameLogic.Bag;
  10. using GameLogic.Combat;
  11. using GameLogic.Combat.CombatTool;
  12. using GameLogic.Player;
  13. using UnityEngine;
  14. using Utility;
  15. public class DialogueManager : Singleton<DialogueManager>
  16. {
  17. private int currentDialogueID;
  18. private Action onDialogueComplete;
  19. private Action onCancel;
  20. private EventConfig eventConfig;
  21. /// <summary>
  22. /// 开始对话
  23. /// </summary>
  24. public void StartDialogue(int dialogueID, int eventId, Action onComplete = null, Action onCancel = null)
  25. {
  26. this.onCancel = onCancel;
  27. currentDialogueID = dialogueID;
  28. onDialogueComplete = onComplete;
  29. eventConfig = ConfigComponent.Instance.Get<EventConfig>(eventId);
  30. if (eventConfig.EventType == 2)
  31. {
  32. EndDialogue1();
  33. }
  34. else
  35. {
  36. PlayDialogue(dialogueID);
  37. }
  38. }
  39. private void PlayDialogue(int dialogueID)
  40. {
  41. currentDialogueID = dialogueID;
  42. //神识探索的事件记录步骤
  43. if (EventSystemManager.Instance.CurrentEventList != null)
  44. EventSystemManager.Instance.CurrentEventList.curStep = currentDialogueID;
  45. AccountFileInfo.Instance.SavePlayerData();
  46. // 找到当前对话组
  47. var dialogueConfig = ConfigComponent.Instance.Get<EventConditionConfig>(dialogueID);
  48. if (dialogueConfig.ID == 0)
  49. {
  50. EndDialogue();
  51. return;
  52. }
  53. //挂机事件 弹出简单气泡对话
  54. if (eventConfig.EventTriggerType != 2)
  55. {
  56. DialoguePanel.OpenDialoguePanel(dialogueConfig.ID, null, ShowDialogueEventData.MessageShowType.Verbatim,
  57. FishDialogue);
  58. }
  59. else
  60. {
  61. DialogueBubblePanel.OpenDialoguePanel(dialogueConfig.ID, FishDialogue);
  62. }
  63. }
  64. public void FishDialogue(int? selectedOptionID)
  65. {
  66. if (selectedOptionID.HasValue && selectedOptionID.Value!= -1)
  67. {
  68. // 玩家选择了选项,处理结果
  69. SelectOption(selectedOptionID.Value);
  70. }
  71. //取消事件
  72. else if (selectedOptionID.HasValue && selectedOptionID.Value == -1)
  73. {
  74. onCancel?.Invoke();
  75. }
  76. else
  77. {
  78. // 无选
  79. EndDialogue1();
  80. }
  81. }
  82. /// <summary>
  83. /// 处理选项选择
  84. /// </summary>
  85. public void SelectOption(int optionID)
  86. {
  87. PlayDialogue(optionID);
  88. }
  89. /// <summary>
  90. /// 结束对话
  91. /// </summary>
  92. private async void EndDialogue1()
  93. {
  94. EventConditionConfig dialogueConfig = ConfigComponent.Instance.Get<EventConditionConfig>(currentDialogueID);
  95. bool isCombatWin = false;
  96. switch (dialogueConfig.optionType)
  97. {
  98. //选项在这里不处理 在ui层处理 所有这里不是走到1 直接return
  99. case 1:
  100. EndDialogue();
  101. return;
  102. //进入战斗
  103. case 2:
  104. LogTool.Log("对话结束,进入战斗");
  105. //不是一次性事件弹出boss界面
  106. if (eventConfig.EventTriggerType !=2)
  107. {
  108. bool relust = await BossInfoPanel.OpenPanel(dialogueConfig.optionPara1[0]);
  109. if (relust)
  110. {
  111. CTask cTask = CTask.Create();
  112. CombatDrive.Instance.LoadLevelBattleCombat(dialogueConfig.optionPara1[0],
  113. delegate(bool isWin)
  114. {
  115. LogTool.Log("战斗完成" + isWin);
  116. isCombatWin = isWin;
  117. cTask.SetResult();
  118. });
  119. await cTask;
  120. CombatDrive.Instance.CombatController.ChangeState(CombatController.idle);
  121. }
  122. else
  123. {
  124. onCancel?.Invoke();
  125. return;
  126. }
  127. }
  128. else
  129. {
  130. CTask cTask = CTask.Create();
  131. CombatDrive.Instance.LoadLevelBattleCombat(dialogueConfig.optionPara1[0],
  132. delegate(bool isWin)
  133. {
  134. LogTool.Log("战斗完成" + isWin);
  135. isCombatWin = isWin;
  136. cTask.SetResult();
  137. });
  138. await cTask;
  139. CombatDrive.Instance.CombatController.ChangeState(CombatController.idle);
  140. }
  141. break;
  142. //获得奖励
  143. case 3:
  144. List<ItemInfo> itemInfos = new List<ItemInfo>();
  145. for (var i = 0; i < dialogueConfig.PrizeIDs.Length; i++)
  146. {
  147. DropConfig dropConfig = ConfigComponent.Instance.Get<DropConfig>(dialogueConfig.PrizeIDs[i]);
  148. if (dropConfig.dropType == 3)
  149. {
  150. ItemInfo itemInfo = new ItemInfo(dropConfig.dropGroupID[0], dialogueConfig.PrizeNums[i]);
  151. itemInfos.Add(itemInfo);
  152. }
  153. else
  154. {
  155. List<ItemInfo> items = DropManager.Instance.DropItem(dialogueConfig.PrizeIDs[i]);
  156. itemInfos.AddRange(items);
  157. }
  158. }
  159. await OpenRewardsPanel(eventConfig.ID, itemInfos);
  160. LogTool.Log("对话结束,获得奖励");
  161. break;
  162. //任务检测
  163. case 4:
  164. bool isComplete = TaskManager.Instance.IsTaskComplete(dialogueConfig.optionPara1[0]);
  165. if (!isComplete)
  166. {
  167. return;
  168. }
  169. break;
  170. }
  171. //如果有下一个对话id 走下一个id
  172. if (dialogueConfig.ResultOptions != null && dialogueConfig.ResultOptions.Length > 0)
  173. {
  174. if (dialogueConfig.optionType == 2)
  175. {
  176. if (isCombatWin)
  177. {
  178. PlayDialogue(dialogueConfig.ResultOptions[0]);
  179. }
  180. else
  181. {
  182. PlayDialogue(dialogueConfig.ResultOptions[1]);
  183. }
  184. }
  185. else
  186. {
  187. PlayDialogue(dialogueConfig.ResultOptions[0]);
  188. }
  189. }
  190. else
  191. {
  192. EndDialogue();
  193. }
  194. }
  195. /// <summary>
  196. /// 结束对话
  197. /// </summary>
  198. private void EndDialogue()
  199. {
  200. onDialogueComplete?.Invoke();
  201. }
  202. public async CTask OpenRewardsPanel(int eventId, List<ItemInfo> rewardsDic, Action onClose = null, int titleId = 0)
  203. {
  204. EventConfig eventConfig = ConfigComponent.Instance.Get<EventConfig>(eventId);
  205. if (eventConfig.EventTriggerType == 2)
  206. {
  207. Vector3 worldPos =CombatDrive.Instance.CombatController.playerHeroEntity.combatHeroGameObject.hpTransform.position;
  208. worldPos.y += 0.5f;
  209. await ShowItemNumberCom.Open(worldPos, rewardsDic[0]);
  210. await TimerComponent.Instance.WaitAsync(100);
  211. }
  212. else
  213. {
  214. RewardsPanel rewardsPanel = await RewardsPanel.OpenPanel(rewardsDic, onClose, titleId);
  215. await rewardsPanel.UIClosed();
  216. }
  217. }
  218. }