PlayerManager.cs 31 KB

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