PlayerManager.cs 32 KB

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