/// <summary> /// 词条状态的一次更新 /// </summary> private void EntryStateInit() { foreach (KeyValuePair <int, EntryDataInfo> item in idToEntryDataInfoDic) { if (item.Value.UnlockDick.Count == 0) { if (!playerState.EntryEnableList.Contains(item.Value.ID)) { playerState.EntryEnableList.Add(item.Value.ID); } } else { var taskChecks = item.Value.UnlockDick.Where(temp => temp.Key == EntryDataInfo.EnumEntryUnlockType.OverTask).ToArray(); foreach (var taskCheck in taskChecks) { TaskMap.RunTimeTaskInfo taskInfo = runtimeTaskData.GetTasksWithID(taskCheck.Value, false); if (taskInfo.IsOver && !playerState.EntryEnableList.Contains(item.Value.ID)) { playerState.EntryEnableList.Add(item.Value.ID); } } } } }
/// <summary> /// 当前任务状态发生变化 /// </summary> /// <param name="iNowTaskState"></param> /// <param name="fieldName"></param> private void INowTaskStateChanged(INowTaskState iNowTaskState, string fieldName) { //开始任务 if (string.Equals(fieldName, GameState.GetFieldNameStatic <INowTaskState, int>(temp => temp.StartTask))) { Init(); // 如果存在该任务且该任务是主线 TaskMap.RunTimeTaskInfo runTimeTaskInfo = runtimeTasksData.GetTasksWithID(iNowTaskState.StartTask, true); if (runTimeTaskInfo != null && runTimeTaskInfo.TaskInfoStruct.TaskType == TaskMap.Enums.EnumTaskType.Main && !runTimeTaskInfo.TaskInfoStruct.NeedShowTalk && runTimeTaskInfo.TaskInfoStruct.NeedShowImageTip) { Debug.Log("显示图片提示:" + runTimeTaskInfo.ID); string directoryPath = runTimeTaskInfo.TaskInfoStruct.ShowImageTipDirectoryName; if (!string.IsNullOrEmpty(directoryPath))//该文件夹不为空 { directoryPath = ResourceDirectoryPath + "/" + directoryPath; needShowArray = Resources.LoadAll <Sprite>(directoryPath); if (needShowArray.Length > 0) { gameObject.SetActive(true); //显示面板 nowPage = 0; ShowImageTip(); //显示 } } } } }
/// <summary> /// 在所有的检测字典以及集合中移除指定的任务 (主要使用与完成以及放弃任务) /// 如果检测到该任务已经失败;如果检测到任务已经完成 /// </summary> /// <param name="taskID">任务id</param> /// <param name="all">是否将人物从等待接取集合中移除吗</param> private void RemoveTaskByIDAtDicAndList(int taskID, bool all = false) { if (!all)//如果不从等待接取集合中移除 { TaskMap.RunTimeTaskInfo runTimeTaskInfo = runTimeTaskInfos_Start.Where(temp => temp.ID == taskID).FirstOrDefault(); if (runTimeTaskInfo != null) { if (runTimeTaskInfos_Wait.Count(temp => temp.ID == taskID) <= 0) { runTimeTaskInfos_Wait.Add(runTimeTaskInfo); } runTimeTaskInfos_Start.Remove(runTimeTaskInfo); } } else//如果从等待集合中移除 { runTimeTaskInfos_Start.RemoveAll(temp => temp.ID == taskID); runTimeTaskInfos_Wait.RemoveAll(temp => temp.ID == taskID); } //从字典中移除 checkPostionRunTimeDic.Remove(taskID); checkNPCRunTimeDic.Remove(taskID); checkMonsterRunTimeDic.Remove(taskID); checkGoodsRunTimeDic.Remove(taskID); checkSpecialRunTimeDic.Remove(taskID); }
/// <summary> /// 处理该任务的事件 /// </summary> /// <param name="runTimeTaskInfo"></param> public void TriggeringEvents(TaskMap.RunTimeTaskInfo runTimeTaskInfo) { if (runTimeTaskInfo.TaskInfoStruct.TaskEventTriggerDic != null) { if (runTimeTaskInfo.TaskInfoStruct.TaskEventTriggerDic.ContainsKey(runTimeTaskInfo.TaskProgress)) { List <TaskMap.TaskEventData> taskEventDataList = runTimeTaskInfo.TaskInfoStruct.TaskEventTriggerDic[runTimeTaskInfo.TaskProgress]; if (taskEventDataList != null) { foreach (TaskMap.TaskEventData taskEventData in taskEventDataList) { TaskMap.TaskEventData taskEventData_clone = taskEventData.Clone(); taskEventData_clone.TaskID = runTimeTaskInfo.ID; if (taskEventData != null) { List <int> ids = eventTypeToIDsDic[taskEventData.EventType]; foreach (var id in ids) { try { idToCallBackDic[id](taskEventData_clone); } catch { } } } } } } } }
/// <summary> /// 放弃任务 /// </summary> /// <param name="taskID"></param> public void GiveUPTask(int taskID) { TaskMap.RunTimeTaskInfo runTimeTaskInfo = runTimeTaskInfos_Start.Where(temp => temp.ID == taskID && temp.TaskInfoStruct.TaskType != TaskMap.Enums.EnumTaskType.Main).FirstOrDefault(); if (runTimeTaskInfo != null) { RemoveTaskByIDAtDicAndList(runTimeTaskInfo.ID); runTimeTaskInfo.IsStart = false; //触发事件 iNowTaskStateEvent.TriggeringEvents(runTimeTaskInfo); } }
/// <summary> /// 检测任务(关于击杀怪物) /// </summary> /// <param name="monsterID">怪物的id</param> bool CheckNowTaskMonster(int monsterID) { if (checkMonsterRunTimeDic == null) { return(false); } if (checkMonsterDicTempList == null) { checkMonsterDicTempList = new List <TaskMap.RunTimeTaskInfo>(); } if (checkMonsterRunTimeDic.Count > 0) { checkMonsterDicTempList.Clear(); foreach (KeyValuePair <int, TaskMap.RunTimeTaskInfo> checkMonsterRunTime in checkMonsterRunTimeDic) { TaskMap.RunTimeTaskInfo runTimeTaskInfo = checkMonsterRunTime.Value; if (!runTimeTaskInfo.TaskInfoStruct.NeedKillMonsterCount.ContainsKey((EnumMonsterType)monsterID))//如果该任务不需要判断该怪物 { continue; } runTimeTaskInfo.TaskInfoStruct.GameKillMonsterCount[(EnumMonsterType)monsterID] += 1;//击杀怪物数量加1 bool isOver = true; foreach (KeyValuePair <EnumMonsterType, int> item in runTimeTaskInfo.TaskInfoStruct.GameKillMonsterCount) { if (item.Value < runTimeTaskInfo.TaskInfoStruct.NeedKillMonsterCount[(EnumMonsterType)monsterID]) { isOver = false; break; } } if (isOver) { checkMonsterDicTempList.Add(checkMonsterRunTime.Value); } } if (checkMonsterDicTempList.Count > 0) { foreach (TaskMap.RunTimeTaskInfo runTimeTaskInfo in checkMonsterDicTempList) { //如果检测出已经完成则移除 checkMonsterRunTimeDic.Remove(runTimeTaskInfo.ID); if (!HasCheckTaskID(runTimeTaskInfo.ID))//如果不存在检测项了则直接完成任务 { OverTaskID = runTimeTaskInfo.ID; return(true); } } } } return(false); }
/// <summary> /// 标记当前任务 /// </summary> private void MarkTaskToMap() { if (nowTaskItem) { TaskMap.RunTimeTaskInfo runTimeTaskInfo = nowTaskItem.value as TaskMap.RunTimeTaskInfo; if (runTimeTaskInfo != null) { if (iMapState.MarkTaskID == runTimeTaskInfo.ID)//如果相等则取消标记 { iMapState.MarkTaskID = -1; } else//如果不想等则重新标记 { iMapState.MarkTaskID = runTimeTaskInfo.ID; } } } }
/// <summary> /// 检测任务(关于特殊状态) /// </summary> /// <param name="specialTypeID"></param> /// <returns></returns> bool CheckNowTaskSpecial(int specialTypeID) { if (checkSpecialRunTimeDic == null) { return(false); } if (checkSpecialDicTempList == null) { checkSpecialDicTempList = new List <TaskMap.RunTimeTaskInfo>(); } if (checkSpecialRunTimeDic.Count > 0) { checkSpecialDicTempList.Clear(); foreach (KeyValuePair <int, TaskMap.RunTimeTaskInfo> checkSpecialRunTime in checkSpecialRunTimeDic) { TaskMap.RunTimeTaskInfo runTimeTaskInfo = checkSpecialRunTime.Value; if (runTimeTaskInfo.TaskInfoStruct.NeedSpecialCheck == TaskMap.Enums.EnumTaskSpecialCheck.None)//该任务不需要判断特殊状态 { continue; } TaskMap.Enums.EnumTaskSpecialCheck specialType = (TaskMap.Enums.EnumTaskSpecialCheck)specialTypeID; if (specialType == TaskMap.Enums.EnumTaskSpecialCheck.None) { continue; } if (runTimeTaskInfo.TaskInfoStruct.NeedSpecialCheck != specialType) { continue; } checkSpecialDicTempList.Add(runTimeTaskInfo); } if (checkSpecialDicTempList.Count > 0) { foreach (TaskMap.RunTimeTaskInfo runTimeTaskInfo in checkSpecialDicTempList) { //如果检测出已完成则移除 checkSpecialRunTimeDic.Remove(runTimeTaskInfo.ID); //此处不完成任务,因为这时候很可能处于特殊状态 } } } return(false); }
/// <summary> /// 显示当前任务 /// </summary> private void ShowNowTask() { TaskMap.RunTimeTaskInfo runTimeTaskInfo = null; //显示地图标记的任务 if (iMapState.MarkTaskID > -1) { runTimeTaskInfo = runTimeTasksData.GetAllToDoList().Where(temp => temp.ID == iMapState.MarkTaskID && temp.IsStart).FirstOrDefault(); } //如果地图没有标记或者标记的任务已经被完成了,则显示当前的第一个主线任务 if (runTimeTaskInfo == null) { runTimeTaskInfo = runTimeTasksData.GetAllToDoList().Where(temp => temp.TaskInfoStruct.TaskType == TaskMap.Enums.EnumTaskType.Main && temp.IsStart).FirstOrDefault(); } //如果主线已经做完了,则选取第一个任务 if (runTimeTaskInfo == null) { runTimeTaskInfo = runTimeTasksData.GetAllToDoList().Where(temp => temp.TaskInfoStruct.TaskType != TaskMap.Enums.EnumTaskType.Main && temp.IsStart).FirstOrDefault(); } //如果当前存在任务则显示 if (runTimeTaskInfo != null) { taskTitleObj.SetActive(true); taskValueObj.SetActive(true); gameObject.GetComponent <Image>().color = new Color(1, 1, 1, 0.3f); taskTitleText.text = runTimeTaskInfo.TaskInfoStruct.TaskTitile; taskValueText.text = runTimeTaskInfo.TaskInfoStruct.TaskExplain; StartCoroutine(WaitUpdateValueText());//用于刷新显示 verticalLayoutGroup.SetLayoutHorizontal(); verticalLayoutGroup.SetLayoutVertical(); } //如果当前不存在任务则隐藏 else { taskTitleObj.SetActive(false); taskValueObj.SetActive(false); gameObject.GetComponent <Image>().color = new Color(1, 1, 1, 0); taskTitleText.text = ""; taskValueText.text = ""; } }
/// <summary> /// 展示当前任务的说明与进度 /// </summary> private void ExplanNowItem() { if (!nowTaskItem) { taskExplanText.text = ""; } else { //显示任务 TaskMap.RunTimeTaskInfo runTimeTaskInfo = nowTaskItem.value as TaskMap.RunTimeTaskInfo; if (runTimeTaskInfo != null) { taskExplanText.text = runTimeTaskInfo.TaskInfoStruct.TaskExplain; //根据类型以及其他信息显示完善的数据信息 //throw new Exception("未完善"); } else { taskExplanText.text = ""; } } }
/// <summary> /// 初始化对话 /// </summary> private void InitTalk() { fisrtKeyUP = false; int touchNPCID = iInteractiveState.ClickInteractiveNPCID; TaskMap.RunTimeTaskInfo[] runTimeTaskInfos = runtimeTasksData.GetAllToDoList() .Where(temp => temp.TaskInfoStruct.ReceiveTaskNpcId == touchNPCID && temp.IsOver == false && temp.IsStart == false) .ToArray(); //首先选择 TaskMap.RunTimeTaskInfo runTimeTaskInfo = runTimeTaskInfos.Where(temp => temp.TaskInfoStruct.TaskType == TaskMap.Enums.EnumTaskType.Spur).FirstOrDefault(); if (runTimeTaskInfo == null) { runTimeTaskInfo = runTimeTaskInfos.Where(temp => temp.TaskInfoStruct.TaskType == TaskMap.Enums.EnumTaskType.Repeat).FirstOrDefault(); } if (runTimeTaskInfo != null) { this.runTimeTaskInfo = runTimeTaskInfo;//这个表示当前的任务 DialogueCondition[] dialogueConditions = dialogueStructData.SearchDialogueConditionsByNPCID(runTimeTaskInfo.TaskInfoStruct.ReceiveTaskNpcId, temp => temp.enumDialogueType == EnumDialogueType.Ask).ToArray(); DialoguePoint taskPoint; dialogueCodition = dialogueConditions.Where(temp => DialoguePointHasThisTask(temp.topPoint, this.runTimeTaskInfo.ID.ToString(), out taskPoint)).FirstOrDefault(); if (dialogueCodition != null)//如果存在该任务 { this.nowDialoguePoint = this.dialogueCodition.topPoint; InitDontShowTalk(dialogueCodition); ShowTalk(); } else { gameObject.SetActive(false); } } else { gameObject.SetActive(false); } }
/// <summary> /// 当前任务状态发生变化 /// </summary> /// <param name="iNowTaskState"></param> /// <param name="fieldName"></param> private void INowTaskStateChanged(INowTaskState iNowTaskState, string fieldName) { //开始任务 if (string.Equals(fieldName, GameState.GetFieldNameStatic <INowTaskState, int>(temp => temp.StartTask))) { Init(); // 如果存在该任务且该任务是主线 TaskMap.RunTimeTaskInfo runTimeTaskInfo = runtimeTasksData.GetTasksWithID(iNowTaskState.StartTask, true); if (runTimeTaskInfo != null && runTimeTaskInfo.TaskInfoStruct.TaskType == TaskMap.Enums.EnumTaskType.Main && runTimeTaskInfo.TaskInfoStruct.NeedShowTalk && !runTimeTaskInfo.TaskInfoStruct.NeedShowImageTip) { DialogueCondition dialogueCodition = dialogueStructData.SearchDialogueConditionsByNPCID(-1, temp => temp.enumDialogueType == EnumDialogueType.Task && temp.thisTask == iNowTaskState.StartTask).FirstOrDefault(); if (dialogueCodition != null) { gameObject.SetActive(true); //显示面板 InitTalk(dialogueCodition); //初始化对话 } } } else if (string.Equals(fieldName, GameState.GetFieldNameStatic <INowTaskState, int>(temp => temp.OverTaskID))) { Init(); // 如果存在该任务且该任务是主线 TaskMap.RunTimeTaskInfo runTimeTaskInfo = runtimeTasksData.GetTasksWithID(iNowTaskState.OverTaskID, false); if (runTimeTaskInfo != null && runTimeTaskInfo.TaskInfoStruct.TaskType == TaskMap.Enums.EnumTaskType.Main && runTimeTaskInfo.TaskInfoStruct.NeedShowTalk) { Debug.Log("显示结束任务对话:" + runTimeTaskInfo.ID); DialogueCondition dialogueCodition = dialogueStructData.SearchDialogueConditionsByNPCID(-1, temp => temp.enumDialogueType == EnumDialogueType.Task && temp.overTask == iNowTaskState.OverTaskID).FirstOrDefault(); if (dialogueCodition != null) { gameObject.SetActive(true); //显示面板 InitTalk(dialogueCodition); //初始化对话 } } } }
/// <summary> /// 判断任务情况 /// </summary> /// <param name="iNowTaskState"></param> /// <param name="fieldName"></param> private void CheckTask(INowTaskState iNowTaskState) { if (iNowTaskState != null && NPCDataInfo != null && NPCDataInfo.NPCShowCondition != null && runTimeTaskData != null) { NPCDataInfo.NPCShowCondition.TaskCoditionHidePath = false; if (NPCDataInfo.NPCShowCondition.TaskConditionsHide != null && NPCDataInfo.NPCShowCondition.TaskConditionsHide.Length > 0) { foreach (var item in NPCDataInfo.NPCShowCondition.TaskConditionsHide) { TaskMap.RunTimeTaskInfo runtimeTaskInfo = runTimeTaskData.GetTasksWithID(item.TaskID, false); if (runtimeTaskInfo != null && runtimeTaskInfo.TaskProgress == item.TaskState) { NPCDataInfo.NPCShowCondition.TaskCoditionHidePath = true; break; } } } NPCDataInfo.NPCShowCondition.TaskCoditionShowPath = false; if (NPCDataInfo.NPCShowCondition.TaskConditionShow != null && NPCDataInfo.NPCShowCondition.TaskConditionShow.Length > 0) { foreach (var item in NPCDataInfo.NPCShowCondition.TaskConditionShow) { TaskMap.RunTimeTaskInfo runtimeTaskInfo = runTimeTaskData.GetTasksWithID(item.TaskID, false); if (runtimeTaskInfo != null && runtimeTaskInfo.TaskProgress == item.TaskState) { NPCDataInfo.NPCShowCondition.TaskCoditionShowPath = true; break; } } } else { NPCDataInfo.NPCShowCondition.TaskCoditionShowPath = true; } } UpdateShow(); }
/// <summary> /// 检测怪物数据的状态 /// 和玩家位置进行对比,用于创建移动或设置怪物AI /// </summary> private void CheckMonsterDataInfoState() { if (monsterDataInfos == null || thisSceneCanCheckMonsterObjDic == null || allMonsterObjDic == null || thisSceneCanCheckMonsterObjList == null) { return; } IPlayerState iPlayerState = GameState.Instance.GetEntity <IPlayerState>(); if (iPlayerState.PlayerObj == null) { return; } //判断大区域 bool objListChanged = false;//对象集合是否发生了变化 //检测触发区域是否会发生变化 foreach (MonsterDataInfo monsterDataInfo in monsterDataInfos) { float distance = Vector2.Distance( new Vector2(monsterDataInfo.Center.x, monsterDataInfo.Center.z) , new Vector2(iPlayerState.PlayerObj.transform.position.x, iPlayerState.PlayerObj.transform.position.z)); if (distance > monsterDataInfo.Range + MaxRangeLeaveDistance) { if (thisSceneCanCheckMonsterObjDic.ContainsKey(monsterDataInfo)) { thisSceneCanCheckMonsterObjDic.Remove(monsterDataInfo); objListChanged = true; } } else if (distance <= monsterDataInfo.Range) { //获取当前任务状态是否可以显示 bool taskPass = monsterDataInfo.CanShowThis(temp => { TaskMap.RunTimeTaskInfo tempTaskInfoStruct = runtimeTaskData.GetTasksWithID(temp, false); if (tempTaskInfoStruct == null) { return(TaskMap.Enums.EnumTaskProgress.NoTake); } return(tempTaskInfoStruct.TaskProgress); }); if (taskPass)//可以显示 { if (!thisSceneCanCheckMonsterObjDic.ContainsKey(monsterDataInfo)) { if (!allMonsterObjDic.ContainsKey(monsterDataInfo)) { allMonsterObjDic.Add(monsterDataInfo, new List <GameObject>()); } thisSceneCanCheckMonsterObjDic.Add(monsterDataInfo, allMonsterObjDic[monsterDataInfo]); objListChanged = true; } } else//不可以显示 { if (thisSceneCanCheckMonsterObjDic.ContainsKey(monsterDataInfo)) { thisSceneCanCheckMonsterObjDic.Remove(monsterDataInfo); objListChanged = true; } } } } //移除所有对象字典空元素 foreach (KeyValuePair <MonsterDataInfo, List <GameObject> > tempData in allMonsterObjDic) { tempData.Value.RemoveAll(temp => temp == null); } //检测触发区域内的对象生成情况 foreach (KeyValuePair <MonsterDataInfo, List <GameObject> > tempData in thisSceneCanCheckMonsterObjDic) { MonsterDataInfo monsterDataInfo = tempData.Key; switch (monsterDataInfo.AIType) { case EnumMonsterAIType.Trigger: //触发型(更新时间到了并且在触发区域被且没有任何怪物时生成) MonsterAIData_Trigger monsterAIData_Trigger = monsterDataInfo.AIData as MonsterAIData_Trigger; if (monsterAIData_Trigger != null && tempData.Value.Count == 0 && monsterAIData_Trigger.NowUpdateTime <= 0) { float distance = Vector2.Distance( new Vector2(monsterDataInfo.Center.x, monsterDataInfo.Center.z) , new Vector2(iPlayerState.PlayerObj.transform.position.x, iPlayerState.PlayerObj.transform.position.z)); if (distance < monsterAIData_Trigger.TriggerRange && monsterDataInfo.MonsterPrefab != null) { monsterAIData_Trigger.NowUpdateTime = monsterAIData_Trigger.UpdateTime; //生成怪物 for (int i = 0; i < monsterAIData_Trigger.Count; i++) { Vector3 createPos = new Vector3( UnityEngine.Random.Range(monsterDataInfo.Center.x - monsterAIData_Trigger.CreateRange, monsterDataInfo.Center.x + monsterAIData_Trigger.CreateRange), monsterDataInfo.Center.y, UnityEngine.Random.Range(monsterDataInfo.Center.z - monsterAIData_Trigger.CreateRange, monsterDataInfo.Center.z + monsterAIData_Trigger.CreateRange)); GameObject createObj = GameObject.Instantiate <GameObject>(monsterDataInfo.MonsterPrefab, createPos, Quaternion.identity); MonsterControl monsterControl = createObj.AddComponent <MonsterControl>(); monsterControl.SameGroupObjList = tempData.Value; monsterControl.monsterDataInfo = tempData.Key; tempData.Value.Add(createObj); //设置位置(MonsterControl内部会进行y轴的设置) //createObj.transform.position = new Vector3( // UnityEngine.Random.Range(monsterDataInfo.Center.x - monsterAIData_Trigger.TriggerRange, monsterDataInfo.Center.x + monsterAIData_Trigger.TriggerRange), // monsterDataInfo.Center.y, // UnityEngine.Random.Range(monsterDataInfo.Center.z - monsterAIData_Trigger.TriggerRange, monsterDataInfo.Center.z + monsterAIData_Trigger.TriggerRange)); } objListChanged = true; } } break; case EnumMonsterAIType.GoOnPatrol: //巡逻型(更新时间到了并且怪物集合数量少与最大数量时生成) MonsterAIData_GoOnPatrol monsterAIData_GoOnPatrol = monsterDataInfo.AIData as MonsterAIData_GoOnPatrol; if (monsterAIData_GoOnPatrol != null && tempData.Value.Count < monsterAIData_GoOnPatrol.Count && monsterAIData_GoOnPatrol.NowUpdateTime <= 0) { monsterAIData_GoOnPatrol.NowUpdateTime = monsterAIData_GoOnPatrol.UpdateTime; //生成怪物 int createCount = monsterAIData_GoOnPatrol.Count - tempData.Value.Count; for (int i = 0; i < createCount; i++) { Vector3 createPos = new Vector3( UnityEngine.Random.Range(monsterDataInfo.Center.x - monsterAIData_GoOnPatrol.CreateRange, monsterDataInfo.Center.x + monsterAIData_GoOnPatrol.CreateRange), monsterDataInfo.Center.y, UnityEngine.Random.Range(monsterDataInfo.Center.z - monsterAIData_GoOnPatrol.CreateRange, monsterDataInfo.Center.z + monsterAIData_GoOnPatrol.CreateRange)); GameObject createObj = GameObject.Instantiate <GameObject>(monsterDataInfo.MonsterPrefab, createPos, Quaternion.identity); MonsterControl monsterControl = createObj.AddComponent <MonsterControl>(); monsterControl.SameGroupObjList = tempData.Value; monsterControl.monsterDataInfo = tempData.Key; tempData.Value.Add(createObj); //设置位置(MonsterControl内部会进行y轴的设置) //createObj.transform.position = new Vector3( // UnityEngine.Random.Range(monsterDataInfo.Center.x - monsterAIData_GoOnPatrol.CreateRange, monsterDataInfo.Center.x + monsterAIData_GoOnPatrol.CreateRange), // monsterDataInfo.Center.y, // UnityEngine.Random.Range(monsterDataInfo.Center.z - monsterAIData_GoOnPatrol.CreateRange, monsterDataInfo.Center.z + monsterAIData_GoOnPatrol.CreateRange)); } objListChanged = true; } break; case EnumMonsterAIType.Boss: //boss型(更新时间到了并且怪物没有生成是生成) MonsterAIData_Boss monsterAIData_Boss = monsterDataInfo.AIData as MonsterAIData_Boss; if (monsterAIData_Boss != null && tempData.Value.Count == 0 && monsterAIData_Boss.NowUpdateTime <= 0) { monsterAIData_Boss.NowUpdateTime = monsterAIData_Boss.UpdateTime; //生成怪物 GameObject createObj = GameObject.Instantiate <GameObject>(monsterDataInfo.MonsterPrefab); MonsterControl monsterControl = createObj.AddComponent <MonsterControl>(); monsterControl.SameGroupObjList = tempData.Value; monsterControl.monsterDataInfo = tempData.Key; tempData.Value.Add(createObj); //设置位置(MonsterControl内部会进行y轴的设置) createObj.transform.position = new Vector3( monsterDataInfo.Center.x, monsterDataInfo.Center.y, monsterDataInfo.Center.z); objListChanged = true; } break; } } //刷新时间 foreach (KeyValuePair <MonsterDataInfo, List <GameObject> > tempData in allMonsterObjDic) { switch (tempData.Key.AIType) { case EnumMonsterAIType.Trigger: if (tempData.Value.Count == 0 && tempData.Key.AIData != null) { tempData.Key.AIData.NowUpdateTime -= UpdateTime; } break; case EnumMonsterAIType.GoOnPatrol: MonsterAIData_GoOnPatrol monsterAIData_GoOnPatrol = tempData.Key.AIData as MonsterAIData_GoOnPatrol; if (monsterAIData_GoOnPatrol != null && tempData.Value.Count < monsterAIData_GoOnPatrol.Count) { monsterAIData_GoOnPatrol.NowUpdateTime -= UpdateTime; } break; case EnumMonsterAIType.Boss: if (tempData.Value.Count == 0 && tempData.Key.AIData != null) { tempData.Key.AIData.NowUpdateTime -= UpdateTime; } break; } } //重新构建检测集合 if (objListChanged) { thisSceneCanCheckMonsterObjList.Clear(); foreach (KeyValuePair <MonsterDataInfo, List <GameObject> > tempData in thisSceneCanCheckMonsterObjDic) { thisSceneCanCheckMonsterObjList.AddRange(tempData.Value); } } //移除检测集合的空元素 thisSceneCanCheckMonsterObjList.RemoveAll(temp => temp == null); }
/// <summary> /// 设置正在执行的任务的检测分类 /// </summary> /// <param name="runTimeTaskInfo">正在执行的任务</param> void SetStartTaskCheckClassify(TaskMap.RunTimeTaskInfo runTimeTaskInfo) { if (runTimeTaskInfo == null || runTimeTaskInfo.IsOver) { return; } //NPC检测(是否存在交任务的npc) if (runTimeTaskInfo.TaskInfoStruct.DeliveryTaskNpcId > 0) { checkNPCRunTimeDic.Add(runTimeTaskInfo.ID, runTimeTaskInfo); } //位置检测(与NPC检测互斥,如果存在交任务的npc则不检测位置(但是使用其中的场景)) else if (runTimeTaskInfo.TaskInfoStruct.DeliveryTaskLocation != null) { checkPostionRunTimeDic.Add(runTimeTaskInfo.ID, runTimeTaskInfo); } //击杀怪物检测 if (runTimeTaskInfo.TaskInfoStruct.NeedKillMonsterCount != null && runTimeTaskInfo.TaskInfoStruct.NeedKillMonsterCount.Count(temp => temp.Value > 0) > 0) { if (runTimeTaskInfo.TaskInfoStruct.GameKillMonsterCount == null) { runTimeTaskInfo.TaskInfoStruct.GameKillMonsterCount = new Dictionary <EnumMonsterType, int>(); } bool mustAdd = false; foreach (KeyValuePair <EnumMonsterType, int> item in runTimeTaskInfo.TaskInfoStruct.NeedKillMonsterCount) { if (!runTimeTaskInfo.TaskInfoStruct.GameKillMonsterCount.ContainsKey(item.Key)) { runTimeTaskInfo.TaskInfoStruct.GameKillMonsterCount.Add(item.Key, 0); } if (runTimeTaskInfo.TaskInfoStruct.GameKillMonsterCount[item.Key] < item.Value) { mustAdd = true; } } if (mustAdd) { checkMonsterRunTimeDic.Add(runTimeTaskInfo.ID, runTimeTaskInfo); } } //获取物品检测 if (runTimeTaskInfo.TaskInfoStruct.NeedGetGoodsCount != null && runTimeTaskInfo.TaskInfoStruct.NeedGetGoodsCount.Count(temp => temp.Value > 0) > 0) { if (runTimeTaskInfo.TaskInfoStruct.GameGetGoodsCount == null) { runTimeTaskInfo.TaskInfoStruct.GameGetGoodsCount = new Dictionary <EnumGoodsType, int>(); } bool mustAdd = false; foreach (KeyValuePair <EnumGoodsType, int> item in runTimeTaskInfo.TaskInfoStruct.NeedGetGoodsCount) { if (!runTimeTaskInfo.TaskInfoStruct.GameGetGoodsCount.ContainsKey(item.Key)) { runTimeTaskInfo.TaskInfoStruct.GameGetGoodsCount.Add(item.Key, 0); } if (runTimeTaskInfo.TaskInfoStruct.GameGetGoodsCount[item.Key] < item.Value) { mustAdd = true; } } if (mustAdd) { checkGoodsRunTimeDic.Add(runTimeTaskInfo.ID, runTimeTaskInfo); } ; } //特殊状态检测 if (runTimeTaskInfo.TaskInfoStruct.NeedSpecialCheck != TaskMap.Enums.EnumTaskSpecialCheck.None) { checkSpecialRunTimeDic.Add(runTimeTaskInfo.ID, runTimeTaskInfo); } }
/// <summary> /// 展示对话 /// </summary> private void ShowTalk() { DialogueValue dialogueValue = dialogueStructData.SearchDialogueValueByID(nowDialoguePoint.dialogueID); titleText.text = dialogueValue.showValue; int childCount = selectItemBackTrans.childCount; Transform[] childTransfroms = new Transform[childCount]; for (int i = 0; i < childCount; i++) { childTransfroms[i] = selectItemBackTrans.GetChild(i); } for (int i = 0; i < childCount; i++) { if (!Transform.Equals(childTransfroms[i], exampleItemObj.transform))//如果不是例子对象则销毁 { GameObject.DestroyImmediate(childTransfroms[i].gameObject); } } showItemList.Clear(); //添加 Action <string, Action <Transform> > AddItemAction = (showValue, ClickCallback) => { GameObject createItemObj = GameObject.Instantiate <GameObject>(exampleItemObj); createItemObj.transform.SetParent(selectItemBackTrans); createItemObj.SetActive(true); Transform itemTextTrans = createItemObj.transform.GetChild(0); Text itemText = itemTextTrans.GetComponent <Text>(); itemText.text = showValue; showItemList.Add(createItemObj.transform); //添加事件 EventTrigger eventTrigger = createItemObj.AddComponent <EventTrigger>(); eventTrigger.triggers = new List <EventTrigger.Entry>(); //点击事件 EventTrigger.Entry entry_Click = new EventTrigger.Entry(); entry_Click.eventID = EventTriggerType.PointerClick; entry_Click.callback = new EventTrigger.TriggerEvent(); entry_Click.callback.AddListener(temp => ClickCallback(createItemObj.transform)); eventTrigger.triggers.Add(entry_Click); //鼠标进入事件 EventTrigger.Entry entry_Enter = new EventTrigger.Entry(); entry_Enter.eventID = EventTriggerType.PointerEnter; entry_Enter.callback = new EventTrigger.TriggerEvent(); entry_Enter.callback.AddListener(temp => { createItemObj.GetComponent <Image>().color = new Color(1, 1, 1, 0.4f); selectItemIndex = showItemList.IndexOf(createItemObj.transform); }); eventTrigger.triggers.Add(entry_Enter); //鼠标离开事件 EventTrigger.Entry entry_Leave = new EventTrigger.Entry(); entry_Leave.eventID = EventTriggerType.PointerExit; entry_Leave.callback = new EventTrigger.TriggerEvent(); entry_Leave.callback.AddListener(temp => createItemObj.GetComponent <Image>().color = new Color(1, 1, 1, 0)); eventTrigger.triggers.Add(entry_Leave); }; DialoguePoint[] childPoints = nowDialoguePoint.childDialoguePoints; foreach (DialoguePoint dialoguePoint in childPoints) //便利添加子选项 { if (dontShowDialoguePointList.Contains(dialoguePoint)) //不显示的不添加 { continue; } DialogueValue childDialogueValue = dialogueStructData.SearchDialogueValueByID(dialoguePoint.dialogueID); AddItemAction(childDialogueValue.titleValue, temp => { int index = showItemList.IndexOf(temp); DialoguePoint[] nowShowChildsPoints = nowDialoguePoint.childDialoguePoints.Where(point => !dontShowDialoguePointList.Contains(point)).ToArray(); if (index < 0 || index >= nowShowChildsPoints.Length) { return; } DialoguePoint clickPoint = nowShowChildsPoints[index]; if (clickPoint.childDialoguePoints == null || clickPoint.childDialoguePoints.Length == 0) //如果有任务则接取,如果没有则不做处理 { DialogueValue clickValue = dialogueStructData.SearchDialogueValueByID(clickPoint.dialogueID); if (!string.IsNullOrEmpty(clickValue.otherValue)) { int taskID = -1; if (int.TryParse(clickValue.otherValue, out taskID)) { TaskMap.RunTimeTaskInfo runTimeTaskInfo = runtimeTasksData.GetTasksWithID(taskID); if (runTimeTaskInfo != null && runTimeTaskInfo.IsOver == false && runTimeTaskInfo.IsStart == false) { iNowTaskState.StartTask = runTimeTaskInfo.ID; gameObject.SetActive(false); } } } } else //继续进入下面节点 { nowDialoguePoint = clickPoint; ShowTalk(); } }); } //最后添加一个返回选项 AddItemAction("返回", temp => { if (nowDialoguePoint.parentDialoguePoint != null) { nowDialoguePoint = nowDialoguePoint.parentDialoguePoint; ShowTalk(); } else { gameObject.SetActive(false); } }); StartCoroutine(UpdateContentSizeFitter(panelContentSizeFitter)); //选择第一个下标 selectItemIndex = 0; SetSelectItemIndex(); }
/// <summary> /// 检测任务(关于物品) /// 物品在外部进行填入(这里只处理检测和移除,物品的生成不做处理) /// </summary> /// <param name="goodsID">变动了的物品的类型id(EnumGoodsType枚举),内部会判断物品类型,不论是丢弃或者增加</param> bool CheckNowTaskGoods(int goodsID) { if (checkGoodsRunTimeDic == null) { return(false); } if (checkGoodsDicTempList == null) { checkGoodsDicTempList = new List <TaskMap.RunTimeTaskInfo>(); } if (checkGoodsRunTimeDic.Count > 0) { checkGoodsDicTempList.Clear(); foreach (KeyValuePair <int, TaskMap.RunTimeTaskInfo> checkGoodsRunTime in checkGoodsRunTimeDic) { TaskMap.RunTimeTaskInfo runTimeTaskInfo = checkGoodsRunTime.Value; if (!runTimeTaskInfo.TaskInfoStruct.NeedGetGoodsCount.ContainsKey((EnumGoodsType)goodsID))//如果该任务不需要判断该物品 { continue; } PlayGoods playerGoods = playerState.PlayerAllGoods.Where(temp => (int)temp.GoodsInfo.EnumGoodsType == goodsID).FirstOrDefault(); if (playerGoods == null) { continue; } runTimeTaskInfo.TaskInfoStruct.GameGetGoodsCount[(EnumGoodsType)goodsID] = playerGoods.Count; bool isOver = true; foreach (KeyValuePair <EnumGoodsType, int> item in runTimeTaskInfo.TaskInfoStruct.NeedGetGoodsCount) { if (runTimeTaskInfo.TaskInfoStruct.GameGetGoodsCount[item.Key] < item.Value) { isOver = false; break; } } if (isOver) { checkGoodsDicTempList.Add(checkGoodsRunTime.Value); } } if (checkGoodsDicTempList.Count > 0) { foreach (TaskMap.RunTimeTaskInfo runTimeTaskInfo in checkGoodsDicTempList) { //如果检测出已完成则移除 checkGoodsRunTimeDic.Remove(runTimeTaskInfo.ID); if (!HasCheckTaskID(runTimeTaskInfo.ID))//如果不存在检测项了则直接完成任务 { OverTaskID = runTimeTaskInfo.ID; //完成以后从物品栏中移除指定的物品 foreach (KeyValuePair <EnumGoodsType, int> item in runTimeTaskInfo.TaskInfoStruct.GameGetGoodsCount) { playerState.PlayerAllGoods .Where(temp => temp.GoodsInfo.EnumGoodsType == item.Key).ToList() .ForEach(temp => temp.Count -= item.Value); playerState.PlayerAllGoods.RemoveAll(temp => temp.Count <= 0); } GoodsChanged = true; return(true); } } } } return(false); }