DialogueManager.cs 10 KB

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