EventSystemManager.cs 44 KB

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