PlayerManager.cs 32 KB

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