PlayerManager.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832
  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. timer += Time.deltaTime;
  308. if (timer > 1)
  309. {
  310. timer = 0;
  311. // PlayerManager.Instance.myHero.heroData.exp += myHero.powerUpConfig.AutoXiuwei;
  312. // AccountFileInfo.Instance.SavePlayerData();
  313. if (AccountFileInfo.Instance.playerData.QiankundaiDropTimer <= gameConstantConfig.qiankundaiMaxTime)
  314. {
  315. AccountFileInfo.Instance.playerData.QiankundaiDropTimer++;
  316. QianKunDaiAward();
  317. AccountFileInfo.Instance.SavePlayerData();
  318. }
  319. }
  320. //每天刷新
  321. EveryDayRefence();
  322. foreach (var keyValuePair in AccountFileInfo.Instance.playerData.daoYouGuaiJiDatas)
  323. {
  324. if (!keyValuePair.isLeave && TimeHelper.ClientNow() > keyValuePair.leaveTime)
  325. {
  326. //判断概率给奖励
  327. isUpdate = true;
  328. keyValuePair.isLeave = true;
  329. AccountFileInfo.DaoYouData daoYouData =
  330. AccountFileInfo.Instance.playerData.daoYouDatas.FirstOrDefault(d =>
  331. d.id == keyValuePair.daoyouDataID);
  332. DaoyouModelConfig daoyouModelConfig =
  333. ConfigComponent.Instance.Get<DaoyouModelConfig>(daoYouData.id);
  334. int bl = GetBl(daoYouData, daoyouModelConfig.guajiBuffID[0]);
  335. int randomValue1 = Random.Range(0, 101);
  336. LogTool.Log("道友随机怪率:" + randomValue1 + " 比例:" + bl);
  337. List<AccountFileInfo.ItemData> itemDatas = new List<AccountFileInfo.ItemData>();
  338. if (randomValue1 < bl)
  339. {
  340. for (var i = 1; i < daoyouModelConfig.guajiBuffID.Length; i++)
  341. {
  342. int count = GetBl(daoYouData, daoyouModelConfig.guajiBuffID[i]);
  343. guajibuff guajibuff =
  344. ConfigComponent.Instance.Get<guajibuff>(daoyouModelConfig.guajiBuffID[i]);
  345. switch (guajibuff.paraValue)
  346. {
  347. case 1:
  348. itemDatas.Add(new AccountFileInfo.ItemData(1003, count));
  349. LogTool.Log("道友获得道具id:" + 1003 + " 数量:" + count);
  350. break;
  351. case 2:
  352. itemDatas.Add(new AccountFileInfo.ItemData(1001, count));
  353. LogTool.Log("道友获得道具id:" + 1001 + " 数量:" + count);
  354. break;
  355. case 3:
  356. itemDatas.Add(new AccountFileInfo.ItemData(1005, count));
  357. LogTool.Log("道友获得道具id:" + 1005 + " 数量:" + count);
  358. break;
  359. case 4:
  360. itemDatas.Add(new AccountFileInfo.ItemData(1006, count));
  361. LogTool.Log("道友获得道具id:" + 1006 + " 数量:" + count);
  362. break;
  363. }
  364. }
  365. }
  366. keyValuePair.items.AddRange(itemDatas);
  367. }
  368. }
  369. if (isUpdate)
  370. {
  371. AccountFileInfo.Instance.SavePlayerData();
  372. EventManager.Instance.Dispatch(CustomEventType.DaoYouCounUpdate, null);
  373. isUpdate = false;
  374. }
  375. }
  376. private void EveryDayRefence()
  377. {
  378. if (TimeHelper.ClientNow() > AccountFileInfo.Instance.playerData.nextRefence)
  379. {
  380. AccountFileInfo.Instance.playerData.nextRefence =
  381. TimeHelper.GetBaseRefreshTime(TimeHelper.ClientNow());
  382. AccountFileInfo.Instance.playerData.todayUseExpElixrPanelCount = 0;
  383. AccountFileInfo.Instance.playerData.todayDivineSensePoint = 0;
  384. foreach (var playerDataSummonData in AccountFileInfo.Instance.playerData.SummonDatas)
  385. {
  386. playerDataSummonData.onePayCount = 0;
  387. playerDataSummonData.tenPayCount = 0;
  388. playerDataSummonData.oneFreeCount = 0;
  389. playerDataSummonData.nextOneFreeTime = 0;
  390. playerDataSummonData.tenFreeCount = 0;
  391. playerDataSummonData.nextTenFreeTime = 0;
  392. }
  393. AccountFileInfo.Instance.SavePlayerData();
  394. }
  395. }
  396. public async CTask ChangeMap(int mapId, bool isShowUI = true)
  397. {
  398. SmallPlacesConfig currentSmallPlacesConfig =
  399. ConfigComponent.Instance.Get<SmallPlacesConfig>(PlayerManager.Instance.CurrentsmallPlaces.id);
  400. SmallPlacesConfig smallPlacesConfig = ConfigComponent.Instance.Get<SmallPlacesConfig>(mapId);
  401. if (smallPlacesConfig.ID == 0)
  402. return;
  403. AccountFileInfo.SmallPlacesData lastSmallPlacesData =
  404. PlayerManager.Instance.GetSmallPlacesData(smallPlacesConfig.ID - 1);
  405. SmallPlacesConfig lastSmallPlacesConfig =
  406. ConfigComponent.Instance.Get<SmallPlacesConfig>(smallPlacesConfig.ID - 1);
  407. if (smallPlacesConfig.ID > 1 && (lastSmallPlacesData == null ||
  408. lastSmallPlacesData.completionEventCount <
  409. lastSmallPlacesConfig.CompletionEventCount))
  410. {
  411. return;
  412. }
  413. if (lastSmallPlacesConfig.UnlockEnvetid != 0)
  414. {
  415. AccountFileInfo.EventList eventList =
  416. AccountFileInfo.Instance.playerData.completeEvents.FirstOrDefault(ce =>
  417. ce.eventID == lastSmallPlacesConfig.UnlockEnvetid);
  418. if (eventList == null || !eventList.isCompleted)
  419. {
  420. return;
  421. }
  422. }
  423. UIManager.Instance.HindCurrAllShowPanel();
  424. _cTask = CTask.Create();
  425. AccountFileInfo.SmallPlacesData smallPlacesData =
  426. PlayerManager.Instance.GetSmallPlacesData(smallPlacesConfig.ID);
  427. if (smallPlacesData == null)
  428. {
  429. smallPlacesData = new AccountFileInfo.SmallPlacesData();
  430. smallPlacesData.id = smallPlacesConfig.ID;
  431. AccountFileInfo.Instance.playerData.smallPlacesDatas.Add(smallPlacesData);
  432. }
  433. AccountFileInfo.PlacesData currentPlacesData = PlayerManager.Instance.GetPlacesData(smallPlacesConfig.ID);
  434. if (currentPlacesData == null)
  435. {
  436. currentPlacesData = new AccountFileInfo.PlacesData();
  437. currentPlacesData.id = smallPlacesConfig.PlacesId;
  438. AccountFileInfo.Instance.playerData.placesDatas.Add(currentPlacesData);
  439. }
  440. PlayerManager.Instance.CurrentsmallPlaces = smallPlacesData;
  441. if (currentSmallPlacesConfig.PlacesId == smallPlacesConfig.PlacesId)
  442. {
  443. CombatController.currActiveCombat.ChangeState(CombatController.miniSceneSwitch);
  444. }
  445. else
  446. {
  447. CombatController.currActiveCombat.ChangeState(CombatController.sceneSwitch);
  448. }
  449. await _cTask;
  450. if (isShowUI)
  451. UIManager.Instance.ShowLastHindAllShowPanel();
  452. EventManager.Instance.Dispatch(CustomEventType.ChangeMap, null);
  453. }
  454. public void QianKunDaiAward()
  455. {
  456. foreach (var playerDataQiankundaiData in AccountFileInfo.Instance.playerData.QiankundaiDatas)
  457. {
  458. //重置掉落次数
  459. QiankundaiConfig qiankundaiConfig =
  460. ConfigComponent.Instance.Get<QiankundaiConfig>(playerDataQiankundaiData.id);
  461. if (qiankundaiConfig.dropType != 2 &&
  462. TimeHelper.ClientNow() >= playerDataQiankundaiData.refenceTime)
  463. {
  464. if (qiankundaiConfig.dropPara1 == 1)
  465. {
  466. playerDataQiankundaiData.refenceTime = TimeHelper.ClientNow() + 60 * 60 * 1000;
  467. }
  468. else if (qiankundaiConfig.dropPara1 == 2)
  469. {
  470. playerDataQiankundaiData.refenceTime =
  471. TimeHelper.GetBaseRefreshTime(TimeHelper.ClientNow());
  472. }
  473. else if (qiankundaiConfig.dropPara1 == 3)
  474. {
  475. }
  476. playerDataQiankundaiData.dropCount = 0;
  477. }
  478. if (myHero.powerUpConfig.ID >= qiankundaiConfig.dropLevel[0] &&
  479. myHero.powerUpConfig.ID <= qiankundaiConfig.dropLevel[1])
  480. {
  481. if (playerDataQiankundaiData.dropCount < qiankundaiConfig.dropPara2 ||
  482. qiankundaiConfig.dropPara2 == -1)
  483. {
  484. playerDataQiankundaiData.dropTime++;
  485. if (playerDataQiankundaiData.dropTime >= qiankundaiConfig.dropTypePara)
  486. {
  487. //发放奖励
  488. for (var i = 0; i < qiankundaiConfig.ChoukaID.Length; i++)
  489. {
  490. List<ItemInfo> itemInfos = DropManager.Instance.Drop(qiankundaiConfig.ChoukaID[i],
  491. qiankundaiConfig.DropCount[i]);
  492. foreach (var itemInfo in itemInfos)
  493. {
  494. AccountFileInfo.ItemData itemData =
  495. AccountFileInfo.Instance.playerData.QiankundaiItemDatas.FirstOrDefault(i =>
  496. i.itemId == itemInfo.itemID);
  497. if (itemData != null)
  498. {
  499. itemData.itemCount += itemInfo.count.Value;
  500. }
  501. else
  502. {
  503. itemData = itemInfo.ToItemData();
  504. AccountFileInfo.Instance.playerData.QiankundaiItemDatas.Add(itemData);
  505. }
  506. }
  507. }
  508. playerDataQiankundaiData.dropCount = 0;
  509. playerDataQiankundaiData.dropTime = 0;
  510. }
  511. }
  512. }
  513. // AccountFileInfo.Instance.SavePlayerData();
  514. }
  515. }
  516. public void CalculateOfflineRewards()
  517. {
  518. int exitMiao = (int)((TimeHelper.ClientNow() - AccountFileInfo.Instance.playerData.ExitTime) / 1000);
  519. if (exitMiao <= 0)
  520. return;
  521. if (AccountFileInfo.Instance.playerData.QiankundaiDropTimer <=
  522. gameConstantConfig.qiankundaiMaxTime &&
  523. exitMiao > 0)
  524. {
  525. int miao = AccountFileInfo.Instance.playerData.QiankundaiDropTimer + exitMiao;
  526. miao = miao >= gameConstantConfig.qiankundaiMaxTime
  527. ? gameConstantConfig.qiankundaiMaxTime - AccountFileInfo.Instance.playerData.QiankundaiDropTimer
  528. : exitMiao;
  529. AccountFileInfo.Instance.playerData.QiankundaiDropTimer += miao;
  530. for (int i = 0; i < miao; i++)
  531. {
  532. QianKunDaiAward();
  533. }
  534. }
  535. HeroPowerUpConfig heroPowerUpConfig = myHero.powerUpConfig;
  536. if (AccountFileInfo.Instance.playerData.divineSensePoint < heroPowerUpConfig.ShenshiMax)
  537. {
  538. int miao = 0;
  539. if (AccountFileInfo.Instance.playerData.todayDivineSensePoint <
  540. gameConstantConfig.shenshiPointRecSPD[0])
  541. {
  542. float todayResidueShenShi = gameConstantConfig.shenshiPointRecSPD[0] -
  543. AccountFileInfo.Instance.playerData.todayDivineSensePoint;
  544. todayResidueShenShi =
  545. AccountFileInfo.Instance.playerData.divineSensePoint + todayResidueShenShi >
  546. heroPowerUpConfig.ShenshiMax
  547. ? heroPowerUpConfig.ShenshiMax - AccountFileInfo.Instance.playerData.divineSensePoint
  548. : todayResidueShenShi;
  549. miao = (int)(todayResidueShenShi / gameConstantConfig.shenshiPointRecSPD[1]);
  550. miao = miao > exitMiao ? exitMiao : miao;
  551. float todayResidue = gameConstantConfig.shenshiPointRecSPD[1] * miao;
  552. todayResidue = todayResidue + AccountFileInfo.Instance.playerData.divineSensePoint >
  553. heroPowerUpConfig.ShenshiMax
  554. ? heroPowerUpConfig.ShenshiMax - AccountFileInfo.Instance.playerData.divineSensePoint
  555. : todayResidue;
  556. AccountFileInfo.Instance.playerData.todayDivineSensePoint += todayResidue;
  557. AccountFileInfo.Instance.playerData.divineSensePoint += todayResidue;
  558. }
  559. int residueExitMiao = exitMiao - miao;
  560. if (residueExitMiao > 0)
  561. {
  562. float todaySs2 = gameConstantConfig.shenshiPointRecSPD[2] * residueExitMiao;
  563. float allShenshi = todaySs2 + AccountFileInfo.Instance.playerData.divineSensePoint;
  564. todaySs2 = allShenshi > heroPowerUpConfig.ShenshiMax
  565. ? heroPowerUpConfig.ShenshiMax - allShenshi
  566. : todaySs2;
  567. AccountFileInfo.Instance.playerData.divineSensePoint += todaySs2;
  568. }
  569. }
  570. EventManager.Instance.Dispatch(CustomEventType.DivineSensePointChange, null);
  571. AccountFileInfo.Instance.playerData.ExitTime = 0;
  572. AccountFileInfo.Instance.SavePlayerData();
  573. }
  574. public void AddTestHeroInfo(TestCombatHeroConfig.TestHeroInfoConfig testHeroInfoConfig)
  575. {
  576. isTest = true;
  577. GongFaControl.allSkill.Clear();
  578. SkillConfig[] allSkillConfig = ConfigComponent.Instance.GetAll<SkillConfig>();
  579. for (int i = 0; i < allSkillConfig.Length; i++)
  580. {
  581. SkillConfig skillConfig = allSkillConfig[i];
  582. if (skillConfig.level == testHeroInfoConfig.skillStart)
  583. {
  584. SkillInfo skillInfo = new SkillInfo(skillConfig.ID, testHeroInfoConfig.skillLevel);
  585. skillInfo.index = -1;
  586. GongFaControl.AddSkillInfo(skillInfo);
  587. }
  588. }
  589. AccountFileInfo.HeroData heroData = new AccountFileInfo.HeroData();
  590. heroData.heroModelId = testHeroInfoConfig.heroID;
  591. heroData.heroPowerId = testHeroInfoConfig.level;
  592. myHero = new HeroInfo();
  593. myHero.InitHero(heroData);
  594. if (testHeroInfoConfig.skill.Count > 0)
  595. {
  596. GongFaControl.allSkill.Clear();
  597. for (int i = 0; i < testHeroInfoConfig.skill.Count; i++)
  598. {
  599. SkillInfo skillInfo = new SkillInfo(testHeroInfoConfig.skill[i], testHeroInfoConfig.skillLevel,
  600. testHeroInfoConfig.skillStart);
  601. skillInfo.index = i;
  602. GongFaControl.AddSkillInfo(skillInfo);
  603. }
  604. }
  605. else
  606. {
  607. SkillInfo[] skillInfos = GongFaControl.allUseSkill;
  608. for (int i = 0; i < skillInfos.Length; i++)
  609. {
  610. if (skillInfos[i] != null)
  611. {
  612. SkillInfo skillInfo = new SkillInfo(skillInfos[i].skillConfig.IDGroup,
  613. testHeroInfoConfig.skillLevel,
  614. testHeroInfoConfig.skillStart);
  615. skillInfo.index = i;
  616. GongFaControl.allUseSkill[i] = skillInfo;
  617. }
  618. }
  619. }
  620. if (testHeroInfoConfig.magicWeaponId.Count > 0)
  621. {
  622. int fbLevel = ((testHeroInfoConfig.level - 1) / 10) + 1;
  623. if (fbLevel <= 0)
  624. {
  625. fbLevel = 1;
  626. }
  627. for (int i = 0; i < testHeroInfoConfig.magicWeaponId.Count; i++)
  628. {
  629. FaBaoInfo faBaoInfo = new FaBaoInfo(testHeroInfoConfig.magicWeaponId[i], fbLevel);
  630. faBaoInfo.FaBaoData.useIndex = i;
  631. FaBaoControl.FightFaBao[i] = faBaoInfo;
  632. FaBaoControl.AddFaBao(faBaoInfo);
  633. }
  634. }
  635. float[] qiangDu = new float[] { 0, 35.7f, 98f, 138.7f, 199.3f, 216f };
  636. int qiangDuLevelId = Mathf.CeilToInt(testHeroInfoConfig.level / 5f);
  637. HeroQiangDuAddConfig heroQiangDuAddConfig = ConfigComponent.Instance.Get<HeroQiangDuAddConfig>(qiangDuLevelId);
  638. int index = Mathf.RoundToInt(heroQiangDuAddConfig.qiangDuZhi) - 1;
  639. myHero.hp = (EncryptionLong)(myHero.hp.Value * (qiangDu[index] / 100f + 1));
  640. myHero.attack = (EncryptionLong)(myHero.attack.Value * (qiangDu[index] / 100f + 1));
  641. myHero.defense = (EncryptionLong)(myHero.defense.Value * (qiangDu[index] / 100f + 1));
  642. // for (int i = 0; i < 4; i++)
  643. // {
  644. // FaBaoControl.FightFaBao[i] = FaBaoControl.myAllFaBao[i];
  645. // }
  646. myHero.hp += testHeroInfoConfig.hp;
  647. myHero.attack += testHeroInfoConfig.att;
  648. myHero.defense += testHeroInfoConfig.def;
  649. myHero.Metal += testHeroInfoConfig.jing;
  650. myHero.Wood += testHeroInfoConfig.mu;
  651. myHero.Water += testHeroInfoConfig.shui;
  652. myHero.Fire += testHeroInfoConfig.huo;
  653. myHero.Earth += testHeroInfoConfig.tu;
  654. myHero.TaoismSkillId = 601011;
  655. myHero.MagicWeaponID.Clear();
  656. myHero.MagicWeaponID.AddRange(FaBaoControl.FightFaBao);
  657. // for (int i = 0; i < FaBaoControl.FightFaBao.Length; i++)
  658. // {
  659. // FaBaoInfo faBaoInfo = FaBaoControl.FightFaBao[i];
  660. // if (faBaoInfo != null)
  661. // {
  662. // foreach (var VARIABLE in faBaoInfo.attriButedIC)
  663. // {
  664. // switch (VARIABLE.Key)
  665. // {
  666. // case 1:
  667. // myHero.hp += VARIABLE.Value;
  668. // break;
  669. // case 2:
  670. // myHero.defense += VARIABLE.Value;
  671. // break;
  672. // case 3:
  673. // myHero.attack += VARIABLE.Value;
  674. // break;
  675. // }
  676. // }
  677. // }
  678. // }
  679. }
  680. /// <summary>
  681. /// 保存英雄数据
  682. /// </summary>
  683. /// <param name="heroInfo"></param>
  684. public void SaveHeroData(HeroInfo heroInfo)
  685. {
  686. AccountFileInfo.Instance.playerData.heroData = heroInfo.heroData;
  687. AccountFileInfo.Instance.SavePlayerData();
  688. }
  689. /// <summary>
  690. /// 时间(秒)转换位小时分钟秒
  691. /// </summary>
  692. /// <param name="miao"></param>
  693. /// <returns></returns>
  694. public static string TimeToHSM(long miao)
  695. {
  696. long fen = miao / 60;
  697. miao = miao % 60;
  698. long xiaoShi = fen / 60;
  699. long tian = xiaoShi / 24;
  700. xiaoShi = xiaoShi % 24;
  701. fen = fen % 60;
  702. if (tian > 0)
  703. {
  704. return $"{tian}天{xiaoShi}小時";
  705. }
  706. else
  707. {
  708. if (xiaoShi <= 0 && fen <= 59)
  709. {
  710. return $"{fen}分{miao}秒";
  711. }
  712. else
  713. {
  714. return $"{xiaoShi}小時{fen}分";
  715. }
  716. }
  717. }
  718. }