EventSystemManager.cs 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214
  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 tipMessagePanel = await TipMessagePanel.OpenTipMessagePanel(
  545. $"该任务需要先解锁[{LanguageManager.Instance.Text(lastSmallPlacesConfig.placeName)}], 完成{lastSmallPlacesConfig.CompletionEventCount}个任务后, 可解锁.");
  546. tipMessagePanel.UIClosed(() =>
  547. {
  548. if (PlayerGuideManager.Instance.GuideIsCanDo(3))
  549. {
  550. PlayerGuideManager.Instance.SetGuid(3);
  551. }
  552. });
  553. return;
  554. }
  555. if (lastSmallPlacesConfig.UnlockEnvetid != 0)
  556. {
  557. AccountFileInfo.EventList eventList =
  558. AccountFileInfo.Instance.playerData.completeEvents.FirstOrDefault(ce =>
  559. ce.eventID == lastSmallPlacesConfig.UnlockEnvetid);
  560. if (eventList == null || !eventList.isCompleted)
  561. {
  562. var econfig = ConfigComponent.Instance.Get<EventConfig>(lastSmallPlacesConfig.UnlockEnvetid);
  563. TipMessagePanel.OpenTipMessagePanel(
  564. $"该任务需要先解锁[{LanguageManager.Instance.Text(lastSmallPlacesConfig.placeName)}], 完成{econfig.EventName}任务后, 可解锁.");
  565. return;
  566. }
  567. }
  568. SmallPlacesConfig SmallPlacesConfig =
  569. ConfigComponent.Instance.Get<SmallPlacesConfig>(eventConfig.SmallPlacesId);
  570. CTask<bool> cT = CTask<bool>.Create();
  571. PlacesInfoPanel.OpenPanel(SmallPlacesConfig.PlacesId, (b) => { cT.SetResult(b); });
  572. await cT;
  573. if (eventConfig.SmallPlacesId != PlayerManager.Instance.CurrentsmallPlaces.id)
  574. {
  575. return;
  576. }
  577. // if (!cT.Result)
  578. // {
  579. // return;
  580. // }
  581. }
  582. }
  583. else if (eventConfig.placeID > 0)
  584. {
  585. if (eventConfig.placeID != smallPlacesConfig.PlacesId)
  586. {
  587. CTask<bool> cT = CTask<bool>.Create();
  588. PlacesInfoPanel.OpenPanel(eventConfig.placeID, (b) => { cT.SetResult(b); });
  589. await cT;
  590. smallPlacesConfig =
  591. ConfigComponent.Instance.Get<SmallPlacesConfig>(PlayerManager.Instance.CurrentsmallPlaces.id);
  592. if (eventConfig.placeID != smallPlacesConfig.PlacesId)
  593. {
  594. return;
  595. }
  596. }
  597. }
  598. CTask cTask = CTask.Create();
  599. this.onCompleteCallback = oncompleteCallBack;
  600. isTriggerEvent = true;
  601. LogTool.Log(
  602. $"触发事件: {LanguageManager.Instance.Text(eventConfig.EventName)} (ID: {eventConfig.ID}, 品质: {eventConfig.EventQuality})");
  603. int dialogueID = 0;
  604. if (evt.curStep == 0)
  605. {
  606. dialogueID = eventConfig.EventLinksId[0];
  607. }
  608. else
  609. {
  610. dialogueID = evt.curStep;
  611. }
  612. CurrentEventList = evt;
  613. CombatDrive.Instance.CombatController.ChangeState(CombatController.idle);
  614. DialogueManager.Instance.StartDialogue(CurrentEventList, dialogueID, eventConfig.ID, () =>
  615. {
  616. CompleteEvent(CurrentEventList);
  617. cTask.SetResult();
  618. }, () =>
  619. {
  620. CancelEvent(CurrentEventList);
  621. cTask.SetResult();
  622. });
  623. DivineSenceEventPreviewPanel divineSenceEventPreviewPanel =
  624. UIManager.Instance.GetComponent<DivineSenceEventPreviewPanel>();
  625. AppBarPanel appBarPanel = UIManager.Instance.GetComponent<AppBarPanel>();
  626. // DivineSenceInfoPanel divineSenceInfoPanel = UIManager.Instance.GetComponent<DivineSenceInfoPanel>();
  627. if (divineSenceEventPreviewPanel != null && !divineSenceEventPreviewPanel.IsClose)
  628. {
  629. divineSenceEventPreviewPanel.GObjectPoolInterface.SetActive(false);
  630. }
  631. if (appBarPanel != null && !appBarPanel.IsClose)
  632. {
  633. appBarPanel.GObjectPoolInterface.SetActive(false);
  634. }
  635. // if (divineSenceInfoPanel != null)
  636. // {
  637. // divineSenceInfoPanel.GObjectPoolInterface.SetActive(false);
  638. // }
  639. await cTask;
  640. if (divineSenceEventPreviewPanel != null && !divineSenceEventPreviewPanel.IsClose)
  641. {
  642. divineSenceEventPreviewPanel.GObjectPoolInterface.SetActive(true);
  643. }
  644. if (appBarPanel != null && !appBarPanel.IsClose)
  645. {
  646. appBarPanel.GObjectPoolInterface.SetActive(true);
  647. }
  648. // if (divineSenceInfoPanel != null)
  649. // {
  650. // divineSenceInfoPanel.GObjectPoolInterface.SetActive(true);
  651. // }
  652. }
  653. //任务是否完成
  654. public bool IsEvenkLinkComplete(AccountFileInfo.EventConditionData eventCondition)
  655. {
  656. EventConditionConfig eventConditionConfig =
  657. ConfigComponent.Instance.Get<EventConditionConfig>(eventCondition.eventCondition);
  658. if (eventCondition != null)
  659. {
  660. return eventCondition.fishCount >= eventConditionConfig.finishCount;
  661. }
  662. return false;
  663. }
  664. public bool CeekEventGroupComplete(List<AccountFileInfo.EventConditionData> eventConditions)
  665. {
  666. Map<int, List<AccountFileInfo.EventConditionData>> eventConditionDataGroup =
  667. new Map<int, List<AccountFileInfo.EventConditionData>>();
  668. foreach (var eventConditionData in eventConditions)
  669. {
  670. EventConditionConfig eventConditionConfig =
  671. ConfigComponent.Instance.Get<EventConditionConfig>(eventConditionData.eventCondition);
  672. if (!eventConditionDataGroup.ContainsKey(eventConditionConfig.Operation))
  673. {
  674. eventConditionDataGroup.Add(eventConditionConfig.Operation,
  675. new List<AccountFileInfo.EventConditionData>());
  676. }
  677. eventConditionDataGroup[eventConditionConfig.Operation].Add(eventConditionData);
  678. }
  679. bool isUlock = true;
  680. //分组检测 其中一个组绑定成功就可以执行
  681. foreach (var keyValuePair in eventConditionDataGroup)
  682. {
  683. isUlock = true;
  684. foreach (var eventConditionData in keyValuePair.Value)
  685. {
  686. if (!IsEvenkLinkComplete(eventConditionData))
  687. {
  688. isUlock = false;
  689. }
  690. }
  691. if (isUlock)
  692. {
  693. return isUlock;
  694. }
  695. }
  696. return isUlock;
  697. }
  698. public void CeekEventCompletes(int type, int[] value)
  699. {
  700. foreach (var playerDataEventLinkData in AccountFileInfo.Instance.playerData.eventList)
  701. {
  702. foreach (var eventLinkData in playerDataEventLinkData.eventLinks)
  703. {
  704. foreach (var eventConditionData in eventLinkData.eventConditions)
  705. {
  706. CeekTaskComplete(eventConditionData, type, value);
  707. }
  708. }
  709. }
  710. EventManager.Instance.Dispatch(CustomEventType.RemoveEvent, null);
  711. }
  712. public void CeekTaskComplete(AccountFileInfo.EventConditionData conditionData, int type, int[] value)
  713. {
  714. EventConditionConfig eventConditionConfig =
  715. ConfigComponent.Instance.Get<EventConditionConfig>(conditionData.eventCondition);
  716. if (IsEvenkLinkComplete(conditionData))
  717. return;
  718. switch (type)
  719. {
  720. //检测背包道具
  721. case 1:
  722. if (eventConditionConfig.ConditionType == 1)
  723. {
  724. conditionData.fishCount +=
  725. (int)PlayerManager.Instance.BagController.GetItemCount(eventConditionConfig.ConditionPara[0]);
  726. if (IsEvenkLinkComplete(conditionData))
  727. {
  728. // CompleteTask(conditionData.guid);
  729. }
  730. }
  731. break;
  732. //境界检测
  733. case 3:
  734. if (eventConditionConfig.ConditionType == 3 && PlayerManager.Instance.myHero.powerUpConfig.ID >=
  735. eventConditionConfig.ConditionPara[0])
  736. {
  737. conditionData.fishCount++;
  738. if (IsEvenkLinkComplete(conditionData))
  739. {
  740. // CompleteTask(conditionData.guid);
  741. }
  742. }
  743. break;
  744. //战斗胜利
  745. case 5:
  746. if (eventConditionConfig.ConditionType == 5 && eventConditionConfig.ConditionPara[0] == value[0])
  747. {
  748. conditionData.fishCount++;
  749. if (IsEvenkLinkComplete(conditionData))
  750. {
  751. // CompleteEvent(conditionData.guid);
  752. }
  753. }
  754. break;
  755. //获得道具
  756. case 6:
  757. if (eventConditionConfig.ConditionType == 6 && eventConditionConfig.ConditionPara[0] == value[0])
  758. {
  759. conditionData.fishCount += value[1];
  760. if (IsEvenkLinkComplete(conditionData))
  761. {
  762. // CompleteEvent(conditionData.guid);
  763. }
  764. }
  765. break;
  766. //使用神识
  767. case 8:
  768. if (eventConditionConfig.ConditionType == 8)
  769. {
  770. conditionData.fishCount += value[0];
  771. if (IsEvenkLinkComplete(conditionData))
  772. {
  773. }
  774. }
  775. break;
  776. }
  777. AccountFileInfo.Instance.SavePlayerData();
  778. }
  779. private void CompleteTask(object taskID)
  780. {
  781. }
  782. //指定type事件
  783. private bool CanEventType(int eventID, ItemInfo itemInfo)
  784. {
  785. if (itemInfo == null)
  786. {
  787. return true;
  788. }
  789. var evt = eventConfigs.Find(e => e.ID == eventID);
  790. if (evt.PrizeType != null && evt.PrizeType.Contains(itemInfo.config.associateVlaue[0]))
  791. {
  792. return true;
  793. }
  794. return false;
  795. }
  796. /// <summary>
  797. /// 检查事件是否满足触发条件。
  798. /// </summary>
  799. private bool CanTriggerEvent(int eventID)
  800. {
  801. var evt = eventConfigs.Find(e => e.ID == eventID);
  802. if (evt.ID == 0)
  803. return false;
  804. switch (evt.EventConditionId)
  805. {
  806. //背包道具检测
  807. case 1:
  808. return PlayerManager.Instance.BagController.GetItemCount(evt.EventValue[0]) >= evt.EventCount;
  809. //境界判断
  810. case 2:
  811. return PlayerManager.Instance.myHero.level >= evt.EventCount;
  812. //概率判断
  813. case 3:
  814. int randomValue1 = Random.Range(0, 1001);
  815. return randomValue1 <= evt.EventCount;
  816. //完成事件判断
  817. case 10:
  818. AccountFileInfo.EventList eventList =
  819. AccountFileInfo.Instance.playerData.completeEvents.FirstOrDefault(ce =>
  820. ce.eventID == evt.EventValue[0]);
  821. return eventList != null;
  822. }
  823. return true;
  824. }
  825. /// <summary>
  826. /// 完成事件
  827. /// </summary>
  828. /// <param name="eventID">事件ID</param>
  829. public void CompleteEvent(int evtId)
  830. {
  831. isTriggerEvent = false;
  832. LogTool.Log($"完成挂机事件{evtId}");
  833. EventConfig eventConfig = ConfigComponent.Instance.Get<EventConfig>(evtId);
  834. AccountFileInfo.EventList eventList = new AccountFileInfo.EventList();
  835. eventList.eventID = evtId;
  836. AccountFileInfo.Instance.playerData.completeEvents.Add(eventList);
  837. PlayerManager.Instance.CurrentsmallPlaces.completionEventCount++;
  838. SmallPlacesConfig smallPlacesConfig =
  839. ConfigComponent.Instance.Get<SmallPlacesConfig>(PlayerManager.Instance.CurrentsmallPlaces.id);
  840. AccountFileInfo.PlacesData placesData = PlayerManager.Instance.GetPlacesData(smallPlacesConfig.PlacesId);
  841. if (placesData.progress < 100)
  842. placesData.progress += eventConfig.Score;
  843. AccountFileInfo.Instance.SavePlayerData();
  844. CombatDrive.Instance.CombatController.ChangeState(CombatController.update);
  845. EventManager.Instance.Dispatch(CustomEventType.CompleteEvent, null);
  846. }
  847. /// <summary>
  848. /// 完成事件
  849. /// </summary>
  850. /// <param name="eventID">事件ID</param>
  851. public async void CompleteEvent(AccountFileInfo.EventList eventList, bool isTriggerEvent = false)
  852. {
  853. this.isTriggerEvent = isTriggerEvent;
  854. LogTool.Log($"完成事件{eventList.eventID}");
  855. EventConfig eventConfig = ConfigComponent.Instance.Get<EventConfig>(eventList.eventID);
  856. AccountFileInfo.EventList ceventList =
  857. AccountFileInfo.Instance.playerData.completeEvents.FirstOrDefault(ce => ce.eventID == eventList.eventID);
  858. PlayerManager.Instance.CurrentsmallPlaces.completionEventCount++;
  859. if (ceventList == null)
  860. {
  861. PlacesConfig[] placesConfigs = ConfigComponent.Instance.GetAll<PlacesConfig>();
  862. int pId = 0;
  863. for (var i = 0; i < placesConfigs.Length; i++)
  864. {
  865. if (placesConfigs[i].MainTaskID == null || placesConfigs[i].ZhixianID == null)
  866. continue;
  867. if (placesConfigs[i].MainTaskID.Contains(eventConfig.ID) ||
  868. placesConfigs[i].ZhixianID.Contains(eventConfig.ID))
  869. {
  870. pId = placesConfigs[i].ID;
  871. break;
  872. }
  873. }
  874. if (pId == 0)
  875. {
  876. SmallPlacesConfig smallPlacesConfig =
  877. ConfigComponent.Instance.Get<SmallPlacesConfig>(PlayerManager.Instance.CurrentsmallPlaces.id);
  878. AccountFileInfo.PlacesData
  879. placesData = PlayerManager.Instance.GetPlacesData(smallPlacesConfig.PlacesId);
  880. placesData.progress += eventConfig.Score;
  881. }
  882. else
  883. {
  884. PlayerManager.Instance.GetPlacesData(pId).progress += eventConfig.Score;
  885. }
  886. }
  887. List<ItemInfo> itemInfos = new List<ItemInfo>();
  888. if (eventConfig.PrizeIDs != null)
  889. {
  890. for (var i = 0; i < eventConfig.PrizeIDs.Length; i++)
  891. {
  892. DropConfig dropConfig = ConfigComponent.Instance.Get<DropConfig>(eventConfig.PrizeIDs[i]);
  893. if (dropConfig.dropType == 3)
  894. {
  895. if (eventConfig.PrizeNums[i] < 0)
  896. {
  897. List<ItemInfo> items =
  898. DropManager.Instance.Drop(dropConfig.dropGroupID[0], eventConfig.PrizeNums[i]);
  899. if (items != null)
  900. itemInfos.AddRange(items);
  901. }
  902. else
  903. {
  904. ItemInfo itemInfo = new ItemInfo(dropConfig.dropGroupID[0], eventConfig.PrizeNums[i]);
  905. itemInfos.Add(itemInfo);
  906. }
  907. }
  908. else
  909. {
  910. List<ItemInfo> items = DropManager.Instance.DropItem(eventConfig.PrizeIDs[i]);
  911. if (items != null)
  912. itemInfos.AddRange(items);
  913. }
  914. // itemInfos.Add(new ItemInfo(eventConfig.PrizeIDs[i], eventConfig.PrizeNums[i]));
  915. }
  916. }
  917. foreach (var eventListItemInfo in eventList.itemInfos)
  918. {
  919. itemInfos.Add(new ItemInfo(eventListItemInfo));
  920. }
  921. PlayerManager.Instance.BagController.AddItem(itemInfos);
  922. if (eventConfig.EventTriggerType == 4)
  923. {
  924. eventList.isCompleted = true;
  925. AccountFileInfo.Instance.playerData.completeEvents.Add(eventList);
  926. AccountFileInfo.Instance.playerData.eventList.Remove(eventList);
  927. TaskInfoPanel taskInfoPanel = await TaskInfoPanel.OpenPanel(eventList, 2);
  928. await taskInfoPanel.UIClosed();
  929. }
  930. else
  931. {
  932. //先不移除 下次探索神识移除
  933. eventList.isCompleted = true;
  934. }
  935. RewardsPanel rewardsPanel = await RewardsPanel.OpenPanel(itemInfos);
  936. await rewardsPanel.UIClosed();
  937. if (AccountFileInfo.Instance.playerData.CurrentZuiZhongEventListId == eventList.guid)
  938. {
  939. AccountFileInfo.Instance.playerData.CurrentZuiZhongEventListId = 0;
  940. UpdateZuizhongEventData();
  941. }
  942. AccountFileInfo.Instance.SavePlayerData();
  943. CombatDrive.Instance.CombatController.ChangeState(CombatController.update);
  944. EventManager.Instance.Dispatch(CustomEventType.CompleteEvent, null);
  945. onCompleteCallback?.Invoke();
  946. onCompleteCallback = null;
  947. }
  948. /// <summary>
  949. /// 完成事件
  950. /// </summary>
  951. /// <param name="eventID">事件ID</param>
  952. public void CompleteEvent(AccountFileInfo.EventLinkData eventLinkData)
  953. {
  954. }
  955. /// <summary>
  956. /// 取消事件
  957. /// </summary>
  958. /// <param name="eventID">事件ID</param>
  959. public void CancelEvent(AccountFileInfo.EventList eventList)
  960. {
  961. LogTool.Log($"取消事件{eventList.eventID}");
  962. isTriggerEvent = false;
  963. EventManager.Instance.Dispatch(CustomEventType.CompleteEvent, null);
  964. CombatDrive.Instance.CombatController.ChangeState(CombatController.update);
  965. onCompleteCallback?.Invoke();
  966. onCompleteCallback = null;
  967. if (PlayerGuideManager.Instance.GuideIsCanDo(2))
  968. {
  969. PlayerGuideManager.Instance.SetGuid(2);
  970. }
  971. }
  972. public void RemoveEvent(AccountFileInfo.EventList eventList)
  973. {
  974. AccountFileInfo.Instance.playerData.eventList.Remove(eventList);
  975. AccountFileInfo.Instance.SavePlayerData();
  976. EventManager.Instance.Dispatch(CustomEventType.RemoveEvent, null);
  977. }
  978. /// <summary>
  979. /// 获得主线事件
  980. /// </summary>
  981. /// <returns></returns>
  982. public AccountFileInfo.EventList GetMainEventDta()
  983. {
  984. foreach (var eventList in AccountFileInfo.Instance.playerData.eventList)
  985. {
  986. EventConfig eventConfig = ConfigComponent.Instance.Get<EventConfig>(eventList.eventID);
  987. if (eventConfig.EventTriggerType == 4)
  988. {
  989. return eventList;
  990. }
  991. }
  992. return null;
  993. }
  994. public void CancelEvent()
  995. {
  996. CombatDrive.Instance.CombatController.ChangeState(CombatController.update);
  997. DialogueManager.Instance.ChancleEvent();
  998. CurrentEventList = null;
  999. isTriggerEvent = false;
  1000. }
  1001. }