EventSystemManager.cs 42 KB

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