EventSystemManager.cs 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Common.Utility.CombatEvent;
  5. using Core.Audio;
  6. using Core.Event.Event;
  7. using Core.Language;
  8. using Excel2Json;
  9. using Fort23.Core;
  10. using Fort23.Mono;
  11. using Fort23.UTool;
  12. using GameLogic.Bag;
  13. using GameLogic.Combat;
  14. using GameLogic.Combat.CombatTool;
  15. using GameLogic.Player;
  16. using Mono.Utility;
  17. using UnityEngine;
  18. using Utility;
  19. using EventConfig = Excel2Json.EventConfig;
  20. using Random = UnityEngine.Random;
  21. public class EventSystemManager : Singleton<EventSystemManager>
  22. {
  23. List<EventConfig> eventConfigs = new List<EventConfig>();
  24. public AccountFileInfo.EventList CurrentEventList;
  25. public bool isTriggerEvent;
  26. List<DivineSenseConfig> divineSenseConfigs = new List<DivineSenseConfig>();
  27. List<int> qualitys = new List<int>() { 1, 2, 3, 4, 5, 6 };
  28. public bool isOpenUi;
  29. Action onCompleteCallback;
  30. public Map<int, List<EventConfig>> eventConfigsMap = new Map<int, List<EventConfig>>();
  31. // public Map<int, AccountFileInfo.EventConditionData> EventConditionDataMap = new Map<int, AccountFileInfo.EventConditionData>();
  32. public void CustomInit()
  33. {
  34. eventConfigs = ConfigComponent.Instance.GetAll<EventConfig>().ToList();
  35. divineSenseConfigs = ConfigComponent.Instance.GetAll<DivineSenseConfig>().ToList();
  36. if (AccountFileInfo.Instance.playerData.divineSensePoint < 0)
  37. {
  38. AccountFileInfo.Instance.playerData.divineSensePoint = 0;
  39. AccountFileInfo.Instance.playerData.todayDivineSensePoint = 0;
  40. EventManager.Instance.Dispatch(CustomEventType.DivineSensePointChange, null);
  41. }
  42. foreach (var eventConfig in eventConfigs)
  43. {
  44. if (eventConfig.XiantuID != 0)
  45. {
  46. if (eventConfigsMap.ContainsKey(eventConfig.XiantuID))
  47. {
  48. eventConfigsMap[eventConfig.XiantuID].Add(eventConfig);
  49. }
  50. else
  51. {
  52. eventConfigsMap.Add(eventConfig.XiantuID, new List<EventConfig>() { eventConfig });
  53. }
  54. }
  55. }
  56. StaticUpdater.Instance.AddRenderUpdateCallBack(Update);
  57. EventManager.Instance.AddEventListener(CustomEventType.DetectRandomEvent, RenfenceRandomEvent);
  58. EventManager.Instance.AddEventListener(CustomEventType.ItemUpdate, ItemUpdate);
  59. EventManager.Instance.AddEventListener(CustomEventType.JingJieUpgrade, JingJieUpgrade);
  60. EventManager.Instance.AddEventListener(CustomEventType.CancelEvent, Cancel);
  61. EventManager.Instance.AddEventListener(CustomEventType.AddEvent,BagAddEvent);
  62. }
  63. private void BagAddEvent(IEventData e)
  64. {
  65. DefaultEventData defaultEventData = e as DefaultEventData;
  66. AccountFileInfo.EventList eventList = AddEvent((int)defaultEventData.eventData);
  67. if (eventList != null)
  68. {
  69. AccountFileInfo.Instance.playerData.eventList.Add(eventList);
  70. AccountFileInfo.Instance.SavePlayerData();
  71. }
  72. }
  73. private void Cancel(IEventData e)
  74. {
  75. CancelEvent();
  76. }
  77. private void JingJieUpgrade(IEventData e)
  78. {
  79. CeekEventCompletes(3, null);
  80. }
  81. private void ItemUpdate(IEventData e)
  82. {
  83. ItemUpdateData data = e as ItemUpdateData;
  84. CeekEventCompletes(1, new[] { data.ItemInfo.itemID });
  85. CeekEventCompletes(6, new[] { data.ItemInfo.itemID, data.Count });
  86. }
  87. private void RenfenceRandomEvent(IEventData e)
  88. {
  89. DetectRandomEvents();
  90. }
  91. private float timer = 0;
  92. private void Update()
  93. {
  94. timer += Time.deltaTime;
  95. if (timer > 1)
  96. {
  97. timer = 0;
  98. HeroPowerUpConfig heroPowerUpConfig = PlayerManager.Instance.myHero.powerUpConfig;
  99. if (AccountFileInfo.Instance.playerData.divineSensePoint < heroPowerUpConfig.ShenshiMax)
  100. {
  101. if (AccountFileInfo.Instance.playerData.todayDivineSensePoint <
  102. PlayerManager.Instance.gameConstantConfig.shenshiPointRecSPD[0])
  103. {
  104. AccountFileInfo.Instance.playerData.todayDivineSensePoint +=
  105. PlayerManager.Instance.gameConstantConfig.shenshiPointRecSPD[1];
  106. AccountFileInfo.Instance.playerData.divineSensePoint +=
  107. PlayerManager.Instance.gameConstantConfig.shenshiPointRecSPD[1];
  108. }
  109. else
  110. {
  111. AccountFileInfo.Instance.playerData.divineSensePoint +=
  112. PlayerManager.Instance.gameConstantConfig.shenshiPointRecSPD[2];
  113. }
  114. EventManager.Instance.Dispatch(CustomEventType.DivineSensePointChange, null);
  115. AccountFileInfo.Instance.SavePlayerData();
  116. }
  117. }
  118. }
  119. public List<AccountFileInfo.EventList> UseDivinesense(int useCount, List<ItemInfo> useItems)
  120. {
  121. //使用神识先移除完成的事件
  122. List<AccountFileInfo.EventList> removeEvents = new List<AccountFileInfo.EventList>();
  123. foreach (var eventList in AccountFileInfo.Instance.playerData.eventList)
  124. {
  125. if (eventList.isCompleted)
  126. {
  127. removeEvents.Add(eventList);
  128. }
  129. }
  130. foreach (var removeEvent in removeEvents)
  131. {
  132. AccountFileInfo.Instance.playerData.completeEvents.Add(removeEvent);
  133. AccountFileInfo.Instance.playerData.eventList.Remove(removeEvent);
  134. }
  135. AccountFileInfo.Instance.SavePlayerData();
  136. HeroPowerUpConfig heroPowerUpConfig = PlayerManager.Instance.myHero.powerUpConfig;
  137. int count = (int)(AccountFileInfo.Instance.playerData.divineSensePoint /
  138. PlayerManager.Instance.gameConstantConfig.DetectEventCount);
  139. if (count <= 0)
  140. {
  141. //神识值不够
  142. return null;
  143. }
  144. int maxCount = heroPowerUpConfig.ShenshiMax / PlayerManager.Instance.gameConstantConfig.DetectEventCount;
  145. count = count + GetShenShiCount() > maxCount ? maxCount - GetShenShiCount() : count;
  146. if (useCount > count)
  147. {
  148. LogTool.Error("神识值不够");
  149. return null;
  150. }
  151. CeekEventCompletes(8, new[] { 1 });
  152. EventManager.Instance.Dispatch(CustomEventType.DivineSensePointChange, null);
  153. var eventConfigs = DetectEvents(useCount, useItems);
  154. if (eventConfigs == null || eventConfigs.Count == 0)
  155. {
  156. TipMessagePanel.OpenTipMessagePanel("没有可以触发的事件");
  157. return default;
  158. }
  159. //扣除神识值 增加神识经验
  160. int xiaoHao = eventConfigs.Count * PlayerManager.Instance.gameConstantConfig.DetectEventCount;
  161. xiaoHao = xiaoHao > AccountFileInfo.Instance.playerData.divineSensePoint
  162. ? (int)AccountFileInfo.Instance.playerData.divineSensePoint
  163. : xiaoHao;
  164. AccountFileInfo.Instance.playerData.divineSenseexp += xiaoHao;
  165. AccountFileInfo.Instance.playerData.divineSensePoint -= xiaoHao;
  166. // 神识升级逻辑
  167. UpDivinesense();
  168. AccountFileInfo.Instance.playerData.eventList.AddRange(eventConfigs);
  169. UpdateZuizhongEventData();
  170. AccountFileInfo.Instance.SavePlayerData();
  171. return eventConfigs;
  172. }
  173. public void UpdateZuizhongEventData()
  174. {
  175. AccountFileInfo.EventList eventList = AccountFileInfo.Instance.playerData.eventList.FirstOrDefault(e =>
  176. e.guid == AccountFileInfo.Instance.playerData.CurrentZuiZhongEventListId);
  177. if (eventList == null || eventList.guid == 0)
  178. {
  179. var mainEventData = GetMainEventDta();
  180. if (mainEventData != null)
  181. {
  182. AccountFileInfo.Instance.playerData.CurrentZuiZhongEventListId = mainEventData.guid;
  183. }
  184. else if (AccountFileInfo.Instance.playerData.eventList.Count > 0)
  185. {
  186. AccountFileInfo.EventList eventList1 =
  187. AccountFileInfo.Instance.playerData.eventList.FirstOrDefault(e =>
  188. !e.isCompleted && !e.isCompleted1);
  189. if (eventList1 != null)
  190. AccountFileInfo.Instance.playerData.CurrentZuiZhongEventListId = eventList1.guid;
  191. }
  192. }
  193. }
  194. private void UpDivinesense()
  195. {
  196. if (AccountFileInfo.Instance.playerData.divineSenseLevel >= divineSenseConfigs.Count)
  197. {
  198. return;
  199. }
  200. for (var i = AccountFileInfo.Instance.playerData.divineSenseLevel - 1; i < divineSenseConfigs.Count; i++)
  201. {
  202. if (AccountFileInfo.Instance.playerData.divineSenseexp >= divineSenseConfigs[i].exp)
  203. {
  204. AccountFileInfo.Instance.playerData.divineSenseexp -= divineSenseConfigs[i].exp;
  205. AccountFileInfo.Instance.playerData.divineSenseLevel = divineSenseConfigs[i + 1].ID;
  206. }
  207. }
  208. AccountFileInfo.Instance.SavePlayerData();
  209. }
  210. public int GetShenShiCount()
  211. {
  212. int count = 0;
  213. foreach (var eventList in AccountFileInfo.Instance.playerData.eventList)
  214. {
  215. EventConfig eventConfig = ConfigComponent.Instance.Get<EventConfig>(eventList.eventID);
  216. if (eventList == null || eventList.eventID == 0 || eventList.isCompleted ||
  217. eventConfig.EventTriggerType == 4)
  218. continue;
  219. if (eventConfig.EventTriggerType != 5)
  220. {
  221. count++;
  222. }
  223. }
  224. return count;
  225. }
  226. public bool BagIsEvent(int eventID)
  227. {
  228. foreach (var eventList in AccountFileInfo.Instance.playerData.eventList)
  229. {
  230. if (eventList.eventID == eventID)
  231. {
  232. return true;
  233. }
  234. }
  235. return false;
  236. }
  237. public int GetBagEventCount(int eventID)
  238. {
  239. int count = 0;
  240. foreach (var eventList in AccountFileInfo.Instance.playerData.eventList)
  241. {
  242. if (eventList.eventID == eventID)
  243. {
  244. count++;
  245. }
  246. }
  247. return count;
  248. }
  249. // public bool IsRefenceEvent(int eventID)
  250. // {
  251. // EventConfig eventConfig = ConfigComponent.Instance.Get<EventConfig>(eventID);
  252. // }
  253. public bool IsEventCompleted(int eventID)
  254. {
  255. foreach (var eventList in AccountFileInfo.Instance.playerData.completeEvents)
  256. {
  257. if (eventList.eventID == eventID)
  258. {
  259. return true;
  260. }
  261. }
  262. foreach (var eventList in AccountFileInfo.Instance.playerData.eventList)
  263. {
  264. if (eventList.eventID == eventID && eventList.isCompleted)
  265. {
  266. return true;
  267. }
  268. }
  269. return false;
  270. }
  271. private List<AccountFileInfo.EventList> DetectEvents(int eventCount, List<ItemInfo> useItems)
  272. {
  273. SmallPlacesConfig smallPlacesConfig =
  274. ConfigComponent.Instance.Get<SmallPlacesConfig>(PlayerManager.Instance.CurrentsmallPlaces.id);
  275. PlacesConfig bigMap = ConfigComponent.Instance.Get<PlacesConfig>(smallPlacesConfig.PlacesId);
  276. DivineSenseConfig divineSenseConfig =
  277. ConfigComponent.Instance.Get<DivineSenseConfig>(AccountFileInfo.Instance.playerData.divineSenseLevel);
  278. LogTool.Log($"使用神识,神识等级:{AccountFileInfo.Instance.playerData.divineSenseLevel}");
  279. List<AccountFileInfo.EventList> eventLists = new List<AccountFileInfo.EventList>();
  280. //取消根据主线进度刷新啊支线任务
  281. //现在改成优先刷新满足条件的支线任务然后判断概率是否刷新
  282. //找出可以刷新的支线任务
  283. // if (bigMap.ZhixianActivatedPercentage != null)
  284. // {
  285. // List<EventConfig> zhiXianEvents = new List<EventConfig>();
  286. // for (var i = 0; i < bigMap.ZhixianActivatedPercentage.Length; i++)
  287. // {
  288. // if (PlayerManager.Instance.PlacesBl >= bigMap.ZhixianActivatedPercentage[i])
  289. // {
  290. // if (!BagIsEvent(bigMap.ZhixianID[i]) && !IsEventTrigger(bigMap.ZhixianID[i]) &&
  291. // CanTriggerEvent(bigMap.ZhixianID[i]))
  292. // {
  293. // zhiXianEvents.Add(ConfigComponent.Instance.Get<EventConfig>(bigMap.ZhixianID[i]));
  294. // }
  295. // }
  296. // }
  297. //
  298. // foreach (var c in zhiXianEvents)
  299. // {
  300. // AccountFileInfo.EventList eventList = AddEvent(c.ID);
  301. // if (eventList != null)
  302. // {
  303. // eventLists.Add(eventList);
  304. // eventCount--;
  305. //
  306. // if (eventCount == 0)
  307. // {
  308. // return eventLists;
  309. // }
  310. // }
  311. // }
  312. // }
  313. for (int i = 0; i < eventCount; i++)
  314. {
  315. //刷新支线任务
  316. List<EventConfig> zhiXianEvents = eventConfigs.Where(e =>
  317. e.EventTriggerType == 6 && !BagIsEvent(e.ID) && !IsEventCompleted(e.ID) &&
  318. ((e.SmallPlacesId == 0 && e.placeID == 0) ||
  319. (e.SmallPlacesId != 0 && e.SmallPlacesId == smallPlacesConfig.ID) ||
  320. (e.SmallPlacesId == 0 && e.placeID == smallPlacesConfig.PlacesId)) &&
  321. eventLists.FirstOrDefault(el => el.eventID == e.ID) == null && CanTriggerEvent(e.ID)).ToList();
  322. if (zhiXianEvents.Count > 0)
  323. {
  324. var zhixianEvnetConfig = zhiXianEvents[0];
  325. int randomValueZhiXian = Random.Range(0, 101);
  326. if (randomValueZhiXian <= zhixianEvnetConfig.RefreshProbability)
  327. {
  328. AccountFileInfo.EventList eventList = AddEvent(zhixianEvnetConfig.ID);
  329. if (eventList != null)
  330. {
  331. eventLists.Add(eventList);
  332. LogTool.Log("刷新支线任务:id:" + zhixianEvnetConfig.ID);
  333. continue;
  334. }
  335. }
  336. }
  337. int randomValue3 = Random.Range(0, 101);
  338. //先刷事件关联的事件
  339. if (randomValue3 <= PlayerManager.Instance.gameConstantConfig.RefreshRelevanceEventProbability)
  340. {
  341. bool isRefence = false;
  342. foreach (var eventList in AccountFileInfo.Instance.playerData.eventList)
  343. {
  344. foreach (var eventListEventLink in eventList.eventLinks)
  345. {
  346. foreach (var eventConditionData in eventListEventLink.eventConditions)
  347. {
  348. if (IsEvenkLinkComplete(eventConditionData))
  349. continue;
  350. EventConditionConfig eventConditionConfig =
  351. ConfigComponent.Instance.Get<EventConditionConfig>(eventConditionData.eventCondition);
  352. for (var i1 = 0; i1 < eventConditionConfig.RelatedEvents?.Length; i1++)
  353. {
  354. EventConfig eventConfig1 =
  355. ConfigComponent.Instance.Get<EventConfig>(eventConditionConfig.RelatedEvents[i1]);
  356. int count = 0;
  357. foreach (var list in eventLists)
  358. {
  359. if (list.eventID == eventConfig1.ID)
  360. {
  361. count++;
  362. }
  363. }
  364. if (GetBagEventCount(eventConfig1.ID) + count >= eventConfig1.RefreshCount)
  365. {
  366. continue;
  367. }
  368. int randomValue4 = Random.Range(0, 101);
  369. if (randomValue4 <= eventConfig1.RefreshProbability)
  370. {
  371. var eventList1 = AddEvent(eventConfig1.ID);
  372. if (eventList1 != null)
  373. {
  374. eventLists.Add(AddEvent(eventConfig1.ID));
  375. isRefence = true;
  376. }
  377. else
  378. {
  379. LogTool.Error("管理事件没有刷新出来 id:" + eventConfig1.ID);
  380. }
  381. break;
  382. }
  383. }
  384. }
  385. }
  386. }
  387. if (isRefence)
  388. continue;
  389. }
  390. //概率
  391. ItemInfo itemInfoType1 = null;
  392. //类型
  393. ItemInfo itemInfoType2 = null;
  394. foreach (var itemInfo in useItems)
  395. {
  396. if (itemInfo.config.associateID == 6)
  397. {
  398. itemInfoType1 = itemInfo;
  399. }
  400. else if (itemInfo.config.associateID == 7)
  401. {
  402. itemInfoType2 = itemInfo;
  403. }
  404. }
  405. float[] QualityBonusChance = divineSenseConfig.QualityBonusChance.ToArray();
  406. if (itemInfoType1 != null)
  407. {
  408. QualityBonusChance[itemInfoType1.config.associateVlaue[0] - 1] *=
  409. itemInfoType1.config.associateVlaue[1];
  410. }
  411. //先掉落出品质
  412. int quality = UtilTools.GetRandomByWeight(qualitys, QualityBonusChance);
  413. // 获取通用事件
  414. List<EventConfig> globalEvents = eventConfigs.Where(e =>
  415. e.EventTriggerType == 1 && e.EventQuality == quality &&
  416. eventLists.FirstOrDefault(el => el.eventID == e.ID) == null && CanTriggerEvent(e.ID) &&
  417. CanEventType(e.ID, itemInfoType2)).ToList();
  418. //场景特定事件
  419. List<EventConfig> candidateEvents = eventConfigs.Where(e =>
  420. e.EventQuality == quality &&
  421. eventLists.FirstOrDefault(el => el.eventID == e.ID) == null && CanTriggerEvent(e.ID) &&
  422. CanEventType(e.ID, itemInfoType2)).ToList();
  423. if (candidateEvents.Count == 0 && globalEvents.Count == 0)
  424. {
  425. continue;
  426. }
  427. if (itemInfoType1 != null)
  428. {
  429. //TODO 消耗:神识符(概率)
  430. PlayerManager.Instance.BagController.DeductItem(itemInfoType1.itemID, 1);
  431. }
  432. if (itemInfoType2 != null)
  433. {
  434. //TODO 消耗:神识符箓(特定资源)
  435. PlayerManager.Instance.BagController.DeductItem(itemInfoType2.itemID, 1);
  436. }
  437. int randomValue1 = Random.Range(0, 101);
  438. // 达到怪率刷新场景特定事件
  439. //不然刷新通用事件(每个地图都可以刷的)
  440. if (randomValue1 < bigMap.DivineSenseGeneralProbability && candidateEvents.Count > 0)
  441. {
  442. int randomValue2 = Random.Range(0, candidateEvents.Count);
  443. var eventList = AddEvent(candidateEvents[randomValue2].ID);
  444. if (eventList != null)
  445. {
  446. eventLists.Add(eventList);
  447. }
  448. else
  449. {
  450. LogTool.Error("场景没有刷新出来 id:" + candidateEvents[randomValue2].ID);
  451. }
  452. }
  453. else if (globalEvents.Count > 0)
  454. {
  455. List<int> quanzhong = new List<int>();
  456. for (var i1 = 0; i1 < globalEvents.Count; i1++)
  457. {
  458. quanzhong.Add(globalEvents[i1].RefreshProbability);
  459. }
  460. var eventconfig = UtilTools.GetRandomByWeight(globalEvents, quanzhong.ToArray());
  461. // int randomValue2 = Random.Range(0, globalEvents.Count);
  462. var eventList = AddEvent(eventconfig.ID);
  463. if (eventList != null)
  464. {
  465. eventLists.Add(eventList);
  466. }
  467. else
  468. {
  469. LogTool.Error("通用事件没有刷新出来 id:" + eventconfig.ID);
  470. }
  471. }
  472. }
  473. if (eventLists.Count == 0)
  474. {
  475. LogTool.Error("没有可以触发的事件");
  476. return null;
  477. }
  478. return eventLists;
  479. }
  480. //添加事件
  481. public AccountFileInfo.EventList AddEvent(int eventID)
  482. {
  483. CanTriggerEvent(eventID);
  484. EventConfig eventConfig = ConfigComponent.Instance.Get<EventConfig>(eventID);
  485. AccountFileInfo.EventList eventList = null;
  486. if (eventConfig.ID == 0)
  487. {
  488. return null;
  489. }
  490. //主线任务只能刷一次
  491. if (eventConfig.EventTriggerType == 4 || eventConfig.EventTriggerType == 6)
  492. {
  493. AccountFileInfo.EventList e =
  494. AccountFileInfo.Instance.playerData.eventList.FirstOrDefault(e => e.eventID == eventID);
  495. if (e == null)
  496. {
  497. e = AccountFileInfo.Instance.playerData.completeEvents.FirstOrDefault(e => e.eventID == eventID);
  498. if (e == null)
  499. {
  500. eventList = new AccountFileInfo.EventList();
  501. eventList.eventID = eventID;
  502. }
  503. else
  504. {
  505. return null;
  506. }
  507. eventList.guid = IdGenerater.GenerateIdInt();
  508. eventList.curStep = eventConfig.EventLinksId[0];
  509. eventList.selectEventLinkIds.Add(eventConfig.EventLinksId[0]);
  510. //记录英雄等级 神识刷出来的战斗等级不变
  511. if (PlayerManager.Instance.myHero != null)
  512. eventList.heroLevel = PlayerManager.Instance.myHero.level.Value;
  513. }
  514. }
  515. else
  516. {
  517. eventList = new AccountFileInfo.EventList();
  518. eventList.eventID = eventID;
  519. eventList.guid = IdGenerater.GenerateIdInt();
  520. eventList.curStep = eventConfig.EventLinksId[0];
  521. eventList.selectEventLinkIds.Add(eventConfig.EventLinksId[0]);
  522. //记录英雄等级 神识刷出来的战斗等级不变
  523. if (PlayerManager.Instance.myHero != null)
  524. eventList.heroLevel = PlayerManager.Instance.myHero.level.Value;
  525. }
  526. //初始化神识链条,用于监听条件是否完成
  527. if (eventList != null && eventConfig.EventType != 2)
  528. {
  529. //一开始就把道具掉落出来 ui上要显示
  530. if (eventConfig.PrizeIDs != null)
  531. {
  532. for (var i = 0; i < eventConfig.PrizeIDs.Length; i++)
  533. {
  534. List<ItemInfo> itemInfoss = DropManager.Instance.Drop(eventConfig.PrizeIDs[i],
  535. eventConfig.PrizeNums[i]);
  536. foreach (var itemInfo in itemInfoss)
  537. {
  538. eventList.itemInfos.Add(itemInfo.ToItemData());
  539. }
  540. // DropConfig dropConfig = ConfigComponent.Instance.Get<DropConfig>(eventConfig.PrizeIDs[i]);
  541. // if (dropConfig.dropType == 3)
  542. // {
  543. //
  544. //
  545. //
  546. // ItemConfig itemConfig = ConfigComponent.Instance.Get<ItemConfig>(dropConfig.dropGroupID[0]);
  547. // if (itemConfig.associateID == 14)
  548. // {
  549. // List<ItemInfo> itemInfoss = DropManager.Instance.Drop(eventConfig.PrizeIDs[i],
  550. // eventConfig.PrizeNums[i]);
  551. // foreach (var itemInfo in itemInfoss)
  552. // {
  553. // eventList.itemInfos.Add(itemInfo.ToItemData());
  554. // }
  555. // }
  556. //
  557. // else
  558. // {
  559. // ItemInfo itemInfo = new ItemInfo(dropConfig.dropGroupID[0], eventConfig.PrizeNums[i]);
  560. // eventList.itemInfos.Add(itemInfo.ToItemData());
  561. // }
  562. // }
  563. // else
  564. // {
  565. // List<ItemInfo> items =
  566. // DropManager.Instance.Drop(eventConfig.PrizeIDs[i], eventConfig.PrizeNums[i]);
  567. // foreach (var itemInfo in items)
  568. // {
  569. // eventList.itemInfos.Add(itemInfo.ToItemData());
  570. // }
  571. // }
  572. }
  573. }
  574. foreach (var i in eventConfig.EventLinksId)
  575. {
  576. EventLinkConfig eventLinkConfig = ConfigComponent.Instance.Get<EventLinkConfig>(i);
  577. AccountFileInfo.EventLinkData eventLinkData = new AccountFileInfo.EventLinkData();
  578. eventLinkData.eventId = eventID;
  579. eventLinkData.eventLinkId = i;
  580. if (eventLinkConfig.ConditionId != null)
  581. {
  582. foreach (var i1 in eventLinkConfig.ConditionId)
  583. {
  584. AccountFileInfo.EventConditionData
  585. eventConditionData = new AccountFileInfo.EventConditionData();
  586. eventConditionData.eventId = eventList.eventID;
  587. eventConditionData.eventCondition = i1;
  588. eventLinkData.eventConditions.Add(eventConditionData);
  589. //初始化先检测一些条件
  590. CeekTaskComplete(eventConditionData, 1, null);
  591. CeekTaskComplete(eventConditionData, 3, null);
  592. }
  593. }
  594. eventList.eventLinks.Add(eventLinkData);
  595. }
  596. }
  597. return eventList;
  598. }
  599. /// <summary>
  600. /// 触发随机事件
  601. /// </summary>
  602. public void DetectRandomEvents()
  603. {
  604. if (isTriggerEvent)
  605. return;
  606. if (isOpenUi)
  607. return;
  608. // 获取随机事件
  609. List<EventConfig> randomEvents =
  610. eventConfigs.Where(e => e.EventTriggerType == 2 && CanTriggerEvent(e.ID)).ToList();
  611. if (randomEvents.Count == 0)
  612. {
  613. LogTool.Warning("没有可以刷新的事件");
  614. return;
  615. }
  616. int idex = Random.Range(0, randomEvents.Count);
  617. TriggerEvent(randomEvents[idex]);
  618. }
  619. /// <summary>
  620. /// 挂机事件触发
  621. /// </summary>
  622. public void TriggerEvent(EventConfig evt)
  623. {
  624. if (isTriggerEvent)
  625. return;
  626. isTriggerEvent = true;
  627. LogTool.Log($"触发事件: {evt.EventName} (ID: {evt.ID}, 品质: {evt.EventQuality})");
  628. CombatDrive.Instance.CombatController.ChangeState(CombatController.idle);
  629. AccountFileInfo.EventList eventList = AddEvent(evt.ID);
  630. CurrentEventList = eventList;
  631. DialogueManager.Instance.StartDialogue(eventList, evt.EventLinksId[0], evt.ID,
  632. () => { CompleteEvent(evt.ID); });
  633. }
  634. /// <summary>
  635. /// 其他类型事件触发
  636. /// </summary>
  637. public async CTask TriggerEvent(AccountFileInfo.EventList evt, Action oncompleteCallBack = null,
  638. Action uiOpenOverCallBack = null)
  639. {
  640. // ChancleEvent();
  641. if (isTriggerEvent)
  642. return;
  643. EventConfig eventConfig = ConfigComponent.Instance.Get<EventConfig>(evt.eventID);
  644. SmallPlacesConfig smallPlacesConfig =
  645. ConfigComponent.Instance.Get<SmallPlacesConfig>(PlayerManager.Instance.CurrentsmallPlaces.id);
  646. if (eventConfig.SmallPlacesId > 0)
  647. {
  648. if (eventConfig.SmallPlacesId != PlayerManager.Instance.CurrentsmallPlaces.id)
  649. {
  650. AccountFileInfo.SmallPlacesData lastSmallPlacesData =
  651. PlayerManager.Instance.GetSmallPlacesData(eventConfig.SmallPlacesId - 1);
  652. SmallPlacesConfig lastSmallPlacesConfig =
  653. ConfigComponent.Instance.Get<SmallPlacesConfig>(eventConfig.SmallPlacesId - 1);
  654. SmallPlacesConfig currentSmallPlacesConfig =
  655. ConfigComponent.Instance.Get<SmallPlacesConfig>(eventConfig.SmallPlacesId);
  656. if (currentSmallPlacesConfig.ID > 1 && (lastSmallPlacesData == null ||
  657. lastSmallPlacesData.completionEventCount <
  658. lastSmallPlacesConfig.CompletionEventCount))
  659. {
  660. string tips = LanguageManager.Instance.Text(10379,
  661. lastSmallPlacesConfig.CompletionEventCount - lastSmallPlacesData?.completionEventCount);
  662. // TipMessagePanel tipMessagePanel = await TipMessagePanel.OpenTipMessagePanel(tips);
  663. bool isOk = await TipsPanle.OpenPnael("", tips +"\n" + LanguageManager.Instance.Text(10823));
  664. if (isOk)
  665. {
  666. SkiptoHelper.Skipto(8);
  667. }
  668. // if (eventConfig.ID == 10002 && PlayerGuideManager.Instance.GuideIsCanDo(3))
  669. // {
  670. // PlayerGuideManager.Instance.SetGuid(3);
  671. // }
  672. AudioManager.Instance.PlayAudio("ui_chaozuoshibai.wav");
  673. return;
  674. }
  675. if (lastSmallPlacesConfig.UnlockEnvetid != 0)
  676. {
  677. AccountFileInfo.EventList eventList =
  678. AccountFileInfo.Instance.playerData.completeEvents.FirstOrDefault(ce =>
  679. ce.eventID == lastSmallPlacesConfig.UnlockEnvetid);
  680. if (eventList == null || !eventList.isCompleted)
  681. {
  682. var econfig = ConfigComponent.Instance.Get<EventConfig>(lastSmallPlacesConfig.UnlockEnvetid);
  683. TipMessagePanel.OpenTipMessagePanel(LanguageManager.Instance.Text(10380,
  684. LanguageManager.Instance.Text(lastSmallPlacesConfig.placeName),
  685. LanguageManager.Instance.Text(econfig.EventName)));
  686. AudioManager.Instance.PlayAudio("ui_chaozuoshibai.wav");
  687. return;
  688. }
  689. }
  690. SmallPlacesConfig SmallPlacesConfig =
  691. ConfigComponent.Instance.Get<SmallPlacesConfig>(eventConfig.SmallPlacesId);
  692. CTask<bool> cT = CTask<bool>.Create();
  693. PlacesInfoPanel.OpenPanel(SmallPlacesConfig.PlacesId, (b) => { cT.SetResult(b); },
  694. eventConfig.SmallPlacesId);
  695. await cT;
  696. if (eventConfig.SmallPlacesId != PlayerManager.Instance.CurrentsmallPlaces.id)
  697. {
  698. return;
  699. }
  700. // if (!cT.Result)
  701. // {
  702. // return;
  703. // }
  704. }
  705. }
  706. else if (eventConfig.placeID > 0)
  707. {
  708. if (eventConfig.placeID != smallPlacesConfig.PlacesId)
  709. {
  710. CTask<bool> cT = CTask<bool>.Create();
  711. PlacesInfoPanel.OpenPanel(eventConfig.placeID, (b) => { cT.SetResult(b); });
  712. await cT;
  713. smallPlacesConfig =
  714. ConfigComponent.Instance.Get<SmallPlacesConfig>(PlayerManager.Instance.CurrentsmallPlaces.id);
  715. if (eventConfig.placeID != smallPlacesConfig.PlacesId)
  716. {
  717. return;
  718. }
  719. }
  720. }
  721. CTask cTask = CTask.Create();
  722. this.onCompleteCallback = oncompleteCallBack;
  723. isTriggerEvent = true;
  724. LogTool.Log(
  725. $"触发事件: {LanguageManager.Instance.Text(eventConfig.EventName)} (ID: {eventConfig.ID}, 品质: {eventConfig.EventQuality})");
  726. int dialogueID = 0;
  727. if (evt.curStep == 0)
  728. {
  729. dialogueID = eventConfig.EventLinksId[0];
  730. }
  731. else
  732. {
  733. dialogueID = evt.curStep;
  734. }
  735. CurrentEventList = evt;
  736. CombatDrive.Instance.CombatController.ChangeState(CombatController.idle);
  737. await DialogueManager.Instance.StartDialogue(CurrentEventList, dialogueID, eventConfig.ID, async () =>
  738. {
  739. EventConfig eventConfig = ConfigComponent.Instance.Get<EventConfig>(CurrentEventList.eventID);
  740. if (eventConfig.EventTriggerType != 4)
  741. {
  742. CompleteEvent(CurrentEventList);
  743. }
  744. else
  745. {
  746. CurrentEventList.isCompleted1 = true;
  747. AccountFileInfo.Instance.SavePlayerData();
  748. CombatDrive.Instance.CombatController.ChangeState(CombatController.update);
  749. onCompleteCallback?.Invoke();
  750. onCompleteCallback = null;
  751. if (eventConfig.ID != 10001)
  752. {
  753. await UIManager.Instance.HideUIUIPanel<DivineSenceEventPreviewPanel>();
  754. UIManager.Instance.HideUIUIPanel<DivineSenceInfoPanel>();
  755. }
  756. EventManager.Instance.Dispatch(CustomEventType.CompleteUpdate, null);
  757. }
  758. cTask.SetResult();
  759. }, () =>
  760. {
  761. CancelEvent(CurrentEventList);
  762. cTask.SetResult();
  763. });
  764. uiOpenOverCallBack?.Invoke();
  765. DivineSenceEventPreviewPanel divineSenceEventPreviewPanel =
  766. UIManager.Instance.GetComponent<DivineSenceEventPreviewPanel>();
  767. AppBarPanel appBarPanel = UIManager.Instance.GetComponent<AppBarPanel>();
  768. // DivineSenceInfoPanel divineSenceInfoPanel = UIManager.Instance.GetComponent<DivineSenceInfoPanel>();
  769. if (divineSenceEventPreviewPanel != null && !divineSenceEventPreviewPanel.IsClose)
  770. {
  771. divineSenceEventPreviewPanel.GObjectPoolInterface.SetActive(false);
  772. }
  773. // if (appBarPanel != null && !appBarPanel.IsClose)
  774. // {
  775. // appBarPanel.GObjectPoolInterface.SetActive(false);
  776. // }
  777. // if (divineSenceInfoPanel != null)
  778. // {
  779. // divineSenceInfoPanel.GObjectPoolInterface.SetActive(false);
  780. // }
  781. await cTask;
  782. if (divineSenceEventPreviewPanel != null && !divineSenceEventPreviewPanel.IsClose)
  783. {
  784. divineSenceEventPreviewPanel.GObjectPoolInterface.SetActive(true);
  785. }
  786. if (appBarPanel != null && !appBarPanel.IsClose)
  787. {
  788. appBarPanel.GObjectPoolInterface.SetActive(true);
  789. }
  790. // if (divineSenceInfoPanel != null)
  791. // {
  792. // divineSenceInfoPanel.GObjectPoolInterface.SetActive(true);
  793. // }
  794. }
  795. //任务是否完成
  796. public bool IsEvenkLinkComplete(AccountFileInfo.EventConditionData eventCondition)
  797. {
  798. EventConditionConfig eventConditionConfig =
  799. ConfigComponent.Instance.Get<EventConditionConfig>(eventCondition.eventCondition);
  800. if (eventCondition != null)
  801. {
  802. return eventCondition.fishCount >= eventConditionConfig.finishCount;
  803. }
  804. return false;
  805. }
  806. public bool IsCeekEventGroupComplete(List<AccountFileInfo.EventConditionData> eventConditions)
  807. {
  808. Map<int, List<AccountFileInfo.EventConditionData>> eventConditionDataGroup =
  809. new Map<int, List<AccountFileInfo.EventConditionData>>();
  810. foreach (var eventConditionData in eventConditions)
  811. {
  812. EventConditionConfig eventConditionConfig =
  813. ConfigComponent.Instance.Get<EventConditionConfig>(eventConditionData.eventCondition);
  814. if (!eventConditionDataGroup.ContainsKey(eventConditionConfig.Operation))
  815. {
  816. eventConditionDataGroup.Add(eventConditionConfig.Operation,
  817. new List<AccountFileInfo.EventConditionData>());
  818. }
  819. eventConditionDataGroup[eventConditionConfig.Operation].Add(eventConditionData);
  820. }
  821. bool isUlock = true;
  822. //分组检测 其中一个组绑定成功就可以执行
  823. foreach (var keyValuePair in eventConditionDataGroup)
  824. {
  825. isUlock = true;
  826. foreach (var eventConditionData in keyValuePair.Value)
  827. {
  828. if (!IsEvenkLinkComplete(eventConditionData))
  829. {
  830. isUlock = false;
  831. }
  832. }
  833. if (isUlock)
  834. {
  835. return isUlock;
  836. }
  837. }
  838. return isUlock;
  839. }
  840. public void CeekEventCompletes(int type, int[] value)
  841. {
  842. foreach (var playerDataEventLinkData in AccountFileInfo.Instance.playerData.eventList)
  843. {
  844. foreach (var eventLinkData in playerDataEventLinkData.eventLinks)
  845. {
  846. foreach (var eventConditionData in eventLinkData.eventConditions)
  847. {
  848. CeekTaskComplete(eventConditionData, type, value);
  849. }
  850. }
  851. // if (playerDataEventLinkData.eventID == 10001 && playerDataEventLinkData.curStep == 1000104 &&
  852. // IsCeekEventGroupComplete(playerDataEventLinkData.eventLinks[3].eventConditions))
  853. // {
  854. // isTriggerEvent = false;
  855. // TriggerEvent(playerDataEventLinkData);
  856. // }
  857. }
  858. EventManager.Instance.Dispatch(CustomEventType.RemoveEvent, null);
  859. }
  860. public void CeekTaskComplete(AccountFileInfo.EventConditionData conditionData, int type, int[] value)
  861. {
  862. EventConditionConfig eventConditionConfig =
  863. ConfigComponent.Instance.Get<EventConditionConfig>(conditionData.eventCondition);
  864. if (IsEvenkLinkComplete(conditionData) && eventConditionConfig.ConditionType != 1)
  865. return;
  866. switch (type)
  867. {
  868. //检测背包道具
  869. case 1:
  870. if (eventConditionConfig.ConditionType == 1)
  871. {
  872. conditionData.fishCount =
  873. (int)PlayerManager.Instance.BagController.GetItemCount(eventConditionConfig.ConditionPara[0]);
  874. if (IsEvenkLinkComplete(conditionData))
  875. {
  876. // CompleteTask(conditionData.guid);
  877. }
  878. }
  879. break;
  880. //境界检测
  881. case 3:
  882. if (eventConditionConfig.ConditionType == 3 && PlayerManager.Instance.myHero.powerUpConfig.ID >=
  883. eventConditionConfig.ConditionPara[0])
  884. {
  885. conditionData.fishCount++;
  886. if (IsEvenkLinkComplete(conditionData))
  887. {
  888. // CompleteTask(conditionData.guid);
  889. }
  890. }
  891. break;
  892. //战斗胜利
  893. case 5:
  894. if (eventConditionConfig.ConditionType == 5 && eventConditionConfig.ConditionPara[0] == value[0])
  895. {
  896. conditionData.fishCount++;
  897. if (IsEvenkLinkComplete(conditionData))
  898. {
  899. // CompleteEvent(conditionData.guid);
  900. }
  901. }
  902. break;
  903. //获得道具
  904. case 6:
  905. if (eventConditionConfig.ConditionType == 6 && eventConditionConfig.ConditionPara[0] == value[0])
  906. {
  907. conditionData.fishCount += value[1];
  908. if (IsEvenkLinkComplete(conditionData))
  909. {
  910. // CompleteEvent(conditionData.guid);
  911. }
  912. }
  913. break;
  914. //使用神识
  915. case 8:
  916. if (eventConditionConfig.ConditionType == 8)
  917. {
  918. conditionData.fishCount += value[0];
  919. if (IsEvenkLinkComplete(conditionData))
  920. {
  921. }
  922. }
  923. break;
  924. //完成某个事件
  925. case 10:
  926. if (eventConditionConfig.ConditionType == 10 &&
  927. EventSystemManager.Instance.IsEventCompleted(eventConditionConfig.ConditionPara[0]))
  928. {
  929. conditionData.fishCount++;
  930. if (IsEvenkLinkComplete(conditionData))
  931. {
  932. }
  933. }
  934. break;
  935. }
  936. AccountFileInfo.Instance.SavePlayerData();
  937. }
  938. private void CompleteTask(object taskID)
  939. {
  940. }
  941. //指定type事件
  942. private bool CanEventType(int eventID, ItemInfo itemInfo)
  943. {
  944. if (itemInfo == null)
  945. {
  946. return true;
  947. }
  948. var evt = eventConfigs.Find(e => e.ID == eventID);
  949. if (evt.PrizeType != null && evt.PrizeType.Contains(itemInfo.config.associateVlaue[0]))
  950. {
  951. return true;
  952. }
  953. return false;
  954. }
  955. /// <summary>
  956. /// 检查事件是否满足触发条件。
  957. /// </summary>
  958. private bool CanTriggerEvent(int eventID)
  959. {
  960. var evt = eventConfigs.Find(e => e.ID == eventID);
  961. if (evt.ID == 0)
  962. return false;
  963. if (evt.EventConditionId == null)
  964. return true;
  965. bool isCan = true;
  966. for (var i = 0; i < evt.EventConditionId.Length; i++)
  967. {
  968. switch (evt.EventConditionId[i])
  969. {
  970. //背包道具检测
  971. case 1:
  972. if (evt.EventCount == null)
  973. {
  974. return false;
  975. }
  976. if (PlayerManager.Instance.BagController.GetItemCount(evt.EventValue[i]) < evt.EventCount[i])
  977. {
  978. isCan = false;
  979. return false;
  980. }
  981. break;
  982. //境界判断
  983. case 3:
  984. if (evt.EventValue == null)
  985. {
  986. return false;
  987. }
  988. if (PlayerManager.Instance.myHero.level < evt.EventValue[i])
  989. {
  990. isCan = false;
  991. return false;
  992. }
  993. break;
  994. //概率判断
  995. case 7:
  996. if (evt.EventValue == null)
  997. {
  998. return false;
  999. }
  1000. int randomValue1 = Random.Range(0, 1001);
  1001. if (randomValue1 > evt.EventValue[i])
  1002. {
  1003. isCan = false;
  1004. return false;
  1005. }
  1006. break;
  1007. //完成事件判断
  1008. case 10:
  1009. if (evt.EventValue == null)
  1010. {
  1011. return false;
  1012. }
  1013. AccountFileInfo.EventList eventList =
  1014. AccountFileInfo.Instance.playerData.completeEvents.FirstOrDefault(ce =>
  1015. ce.eventID == evt.EventValue[i]);
  1016. if (eventList == null)
  1017. {
  1018. isCan = false;
  1019. return false;
  1020. }
  1021. break;
  1022. }
  1023. }
  1024. return isCan;
  1025. }
  1026. /// <summary>
  1027. /// 完成事件
  1028. /// </summary>
  1029. /// <param name="eventID">事件ID</param>
  1030. public void CompleteEvent(int evtId)
  1031. {
  1032. isTriggerEvent = false;
  1033. LogTool.Log($"完成挂机事件{evtId}");
  1034. EventConfig eventConfig = ConfigComponent.Instance.Get<EventConfig>(evtId);
  1035. AccountFileInfo.EventList eventList = new AccountFileInfo.EventList();
  1036. eventList.eventID = evtId;
  1037. AccountFileInfo.Instance.playerData.completeEvents.Add(eventList);
  1038. int placesId = PlayerManager.Instance.GetMaxSmallPlacesId();
  1039. AccountFileInfo.SmallPlacesData smallPlacesData = PlayerManager.Instance.GetSmallPlacesData(placesId);
  1040. if (smallPlacesData != null)
  1041. {
  1042. smallPlacesData.completionEventCount++;
  1043. }
  1044. SmallPlacesConfig smallPlacesConfig =
  1045. ConfigComponent.Instance.Get<SmallPlacesConfig>(PlayerManager.Instance.CurrentsmallPlaces.id);
  1046. AccountFileInfo.PlacesData placesData = PlayerManager.Instance.GetPlacesData(smallPlacesConfig.PlacesId);
  1047. if (placesData.progress < 100)
  1048. placesData.progress += eventConfig.Score;
  1049. AccountFileInfo.Instance.SavePlayerData();
  1050. CombatDrive.Instance.CombatController.ChangeState(CombatController.update);
  1051. EventManager.Instance.Dispatch(CustomEventType.CompleteEvent, null);
  1052. }
  1053. /// <summary>
  1054. /// 完成事件
  1055. /// </summary>
  1056. /// <param name="eventID">事件ID</param>
  1057. public async void CompleteEvent(AccountFileInfo.EventList eventList, bool isTriggerEvent = false)
  1058. {
  1059. this.isTriggerEvent = isTriggerEvent;
  1060. LogTool.Log($"完成事件{eventList.eventID}");
  1061. EventConfig eventConfig = ConfigComponent.Instance.Get<EventConfig>(eventList.eventID);
  1062. AccountFileInfo.EventList ceventList =
  1063. AccountFileInfo.Instance.playerData.completeEvents.FirstOrDefault(ce => ce.eventID == eventList.eventID);
  1064. int placesId = PlayerManager.Instance.GetMaxSmallPlacesId();
  1065. AccountFileInfo.SmallPlacesData smallPlacesData = PlayerManager.Instance.GetSmallPlacesData(placesId);
  1066. if (smallPlacesData != null)
  1067. {
  1068. smallPlacesData.completionEventCount++;
  1069. }
  1070. if (ceventList == null)
  1071. {
  1072. PlacesConfig[] placesConfigs = ConfigComponent.Instance.GetAll<PlacesConfig>();
  1073. int pId = 0;
  1074. for (var i = 0; i < placesConfigs.Length; i++)
  1075. {
  1076. if (placesConfigs[i].MainTaskID == null || placesConfigs[i].ZhixianID == null)
  1077. continue;
  1078. if (placesConfigs[i].MainTaskID.Contains(eventConfig.ID) ||
  1079. placesConfigs[i].ZhixianID.Contains(eventConfig.ID))
  1080. {
  1081. pId = placesConfigs[i].ID;
  1082. break;
  1083. }
  1084. }
  1085. if (pId == 0)
  1086. {
  1087. SmallPlacesConfig smallPlacesConfig =
  1088. ConfigComponent.Instance.Get<SmallPlacesConfig>(PlayerManager.Instance.CurrentsmallPlaces.id);
  1089. AccountFileInfo.PlacesData
  1090. placesData = PlayerManager.Instance.GetPlacesData(smallPlacesConfig.PlacesId);
  1091. placesData.progress += eventConfig.Score;
  1092. }
  1093. else
  1094. {
  1095. PlayerManager.Instance.GetPlacesData(pId).progress += eventConfig.Score;
  1096. }
  1097. }
  1098. List<ItemInfo> itemInfos = new List<ItemInfo>();
  1099. foreach (var eventListItemInfo in eventList.itemInfos)
  1100. {
  1101. itemInfos.Add(new ItemInfo(eventListItemInfo));
  1102. }
  1103. //TODO 完成事件 (eventConfig)
  1104. PlayerManager.Instance.BagController.AddItem(itemInfos);
  1105. if (eventConfig.EventTriggerType == 4)
  1106. {
  1107. eventList.isCompleted = true;
  1108. AccountFileInfo.Instance.playerData.completeEvents.Add(eventList);
  1109. AccountFileInfo.Instance.playerData.eventList.Remove(eventList);
  1110. TaskInfoPanel taskInfoPanel = await TaskInfoPanel.OpenPanel(eventList, 2);
  1111. await taskInfoPanel.UIClosed();
  1112. }
  1113. else
  1114. {
  1115. //先不移除 下次探索神识移除
  1116. eventList.isCompleted = true;
  1117. }
  1118. CeekEventCompletes(10, null);
  1119. if (itemInfos != null && itemInfos.Count > 0)
  1120. {
  1121. RewardsPanel rewardsPanel = await RewardsPanel.OpenPanel(itemInfos);
  1122. await rewardsPanel.UIClosed();
  1123. }
  1124. if (eventConfig.EventTriggerType == 4)
  1125. {
  1126. await UIManager.Instance.HideUIUIPanel<DivineSenceEventPreviewPanel>();
  1127. UIManager.Instance.HideUIUIPanel<DivineSenceInfoPanel>();
  1128. }
  1129. if (AccountFileInfo.Instance.playerData.CurrentZuiZhongEventListId == eventList.guid)
  1130. {
  1131. AccountFileInfo.Instance.playerData.CurrentZuiZhongEventListId = 0;
  1132. UpdateZuizhongEventData();
  1133. }
  1134. AccountFileInfo.Instance.SavePlayerData();
  1135. CombatDrive.Instance.CombatController.ChangeState(CombatController.update);
  1136. EventManager.Instance.Dispatch(CustomEventType.CompleteEvent, null);
  1137. EventManager.Instance.Dispatch(CustomEventType.CompleteUpdate, null);
  1138. onCompleteCallback?.Invoke();
  1139. onCompleteCallback = null;
  1140. }
  1141. /// <summary>
  1142. /// 完成事件
  1143. /// </summary>
  1144. /// <param name="eventID">事件ID</param>
  1145. public void CompleteEvent(AccountFileInfo.EventLinkData eventLinkData)
  1146. {
  1147. }
  1148. /// <summary>
  1149. /// 取消事件
  1150. /// </summary>
  1151. /// <param name="eventID">事件ID</param>
  1152. public async void CancelEvent(AccountFileInfo.EventList eventList)
  1153. {
  1154. LogTool.Log($"取消事件{eventList.eventID}");
  1155. isTriggerEvent = false;
  1156. EventManager.Instance.Dispatch(CustomEventType.CompleteUpdate, null);
  1157. // EventManager.Instance.Dispatch(CustomEventType.CompleteEvent, null);
  1158. CombatDrive.Instance.CombatController.ChangeState(CombatController.update);
  1159. onCompleteCallback?.Invoke();
  1160. onCompleteCallback = null;
  1161. EventConfig eventConfig = ConfigComponent.Instance.Get<EventConfig>(eventList.eventID);
  1162. if (eventConfig.EventTriggerType == 4)
  1163. {
  1164. await UIManager.Instance.HideUIUIPanel<DivineSenceEventPreviewPanel>();
  1165. await UIManager.Instance.HideUIUIPanel<DivineSenceInfoPanel>();
  1166. }
  1167. if (eventConfig.ID == 10001 && PlayerGuideManager.Instance.GuideIsCanDo(2))
  1168. {
  1169. PlayerGuideManager.Instance.SetGuid(2);
  1170. }
  1171. }
  1172. public void RemoveEvent(AccountFileInfo.EventList eventList)
  1173. {
  1174. AccountFileInfo.Instance.playerData.eventList.Remove(eventList);
  1175. AccountFileInfo.Instance.SavePlayerData();
  1176. EventManager.Instance.Dispatch(CustomEventType.RemoveEvent, null);
  1177. }
  1178. /// <summary>
  1179. /// 获得主线事件
  1180. /// </summary>
  1181. /// <returns></returns>
  1182. public AccountFileInfo.EventList GetMainEventDta()
  1183. {
  1184. foreach (var eventList in AccountFileInfo.Instance.playerData.eventList)
  1185. {
  1186. EventConfig eventConfig = ConfigComponent.Instance.Get<EventConfig>(eventList.eventID);
  1187. if (eventConfig.EventTriggerType == 4)
  1188. {
  1189. return eventList;
  1190. }
  1191. }
  1192. return null;
  1193. }
  1194. public void CancelEvent()
  1195. {
  1196. CombatDrive.Instance.CombatController.ChangeState(CombatController.update);
  1197. DialogueManager.Instance.ChancleEvent();
  1198. CurrentEventList = null;
  1199. isTriggerEvent = false;
  1200. }
  1201. }