EventSystemManager.cs 43 KB

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