using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Concurrent;
using YLTask;
using GameFramework.Event;
using UnityGameFramework.Runtime;
///
/// 任务事件处理者 基准的
///
public partial class TaskEventProcessor : Singleton
{
delegate void TaskEventFuntion(GameEventArgs finish);
// key:Enum_EventType + Enum_TaskCmdType
Dictionary _TaskEventDict;
public void Init()
{
_TaskEventDict = new Dictionary();
EventComponent eventCmpt = GameEntry.GetComponent();
eventCmpt.Subscribe(TaskCardEventAdd.EventId, ProcessorEventAdd);
eventCmpt.Subscribe(TaskCardEventAtive.EventId, ProcessorEventStart);
eventCmpt.Subscribe(TaskCardEventFinish.EventId, ProcessorEventFinishCard);
eventCmpt.Subscribe(TaskEventStepProcess.EventId, ProcessorEventProcess);
eventCmpt.Subscribe(TaskEventStepFinish.EventId, ProcessorEventFinished);
this.InitDialog();
this.InitKill();
this.InitGainItem();
this.InitModifier();
}
public void Clean()
{
EventComponent eventCmpt = GameEntry.GetComponent();
if (eventCmpt.Check(TaskCardEventAdd.EventId, ProcessorEventAdd))
eventCmpt.Unsubscribe(TaskCardEventAdd.EventId, ProcessorEventAdd);
if (eventCmpt.Check(TaskCardEventAtive.EventId, ProcessorEventStart))
eventCmpt.Unsubscribe(TaskCardEventAtive.EventId, ProcessorEventStart);
if (eventCmpt.Check(TaskCardEventFinish.EventId, ProcessorEventFinishCard))
eventCmpt.Unsubscribe(TaskCardEventFinish.EventId, ProcessorEventFinishCard);
if (eventCmpt.Check(TaskEventStepProcess.EventId, ProcessorEventProcess))
eventCmpt.Unsubscribe(TaskEventStepProcess.EventId, ProcessorEventProcess);
if (eventCmpt.Check(TaskEventStepFinish.EventId, ProcessorEventFinished))
eventCmpt.Unsubscribe(TaskEventStepFinish.EventId, ProcessorEventFinished);
this.CleanMonifier();
}
///
/// 获得任务卡
///
///
///
public void ProcessorEventAdd(object sender, GameEventArgs e)
{
// 粗暴处理
// 刷新任务进度
UI_TaskTracking.UpdateTaskInfo();
// 任务卡获得效果队列
TaskCardEventAdd eventADD = e as TaskCardEventAdd;
if (eventADD.cardVo.nMo.GetTaskCardExt().type == (int)TaskCardType.TaskCardType_Chief ||
eventADD.cardVo.nMo.GetTaskCardExt().type == (int)TaskCardType.TaskCardType_College ||
eventADD.cardVo.nMo.GetTaskCardExt().type == (int)TaskCardType.TaskCardType_Daily)
{
return;
}
PopupEffectQueueHelper.Instance.ShowEffect(ePopupEffectType.GetTaskCardEffect, eventADD.cardVo);
}
///
/// 任务卡激活
///
///
///
public void ProcessorEventStart(object sender, GameEventArgs e)
{
TaskCardEventAtive start = e as TaskCardEventAtive;
TaskCardVo vo = start.cardVo;
NpcManager.Instance.RefreshTaskCardVo(vo);
vo.curSteps.ForEach(stp =>
{
Enum_TaskCmdType eType = (Enum_TaskCmdType)stp.mo().cmd;
if (_TaskEventDict.ContainsKey(Enum_EventType.TaskCardActived + eType.ToString()))
{
start.stepVo = stp;
// 激活卡片 StartAction
if (start.stepVo.ShouldDoStartAction())
{
int gateId = stp.mo().StartAction.ParamList[0];
int stageId = stp.mo().StartAction.ParamList[1];
List paramList = start.stepVo.mo().StartAction.ParamList;
int npdID = paramList[0];
int stageID = paramList[1];
PanelHelper.Instance.ShowPanel("UI_TaskDialogWindow", panel =>
{
panel.GetComponent().Init(0, npdID, stageID, npdID + "_" + stageID + "_" + 0, 0, null);
panel.GetComponent().SetTaskActionData(int.Parse(vo.uid), start.stepVo.typeId, 1);
});
}
// 激活卡片 不同事件处理
_TaskEventDict[Enum_EventType.TaskCardActived + eType.ToString()](start);
// 刷新任务进度
UI_TaskTracking.UpdateTaskInfo();
}
});
}
///
/// 任务卡完成
///
///
///
public void ProcessorEventFinishCard(object sender, GameEventArgs e)
{
// 任务卡完成效果队列
TaskCardEventFinish eventFinish = e as TaskCardEventFinish;
// UI_TipsWindow.InitStaticDialog("恭喜", "完成任务:"+ eventFinish.cardVo.nMo.name);///需要从这种变成下一种,如果不满意再改动.
UI_TipsWindow.InitFloatDialog("完成任务:" + eventFinish.cardVo.nMo.name);
// 友盟统计: 任务卡完成
AndroidInteractive.CallJavaFunction("onEvent", "e_task", "task_complete", eventFinish.cardVo.typeId.ToString());
StatHelper.Instance.AddEvent("e_task","complete", eventFinish.cardVo.typeId.ToString());
// 粗暴处理
// 刷新任务进度
UI_TaskTracking.UpdateTaskInfo(eventFinish.cardVo);
// 任务卡获得效果队列
if (eventFinish.cardVo.nMo.GetTaskCardExt().type == (int)TaskCardType.TaskCardType_Chief ||
eventFinish.cardVo.nMo.GetTaskCardExt().type == (int)TaskCardType.TaskCardType_College ||
eventFinish.cardVo.nMo.GetTaskCardExt().type == (int)TaskCardType.TaskCardType_Daily)
{
return;
}
PopupEffectQueueHelper.Instance.ShowEffect(ePopupEffectType.CompleteTaskCardEffect, eventFinish.cardVo);
}
///
/// 任务步骤有更新
///
///
///
public void ProcessorEventProcess(object sender, GameEventArgs e)
{
TaskEventStepProcess process = e as TaskEventStepProcess;
TaskCardVo vo = process.cardVo;
NpcManager.Instance.RefreshTaskCardVo(vo);
vo.curSteps.ForEach(stp =>
{
Enum_TaskCmdType eType = (Enum_TaskCmdType)stp.mo().cmd;
LogHelper.Log("任务更新:" + Enum_EventType.MissionStepComplete + " " + eType.ToString());
if (_TaskEventDict.ContainsKey(Enum_EventType.MissionStepProcess + eType.ToString()))
{
// 处理 startAction
Ins_TaskStepVo svo = stp;
//if (svo.ShouldDoStartAction())
//{
// int gateId = stp.mo().StartAction.ParamList[0];
// int stageId = stp.mo().StartAction.ParamList[1];
// List paramList = svo.mo().StartAction.ParamList;
// int npdID = paramList[0];
// int stageID = paramList[1];
// PanelHelper.Instance.ShowPanel("UI_TaskDialogWindow", panel =>
// {
// panel.GetComponent().Init(0, npdID, stageID, npdID + "_" + stageID + "_" + 0, 0, null);
// panel.GetComponent().SetTaskActionData(gateId, stageId, 1);
// });
//}
// 更新步骤
_TaskEventDict[Enum_EventType.MissionStepProcess + eType.ToString()](process);
// 刷新任务进度
UI_TaskTracking.UpdateTaskInfo();
}
});
}
///
/// 任务步骤完成
///
///
///
public void ProcessorEventFinished(object sender, GameEventArgs e)
{
TaskEventStepFinish finish = e as TaskEventStepFinish;
TaskCardVo vo = finish.cardVo;
NpcManager.Instance.RefreshTaskCardVo(vo);
vo.curSteps.ForEach(stp =>
{
Enum_TaskCmdType eType = (Enum_TaskCmdType)stp.mo().cmd;
LogHelper.Log("任务完成:" + Enum_EventType.MissionStepComplete + " " + eType.ToString());
if (_TaskEventDict.ContainsKey(Enum_EventType.MissionStepComplete + eType.ToString()))
{
// 处理 步骤
_TaskEventDict[Enum_EventType.MissionStepComplete + eType.ToString()](finish);
// 处理 finishAction
TaskCardVo cvo = finish.cardVo;
Ins_TaskStepVo svo = finish.stepVo;
if (svo.ShouldDoFinishAction())
{
List paramList = svo.mo().FinishAction.ParamList;
int npcID = paramList[0];
int stageID = paramList[1];
PanelHelper.Instance.ShowPanel("UI_TaskDialogWindow", panel =>
{
panel.GetComponent().Init(1, npcID, stageID, npcID + "_" + stageID + "_" + 0, 0, null);
panel.GetComponent().SetTaskActionData(int.Parse(vo.uid), svo.typeId, 2);
});
}
// 刷新任务进度
UI_TaskTracking.UpdateTaskInfo(vo);
}
});
}
}