DialogueManager.cs 8.5 KB

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