EventSystemManager.cs 39 KB

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