DialogueManager.cs 9.9 KB

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