EventSystemManager.cs 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Common.Utility.CombatEvent;
  5. using Core.Language;
  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 EventConfig = Excel2Json.EventConfig;
  17. using Random = UnityEngine.Random;
  18. public class EventSystemManager : Singleton<EventSystemManager>
  19. {
  20. List<EventConfig> eventConfigs = new List<EventConfig>();
  21. public AccountFileInfo.EventList CurrentEventList;
  22. public bool isTriggerEvent;
  23. List<DivineSenseConfig> divineSenseConfigs = new List<DivineSenseConfig>();
  24. List<int> qualitys = new List<int>() { 1, 2, 3, 4, 5, 6 };
  25. public bool isOpenUi;
  26. Action onCompleteCallback;
  27. public Map<int, List<EventConfig>> eventConfigsMap = new Map<int, List<EventConfig>>();
  28. // public Map<int, AccountFileInfo.EventConditionData> EventConditionDataMap = new Map<int, AccountFileInfo.EventConditionData>();
  29. public void CustomInit()
  30. {
  31. eventConfigs = ConfigComponent.Instance.GetAll<EventConfig>().ToList();
  32. divineSenseConfigs = ConfigComponent.Instance.GetAll<DivineSenseConfig>().ToList();
  33. foreach (var eventConfig in eventConfigs)
  34. {
  35. if (eventConfig.XiantuID != 0)
  36. {
  37. if (eventConfigsMap.ContainsKey(eventConfig.XiantuID))
  38. {
  39. eventConfigsMap[eventConfig.XiantuID].Add(eventConfig);
  40. }
  41. else
  42. {
  43. eventConfigsMap.Add(eventConfig.XiantuID, new List<EventConfig>() { eventConfig });
  44. }
  45. }
  46. }
  47. StaticUpdater.Instance.AddRenderUpdateCallBack(Update);
  48. EventManager.Instance.AddEventListener(CustomEventType.DetectRandomEvent, RenfenceRandomEvent);
  49. EventManager.Instance.AddEventListener(CustomEventType.AddItem, ItemUpdate);
  50. EventManager.Instance.AddEventListener(CustomEventType.JingJieUpgrade, JingJieUpgrade);
  51. EventManager.Instance.AddEventListener(CustomEventType.CancelEvent, Cancel);
  52. }
  53. private void Cancel(IEventData e)
  54. {
  55. CancelEvent();
  56. }
  57. private void JingJieUpgrade(IEventData e)
  58. {
  59. CeekEventCompletes(3, null);
  60. }
  61. private void ItemUpdate(IEventData e)
  62. {
  63. ItemUpdateData data = e as ItemUpdateData;
  64. CeekEventCompletes(1, new[] { data.ItemInfo.itemID });
  65. CeekEventCompletes(6, new[] { data.ItemInfo.itemID, data.Count });
  66. }
  67. private void RenfenceRandomEvent(IEventData e)
  68. {
  69. DetectRandomEvents();
  70. }
  71. private float timer = 0;
  72. private void Update()
  73. {
  74. timer += Time.deltaTime;
  75. if (timer > 1)
  76. {
  77. timer = 0;
  78. HeroPowerUpConfig heroPowerUpConfig = PlayerManager.Instance.myHero.powerUpConfig;
  79. if (AccountFileInfo.Instance.playerData.divineSensePoint < heroPowerUpConfig.ShenshiMax)
  80. {
  81. if (AccountFileInfo.Instance.playerData.todayDivineSensePoint < PlayerManager.Instance.gameConstantConfig.shenshiPointRecSPD[0])
  82. {
  83. AccountFileInfo.Instance.playerData.todayDivineSensePoint += PlayerManager.Instance.gameConstantConfig.shenshiPointRecSPD[1];
  84. AccountFileInfo.Instance.playerData.divineSensePoint += PlayerManager.Instance.gameConstantConfig.shenshiPointRecSPD[1];
  85. }
  86. else
  87. {
  88. AccountFileInfo.Instance.playerData.divineSensePoint += PlayerManager.Instance.gameConstantConfig.shenshiPointRecSPD[2];
  89. }
  90. EventManager.Instance.Dispatch(CustomEventType.DivineSensePointChange, null);
  91. AccountFileInfo.Instance.SavePlayerData();
  92. }
  93. }
  94. }
  95. public List<AccountFileInfo.EventList> UseDivinesense(int useCount, List<ItemInfo> useItems)
  96. {
  97. //使用神识先移除完成的事件
  98. List<AccountFileInfo.EventList> removeEvents = new List<AccountFileInfo.EventList>();
  99. foreach (var eventList in AccountFileInfo.Instance.playerData.eventList)
  100. {
  101. if (eventList.isCompleted)
  102. {
  103. removeEvents.Add(eventList);
  104. }
  105. }
  106. foreach (var removeEvent in removeEvents)
  107. {
  108. AccountFileInfo.Instance.playerData.completeEvents.Add(removeEvent);
  109. AccountFileInfo.Instance.playerData.eventList.Remove(removeEvent);
  110. }
  111. AccountFileInfo.Instance.SavePlayerData();
  112. HeroPowerUpConfig heroPowerUpConfig = PlayerManager.Instance.myHero.powerUpConfig;
  113. int count = (int)(AccountFileInfo.Instance.playerData.divineSensePoint / PlayerManager.Instance.gameConstantConfig.DetectEventCount);
  114. if (count <= 0)
  115. {
  116. //神识值不够
  117. return null;
  118. }
  119. int maxCount = heroPowerUpConfig.ShenshiMax / PlayerManager.Instance.gameConstantConfig.DetectEventCount;
  120. count = count + GetShenShiCount() > maxCount ? maxCount - GetShenShiCount() : count;
  121. if (useCount > count)
  122. {
  123. LogTool.Error("神识值不够");
  124. return null;
  125. }
  126. CeekEventCompletes(8, new[] { 1 });
  127. EventManager.Instance.Dispatch(CustomEventType.DivineSensePointChange, null);
  128. var eventConfigs = DetectEvents(useCount, useItems);
  129. if (eventConfigs == null || eventConfigs.Count == 0)
  130. {
  131. TipMessagePanel.OpenTipMessagePanel("没有可以触发的事件");
  132. return default;
  133. }
  134. //扣除神识值 增加神识经验
  135. int xiaoHao = eventConfigs.Count * PlayerManager.Instance.gameConstantConfig.DetectEventCount;
  136. AccountFileInfo.Instance.playerData.divineSenseexp += xiaoHao;
  137. AccountFileInfo.Instance.playerData.divineSensePoint -= xiaoHao;
  138. // 神识升级逻辑
  139. UpDivinesense();
  140. AccountFileInfo.Instance.playerData.eventList.AddRange(eventConfigs);
  141. UpdateZuizhongEventData();
  142. AccountFileInfo.Instance.SavePlayerData();
  143. return eventConfigs;
  144. }
  145. public void UpdateZuizhongEventData()
  146. {
  147. AccountFileInfo.EventList eventList = AccountFileInfo.Instance.playerData.eventList.FirstOrDefault(e => e.guid == AccountFileInfo.Instance.playerData.CurrentZuiZhongEventListId);
  148. if (eventList == null || eventList.guid == 0)
  149. {
  150. var mainEventData = GetMainEventDta();
  151. if (mainEventData != null)
  152. {
  153. AccountFileInfo.Instance.playerData.CurrentZuiZhongEventListId = mainEventData.guid;
  154. }
  155. else if (AccountFileInfo.Instance.playerData.eventList.Count > 0)
  156. {
  157. AccountFileInfo.Instance.playerData.CurrentZuiZhongEventListId = AccountFileInfo.Instance.playerData.eventList[0].guid;
  158. }
  159. }
  160. }
  161. private void UpDivinesense()
  162. {
  163. if (AccountFileInfo.Instance.playerData.divineSenseLevel >= divineSenseConfigs.Count)
  164. {
  165. return;
  166. }
  167. for (var i = AccountFileInfo.Instance.playerData.divineSenseLevel - 1; i < divineSenseConfigs.Count; i++)
  168. {
  169. if (AccountFileInfo.Instance.playerData.divineSenseexp >= divineSenseConfigs[i].exp)
  170. {
  171. AccountFileInfo.Instance.playerData.divineSenseexp -= divineSenseConfigs[i].exp;
  172. AccountFileInfo.Instance.playerData.divineSenseLevel = divineSenseConfigs[i + 1].ID;
  173. }
  174. }
  175. AccountFileInfo.Instance.SavePlayerData();
  176. }
  177. public int GetShenShiCount()
  178. {
  179. int count = 0;
  180. foreach (var eventList in AccountFileInfo.Instance.playerData.eventList)
  181. {
  182. EventConfig eventConfig = ConfigComponent.Instance.Get<EventConfig>(eventList.eventID);
  183. if (eventList == null || eventList.eventID == 0 || eventList.isCompleted || eventConfig.EventTriggerType == 4)
  184. continue;
  185. if (eventConfig.EventTriggerType != 5)
  186. {
  187. count++;
  188. }
  189. }
  190. return count;
  191. }
  192. public bool BagIsEvent(int eventID)
  193. {
  194. foreach (var eventList in AccountFileInfo.Instance.playerData.eventList)
  195. {
  196. if (eventList.eventID == eventID)
  197. {
  198. return true;
  199. }
  200. }
  201. return false;
  202. }
  203. public int GetBagEventCount(int eventID)
  204. {
  205. int count = 0;
  206. foreach (var eventList in AccountFileInfo.Instance.playerData.eventList)
  207. {
  208. if (eventList.eventID == eventID)
  209. {
  210. count++;
  211. }
  212. }
  213. return count;
  214. }
  215. // public bool IsRefenceEvent(int eventID)
  216. // {
  217. // EventConfig eventConfig = ConfigComponent.Instance.Get<EventConfig>(eventID);
  218. // }
  219. public bool IsEventTrigger(int eventID)
  220. {
  221. foreach (var eventList in AccountFileInfo.Instance.playerData.completeEvents)
  222. {
  223. if (eventList.eventID == eventID)
  224. {
  225. return true;
  226. }
  227. }
  228. return false;
  229. }
  230. private List<AccountFileInfo.EventList> DetectEvents(int eventCount, List<ItemInfo> useItems)
  231. {
  232. SmallPlacesConfig smallPlacesConfig = ConfigComponent.Instance.Get<SmallPlacesConfig>(PlayerManager.Instance.CurrentsmallPlaces.id);
  233. PlacesConfig bigMap = ConfigComponent.Instance.Get<PlacesConfig>(smallPlacesConfig.PlacesId);
  234. DivineSenseConfig divineSenseConfig = ConfigComponent.Instance.Get<DivineSenseConfig>(AccountFileInfo.Instance.playerData.divineSenseLevel);
  235. LogTool.Log($"使用神识,神识等级:{AccountFileInfo.Instance.playerData.divineSenseLevel}");
  236. List<AccountFileInfo.EventList> eventLists = new List<AccountFileInfo.EventList>();
  237. //找出可以刷新的支线任务
  238. if (bigMap.ZhixianActivatedPercentage != null)
  239. {
  240. List<EventConfig> zhiXianEvents = new List<EventConfig>();
  241. for (var i = 0; i < bigMap.ZhixianActivatedPercentage.Length; i++)
  242. {
  243. if (PlayerManager.Instance.PlacesBl >= bigMap.ZhixianActivatedPercentage[i])
  244. {
  245. if (!BagIsEvent(bigMap.ZhixianID[i]) && !IsEventTrigger(bigMap.ZhixianID[i]) && CanTriggerEvent(bigMap.ZhixianID[i]))
  246. {
  247. zhiXianEvents.Add(ConfigComponent.Instance.Get<EventConfig>(bigMap.ZhixianID[i]));
  248. }
  249. }
  250. }
  251. foreach (var c in zhiXianEvents)
  252. {
  253. AccountFileInfo.EventList eventList = AddEvent(c.ID);
  254. if (eventList != null)
  255. {
  256. eventLists.Add(eventList);
  257. eventCount--;
  258. if (eventCount == 0)
  259. {
  260. return eventLists;
  261. }
  262. }
  263. }
  264. }
  265. for (int i = 0; i < eventCount; i++)
  266. {
  267. int randomValue3 = Random.Range(0, 101);
  268. //先刷事件关联的事件
  269. if (randomValue3 <= PlayerManager.Instance.gameConstantConfig.RefreshRelevanceEventProbability)
  270. {
  271. bool isRefence = false;
  272. foreach (var eventList in AccountFileInfo.Instance.playerData.eventList)
  273. {
  274. foreach (var eventListEventLink in eventList.eventLinks)
  275. {
  276. foreach (var eventConditionData in eventListEventLink.eventConditions)
  277. {
  278. if (IsEvenkLinkComplete(eventConditionData))
  279. continue;
  280. EventConditionConfig eventConditionConfig = ConfigComponent.Instance.Get<EventConditionConfig>(eventConditionData.eventCondition);
  281. for (var i1 = 0; i1 < eventConditionConfig.RelatedEvents?.Length; i1++)
  282. {
  283. EventConfig eventConfig1 = ConfigComponent.Instance.Get<EventConfig>(eventConditionConfig.RelatedEvents[i1]);
  284. int count = 0;
  285. foreach (var list in eventLists)
  286. {
  287. if (list.eventID == eventConfig1.ID)
  288. {
  289. count++;
  290. }
  291. }
  292. if (GetBagEventCount(eventConfig1.ID) + count >= eventConfig1.RefreshCount)
  293. {
  294. continue;
  295. }
  296. int randomValue4 = Random.Range(0, 101);
  297. if (randomValue4 <= eventConfig1.RefreshProbability)
  298. {
  299. var eventList1 = AddEvent(eventConfig1.ID);
  300. if (eventList1 != null)
  301. {
  302. eventLists.Add(AddEvent(eventConfig1.ID));
  303. isRefence = true;
  304. }
  305. else
  306. {
  307. LogTool.Error("管理事件没有刷新出来 id:" + eventConfig1.ID);
  308. }
  309. break;
  310. }
  311. }
  312. }
  313. }
  314. }
  315. if (isRefence)
  316. continue;
  317. }
  318. //概率
  319. ItemInfo itemInfoType1 = null;
  320. //类型
  321. ItemInfo itemInfoType2 = null;
  322. foreach (var itemInfo in useItems)
  323. {
  324. if (itemInfo.config.associateID == 6)
  325. {
  326. itemInfoType1 = itemInfo;
  327. }
  328. else if (itemInfo.config.associateID == 7)
  329. {
  330. itemInfoType2 = itemInfo;
  331. }
  332. }
  333. float[] QualityBonusChance = divineSenseConfig.QualityBonusChance.ToArray();
  334. if (itemInfoType1 != null)
  335. {
  336. QualityBonusChance[itemInfoType1.config.associateVlaue[0] - 1] *= itemInfoType1.config.associateVlaue[1];
  337. }
  338. //先掉落出品质
  339. int quality = UtilTools.GetRandomByWeight(qualitys, QualityBonusChance);
  340. // // 获取通用事件
  341. // List<EventConfig> globalEvents = eventConfigs.Where(e => e.EventTriggerType == 1 && CanTriggerEvent(e.ID) && e.EventQuality == quality && !BagIsEvent(e.ID) && eventLists.FirstOrDefault(el => el.eventID == e.ID) == null).ToList();
  342. //
  343. //
  344. // //场景特定事件
  345. // List<EventConfig> candidateEvents = eventConfigs.Where(e => bigMap.SpecialTaskID.Contains(e.ID) && CanTriggerEvent(e.ID) && e.EventQuality == quality && !BagIsEvent(e.ID) && eventLists.FirstOrDefault(el => el.eventID == e.ID) == null).ToList();
  346. // 获取通用事件
  347. List<EventConfig> globalEvents = eventConfigs.Where(e => e.EventTriggerType == 1 && e.EventQuality == quality && eventLists.FirstOrDefault(el => el.eventID == e.ID) == null && CanTriggerEvent(e.ID) && CanEventType(e.ID, itemInfoType2)).ToList();
  348. //场景特定事件
  349. List<EventConfig> candidateEvents = eventConfigs.Where(e => bigMap.SpecialTaskID.Contains(e.ID) && e.EventQuality == quality && eventLists.FirstOrDefault(el => el.eventID == e.ID) == null && CanTriggerEvent(e.ID) && CanEventType(e.ID, itemInfoType2)).ToList();
  350. if (candidateEvents.Count == 0 && globalEvents.Count == 0)
  351. {
  352. continue;
  353. }
  354. int randomValue1 = Random.Range(0, 101);
  355. // 达到怪率刷新场景特定事件
  356. //不然刷新通用事件(每个地图都可以刷的)
  357. if (randomValue1 >= bigMap.DivineSenseGeneralProbability && candidateEvents.Count > 0)
  358. {
  359. int randomValue2 = Random.Range(0, candidateEvents.Count);
  360. var eventList = AddEvent(candidateEvents[randomValue2].ID);
  361. if (eventList != null)
  362. {
  363. eventLists.Add(eventList);
  364. }
  365. else
  366. {
  367. LogTool.Error("场景没有刷新出来 id:" + candidateEvents[randomValue2].ID);
  368. }
  369. }
  370. else if (globalEvents.Count > 0)
  371. {
  372. int randomValue2 = Random.Range(0, globalEvents.Count);
  373. var eventList = AddEvent(globalEvents[randomValue2].ID);
  374. if (eventList != null)
  375. {
  376. eventLists.Add(eventList);
  377. }
  378. else
  379. {
  380. LogTool.Error("通用事件没有刷新出来 id:" + globalEvents[randomValue2].ID);
  381. }
  382. }
  383. }
  384. if (eventLists.Count == 0)
  385. {
  386. LogTool.Error("没有可以触发的事件");
  387. return null;
  388. }
  389. return eventLists;
  390. }
  391. //添加事件
  392. public AccountFileInfo.EventList AddEvent(int eventID)
  393. {
  394. EventConfig eventConfig = ConfigComponent.Instance.Get<EventConfig>(eventID);
  395. AccountFileInfo.EventList eventList = null;
  396. if (eventConfig.ID == 0)
  397. {
  398. return null;
  399. }
  400. //主线任务只能刷一次
  401. if (eventConfig.EventTriggerType == 4 || eventConfig.EventTriggerType == 6)
  402. {
  403. AccountFileInfo.EventList e = AccountFileInfo.Instance.playerData.eventList.FirstOrDefault(e => e.eventID == eventID);
  404. if (e == null)
  405. {
  406. e = AccountFileInfo.Instance.playerData.completeEvents.FirstOrDefault(e => e.eventID == eventID);
  407. if (e == null)
  408. {
  409. eventList = new AccountFileInfo.EventList();
  410. eventList.eventID = eventID;
  411. }
  412. else
  413. {
  414. return null;
  415. }
  416. eventList.guid = IdGenerater.GenerateIdInt();
  417. eventList.curStep = eventConfig.EventLinksId[0];
  418. eventList.selectEventLinkIds.Add(eventConfig.EventLinksId[0]);
  419. //记录英雄等级 神识刷出来的战斗等级不变
  420. if( PlayerManager.Instance.myHero != null)
  421. eventList.heroLevel = PlayerManager.Instance.myHero.level.Value;
  422. }
  423. }
  424. else
  425. {
  426. eventList = new AccountFileInfo.EventList();
  427. eventList.eventID = eventID;
  428. eventList.guid = IdGenerater.GenerateIdInt();
  429. eventList.curStep = eventConfig.EventLinksId[0];
  430. eventList.selectEventLinkIds.Add(eventConfig.EventLinksId[0]);
  431. //记录英雄等级 神识刷出来的战斗等级不变
  432. if( PlayerManager.Instance.myHero != null)
  433. eventList.heroLevel = PlayerManager.Instance.myHero.level.Value;
  434. }
  435. //初始化神识链条,用于监听条件是否完成
  436. if (eventList != null && eventConfig.EventType != 2)
  437. {
  438. foreach (var i in eventConfig.EventLinksId)
  439. {
  440. EventLinkConfig eventLinkConfig = ConfigComponent.Instance.Get<EventLinkConfig>(i);
  441. AccountFileInfo.EventLinkData eventLinkData = new AccountFileInfo.EventLinkData();
  442. eventLinkData.eventId = eventID;
  443. eventLinkData.eventLinkId = i;
  444. if (eventLinkConfig.ConditionId != null)
  445. {
  446. foreach (var i1 in eventLinkConfig.ConditionId)
  447. {
  448. AccountFileInfo.EventConditionData eventConditionData = new AccountFileInfo.EventConditionData();
  449. eventConditionData.eventId = eventList.eventID;
  450. eventConditionData.eventCondition = i1;
  451. eventLinkData.eventConditions.Add(eventConditionData);
  452. //初始化先检测一些条件
  453. CeekTaskComplete(eventConditionData, 1, null);
  454. CeekTaskComplete(eventConditionData, 3, null);
  455. }
  456. }
  457. eventList.eventLinks.Add(eventLinkData);
  458. }
  459. }
  460. return eventList;
  461. }
  462. /// <summary>
  463. /// 触发随机事件
  464. /// </summary>
  465. public void DetectRandomEvents()
  466. {
  467. if (isTriggerEvent)
  468. return;
  469. if (isOpenUi)
  470. return;
  471. // 获取随机事件
  472. List<EventConfig> randomEvents = eventConfigs.Where(e => e.EventTriggerType == 2 && CanTriggerEvent(e.ID)).ToList();
  473. if (randomEvents.Count == 0)
  474. {
  475. LogTool.Warning("没有可以刷新的事件");
  476. return;
  477. }
  478. int idex = Random.Range(0, randomEvents.Count);
  479. TriggerEvent(randomEvents[idex]);
  480. }
  481. /// <summary>
  482. /// 挂机事件触发
  483. /// </summary>
  484. public void TriggerEvent(EventConfig evt)
  485. {
  486. if (isTriggerEvent)
  487. return;
  488. isTriggerEvent = true;
  489. LogTool.Log($"触发事件: {evt.EventName} (ID: {evt.ID}, 品质: {evt.EventQuality})");
  490. CombatDrive.Instance.CombatController.ChangeState(CombatController.idle);
  491. AccountFileInfo.EventList eventList = AddEvent(evt.ID);
  492. CurrentEventList = eventList;
  493. DialogueManager.Instance.StartDialogue(eventList, evt.EventLinksId[0], evt.ID, () => { CompleteEvent(evt.ID); });
  494. }
  495. /// <summary>
  496. /// 其他类型事件触发
  497. /// </summary>
  498. public async CTask TriggerEvent(AccountFileInfo.EventList evt, Action oncompleteCallBack = null)
  499. {
  500. // ChancleEvent();
  501. if (isTriggerEvent)
  502. return;
  503. EventConfig eventConfig = ConfigComponent.Instance.Get<EventConfig>(evt.eventID);
  504. SmallPlacesConfig smallPlacesConfig = ConfigComponent.Instance.Get<SmallPlacesConfig>(PlayerManager.Instance.CurrentsmallPlaces.id);
  505. if (eventConfig.SmallPlacesId > 0)
  506. {
  507. if (eventConfig.SmallPlacesId != PlayerManager.Instance.CurrentsmallPlaces.id)
  508. {
  509. AccountFileInfo.SmallPlacesData lastSmallPlacesData = PlayerManager.Instance.GetSmallPlacesData(eventConfig.SmallPlacesId - 1);
  510. SmallPlacesConfig lastSmallPlacesConfig = ConfigComponent.Instance.Get<SmallPlacesConfig>(eventConfig.SmallPlacesId - 1);
  511. SmallPlacesConfig currentSmallPlacesConfig = ConfigComponent.Instance.Get<SmallPlacesConfig>(eventConfig.SmallPlacesId);
  512. if (currentSmallPlacesConfig.ID > 1 && (lastSmallPlacesData == null || lastSmallPlacesData.completionEventCount < lastSmallPlacesConfig.CompletionEventCount))
  513. {
  514. TipMessagePanel.OpenTipMessagePanel("上一个关卡事件完成度不足,无法切换地图");
  515. return;
  516. }
  517. if (lastSmallPlacesConfig.UnlockEnvetid != 0)
  518. {
  519. AccountFileInfo.EventList eventList = AccountFileInfo.Instance.playerData.completeEvents.FirstOrDefault(ce => ce.eventID == lastSmallPlacesConfig.UnlockEnvetid);
  520. if (eventList == null || !eventList.isCompleted)
  521. {
  522. TipMessagePanel.OpenTipMessagePanel("上一个关卡事件完成度不足,无法切换地图");
  523. return;
  524. }
  525. }
  526. UIManager.Instance.HindCurrAllShowPanel();
  527. CombatDrive.Instance.CombatController.ChangeState(CombatController.update);
  528. CombatController.currActiveCombat.CombatHeroController.Flight(2, -90, 10);
  529. UIManager.Instance.SetEventSystemEnable(false);
  530. await TimerComponent.Instance.WaitAsync(2 * 1000 + 1200);
  531. CombatDrive.Instance.CombatController.ChangeState(CombatController.idle);
  532. UIManager.Instance.SetEventSystemEnable(true);
  533. UIManager.Instance.ShowLastHindAllShowPanel();
  534. PlayerManager.Instance.ChangeMap(eventConfig.SmallPlacesId);
  535. // TipMessagePanel.OpenTipMessagePanel("需要到对应位置触发");
  536. // returnurn;
  537. }
  538. }
  539. else if (eventConfig.placeID > 0)
  540. {
  541. if (eventConfig.placeID != smallPlacesConfig.PlacesId)
  542. {
  543. PlacesConfig placesConfig = ConfigComponent.Instance.Get<PlacesConfig>(eventConfig.placeID);
  544. AccountFileInfo.SmallPlacesData lastSmallPlacesData = PlayerManager.Instance.GetSmallPlacesData(placesConfig.SmallPlacersIds[0] - 1);
  545. SmallPlacesConfig lastSmallPlacesConfig = ConfigComponent.Instance.Get<SmallPlacesConfig>(placesConfig.SmallPlacersIds[0] - 1);
  546. SmallPlacesConfig currentSmallPlacesConfig = ConfigComponent.Instance.Get<SmallPlacesConfig>(placesConfig.SmallPlacersIds[0] );
  547. if (currentSmallPlacesConfig.ID > 1 && (lastSmallPlacesData == null || lastSmallPlacesData.completionEventCount < lastSmallPlacesConfig.CompletionEventCount))
  548. {
  549. TipMessagePanel.OpenTipMessagePanel("上一个关卡事件完成度不足,无法切换地图");
  550. return;
  551. }
  552. if (lastSmallPlacesConfig.UnlockEnvetid != 0)
  553. {
  554. AccountFileInfo.EventList eventList = AccountFileInfo.Instance.playerData.completeEvents.FirstOrDefault(ce => ce.eventID == lastSmallPlacesConfig.UnlockEnvetid);
  555. if (eventList == null || !eventList.isCompleted)
  556. {
  557. TipMessagePanel.OpenTipMessagePanel("上一个关卡事件完成度不足,无法切换地图");
  558. return;
  559. }
  560. }
  561. UIManager.Instance.HindCurrAllShowPanel();
  562. CombatDrive.Instance.CombatController.ChangeState(CombatController.update);
  563. CombatController.currActiveCombat.CombatHeroController.Flight(2, -90, 10);
  564. UIManager.Instance.SetEventSystemEnable(false);
  565. await TimerComponent.Instance.WaitAsync(2 * 1000 + 1200);
  566. CombatDrive.Instance.CombatController.ChangeState(CombatController.idle);
  567. UIManager.Instance.SetEventSystemEnable(true);
  568. UIManager.Instance.ShowLastHindAllShowPanel();
  569. PlayerManager.Instance.ChangeMap(placesConfig.SmallPlacersIds[0]);
  570. return;
  571. }
  572. }
  573. CTask cTask = CTask.Create();
  574. this.onCompleteCallback = oncompleteCallBack;
  575. isTriggerEvent = true;
  576. LogTool.Log($"触发事件: {LanguageManager.Instance.Text(eventConfig.EventName)} (ID: {eventConfig.ID}, 品质: {eventConfig.EventQuality})");
  577. int dialogueID = 0;
  578. if (evt.curStep == 0)
  579. {
  580. dialogueID = eventConfig.EventLinksId[0];
  581. }
  582. else
  583. {
  584. dialogueID = evt.curStep;
  585. }
  586. CurrentEventList = evt;
  587. CombatDrive.Instance.CombatController.ChangeState(CombatController.idle);
  588. DialogueManager.Instance.StartDialogue(CurrentEventList, dialogueID, eventConfig.ID, () =>
  589. {
  590. CompleteEvent(CurrentEventList);
  591. cTask.SetResult();
  592. }, () =>
  593. {
  594. CancelEvent(CurrentEventList);
  595. cTask.SetResult();
  596. });
  597. DivineSenceEventPreviewPanel divineSenceEventPreviewPanel = UIManager.Instance.GetComponent<DivineSenceEventPreviewPanel>();
  598. AppBarPanel appBarPanel = UIManager.Instance.GetComponent<AppBarPanel>();
  599. // DivineSenceInfoPanel divineSenceInfoPanel = UIManager.Instance.GetComponent<DivineSenceInfoPanel>();
  600. if (divineSenceEventPreviewPanel != null && !divineSenceEventPreviewPanel.IsClose)
  601. {
  602. divineSenceEventPreviewPanel.GObjectPoolInterface.SetActive(false);
  603. }
  604. if (appBarPanel != null && !appBarPanel.IsClose)
  605. {
  606. appBarPanel.GObjectPoolInterface.SetActive(false);
  607. }
  608. // if (divineSenceInfoPanel != null)
  609. // {
  610. // divineSenceInfoPanel.GObjectPoolInterface.SetActive(false);
  611. // }
  612. await cTask;
  613. if (divineSenceEventPreviewPanel != null && !divineSenceEventPreviewPanel.IsClose)
  614. {
  615. divineSenceEventPreviewPanel.GObjectPoolInterface.SetActive(true);
  616. }
  617. if (appBarPanel != null && !appBarPanel.IsClose)
  618. {
  619. appBarPanel.GObjectPoolInterface.SetActive(true);
  620. }
  621. // if (divineSenceInfoPanel != null)
  622. // {
  623. // divineSenceInfoPanel.GObjectPoolInterface.SetActive(true);
  624. // }
  625. }
  626. //任务是否完成
  627. public bool IsEvenkLinkComplete(AccountFileInfo.EventConditionData eventCondition)
  628. {
  629. EventConditionConfig eventConditionConfig = ConfigComponent.Instance.Get<EventConditionConfig>(eventCondition.eventCondition);
  630. if (eventCondition != null)
  631. {
  632. return eventCondition.fishCount >= eventConditionConfig.finishCount;
  633. }
  634. return false;
  635. }
  636. public bool CeekEventGroupComplete(List<AccountFileInfo.EventConditionData> eventConditions)
  637. {
  638. Map<int, List<AccountFileInfo.EventConditionData>> eventConditionDataGroup = new Map<int, List<AccountFileInfo.EventConditionData>>();
  639. foreach (var eventConditionData in eventConditions)
  640. {
  641. EventConditionConfig eventConditionConfig = ConfigComponent.Instance.Get<EventConditionConfig>(eventConditionData.eventCondition);
  642. if (!eventConditionDataGroup.ContainsKey(eventConditionConfig.Operation))
  643. {
  644. eventConditionDataGroup.Add(eventConditionConfig.Operation, new List<AccountFileInfo.EventConditionData>());
  645. }
  646. eventConditionDataGroup[eventConditionConfig.Operation].Add(eventConditionData);
  647. }
  648. bool isUlock = true;
  649. //分组检测 其中一个组绑定成功就可以执行
  650. foreach (var keyValuePair in eventConditionDataGroup)
  651. {
  652. isUlock = true;
  653. foreach (var eventConditionData in keyValuePair.Value)
  654. {
  655. if (!IsEvenkLinkComplete(eventConditionData))
  656. {
  657. isUlock = false;
  658. }
  659. }
  660. if (isUlock)
  661. {
  662. return isUlock;
  663. }
  664. }
  665. return isUlock;
  666. }
  667. public void CeekEventCompletes(int type, int[] value)
  668. {
  669. foreach (var playerDataEventLinkData in AccountFileInfo.Instance.playerData.eventList)
  670. {
  671. foreach (var eventLinkData in playerDataEventLinkData.eventLinks)
  672. {
  673. foreach (var eventConditionData in eventLinkData.eventConditions)
  674. {
  675. CeekTaskComplete(eventConditionData, type, value);
  676. }
  677. }
  678. }
  679. EventManager.Instance.Dispatch(CustomEventType.RemoveEvent, null);
  680. }
  681. public void CeekTaskComplete(AccountFileInfo.EventConditionData conditionData, int type, int[] value)
  682. {
  683. EventConditionConfig eventConditionConfig = ConfigComponent.Instance.Get<EventConditionConfig>(conditionData.eventCondition);
  684. if (IsEvenkLinkComplete(conditionData))
  685. return;
  686. switch (type)
  687. {
  688. //检测背包道具
  689. case 1:
  690. if (eventConditionConfig.ConditionType == 1)
  691. {
  692. conditionData.fishCount += (int)PlayerManager.Instance.BagController.GetItemCount(eventConditionConfig.ConditionPara[0]);
  693. if (IsEvenkLinkComplete(conditionData))
  694. {
  695. // CompleteTask(conditionData.guid);
  696. }
  697. }
  698. break;
  699. //境界检测
  700. case 3:
  701. if (eventConditionConfig.ConditionType == 3 && PlayerManager.Instance.myHero.powerUpConfig.ID >= eventConditionConfig.ConditionPara[0])
  702. {
  703. conditionData.fishCount++;
  704. if (IsEvenkLinkComplete(conditionData))
  705. {
  706. // CompleteTask(conditionData.guid);
  707. }
  708. }
  709. break;
  710. //战斗胜利
  711. case 5:
  712. if (eventConditionConfig.ConditionType == 5 && eventConditionConfig.ConditionPara[0] == value[0])
  713. {
  714. conditionData.fishCount++;
  715. if (IsEvenkLinkComplete(conditionData))
  716. {
  717. // CompleteEvent(conditionData.guid);
  718. }
  719. }
  720. break;
  721. //获得道具
  722. case 6:
  723. if (eventConditionConfig.ConditionType == 6 && eventConditionConfig.ConditionPara[0] == value[0])
  724. {
  725. conditionData.fishCount += value[1];
  726. if (IsEvenkLinkComplete(conditionData))
  727. {
  728. // CompleteEvent(conditionData.guid);
  729. }
  730. }
  731. break;
  732. //使用神识
  733. case 8:
  734. if (eventConditionConfig.ConditionType == 8)
  735. {
  736. conditionData.fishCount += value[0];
  737. if (IsEvenkLinkComplete(conditionData))
  738. {
  739. }
  740. }
  741. break;
  742. }
  743. AccountFileInfo.Instance.SavePlayerData();
  744. }
  745. private void CompleteTask(object taskID)
  746. {
  747. }
  748. //指定type事件
  749. private bool CanEventType(int eventID, ItemInfo itemInfo)
  750. {
  751. if (itemInfo == null)
  752. {
  753. return true;
  754. }
  755. var evt = eventConfigs.Find(e => e.ID == eventID);
  756. if (evt.PrizeType != null && evt.PrizeType.Contains(itemInfo.config.associateVlaue[0]))
  757. {
  758. return true;
  759. }
  760. return false;
  761. }
  762. /// <summary>
  763. /// 检查事件是否满足触发条件。
  764. /// </summary>
  765. private bool CanTriggerEvent(int eventID)
  766. {
  767. var evt = eventConfigs.Find(e => e.ID == eventID);
  768. if (evt.ID == 0)
  769. return false;
  770. switch (evt.EventConditionId)
  771. {
  772. //背包道具检测
  773. case 1:
  774. return PlayerManager.Instance.BagController.GetItemCount(evt.EventValue[0]) >= evt.EventCount;
  775. //境界判断
  776. case 2:
  777. return PlayerManager.Instance.myHero.level >= evt.EventCount;
  778. //概率判断
  779. case 3:
  780. int randomValue1 = Random.Range(0, 1001);
  781. return randomValue1 <= evt.EventCount;
  782. //完成事件判断
  783. case 10:
  784. AccountFileInfo.EventList eventList = AccountFileInfo.Instance.playerData.completeEvents.FirstOrDefault(ce => ce.eventID == evt.EventValue[0]);
  785. return eventList != null;
  786. }
  787. return true;
  788. }
  789. /// <summary>
  790. /// 完成事件
  791. /// </summary>
  792. /// <param name="eventID">事件ID</param>
  793. public void CompleteEvent(int evtId)
  794. {
  795. isTriggerEvent = false;
  796. LogTool.Log($"完成挂机事件{evtId}");
  797. EventConfig eventConfig = ConfigComponent.Instance.Get<EventConfig>(evtId);
  798. AccountFileInfo.EventList eventList = new AccountFileInfo.EventList();
  799. eventList.eventID = evtId;
  800. AccountFileInfo.Instance.playerData.completeEvents.Add(eventList);
  801. PlayerManager.Instance.CurrentsmallPlaces.completionEventCount++;
  802. SmallPlacesConfig smallPlacesConfig = ConfigComponent.Instance.Get<SmallPlacesConfig>(PlayerManager.Instance.CurrentsmallPlaces.id);
  803. AccountFileInfo.PlacesData placesData = PlayerManager.Instance.GetPlacesData(smallPlacesConfig.PlacesId);
  804. if (placesData.progress < 100)
  805. placesData.progress += eventConfig.Score;
  806. AccountFileInfo.Instance.SavePlayerData();
  807. CombatDrive.Instance.CombatController.ChangeState(CombatController.update);
  808. EventManager.Instance.Dispatch(CustomEventType.CompleteEvent, null);
  809. }
  810. /// <summary>
  811. /// 完成事件
  812. /// </summary>
  813. /// <param name="eventID">事件ID</param>
  814. public async void CompleteEvent(AccountFileInfo.EventList eventList, bool isTriggerEvent = false)
  815. {
  816. this.isTriggerEvent = isTriggerEvent;
  817. LogTool.Log($"完成事件{eventList.eventID}");
  818. EventConfig eventConfig = ConfigComponent.Instance.Get<EventConfig>(eventList.eventID);
  819. AccountFileInfo.EventList ceventList = AccountFileInfo.Instance.playerData.completeEvents.FirstOrDefault(ce => ce.eventID == eventList.eventID);
  820. PlayerManager.Instance.CurrentsmallPlaces.completionEventCount++;
  821. if (ceventList == null)
  822. {
  823. PlacesConfig[] placesConfigs = ConfigComponent.Instance.GetAll<PlacesConfig>();
  824. int pId = 0;
  825. for (var i = 0; i < placesConfigs.Length; i++)
  826. {
  827. if (placesConfigs[i].MainTaskID == null || placesConfigs[i].ZhixianID == null)
  828. continue;
  829. if (placesConfigs[i].MainTaskID.Contains(eventConfig.ID) ||
  830. placesConfigs[i].ZhixianID.Contains(eventConfig.ID))
  831. {
  832. pId = placesConfigs[i].ID;
  833. break;
  834. }
  835. }
  836. if (pId == 0)
  837. {
  838. SmallPlacesConfig smallPlacesConfig = ConfigComponent.Instance.Get<SmallPlacesConfig>(PlayerManager.Instance.CurrentsmallPlaces.id);
  839. AccountFileInfo.PlacesData placesData = PlayerManager.Instance.GetPlacesData(smallPlacesConfig.PlacesId);
  840. placesData.progress += eventConfig.Score;
  841. }
  842. else
  843. {
  844. PlayerManager.Instance.GetPlacesData(pId).progress += eventConfig.Score;
  845. }
  846. }
  847. List<ItemInfo> itemInfos = new List<ItemInfo>();
  848. if (eventConfig.PrizeIDs != null)
  849. {
  850. for (var i = 0; i < eventConfig.PrizeIDs.Length; i++)
  851. {
  852. DropConfig dropConfig = ConfigComponent.Instance.Get<DropConfig>(eventConfig.PrizeIDs[i]);
  853. if (dropConfig.dropType == 3)
  854. {
  855. ItemInfo itemInfo = new ItemInfo(dropConfig.dropGroupID[0], eventConfig.PrizeNums[i]);
  856. itemInfos.Add(itemInfo);
  857. }
  858. else
  859. {
  860. List<ItemInfo> items = DropManager.Instance.DropItem(eventConfig.PrizeIDs[i]);
  861. if (items != null)
  862. itemInfos.AddRange(items);
  863. }
  864. // itemInfos.Add(new ItemInfo(eventConfig.PrizeIDs[i], eventConfig.PrizeNums[i]));
  865. }
  866. }
  867. foreach (var eventListItemInfo in eventList.itemInfos)
  868. {
  869. itemInfos.Add(new ItemInfo(eventListItemInfo));
  870. }
  871. PlayerManager.Instance.BagController.AddItem(itemInfos);
  872. if (eventConfig.EventTriggerType == 4)
  873. {
  874. eventList.isCompleted = true;
  875. AccountFileInfo.Instance.playerData.completeEvents.Add(eventList);
  876. AccountFileInfo.Instance.playerData.eventList.Remove(eventList);
  877. TaskInfoPanel taskInfoPanel = await TaskInfoPanel.OpenPanel(eventList, 2);
  878. await taskInfoPanel.UIClosed();
  879. }
  880. else
  881. {
  882. //先不移除 下次探索神识移除
  883. eventList.isCompleted = true;
  884. }
  885. RewardsPanel rewardsPanel = await RewardsPanel.OpenPanel(itemInfos);
  886. await rewardsPanel.UIClosed();
  887. if (AccountFileInfo.Instance.playerData.CurrentZuiZhongEventListId == eventList.guid)
  888. {
  889. AccountFileInfo.Instance.playerData.CurrentZuiZhongEventListId = 0;
  890. UpdateZuizhongEventData();
  891. }
  892. AccountFileInfo.Instance.SavePlayerData();
  893. CombatDrive.Instance.CombatController.ChangeState(CombatController.update);
  894. EventManager.Instance.Dispatch(CustomEventType.CompleteEvent, null);
  895. onCompleteCallback?.Invoke();
  896. onCompleteCallback = null;
  897. }
  898. /// <summary>
  899. /// 完成事件
  900. /// </summary>
  901. /// <param name="eventID">事件ID</param>
  902. public void CompleteEvent(AccountFileInfo.EventLinkData eventLinkData)
  903. {
  904. }
  905. /// <summary>
  906. /// 取消事件
  907. /// </summary>
  908. /// <param name="eventID">事件ID</param>
  909. public void CancelEvent(AccountFileInfo.EventList eventList)
  910. {
  911. LogTool.Log($"取消事件{eventList.eventID}");
  912. isTriggerEvent = false;
  913. EventManager.Instance.Dispatch(CustomEventType.CompleteEvent, null);
  914. CombatDrive.Instance.CombatController.ChangeState(CombatController.update);
  915. onCompleteCallback?.Invoke();
  916. onCompleteCallback = null;
  917. }
  918. public void RemoveEvent(AccountFileInfo.EventList eventList)
  919. {
  920. AccountFileInfo.Instance.playerData.eventList.Remove(eventList);
  921. AccountFileInfo.Instance.SavePlayerData();
  922. EventManager.Instance.Dispatch(CustomEventType.RemoveEvent, null);
  923. }
  924. /// <summary>
  925. /// 获得主线事件
  926. /// </summary>
  927. /// <returns></returns>
  928. public AccountFileInfo.EventList GetMainEventDta()
  929. {
  930. foreach (var eventList in AccountFileInfo.Instance.playerData.eventList)
  931. {
  932. EventConfig eventConfig = ConfigComponent.Instance.Get<EventConfig>(eventList.eventID);
  933. if (eventConfig.EventTriggerType == 4)
  934. {
  935. return eventList;
  936. }
  937. }
  938. return null;
  939. }
  940. public void CancelEvent()
  941. {
  942. CombatDrive.Instance.CombatController.ChangeState(CombatController.update);
  943. DialogueManager.Instance.ChancleEvent();
  944. CurrentEventList = null;
  945. isTriggerEvent = false;
  946. }
  947. }