PlayerManager.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Core.Audio;
  5. using Core.Language;
  6. using Core.Utility;
  7. using Excel2Json;
  8. using Fort23.Core;
  9. using Fort23.Mono;
  10. using Fort23.UTool;
  11. using GameLogic.Bag;
  12. using GameLogic.Combat.CombatTool;
  13. using GameLogic.CombatScenesTool;
  14. using GameLogic.Hero;
  15. using GameLogic.Player;
  16. using Mono.Player;
  17. using UnityEngine;
  18. using Utility;
  19. using Random = UnityEngine.Random;
  20. public class PlayerManager : Singleton<PlayerManager>
  21. {
  22. public GameConstantConfig gameConstantConfig;
  23. public GongFaControl GongFaControl;
  24. public FaBaoControl FaBaoControl;
  25. public BagController BagController;
  26. public PlayerGuideDataComponent PlayerGuideDataComponent = new PlayerGuideDataComponent();
  27. public SummonManager SummonManager = new SummonManager();
  28. // public Map<long, List<AccountFileInfo.DaoYouGuaiJiData>> GuaijiDaoYou = new Map<long, List<AccountFileInfo.DaoYouGuaiJiData>>();
  29. public bool isTest;
  30. /// <summary>
  31. /// 玩家角色属性
  32. /// </summary>
  33. public HeroInfo myHero;
  34. public HeroInfo yindaoHeroData;
  35. private string playerName;
  36. public string PlayerName
  37. {
  38. get { return AccountFileInfo.Instance.playerData.playerName; }
  39. set
  40. {
  41. playerName = value;
  42. AccountFileInfo.Instance.playerData.playerName = value;
  43. AccountFileInfo.Instance.SavePlayerData();
  44. }
  45. }
  46. private CTask _cTask;
  47. public long serverTime => TimeHelper.ServerNow();
  48. private AccountFileInfo.SmallPlacesData currentPlaces;
  49. public AccountFileInfo.SmallPlacesData CurrentsmallPlaces
  50. {
  51. get { return currentPlaces; }
  52. set { currentPlaces = value; }
  53. }
  54. public float PlacesBl => GetMapBl(CurrentsmallPlaces.id);
  55. private TimerEntity _timerEntity;
  56. public bool isLogin;
  57. /// <summary>
  58. /// 当前引导id
  59. /// </summary>
  60. public int curGuideGroupId;
  61. public void Init()
  62. {
  63. AccountFileInfo.Instance.LoadPlayerData();
  64. SetConfigs();
  65. InitGameData();
  66. if (string.IsNullOrEmpty(AccountFileInfo.Instance.playerData.playerId))
  67. {
  68. AccountFileInfo.Instance.playerData.playerId = Guid.NewGuid().ToString();
  69. }
  70. if (AccountFileInfo.Instance.playerData.MusicEffects)
  71. {
  72. AudioManager.Instance.SetAudioValue(1);
  73. }
  74. else
  75. {
  76. AudioManager.Instance.SetAudioValue(0);
  77. }
  78. if (AccountFileInfo.Instance.playerData.MusicBg)
  79. {
  80. AudioManager.Instance.SetBgmValue(1);
  81. }
  82. else
  83. {
  84. AudioManager.Instance.SetBgmValue(0);
  85. }
  86. // int m = Random.Range(0, 4 * 60 * 1000);
  87. RandownDaoYou(gameConstantConfig.Daoyoushowuptime + 1000);
  88. QiankundaiConfig[] qiankundaiConfigs = ConfigComponent.Instance.GetAll<QiankundaiConfig>();
  89. foreach (var qiankundaiConfig in qiankundaiConfigs)
  90. {
  91. if (qiankundaiConfig.dropType == 1)
  92. {
  93. AccountFileInfo.QiankundaiData qiankundaiData =
  94. AccountFileInfo.Instance.playerData.QiankundaiDatas.FirstOrDefault(q =>
  95. q.id == qiankundaiConfig.ID);
  96. if (qiankundaiData == null)
  97. {
  98. qiankundaiData = new AccountFileInfo.QiankundaiData();
  99. qiankundaiData.id = qiankundaiConfig.ID;
  100. if (qiankundaiConfig.dropPara1 == 1)
  101. {
  102. qiankundaiData.refenceTime = TimeHelper.ClientNow() + 60 * 60 * 1000;
  103. }
  104. else if (qiankundaiConfig.dropPara1 == 2)
  105. {
  106. qiankundaiData.refenceTime = TimeHelper.GetBaseRefreshTime(TimeHelper.ClientNow());
  107. }
  108. else if (qiankundaiConfig.dropPara1 == 3)
  109. {
  110. }
  111. AccountFileInfo.Instance.playerData.QiankundaiDatas.Add(qiankundaiData);
  112. }
  113. }
  114. }
  115. EveryDayRefence();
  116. CalculateOfflineRewards();
  117. AccountFileInfo.Instance.SavePlayerData();
  118. SummonManager.CustomInit();
  119. isLogin = true;
  120. }
  121. /// <summary>
  122. /// 获得固定时间乾坤袋表
  123. /// </summary>
  124. /// <returns></returns>
  125. public List<QiankundaiConfig> GetFixedTimeQiankundaiConfigs()
  126. {
  127. List<QiankundaiConfig> configs = new List<QiankundaiConfig>();
  128. QiankundaiConfig[] qiankundaiConfigs = ConfigComponent.Instance.GetAll<QiankundaiConfig>();
  129. foreach (var qiankundaiConfig in qiankundaiConfigs)
  130. {
  131. if (qiankundaiConfig.dropType == 2)
  132. {
  133. if (myHero.powerUpConfig.ID >= qiankundaiConfig.dropLevel[0] &&
  134. myHero.powerUpConfig.ID <= qiankundaiConfig.dropLevel[1])
  135. {
  136. configs.Add(qiankundaiConfig);
  137. }
  138. }
  139. }
  140. return configs;
  141. }
  142. //添加心境
  143. public void AddSentimentData(int id)
  144. {
  145. AccountFileInfo.SentimentData sentimentData =
  146. AccountFileInfo.Instance.playerData.SentimentDatas.FirstOrDefault(sd => sd.id == id);
  147. if (sentimentData != null)
  148. {
  149. LogTool.Error("已经用心境 id:" + id);
  150. return;
  151. }
  152. SentimentConfig sentimentConfig = ConfigComponent.Instance.Get<SentimentConfig>(id);
  153. sentimentData = new AccountFileInfo.SentimentData();
  154. sentimentData.id = id;
  155. sentimentData.mainSentiment = new AccountFileInfo.SentimentProperty();
  156. sentimentData.mainSentiment.groupId = sentimentConfig.mainSentimentEffect;
  157. foreach (var i in sentimentConfig.sentimentEffect)
  158. {
  159. AccountFileInfo.SentimentProperty sentimentProperty = new AccountFileInfo.SentimentProperty();
  160. sentimentProperty.groupId = i;
  161. sentimentData.sentimentProperties.Add(sentimentProperty);
  162. }
  163. AccountFileInfo.Instance.playerData.SentimentDatas.Add(sentimentData);
  164. AccountFileInfo.Instance.SavePlayerData();
  165. }
  166. List<AccountFileInfo.DaoYouData> removerDaoYou = new List<AccountFileInfo.DaoYouData>();
  167. public void RandownDaoYou(int m)
  168. {
  169. _timerEntity?.Dispose();
  170. _timerEntity = null;
  171. _timerEntity = TimerComponent.Instance.AddTimer(m, () =>
  172. {
  173. List<AccountFileInfo.DaoYouData> daoYouDatas = AccountFileInfo.Instance.playerData.daoYouDatas.ToList();
  174. foreach (var daoYouData in daoYouDatas)
  175. {
  176. if (daoYouData.favorabilityLv <= 1)
  177. {
  178. removerDaoYou.Add(daoYouData);
  179. continue;
  180. }
  181. foreach (var keyValuePair in AccountFileInfo.Instance.playerData.daoYouGuaiJiDatas)
  182. {
  183. if (daoYouData.id == keyValuePair.daoyouDataID)
  184. {
  185. removerDaoYou.Add(daoYouData);
  186. break;
  187. }
  188. }
  189. }
  190. foreach (var daoYouData in removerDaoYou)
  191. {
  192. daoYouDatas.Remove(daoYouData);
  193. }
  194. removerDaoYou.Clear();
  195. int count = Random.Range(0, daoYouDatas.Count + 1);
  196. count = count > gameConstantConfig.daoyouMaxshowupNum ? gameConstantConfig.daoyouMaxshowupNum : count;
  197. List<AccountFileInfo.DaoYouGuaiJiData> daoyou = new List<AccountFileInfo.DaoYouGuaiJiData>();
  198. for (int i = 0; i < count; i++)
  199. {
  200. int index = Random.Range(0, daoYouDatas.Count);
  201. AccountFileInfo.DaoYouGuaiJiData daoYouGuaiJiData = new AccountFileInfo.DaoYouGuaiJiData();
  202. int time = Random.Range(gameConstantConfig.DaoyouguajiDuration[0],
  203. gameConstantConfig.DaoyouguajiDuration[1]) * 1000;
  204. daoYouGuaiJiData.leaveTime = TimeHelper.ClientNow() + time;
  205. daoYouGuaiJiData.guajiTime = time;
  206. daoYouGuaiJiData.daoyouDataID = daoYouDatas[index].id;
  207. daoyou.Add(daoYouGuaiJiData);
  208. daoYouDatas.RemoveAt(index);
  209. _timerEntity?.Dispose();
  210. _timerEntity = null;
  211. }
  212. if (daoyou.Count > 0)
  213. {
  214. AccountFileInfo.Instance.playerData.daoYouGuaiJiDatas.AddRange(daoyou);
  215. EventManager.Instance.Dispatch(CustomEventType.DaoYouCounUpdate, null);
  216. }
  217. RandownDaoYou(gameConstantConfig.Daoyoushowuptime * 1000);
  218. });
  219. }
  220. public int GetDaoYouLevel(AccountFileInfo.DaoYouData daoYouData)
  221. {
  222. DaoyouModelConfig daoyouModelConfig = ConfigComponent.Instance.Get<DaoyouModelConfig>(daoYouData.id);
  223. int level = (int)(myHero.level.Value * daoyouModelConfig.growupRate * 0.01f);
  224. if (level < 1) level = 1;
  225. return level;
  226. }
  227. public int GetBl(AccountFileInfo.DaoYouData daoYouData, int guajibuffId)
  228. {
  229. DaoyouLevelupConfig daoyouLevelupConfig =
  230. ConfigComponent.Instance.Get<DaoyouLevelupConfig>(daoYouData.favorabilityLv);
  231. int level = GetDaoYouLevel(daoYouData);
  232. DaoyouguajiResourcLevel daoyouguajiResourcLevel = ConfigComponent.Instance.Get<DaoyouguajiResourcLevel>(level);
  233. guajibuff guajibuff = ConfigComponent.Instance.Get<guajibuff>(guajibuffId);
  234. int levelBl = 0;
  235. int bl = 0;
  236. switch (guajibuff.paraValue)
  237. {
  238. case 1:
  239. levelBl = daoyouguajiResourcLevel.para1;
  240. bl = (int)(guajibuff.GivingRate * levelBl * daoyouLevelupConfig.guajiGrowup * 0.01f * 0.01f);
  241. return bl;
  242. break;
  243. case 2:
  244. levelBl = daoyouguajiResourcLevel.para2;
  245. bl = (int)(guajibuff.GivingRate * levelBl * daoyouLevelupConfig.guajiGrowup * 0.01f * 0.01f);
  246. return bl;
  247. break;
  248. case 3:
  249. levelBl = daoyouguajiResourcLevel.para3;
  250. bl = (int)(guajibuff.GivingRate * levelBl * daoyouLevelupConfig.guajiGrowup * 0.01f * 0.01f);
  251. return bl;
  252. break;
  253. case 4:
  254. levelBl = daoyouguajiResourcLevel.para4;
  255. bl = (int)(guajibuff.GivingRate * levelBl * daoyouLevelupConfig.guajiGrowup * 0.01f * 0.01f);
  256. return bl;
  257. break;
  258. case 5:
  259. levelBl = daoyouguajiResourcLevel.para5;
  260. bl = (int)(guajibuff.GivingRate * levelBl * daoyouLevelupConfig.guajiGrowup * 0.01f * 0.001f);
  261. return bl;
  262. break;
  263. default:
  264. return 0;
  265. }
  266. }
  267. private void SetConfigs()
  268. {
  269. gameConstantConfig = ConfigComponent.Instance.Get<GameConstantConfig>(1);
  270. }
  271. private void InitGameData()
  272. {
  273. GongFaControl = new GongFaControl();
  274. FaBaoControl = new FaBaoControl();
  275. BagController = new BagController();
  276. HeroInfo heroInfo = new HeroInfo();
  277. AccountFileInfo.Instance.playerData.heroData.TaoismSkillId = 601011;
  278. heroInfo.InitHero(AccountFileInfo.Instance.playerData.heroData);
  279. myHero = heroInfo;
  280. myHero.TaoismSkillId = 601011;
  281. yindaoHeroData = new HeroInfo();
  282. yindaoHeroData.InitMonster(102, 200);
  283. yindaoHeroData.isMonster = false;
  284. // yindaoHeroData = heroInfo;
  285. yindaoHeroData.TaoismSkillId = 601011;
  286. // myHero= yindaoHeroData;
  287. BagController.Init();
  288. //初始化关卡
  289. CurrentsmallPlaces = GetSmallPlacesData(GetMaxSmallPlacesId());
  290. StaticUpdater.Instance.RemoveRenderUpdateCallBack(Update);
  291. StaticUpdater.Instance.AddRenderUpdateCallBack(Update);
  292. EventManager.Instance.AddEventListener(CustomEventType.CloseLoadingUI, CloseLoadingUI);
  293. }
  294. private void CloseLoadingUI(IEventData e)
  295. {
  296. _cTask?.SetResult();
  297. }
  298. private float timer;
  299. public int GetMaxSmallPlacesId()
  300. {
  301. int placesId = AccountFileInfo.Instance.playerData.smallPlacesDatas.Max(p => p.id);
  302. return placesId;
  303. }
  304. public AccountFileInfo.PlacesData GetPlacesData(int placesId)
  305. {
  306. return AccountFileInfo.Instance.playerData.placesDatas.FirstOrDefault(p => p.id == placesId);
  307. }
  308. public AccountFileInfo.SmallPlacesData GetSmallPlacesData(int smallPlacesId)
  309. {
  310. return AccountFileInfo.Instance.playerData.smallPlacesDatas.FirstOrDefault(p => p.id == smallPlacesId);
  311. }
  312. public float GetMapBl(int map)
  313. {
  314. SmallPlacesConfig smallPlacesConfig = ConfigComponent.Instance.Get<SmallPlacesConfig>(map);
  315. AccountFileInfo.PlacesData placesData = GetPlacesData(smallPlacesConfig.PlacesId);
  316. if (placesData == null)
  317. return 0;
  318. PlacesConfig placesConfig = ConfigComponent.Instance.Get<PlacesConfig>(smallPlacesConfig.PlacesId);
  319. if (placesConfig.TotalScore == 0)
  320. {
  321. return 0;
  322. }
  323. return (float)Math.Round(((float)placesData.progress / placesConfig.TotalScore) * 100, 1);
  324. }
  325. private bool isUpdate = false;
  326. private void Update()
  327. {
  328. if (!TimeHelper.IsNetworkTimeReady)
  329. {
  330. LogTool.Error($"获取网络时间失败,挂机奖励停止计算");
  331. return;
  332. }
  333. timer += Time.deltaTime;
  334. if (timer > 1)
  335. {
  336. timer = 0;
  337. if (AccountFileInfo.Instance.playerData.QiankundaiDropTimer <= gameConstantConfig.qiankundaiMaxTime)
  338. {
  339. AccountFileInfo.Instance.playerData.QiankundaiDropTimer++;
  340. QianKunDaiAward();
  341. AccountFileInfo.Instance.SavePlayerData();
  342. }
  343. }
  344. //每天刷新
  345. EveryDayRefence();
  346. foreach (var keyValuePair in AccountFileInfo.Instance.playerData.daoYouGuaiJiDatas)
  347. {
  348. if (!keyValuePair.isLeave && TimeHelper.ClientNow() > keyValuePair.leaveTime)
  349. {
  350. //判断概率给奖励
  351. isUpdate = true;
  352. keyValuePair.isLeave = true;
  353. AccountFileInfo.DaoYouData daoYouData =
  354. AccountFileInfo.Instance.playerData.daoYouDatas.FirstOrDefault(d =>
  355. d.id == keyValuePair.daoyouDataID);
  356. DaoyouModelConfig daoyouModelConfig =
  357. ConfigComponent.Instance.Get<DaoyouModelConfig>(daoYouData.id);
  358. int bl = GetBl(daoYouData, daoyouModelConfig.guajiBuffID[0]);
  359. int randomValue1 = Random.Range(0, 101);
  360. LogTool.Log("道友随机怪率:" + randomValue1 + " 比例:" + bl);
  361. List<AccountFileInfo.ItemData> itemDatas = new List<AccountFileInfo.ItemData>();
  362. if (randomValue1 < bl)
  363. {
  364. for (var i = 1; i < daoyouModelConfig.guajiBuffID.Length; i++)
  365. {
  366. int count = GetBl(daoYouData, daoyouModelConfig.guajiBuffID[i]);
  367. guajibuff guajibuff =
  368. ConfigComponent.Instance.Get<guajibuff>(daoyouModelConfig.guajiBuffID[i]);
  369. switch (guajibuff.paraValue)
  370. {
  371. case 1:
  372. itemDatas.Add(new AccountFileInfo.ItemData(1003, count));
  373. LogTool.Log("道友获得道具id:" + 1003 + " 数量:" + count);
  374. break;
  375. case 2:
  376. itemDatas.Add(new AccountFileInfo.ItemData(1001, count));
  377. LogTool.Log("道友获得道具id:" + 1001 + " 数量:" + count);
  378. break;
  379. case 3:
  380. itemDatas.Add(new AccountFileInfo.ItemData(1005, count));
  381. LogTool.Log("道友获得道具id:" + 1005 + " 数量:" + count);
  382. break;
  383. case 4:
  384. itemDatas.Add(new AccountFileInfo.ItemData(1006, count));
  385. LogTool.Log("道友获得道具id:" + 1006 + " 数量:" + count);
  386. break;
  387. }
  388. }
  389. }
  390. keyValuePair.items.AddRange(itemDatas);
  391. }
  392. }
  393. if (isUpdate)
  394. {
  395. AccountFileInfo.Instance.SavePlayerData();
  396. EventManager.Instance.Dispatch(CustomEventType.DaoYouCounUpdate, null);
  397. isUpdate = false;
  398. }
  399. }
  400. private void EveryDayRefence()
  401. {
  402. if (TimeHelper.ClientNow() > AccountFileInfo.Instance.playerData.nextRefence)
  403. {
  404. AccountFileInfo.Instance.playerData.nextRefence =
  405. TimeHelper.GetBaseRefreshTime(TimeHelper.ClientNow());
  406. AccountFileInfo.Instance.playerData.todayUseExpElixrPanelCount = 0;
  407. AccountFileInfo.Instance.playerData.todayDivineSensePoint = 0;
  408. foreach (var playerDataSummonData in AccountFileInfo.Instance.playerData.SummonDatas)
  409. {
  410. playerDataSummonData.onePayCount = 0;
  411. playerDataSummonData.tenPayCount = 0;
  412. playerDataSummonData.oneFreeCount = 0;
  413. playerDataSummonData.nextOneFreeTime = 0;
  414. playerDataSummonData.tenFreeCount = 0;
  415. playerDataSummonData.nextTenFreeTime = 0;
  416. }
  417. AccountFileInfo.Instance.SavePlayerData();
  418. }
  419. }
  420. public async CTask ChangeMap(int mapId, bool isShowUI = true)
  421. {
  422. SmallPlacesConfig currentSmallPlacesConfig =
  423. ConfigComponent.Instance.Get<SmallPlacesConfig>(PlayerManager.Instance.CurrentsmallPlaces.id);
  424. SmallPlacesConfig smallPlacesConfig = ConfigComponent.Instance.Get<SmallPlacesConfig>(mapId);
  425. if (smallPlacesConfig.ID == 0)
  426. return;
  427. AccountFileInfo.SmallPlacesData lastSmallPlacesData =
  428. PlayerManager.Instance.GetSmallPlacesData(smallPlacesConfig.ID - 1);
  429. SmallPlacesConfig lastSmallPlacesConfig =
  430. ConfigComponent.Instance.Get<SmallPlacesConfig>(smallPlacesConfig.ID - 1);
  431. if (smallPlacesConfig.ID > 1 && (lastSmallPlacesData == null ||
  432. lastSmallPlacesData.completionEventCount <
  433. lastSmallPlacesConfig.CompletionEventCount))
  434. {
  435. return;
  436. }
  437. if (lastSmallPlacesConfig.UnlockEnvetid != 0)
  438. {
  439. AccountFileInfo.EventList eventList =
  440. AccountFileInfo.Instance.playerData.completeEvents.FirstOrDefault(ce =>
  441. ce.eventID == lastSmallPlacesConfig.UnlockEnvetid);
  442. if (eventList == null || !eventList.isCompleted)
  443. {
  444. return;
  445. }
  446. }
  447. UIManager.Instance.HindCurrAllShowPanel();
  448. _cTask = CTask.Create();
  449. AccountFileInfo.SmallPlacesData smallPlacesData =
  450. PlayerManager.Instance.GetSmallPlacesData(smallPlacesConfig.ID);
  451. if (smallPlacesData == null)
  452. {
  453. smallPlacesData = new AccountFileInfo.SmallPlacesData();
  454. smallPlacesData.id = smallPlacesConfig.ID;
  455. AccountFileInfo.Instance.playerData.smallPlacesDatas.Add(smallPlacesData);
  456. }
  457. AccountFileInfo.PlacesData currentPlacesData = PlayerManager.Instance.GetPlacesData(smallPlacesConfig.ID);
  458. if (currentPlacesData == null)
  459. {
  460. currentPlacesData = new AccountFileInfo.PlacesData();
  461. currentPlacesData.id = smallPlacesConfig.PlacesId;
  462. AccountFileInfo.Instance.playerData.placesDatas.Add(currentPlacesData);
  463. }
  464. PlayerManager.Instance.CurrentsmallPlaces = smallPlacesData;
  465. if (currentSmallPlacesConfig.PlacesId == smallPlacesConfig.PlacesId)
  466. {
  467. CombatController.currActiveCombat.ChangeState(CombatController.miniSceneSwitch);
  468. }
  469. else
  470. {
  471. CombatController.currActiveCombat.ChangeState(CombatController.sceneSwitch);
  472. }
  473. await _cTask;
  474. if (isShowUI)
  475. UIManager.Instance.ShowLastHindAllShowPanel();
  476. EventManager.Instance.Dispatch(CustomEventType.ChangeMap, null);
  477. }
  478. public void QianKunDaiAward()
  479. {
  480. foreach (var playerDataQiankundaiData in AccountFileInfo.Instance.playerData.QiankundaiDatas)
  481. {
  482. //重置掉落次数
  483. QiankundaiConfig qiankundaiConfig =
  484. ConfigComponent.Instance.Get<QiankundaiConfig>(playerDataQiankundaiData.id);
  485. if (qiankundaiConfig.dropType != 2 &&
  486. TimeHelper.ClientNow() >= playerDataQiankundaiData.refenceTime)
  487. {
  488. if (qiankundaiConfig.dropPara1 == 1)
  489. {
  490. playerDataQiankundaiData.refenceTime = TimeHelper.ClientNow() + 60 * 60 * 1000;
  491. }
  492. else if (qiankundaiConfig.dropPara1 == 2)
  493. {
  494. playerDataQiankundaiData.refenceTime =
  495. TimeHelper.GetBaseRefreshTime(TimeHelper.ClientNow());
  496. }
  497. else if (qiankundaiConfig.dropPara1 == 3)
  498. {
  499. }
  500. playerDataQiankundaiData.dropCount = 0;
  501. }
  502. if (myHero.powerUpConfig.ID >= qiankundaiConfig.dropLevel[0] &&
  503. myHero.powerUpConfig.ID <= qiankundaiConfig.dropLevel[1])
  504. {
  505. if (playerDataQiankundaiData.dropCount < qiankundaiConfig.dropPara2 ||
  506. qiankundaiConfig.dropPara2 == -1)
  507. {
  508. playerDataQiankundaiData.dropTime++;
  509. if (playerDataQiankundaiData.dropTime >= qiankundaiConfig.dropTypePara)
  510. {
  511. //发放奖励
  512. for (var i = 0; i < qiankundaiConfig.ChoukaID.Length; i++)
  513. {
  514. List<ItemInfo> itemInfos = DropManager.Instance.Drop(qiankundaiConfig.ChoukaID[i],
  515. qiankundaiConfig.DropCount[i]);
  516. foreach (var itemInfo in itemInfos)
  517. {
  518. AccountFileInfo.ItemData itemData =
  519. AccountFileInfo.Instance.playerData.QiankundaiItemDatas.FirstOrDefault(i =>
  520. i.itemId == itemInfo.itemID);
  521. if (itemData != null)
  522. {
  523. itemData.itemCount += itemInfo.count.Value;
  524. }
  525. else
  526. {
  527. itemData = itemInfo.ToItemData();
  528. AccountFileInfo.Instance.playerData.QiankundaiItemDatas.Add(itemData);
  529. }
  530. }
  531. }
  532. playerDataQiankundaiData.dropCount = 0;
  533. playerDataQiankundaiData.dropTime = 0;
  534. }
  535. }
  536. }
  537. // AccountFileInfo.Instance.SavePlayerData();
  538. }
  539. }
  540. public void CalculateOfflineRewards()
  541. {
  542. int exitMiao = (int)((TimeHelper.ClientNow() - AccountFileInfo.Instance.playerData.ExitTime) / 1000);
  543. if (exitMiao <= 0)
  544. return;
  545. if (AccountFileInfo.Instance.playerData.QiankundaiDropTimer <=
  546. gameConstantConfig.qiankundaiMaxTime &&
  547. exitMiao > 0)
  548. {
  549. int miao = AccountFileInfo.Instance.playerData.QiankundaiDropTimer + exitMiao;
  550. miao = miao >= gameConstantConfig.qiankundaiMaxTime
  551. ? gameConstantConfig.qiankundaiMaxTime - AccountFileInfo.Instance.playerData.QiankundaiDropTimer
  552. : exitMiao;
  553. AccountFileInfo.Instance.playerData.QiankundaiDropTimer += miao;
  554. for (int i = 0; i < miao; i++)
  555. {
  556. QianKunDaiAward();
  557. }
  558. }
  559. HeroPowerUpConfig heroPowerUpConfig = myHero.powerUpConfig;
  560. if (AccountFileInfo.Instance.playerData.divineSensePoint < heroPowerUpConfig.ShenshiMax)
  561. {
  562. int miao = 0;
  563. if (AccountFileInfo.Instance.playerData.todayDivineSensePoint <
  564. gameConstantConfig.shenshiPointRecSPD[0])
  565. {
  566. float todayResidueShenShi = gameConstantConfig.shenshiPointRecSPD[0] -
  567. AccountFileInfo.Instance.playerData.todayDivineSensePoint;
  568. todayResidueShenShi =
  569. AccountFileInfo.Instance.playerData.divineSensePoint + todayResidueShenShi >
  570. heroPowerUpConfig.ShenshiMax
  571. ? heroPowerUpConfig.ShenshiMax - AccountFileInfo.Instance.playerData.divineSensePoint
  572. : todayResidueShenShi;
  573. miao = (int)(todayResidueShenShi / gameConstantConfig.shenshiPointRecSPD[1]);
  574. miao = miao > exitMiao ? exitMiao : miao;
  575. float todayResidue = gameConstantConfig.shenshiPointRecSPD[1] * miao;
  576. todayResidue = todayResidue + AccountFileInfo.Instance.playerData.divineSensePoint >
  577. heroPowerUpConfig.ShenshiMax
  578. ? heroPowerUpConfig.ShenshiMax - AccountFileInfo.Instance.playerData.divineSensePoint
  579. : todayResidue;
  580. if (todayResidue < 0)
  581. todayResidue = 0;
  582. AccountFileInfo.Instance.playerData.todayDivineSensePoint += todayResidue;
  583. AccountFileInfo.Instance.playerData.divineSensePoint += todayResidue;
  584. }
  585. int residueExitMiao = exitMiao - miao;
  586. if (residueExitMiao > 0)
  587. {
  588. float todaySs2 = gameConstantConfig.shenshiPointRecSPD[2] * residueExitMiao;
  589. float allShenshi = todaySs2 + AccountFileInfo.Instance.playerData.divineSensePoint;
  590. todaySs2 = allShenshi > heroPowerUpConfig.ShenshiMax
  591. ? heroPowerUpConfig.ShenshiMax - AccountFileInfo.Instance.playerData.divineSensePoint
  592. : todaySs2;
  593. if (todaySs2 < 0)
  594. todaySs2 = 0;
  595. AccountFileInfo.Instance.playerData.divineSensePoint += todaySs2;
  596. }
  597. }
  598. EventManager.Instance.Dispatch(CustomEventType.DivineSensePointChange, null);
  599. AccountFileInfo.Instance.playerData.ExitTime = 0;
  600. AccountFileInfo.Instance.SavePlayerData();
  601. }
  602. public void AddTestHeroInfo(TestCombatHeroConfig.TestHeroInfoConfig testHeroInfoConfig)
  603. {
  604. isTest = true;
  605. GongFaControl.allSkill.Clear();
  606. SkillConfig[] allSkillConfig = ConfigComponent.Instance.GetAll<SkillConfig>();
  607. for (int i = 0; i < allSkillConfig.Length; i++)
  608. {
  609. SkillConfig skillConfig = allSkillConfig[i];
  610. if (skillConfig.level == testHeroInfoConfig.skillStart)
  611. {
  612. SkillInfo skillInfo = new SkillInfo(skillConfig.ID, testHeroInfoConfig.skillLevel);
  613. skillInfo.index = -1;
  614. GongFaControl.AddSkillInfo(skillInfo);
  615. }
  616. }
  617. AccountFileInfo.HeroData heroData = new AccountFileInfo.HeroData();
  618. heroData.heroModelId = testHeroInfoConfig.heroID;
  619. heroData.heroPowerId = testHeroInfoConfig.level;
  620. myHero = new HeroInfo();
  621. myHero.InitHero(heroData);
  622. if (testHeroInfoConfig.skill.Count > 0)
  623. {
  624. GongFaControl.allSkill.Clear();
  625. for (int i = 0; i < testHeroInfoConfig.skill.Count; i++)
  626. {
  627. SkillInfo skillInfo = new SkillInfo(testHeroInfoConfig.skill[i], testHeroInfoConfig.skillLevel,
  628. testHeroInfoConfig.skillStart);
  629. skillInfo.index = i;
  630. GongFaControl.AddSkillInfo(skillInfo);
  631. }
  632. }
  633. else
  634. {
  635. SkillInfo[] skillInfos = GongFaControl.allUseSkill;
  636. for (int i = 0; i < skillInfos.Length; i++)
  637. {
  638. if (skillInfos[i] != null)
  639. {
  640. SkillInfo skillInfo = new SkillInfo(skillInfos[i].skillConfig.IDGroup,
  641. testHeroInfoConfig.skillLevel,
  642. testHeroInfoConfig.skillStart);
  643. skillInfo.index = i;
  644. GongFaControl.allUseSkill[i] = skillInfo;
  645. }
  646. }
  647. }
  648. if (testHeroInfoConfig.magicWeaponId.Count > 0)
  649. {
  650. int fbLevel = ((testHeroInfoConfig.level - 1) / 10) + 1;
  651. if (fbLevel <= 0)
  652. {
  653. fbLevel = 1;
  654. }
  655. for (int i = 0; i < testHeroInfoConfig.magicWeaponId.Count; i++)
  656. {
  657. FaBaoInfo faBaoInfo = new FaBaoInfo(testHeroInfoConfig.magicWeaponId[i], fbLevel);
  658. faBaoInfo.FaBaoData.useIndex = i;
  659. FaBaoControl.FightFaBao[i] = faBaoInfo;
  660. FaBaoControl.AddFaBao(faBaoInfo);
  661. }
  662. }
  663. float[] qiangDu = new float[] { 0, 35.7f, 98f, 138.7f, 199.3f, 216f };
  664. int qiangDuLevelId = Mathf.CeilToInt(testHeroInfoConfig.level / 5f);
  665. HeroQiangDuAddConfig heroQiangDuAddConfig = ConfigComponent.Instance.Get<HeroQiangDuAddConfig>(qiangDuLevelId);
  666. int index = Mathf.RoundToInt(heroQiangDuAddConfig.qiangDuZhi) - 1;
  667. myHero.hp = (EncryptionLong)(myHero.hp.Value * (qiangDu[index] / 100f + 1));
  668. myHero.attack = (EncryptionLong)(myHero.attack.Value * (qiangDu[index] / 100f + 1));
  669. myHero.defense = (EncryptionLong)(myHero.defense.Value * (qiangDu[index] / 100f + 1));
  670. // for (int i = 0; i < 4; i++)
  671. // {
  672. // FaBaoControl.FightFaBao[i] = FaBaoControl.myAllFaBao[i];
  673. // }
  674. myHero.hp += testHeroInfoConfig.hp;
  675. myHero.attack += testHeroInfoConfig.att;
  676. myHero.defense += testHeroInfoConfig.def;
  677. myHero.Metal += testHeroInfoConfig.jing;
  678. myHero.Wood += testHeroInfoConfig.mu;
  679. myHero.Water += testHeroInfoConfig.shui;
  680. myHero.Fire += testHeroInfoConfig.huo;
  681. myHero.Earth += testHeroInfoConfig.tu;
  682. myHero.TaoismSkillId = 601011;
  683. myHero.MagicWeaponID.Clear();
  684. myHero.MagicWeaponID.AddRange(FaBaoControl.FightFaBao);
  685. // for (int i = 0; i < FaBaoControl.FightFaBao.Length; i++)
  686. // {
  687. // FaBaoInfo faBaoInfo = FaBaoControl.FightFaBao[i];
  688. // if (faBaoInfo != null)
  689. // {
  690. // foreach (var VARIABLE in faBaoInfo.attriButedIC)
  691. // {
  692. // switch (VARIABLE.Key)
  693. // {
  694. // case 1:
  695. // myHero.hp += VARIABLE.Value;
  696. // break;
  697. // case 2:
  698. // myHero.defense += VARIABLE.Value;
  699. // break;
  700. // case 3:
  701. // myHero.attack += VARIABLE.Value;
  702. // break;
  703. // }
  704. // }
  705. // }
  706. // }
  707. }
  708. /// <summary>
  709. /// 保存英雄数据
  710. /// </summary>
  711. /// <param name="heroInfo"></param>
  712. public void SaveHeroData(HeroInfo heroInfo)
  713. {
  714. AccountFileInfo.Instance.playerData.heroData = heroInfo.heroData;
  715. AccountFileInfo.Instance.SavePlayerData();
  716. }
  717. /// <summary>
  718. /// 时间(秒)转换位小时分钟秒
  719. /// </summary>
  720. /// <param name="miao"></param>
  721. /// <returns></returns>
  722. public static string TimeToHSM(long miao)
  723. {
  724. long fen = miao / 60;
  725. miao = miao % 60;
  726. long xiaoShi = fen / 60;
  727. long tian = xiaoShi / 24;
  728. xiaoShi = xiaoShi % 24;
  729. fen = fen % 60;
  730. if (tian > 0)
  731. {
  732. return $"{tian}天{xiaoShi}小時";
  733. }
  734. else
  735. {
  736. if (xiaoShi <= 0 && fen <= 59)
  737. {
  738. return $"{fen}分{miao}秒";
  739. }
  740. else
  741. {
  742. return $"{xiaoShi}小時{fen}分";
  743. }
  744. }
  745. }
  746. }