PlayerManager.cs 32 KB

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