EventSystemManager.cs 44 KB

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