TaskEventProcessorBase.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Collections.Concurrent;
  5. using YLTask;
  6. using GameFramework.Event;
  7. using UnityGameFramework.Runtime;
  8. /// <summary>
  9. /// 任务事件处理者 基准的
  10. /// </summary>
  11. public partial class TaskEventProcessor : Singleton<TaskEventProcessor>
  12. {
  13. delegate void TaskEventFuntion(GameEventArgs finish);
  14. // key:Enum_EventType + Enum_TaskCmdType
  15. Dictionary<string, TaskEventFuntion> _TaskEventDict;
  16. public void Init()
  17. {
  18. _TaskEventDict = new Dictionary<string, TaskEventFuntion>();
  19. EventComponent eventCmpt = GameEntry.GetComponent<EventComponent>();
  20. eventCmpt.Subscribe(TaskCardEventAdd.EventId, ProcessorEventAdd);
  21. eventCmpt.Subscribe(TaskCardEventAtive.EventId, ProcessorEventStart);
  22. eventCmpt.Subscribe(TaskCardEventFinish.EventId, ProcessorEventFinishCard);
  23. eventCmpt.Subscribe(TaskEventStepProcess.EventId, ProcessorEventProcess);
  24. eventCmpt.Subscribe(TaskEventStepFinish.EventId, ProcessorEventFinished);
  25. this.InitDialog();
  26. this.InitKill();
  27. this.InitGainItem();
  28. this.InitModifier();
  29. }
  30. public void Clean()
  31. {
  32. EventComponent eventCmpt = GameEntry.GetComponent<EventComponent>();
  33. if (eventCmpt.Check(TaskCardEventAdd.EventId, ProcessorEventAdd))
  34. eventCmpt.Unsubscribe(TaskCardEventAdd.EventId, ProcessorEventAdd);
  35. if (eventCmpt.Check(TaskCardEventAtive.EventId, ProcessorEventStart))
  36. eventCmpt.Unsubscribe(TaskCardEventAtive.EventId, ProcessorEventStart);
  37. if (eventCmpt.Check(TaskCardEventFinish.EventId, ProcessorEventFinishCard))
  38. eventCmpt.Unsubscribe(TaskCardEventFinish.EventId, ProcessorEventFinishCard);
  39. if (eventCmpt.Check(TaskEventStepProcess.EventId, ProcessorEventProcess))
  40. eventCmpt.Unsubscribe(TaskEventStepProcess.EventId, ProcessorEventProcess);
  41. if (eventCmpt.Check(TaskEventStepFinish.EventId, ProcessorEventFinished))
  42. eventCmpt.Unsubscribe(TaskEventStepFinish.EventId, ProcessorEventFinished);
  43. this.CleanMonifier();
  44. }
  45. /// <summary>
  46. /// 获得任务卡
  47. /// </summary>
  48. /// <param name="sender"></param>
  49. /// <param name="e"></param>
  50. public void ProcessorEventAdd(object sender, GameEventArgs e)
  51. {
  52. // 粗暴处理
  53. // 刷新任务进度
  54. UI_TaskTracking.UpdateTaskInfo();
  55. // 任务卡获得效果队列
  56. TaskCardEventAdd eventADD = e as TaskCardEventAdd;
  57. if (eventADD.cardVo.nMo.GetTaskCardExt().type == (int)TaskCardType.TaskCardType_Chief ||
  58. eventADD.cardVo.nMo.GetTaskCardExt().type == (int)TaskCardType.TaskCardType_College ||
  59. eventADD.cardVo.nMo.GetTaskCardExt().type == (int)TaskCardType.TaskCardType_Daily)
  60. {
  61. return;
  62. }
  63. PopupEffectQueueHelper.Instance.ShowEffect(ePopupEffectType.GetTaskCardEffect, eventADD.cardVo);
  64. }
  65. /// <summary>
  66. /// 任务卡激活
  67. /// </summary>
  68. /// <param name="sender"></param>
  69. /// <param name="e"></param>
  70. public void ProcessorEventStart(object sender, GameEventArgs e)
  71. {
  72. TaskCardEventAtive start = e as TaskCardEventAtive;
  73. TaskCardVo vo = start.cardVo;
  74. NpcManager.Instance.RefreshTaskCardVo(vo);
  75. vo.curSteps.ForEach(stp =>
  76. {
  77. Enum_TaskCmdType eType = (Enum_TaskCmdType)stp.mo().cmd;
  78. if (_TaskEventDict.ContainsKey(Enum_EventType.TaskCardActived + eType.ToString()))
  79. {
  80. start.stepVo = stp;
  81. // 激活卡片 StartAction
  82. if (start.stepVo.ShouldDoStartAction())
  83. {
  84. int gateId = stp.mo().StartAction.ParamList[0];
  85. int stageId = stp.mo().StartAction.ParamList[1];
  86. List<int> paramList = start.stepVo.mo().StartAction.ParamList;
  87. int npdID = paramList[0];
  88. int stageID = paramList[1];
  89. PanelHelper.Instance.ShowPanel("UI_TaskDialogWindow", panel =>
  90. {
  91. panel.GetComponent<UI_TaskDialogWindow>().Init(0, npdID, stageID, npdID + "_" + stageID + "_" + 0, 0, null);
  92. panel.GetComponent<UI_TaskDialogWindow>().SetTaskActionData(int.Parse(vo.uid), start.stepVo.typeId, 1);
  93. });
  94. }
  95. // 激活卡片 不同事件处理
  96. _TaskEventDict[Enum_EventType.TaskCardActived + eType.ToString()](start);
  97. // 刷新任务进度
  98. UI_TaskTracking.UpdateTaskInfo();
  99. }
  100. });
  101. }
  102. /// <summary>
  103. /// 任务卡完成
  104. /// </summary>
  105. /// <param name="sender"></param>
  106. /// <param name="e"></param>
  107. public void ProcessorEventFinishCard(object sender, GameEventArgs e)
  108. {
  109. // 任务卡完成效果队列
  110. TaskCardEventFinish eventFinish = e as TaskCardEventFinish;
  111. // UI_TipsWindow.InitStaticDialog("恭喜", "完成任务:"+ eventFinish.cardVo.nMo.name);///需要从这种变成下一种,如果不满意再改动.
  112. UI_TipsWindow.InitFloatDialog("完成任务:" + eventFinish.cardVo.nMo.name);
  113. // 友盟统计: 任务卡完成
  114. AndroidInteractive.CallJavaFunction("onEvent", "e_task", "task_complete", eventFinish.cardVo.typeId.ToString());
  115. StatHelper.Instance.AddEvent("e_task","complete", eventFinish.cardVo.typeId.ToString());
  116. // 粗暴处理
  117. // 刷新任务进度
  118. UI_TaskTracking.UpdateTaskInfo(eventFinish.cardVo);
  119. // 任务卡获得效果队列
  120. if (eventFinish.cardVo.nMo.GetTaskCardExt().type == (int)TaskCardType.TaskCardType_Chief ||
  121. eventFinish.cardVo.nMo.GetTaskCardExt().type == (int)TaskCardType.TaskCardType_College ||
  122. eventFinish.cardVo.nMo.GetTaskCardExt().type == (int)TaskCardType.TaskCardType_Daily)
  123. {
  124. return;
  125. }
  126. PopupEffectQueueHelper.Instance.ShowEffect(ePopupEffectType.CompleteTaskCardEffect, eventFinish.cardVo);
  127. }
  128. /// <summary>
  129. /// 任务步骤有更新
  130. /// </summary>
  131. /// <param name="sender"></param>
  132. /// <param name="e"></param>
  133. public void ProcessorEventProcess(object sender, GameEventArgs e)
  134. {
  135. TaskEventStepProcess process = e as TaskEventStepProcess;
  136. TaskCardVo vo = process.cardVo;
  137. NpcManager.Instance.RefreshTaskCardVo(vo);
  138. vo.curSteps.ForEach(stp =>
  139. {
  140. Enum_TaskCmdType eType = (Enum_TaskCmdType)stp.mo().cmd;
  141. LogHelper.Log("任务更新:" + Enum_EventType.MissionStepComplete + " " + eType.ToString());
  142. if (_TaskEventDict.ContainsKey(Enum_EventType.MissionStepProcess + eType.ToString()))
  143. {
  144. // 处理 startAction
  145. Ins_TaskStepVo svo = stp;
  146. //if (svo.ShouldDoStartAction())
  147. //{
  148. // int gateId = stp.mo().StartAction.ParamList[0];
  149. // int stageId = stp.mo().StartAction.ParamList[1];
  150. // List<int> paramList = svo.mo().StartAction.ParamList;
  151. // int npdID = paramList[0];
  152. // int stageID = paramList[1];
  153. // PanelHelper.Instance.ShowPanel("UI_TaskDialogWindow", panel =>
  154. // {
  155. // panel.GetComponent<UI_TaskDialogWindow>().Init(0, npdID, stageID, npdID + "_" + stageID + "_" + 0, 0, null);
  156. // panel.GetComponent<UI_TaskDialogWindow>().SetTaskActionData(gateId, stageId, 1);
  157. // });
  158. //}
  159. // 更新步骤
  160. _TaskEventDict[Enum_EventType.MissionStepProcess + eType.ToString()](process);
  161. // 刷新任务进度
  162. UI_TaskTracking.UpdateTaskInfo();
  163. }
  164. });
  165. }
  166. /// <summary>
  167. /// 任务步骤完成
  168. /// </summary>
  169. /// <param name="sender"></param>
  170. /// <param name="e"></param>
  171. public void ProcessorEventFinished(object sender, GameEventArgs e)
  172. {
  173. TaskEventStepFinish finish = e as TaskEventStepFinish;
  174. TaskCardVo vo = finish.cardVo;
  175. NpcManager.Instance.RefreshTaskCardVo(vo);
  176. vo.curSteps.ForEach(stp =>
  177. {
  178. Enum_TaskCmdType eType = (Enum_TaskCmdType)stp.mo().cmd;
  179. LogHelper.Log("任务完成:" + Enum_EventType.MissionStepComplete + " " + eType.ToString());
  180. if (_TaskEventDict.ContainsKey(Enum_EventType.MissionStepComplete + eType.ToString()))
  181. {
  182. // 处理 步骤
  183. _TaskEventDict[Enum_EventType.MissionStepComplete + eType.ToString()](finish);
  184. // 处理 finishAction
  185. TaskCardVo cvo = finish.cardVo;
  186. Ins_TaskStepVo svo = finish.stepVo;
  187. if (svo.ShouldDoFinishAction())
  188. {
  189. List<int> paramList = svo.mo().FinishAction.ParamList;
  190. int npcID = paramList[0];
  191. int stageID = paramList[1];
  192. PanelHelper.Instance.ShowPanel("UI_TaskDialogWindow", panel =>
  193. {
  194. panel.GetComponent<UI_TaskDialogWindow>().Init(1, npcID, stageID, npcID + "_" + stageID + "_" + 0, 0, null);
  195. panel.GetComponent<UI_TaskDialogWindow>().SetTaskActionData(int.Parse(vo.uid), svo.typeId, 2);
  196. });
  197. }
  198. // 刷新任务进度
  199. UI_TaskTracking.UpdateTaskInfo(vo);
  200. }
  201. });
  202. }
  203. }