DialogueManager.cs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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 && !(dialogueConfig.ConditionType == 5 && dialogueConfig.ConditionPara[0] == dialogueConfig.optionPara1[0]))
  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. if (dialogueConfig.NPCID != 0)
  66. {
  67. EventNPC eventNpc = ConfigComponent.Instance.Get<EventNPC>(dialogueConfig.NPCID);
  68. if (eventNpc.ID != 0 && eventNpc.DaoyouID != 0)
  69. {
  70. if (AccountFileInfo.Instance.playerData.daoYouDatas.FirstOrDefault(dy => dy.id == eventNpc.DaoyouID) == null)
  71. {
  72. AccountFileInfo.DaoYouData daoYouData = new AccountFileInfo.DaoYouData();
  73. daoYouData.id =eventNpc.DaoyouID;
  74. daoYouData.favorabilityLv = 1;
  75. AccountFileInfo.Instance.playerData.daoYouDatas.Add(daoYouData);
  76. AccountFileInfo.Instance.SavePlayerData();
  77. }
  78. }
  79. }
  80. AccountFileInfo.Instance.SavePlayerData();
  81. //挂机事件 弹出简单气泡对话
  82. if (eventConfig.EventTriggerType != 2)
  83. {
  84. if (dialogueConfig.LanID != null)
  85. {
  86. DialoguePanel.OpenDialoguePanel(dialogueConfig.ID, null, ShowDialogueEventData.MessageShowType.Verbatim,
  87. FishDialogue);
  88. }
  89. else
  90. {
  91. FishDialogue(null);
  92. }
  93. }
  94. else
  95. {
  96. DialogueBubblePanel.OpenDialoguePanel(dialogueConfig.ID, FishDialogue);
  97. }
  98. }
  99. public void FishDialogue(int? selectedOptionID)
  100. {
  101. if (selectedOptionID.HasValue && selectedOptionID.Value != -1)
  102. {
  103. // 玩家选择了选项,处理结果
  104. SelectOption(selectedOptionID.Value);
  105. }
  106. //取消事件
  107. else if (selectedOptionID.HasValue && selectedOptionID.Value == -1)
  108. {
  109. onCancel?.Invoke();
  110. }
  111. else
  112. {
  113. // 无选
  114. EndDialogue1();
  115. }
  116. }
  117. /// <summary>
  118. /// 处理选项选择
  119. /// </summary>
  120. public void SelectOption(int optionID)
  121. {
  122. PlayDialogue(optionID);
  123. }
  124. /// <summary>
  125. /// 结束对话
  126. /// </summary>
  127. private async void EndDialogue1()
  128. {
  129. EventLinkConfig dialogueConfig = ConfigComponent.Instance.Get<EventLinkConfig>(currentDialogueID);
  130. bool isCombatWin = false;
  131. switch (dialogueConfig.optionType)
  132. {
  133. //选项在这里不处理 在ui层处理 所有这里不是走到1 直接return
  134. case 1:
  135. EndDialogue();
  136. return;
  137. //进入战斗
  138. case 2:
  139. LogTool.Log("对话结束,进入战斗");
  140. //不是一次性事件弹出boss界面
  141. if (eventConfig.EventTriggerType != 2)
  142. {
  143. bool relust = await BossInfoPanel.OpenPanel(dialogueConfig.optionPara1[0]);
  144. if (relust)
  145. {
  146. CTask cTask = CTask.Create();
  147. CombatDrive.Instance.LoadLevelBattleCombat(dialogueConfig.optionPara1[0],true,
  148. delegate(bool isWin)
  149. {
  150. LogTool.Log("战斗完成" + isWin);
  151. isCombatWin = isWin;
  152. cTask.SetResult();
  153. });
  154. await cTask;
  155. CombatDrive.Instance.CombatController.ChangeState(CombatController.idle);
  156. }
  157. else
  158. {
  159. onCancel?.Invoke();
  160. return;
  161. }
  162. }
  163. else
  164. {
  165. CTask cTask = CTask.Create();
  166. CombatDrive.Instance.LoadLevelBattleCombat(dialogueConfig.optionPara1[0],false,
  167. delegate(bool isWin)
  168. {
  169. LogTool.Log("战斗完成" + isWin);
  170. isCombatWin = isWin;
  171. cTask.SetResult();
  172. });
  173. await cTask;
  174. CombatDrive.Instance.CombatController.ChangeState(CombatController.idle);
  175. }
  176. break;
  177. //获得奖励
  178. case 3:
  179. List<ItemInfo> itemInfos = new List<ItemInfo>();
  180. for (var i = 0; i < dialogueConfig.PrizeIDs.Length; i++)
  181. {
  182. DropConfig dropConfig = ConfigComponent.Instance.Get<DropConfig>(dialogueConfig.PrizeIDs[i]);
  183. if (dropConfig.dropType == 3)
  184. {
  185. ItemInfo itemInfo = new ItemInfo(dropConfig.dropGroupID[0], dialogueConfig.PrizeNums[i]);
  186. itemInfos.Add(itemInfo);
  187. }
  188. else
  189. {
  190. List<ItemInfo> items = DropManager.Instance.DropItem(dialogueConfig.PrizeIDs[i]);
  191. itemInfos.AddRange(items);
  192. }
  193. }
  194. await OpenRewardsPanel(eventConfig.ID, itemInfos);
  195. LogTool.Log("对话结束,获得奖励");
  196. break;
  197. //扣除道具
  198. case 4:
  199. PlayerManager.Instance.BagController.DeductItem(dialogueConfig.ConditionPara[0], dialogueConfig.finishCount);
  200. break;
  201. }
  202. if (!EventSystemManager.Instance.IsEvenkLinkComplete(currentDialogueID))
  203. {
  204. onCancel?.Invoke();
  205. return;
  206. }
  207. switch (dialogueConfig.ResultType)
  208. {
  209. //直接走下一个id
  210. case 1:
  211. PlayDialogue(dialogueConfig.ResultOptions[0]);
  212. break;
  213. //根据战斗结果判断走哪一个事件id
  214. case 2:
  215. if (isCombatWin)
  216. {
  217. PlayDialogue(dialogueConfig.ResultOptions[0]);
  218. }
  219. else
  220. {
  221. PlayDialogue(dialogueConfig.ResultOptions[1]);
  222. }
  223. break;
  224. //触发新的事件 eventConfigId
  225. case 3:
  226. // if ()
  227. // {
  228. //
  229. // }
  230. AccountFileInfo.EventList eventList = EventSystemManager.Instance.AddEvent(dialogueConfig.ResultOptions[0]);
  231. if (eventList != null)
  232. {
  233. AccountFileInfo.Instance.playerData.eventList.Add(eventList);
  234. AccountFileInfo.Instance.SavePlayerData();
  235. }
  236. EndDialogue();
  237. break;
  238. //结束事件
  239. default:
  240. // if (eventConfig.EventLinksId.Contains(dialogueConfig.ID))
  241. {
  242. EndDialogue();
  243. }
  244. break;
  245. }
  246. }
  247. /// <summary>
  248. /// 结束对话
  249. /// </summary>
  250. private void EndDialogue()
  251. {
  252. onDialogueComplete?.Invoke();
  253. }
  254. public async CTask OpenRewardsPanel(int eventId, List<ItemInfo> rewardsDic, Action onClose = null, int titleId = 0)
  255. {
  256. EventConfig eventConfig = ConfigComponent.Instance.Get<EventConfig>(eventId);
  257. if (eventConfig.EventTriggerType == 2)
  258. {
  259. Vector3 worldPos = CombatDrive.Instance.CombatController.playerHeroEntity.combatHeroGameObject.hpTransform.position;
  260. worldPos.y += 0.5f;
  261. await ShowItemNumberCom.Open(worldPos, rewardsDic[0]);
  262. await TimerComponent.Instance.WaitAsync(100);
  263. }
  264. else
  265. {
  266. RewardsPanel rewardsPanel = await RewardsPanel.OpenPanel(rewardsDic, onClose, titleId);
  267. await rewardsPanel.UIClosed();
  268. }
  269. }
  270. }