PlayerManager.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878
  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. HeroPowerUpConfig[] heroPowerUpConfigs = ConfigComponent.Instance.GetAll<HeroPowerUpConfig>();
  225. DaoyouModelConfig daoyouModelConfig = ConfigComponent.Instance.Get<DaoyouModelConfig>(daoYouData.id);
  226. int level = (int)(myHero.level.Value * daoyouModelConfig.growupRate * 0.01f);
  227. if (level < 1) level = 1;
  228. if (level > heroPowerUpConfigs.Length) level = heroPowerUpConfigs.Length;
  229. return level;
  230. }
  231. public int GetBl(AccountFileInfo.DaoYouData daoYouData, int guajibuffId)
  232. {
  233. DaoyouLevelupConfig daoyouLevelupConfig =
  234. ConfigComponent.Instance.Get<DaoyouLevelupConfig>(daoYouData.favorabilityLv);
  235. int level = GetDaoYouLevel(daoYouData);
  236. DaoyouguajiResourcLevel daoyouguajiResourcLevel = ConfigComponent.Instance.Get<DaoyouguajiResourcLevel>(level);
  237. guajibuff guajibuff = ConfigComponent.Instance.Get<guajibuff>(guajibuffId);
  238. int levelBl = 0;
  239. int bl = 0;
  240. switch (guajibuff.paraValue)
  241. {
  242. case 1:
  243. levelBl = daoyouguajiResourcLevel.para1;
  244. bl = (int)(guajibuff.GivingRate * levelBl * daoyouLevelupConfig.guajiGrowup * 0.01f * 0.01f);
  245. return bl;
  246. break;
  247. case 2:
  248. levelBl = daoyouguajiResourcLevel.para2;
  249. bl = (int)(guajibuff.GivingRate * levelBl * daoyouLevelupConfig.guajiGrowup * 0.01f * 0.01f);
  250. return bl;
  251. break;
  252. case 3:
  253. levelBl = daoyouguajiResourcLevel.para3;
  254. bl = (int)(guajibuff.GivingRate * levelBl * daoyouLevelupConfig.guajiGrowup * 0.01f * 0.01f);
  255. return bl;
  256. break;
  257. case 4:
  258. levelBl = daoyouguajiResourcLevel.para4;
  259. bl = (int)(guajibuff.GivingRate * levelBl * daoyouLevelupConfig.guajiGrowup * 0.01f * 0.01f);
  260. return bl;
  261. break;
  262. case 5:
  263. levelBl = daoyouguajiResourcLevel.para5;
  264. bl = (int)(guajibuff.GivingRate * levelBl * daoyouLevelupConfig.guajiGrowup * 0.01f * 0.001f);
  265. return bl;
  266. break;
  267. default:
  268. return 0;
  269. }
  270. }
  271. private void SetConfigs()
  272. {
  273. gameConstantConfig = ConfigComponent.Instance.Get<GameConstantConfig>(1);
  274. }
  275. private void InitGameData()
  276. {
  277. GongFaControl = new GongFaControl();
  278. FaBaoControl = new FaBaoControl();
  279. BagController = new BagController();
  280. HeroInfo heroInfo = new HeroInfo();
  281. AccountFileInfo.Instance.playerData.heroData.TaoismSkillId = 601011;
  282. heroInfo.InitHero(AccountFileInfo.Instance.playerData.heroData);
  283. myHero = heroInfo;
  284. myHero.TaoismSkillId = 601011;
  285. yindaoHeroData = new HeroInfo();
  286. yindaoHeroData.InitMonster(102, 200);
  287. yindaoHeroData.isMonster = false;
  288. // yindaoHeroData = heroInfo;
  289. yindaoHeroData.TaoismSkillId = 601011;
  290. // myHero= yindaoHeroData;
  291. BagController.Init();
  292. //初始化关卡
  293. CurrentsmallPlaces = GetSmallPlacesData(GetMaxSmallPlacesId());
  294. StaticUpdater.Instance.RemoveRenderUpdateCallBack(Update);
  295. StaticUpdater.Instance.AddRenderUpdateCallBack(Update);
  296. EventManager.Instance.AddEventListener(CustomEventType.CloseLoadingUI, CloseLoadingUI);
  297. }
  298. private void CloseLoadingUI(IEventData e)
  299. {
  300. _cTask?.SetResult();
  301. }
  302. private float timer;
  303. public int GetMaxSmallPlacesId()
  304. {
  305. int placesId = AccountFileInfo.Instance.playerData.smallPlacesDatas.Max(p => p.id);
  306. return placesId;
  307. }
  308. public AccountFileInfo.PlacesData GetPlacesData(int placesId)
  309. {
  310. return AccountFileInfo.Instance.playerData.placesDatas.FirstOrDefault(p => p.id == placesId);
  311. }
  312. public AccountFileInfo.SmallPlacesData GetSmallPlacesData(int smallPlacesId)
  313. {
  314. return AccountFileInfo.Instance.playerData.smallPlacesDatas.FirstOrDefault(p => p.id == smallPlacesId);
  315. }
  316. public float GetMapBl(int map)
  317. {
  318. SmallPlacesConfig smallPlacesConfig = ConfigComponent.Instance.Get<SmallPlacesConfig>(map);
  319. AccountFileInfo.PlacesData placesData = GetPlacesData(smallPlacesConfig.PlacesId);
  320. if (placesData == null)
  321. return 0;
  322. PlacesConfig placesConfig = ConfigComponent.Instance.Get<PlacesConfig>(smallPlacesConfig.PlacesId);
  323. if (placesConfig.TotalScore == 0)
  324. {
  325. return 0;
  326. }
  327. return (float)Math.Round(((float)placesData.progress / placesConfig.TotalScore) * 100, 1);
  328. }
  329. private bool isUpdate = false;
  330. private void Update()
  331. {
  332. if (!TimeHelper.IsNetworkTimeReady)
  333. {
  334. LogTool.Error($"获取网络时间失败,挂机奖励停止计算");
  335. return;
  336. }
  337. timer += Time.deltaTime;
  338. if (timer > 1)
  339. {
  340. timer = 0;
  341. if (AccountFileInfo.Instance.playerData.QiankundaiDropTimer <= gameConstantConfig.qiankundaiMaxTime)
  342. {
  343. AccountFileInfo.Instance.playerData.QiankundaiDropTimer++;
  344. QianKunDaiAward();
  345. AccountFileInfo.Instance.SavePlayerData();
  346. }
  347. }
  348. //每天刷新
  349. EveryDayRefence();
  350. foreach (var keyValuePair in AccountFileInfo.Instance.playerData.daoYouGuaiJiDatas)
  351. {
  352. if (!keyValuePair.isLeave && TimeHelper.ClientNow() > keyValuePair.leaveTime)
  353. {
  354. //判断概率给奖励
  355. isUpdate = true;
  356. keyValuePair.isLeave = true;
  357. AccountFileInfo.DaoYouData daoYouData =
  358. AccountFileInfo.Instance.playerData.daoYouDatas.FirstOrDefault(d =>
  359. d.id == keyValuePair.daoyouDataID);
  360. DaoyouModelConfig daoyouModelConfig =
  361. ConfigComponent.Instance.Get<DaoyouModelConfig>(daoYouData.id);
  362. int bl = GetBl(daoYouData, daoyouModelConfig.guajiBuffID[0]);
  363. int randomValue1 = Random.Range(0, 101);
  364. LogTool.Log("道友随机怪率:" + randomValue1 + " 比例:" + bl);
  365. List<AccountFileInfo.ItemData> itemDatas = new List<AccountFileInfo.ItemData>();
  366. if (randomValue1 < bl)
  367. {
  368. for (var i = 1; i < daoyouModelConfig.guajiBuffID.Length; i++)
  369. {
  370. int count = GetBl(daoYouData, daoyouModelConfig.guajiBuffID[i]);
  371. guajibuff guajibuff =
  372. ConfigComponent.Instance.Get<guajibuff>(daoyouModelConfig.guajiBuffID[i]);
  373. switch (guajibuff.paraValue)
  374. {
  375. case 1:
  376. itemDatas.Add(new AccountFileInfo.ItemData(1003, count));
  377. LogTool.Log("道友获得道具id:" + 1003 + " 数量:" + count);
  378. break;
  379. case 2:
  380. itemDatas.Add(new AccountFileInfo.ItemData(1001, count));
  381. LogTool.Log("道友获得道具id:" + 1001 + " 数量:" + count);
  382. break;
  383. case 3:
  384. itemDatas.Add(new AccountFileInfo.ItemData(1005, count));
  385. LogTool.Log("道友获得道具id:" + 1005 + " 数量:" + count);
  386. break;
  387. case 4:
  388. itemDatas.Add(new AccountFileInfo.ItemData(1006, count));
  389. LogTool.Log("道友获得道具id:" + 1006 + " 数量:" + count);
  390. break;
  391. }
  392. }
  393. }
  394. keyValuePair.items.AddRange(itemDatas);
  395. }
  396. }
  397. if (isUpdate)
  398. {
  399. AccountFileInfo.Instance.SavePlayerData();
  400. EventManager.Instance.Dispatch(CustomEventType.DaoYouCounUpdate, null);
  401. isUpdate = false;
  402. }
  403. }
  404. private void EveryDayRefence()
  405. {
  406. if (TimeHelper.ClientNow() > AccountFileInfo.Instance.playerData.nextRefence)
  407. {
  408. //每天删一次日志
  409. if (File.Exists(Path.Combine(Application.persistentDataPath, "GameLog.txt")))
  410. {
  411. File.Delete(Path.Combine(Application.persistentDataPath, "GameLog.txt"));
  412. }
  413. AccountFileInfo.Instance.playerData.todayTotalAds = 0;
  414. AccountFileInfo.Instance.playerData.nextRefence =
  415. TimeHelper.GetBaseRefreshTime(TimeHelper.ClientNow());
  416. AccountFileInfo.Instance.playerData.todayUseExpElixrPanelCount = 0;
  417. AccountFileInfo.Instance.playerData.todayDivineSensePoint = 0;
  418. foreach (var playerDataSummonData in AccountFileInfo.Instance.playerData.SummonDatas)
  419. {
  420. playerDataSummonData.onePayCount = 0;
  421. playerDataSummonData.tenPayCount = 0;
  422. playerDataSummonData.oneFreeCount = 0;
  423. playerDataSummonData.nextOneFreeTime = 0;
  424. playerDataSummonData.tenFreeCount = 0;
  425. playerDataSummonData.nextTenFreeTime = 0;
  426. }
  427. AccountFileInfo.Instance.SavePlayerData();
  428. }
  429. }
  430. public async CTask ChangeMap(int mapId, bool isShowUI = true)
  431. {
  432. SmallPlacesConfig currentSmallPlacesConfig =
  433. ConfigComponent.Instance.Get<SmallPlacesConfig>(PlayerManager.Instance.CurrentsmallPlaces.id);
  434. SmallPlacesConfig smallPlacesConfig = ConfigComponent.Instance.Get<SmallPlacesConfig>(mapId);
  435. if (smallPlacesConfig.ID == 0)
  436. return;
  437. AccountFileInfo.SmallPlacesData lastSmallPlacesData =
  438. PlayerManager.Instance.GetSmallPlacesData(smallPlacesConfig.ID - 1);
  439. SmallPlacesConfig lastSmallPlacesConfig =
  440. ConfigComponent.Instance.Get<SmallPlacesConfig>(smallPlacesConfig.ID - 1);
  441. if (smallPlacesConfig.ID > 1 && (lastSmallPlacesData == null ||
  442. lastSmallPlacesData.completionEventCount <
  443. lastSmallPlacesConfig.CompletionEventCount))
  444. {
  445. return;
  446. }
  447. if (lastSmallPlacesConfig.UnlockEnvetid != 0)
  448. {
  449. AccountFileInfo.EventList eventList =
  450. AccountFileInfo.Instance.playerData.completeEvents.FirstOrDefault(ce =>
  451. ce.eventID == lastSmallPlacesConfig.UnlockEnvetid);
  452. if (eventList == null || !eventList.isCompleted)
  453. {
  454. return;
  455. }
  456. }
  457. UIManager.Instance.HindCurrAllShowPanel();
  458. _cTask = CTask.Create();
  459. AccountFileInfo.SmallPlacesData smallPlacesData =
  460. PlayerManager.Instance.GetSmallPlacesData(smallPlacesConfig.ID);
  461. if (smallPlacesData == null)
  462. {
  463. smallPlacesData = new AccountFileInfo.SmallPlacesData();
  464. smallPlacesData.id = smallPlacesConfig.ID;
  465. AccountFileInfo.Instance.playerData.smallPlacesDatas.Add(smallPlacesData);
  466. }
  467. AccountFileInfo.PlacesData currentPlacesData = PlayerManager.Instance.GetPlacesData(smallPlacesConfig.ID);
  468. if (currentPlacesData == null)
  469. {
  470. currentPlacesData = new AccountFileInfo.PlacesData();
  471. currentPlacesData.id = smallPlacesConfig.PlacesId;
  472. AccountFileInfo.Instance.playerData.placesDatas.Add(currentPlacesData);
  473. }
  474. PlayerManager.Instance.CurrentsmallPlaces = smallPlacesData;
  475. if (currentSmallPlacesConfig.PlacesId == smallPlacesConfig.PlacesId)
  476. {
  477. CombatController.currActiveCombat.ChangeState(CombatController.miniSceneSwitch);
  478. }
  479. else
  480. {
  481. CombatController.currActiveCombat.ChangeState(CombatController.sceneSwitch);
  482. }
  483. await _cTask;
  484. if (isShowUI)
  485. UIManager.Instance.ShowLastHindAllShowPanel();
  486. EventManager.Instance.Dispatch(CustomEventType.ChangeMap, null);
  487. }
  488. public void QianKunDaiAward()
  489. {
  490. foreach (var playerDataQiankundaiData in AccountFileInfo.Instance.playerData.QiankundaiDatas)
  491. {
  492. //重置掉落次数
  493. QiankundaiConfig qiankundaiConfig =
  494. ConfigComponent.Instance.Get<QiankundaiConfig>(playerDataQiankundaiData.id);
  495. if (qiankundaiConfig.dropType != 2 &&
  496. TimeHelper.ClientNow() >= playerDataQiankundaiData.refenceTime)
  497. {
  498. if (qiankundaiConfig.dropPara1 == 1)
  499. {
  500. playerDataQiankundaiData.refenceTime = TimeHelper.ClientNow() + 60 * 60 * 1000;
  501. }
  502. else if (qiankundaiConfig.dropPara1 == 2)
  503. {
  504. playerDataQiankundaiData.refenceTime =
  505. TimeHelper.GetBaseRefreshTime(TimeHelper.ClientNow());
  506. }
  507. else if (qiankundaiConfig.dropPara1 == 3)
  508. {
  509. }
  510. playerDataQiankundaiData.dropCount = 0;
  511. }
  512. if (myHero.powerUpConfig.ID >= qiankundaiConfig.dropLevel[0] &&
  513. myHero.powerUpConfig.ID <= qiankundaiConfig.dropLevel[1])
  514. {
  515. if (playerDataQiankundaiData.dropCount < qiankundaiConfig.dropPara2 ||
  516. qiankundaiConfig.dropPara2 == -1)
  517. {
  518. playerDataQiankundaiData.dropTime++;
  519. if (playerDataQiankundaiData.dropTime >= qiankundaiConfig.dropTypePara)
  520. {
  521. //发放奖励
  522. for (var i = 0; i < qiankundaiConfig.ChoukaID.Length; i++)
  523. {
  524. List<ItemInfo> itemInfos = DropManager.Instance.Drop(qiankundaiConfig.ChoukaID[i],
  525. qiankundaiConfig.DropCount[i]);
  526. foreach (var itemInfo in itemInfos)
  527. {
  528. AccountFileInfo.ItemData itemData =
  529. AccountFileInfo.Instance.playerData.QiankundaiItemDatas.FirstOrDefault(i =>
  530. i.itemId == itemInfo.itemID);
  531. if (itemData != null)
  532. {
  533. itemData.itemCount += itemInfo.count.Value;
  534. }
  535. else
  536. {
  537. itemData = itemInfo.ToItemData();
  538. AccountFileInfo.Instance.playerData.QiankundaiItemDatas.Add(itemData);
  539. }
  540. }
  541. }
  542. playerDataQiankundaiData.dropCount = 0;
  543. playerDataQiankundaiData.dropTime = 0;
  544. }
  545. }
  546. }
  547. // AccountFileInfo.Instance.SavePlayerData();
  548. }
  549. }
  550. public void CalculateOfflineRewards()
  551. {
  552. int exitMiao = (int)((TimeHelper.ClientNow() - AccountFileInfo.Instance.playerData.ExitTime) / 1000);
  553. if (exitMiao <= 0)
  554. return;
  555. if (AccountFileInfo.Instance.playerData.QiankundaiDropTimer <=
  556. gameConstantConfig.qiankundaiMaxTime &&
  557. exitMiao > 0)
  558. {
  559. int miao = AccountFileInfo.Instance.playerData.QiankundaiDropTimer + exitMiao;
  560. miao = miao >= gameConstantConfig.qiankundaiMaxTime
  561. ? gameConstantConfig.qiankundaiMaxTime - AccountFileInfo.Instance.playerData.QiankundaiDropTimer
  562. : exitMiao;
  563. AccountFileInfo.Instance.playerData.QiankundaiDropTimer += miao;
  564. for (int i = 0; i < miao; i++)
  565. {
  566. QianKunDaiAward();
  567. }
  568. }
  569. HeroPowerUpConfig heroPowerUpConfig = myHero.powerUpConfig;
  570. if (AccountFileInfo.Instance.playerData.divineSensePoint < heroPowerUpConfig.ShenshiMax)
  571. {
  572. int miao = 0;
  573. if (AccountFileInfo.Instance.playerData.todayDivineSensePoint <
  574. gameConstantConfig.shenshiPointRecSPD[0])
  575. {
  576. float todayResidueShenShi = gameConstantConfig.shenshiPointRecSPD[0] -
  577. AccountFileInfo.Instance.playerData.todayDivineSensePoint;
  578. todayResidueShenShi =
  579. AccountFileInfo.Instance.playerData.divineSensePoint + todayResidueShenShi >
  580. heroPowerUpConfig.ShenshiMax
  581. ? heroPowerUpConfig.ShenshiMax - AccountFileInfo.Instance.playerData.divineSensePoint
  582. : todayResidueShenShi;
  583. miao = (int)(todayResidueShenShi / gameConstantConfig.shenshiPointRecSPD[1]);
  584. miao = miao > exitMiao ? exitMiao : miao;
  585. float todayResidue = gameConstantConfig.shenshiPointRecSPD[1] * miao;
  586. todayResidue = todayResidue + AccountFileInfo.Instance.playerData.divineSensePoint >
  587. heroPowerUpConfig.ShenshiMax
  588. ? heroPowerUpConfig.ShenshiMax - AccountFileInfo.Instance.playerData.divineSensePoint
  589. : todayResidue;
  590. if (todayResidue < 0)
  591. todayResidue = 0;
  592. AccountFileInfo.Instance.playerData.todayDivineSensePoint += todayResidue;
  593. AccountFileInfo.Instance.playerData.divineSensePoint += todayResidue;
  594. }
  595. int residueExitMiao = exitMiao - miao;
  596. if (residueExitMiao > 0)
  597. {
  598. float todaySs2 = gameConstantConfig.shenshiPointRecSPD[2] * residueExitMiao;
  599. float allShenshi = todaySs2 + AccountFileInfo.Instance.playerData.divineSensePoint;
  600. todaySs2 = allShenshi > heroPowerUpConfig.ShenshiMax
  601. ? heroPowerUpConfig.ShenshiMax - AccountFileInfo.Instance.playerData.divineSensePoint
  602. : todaySs2;
  603. if (todaySs2 < 0)
  604. todaySs2 = 0;
  605. AccountFileInfo.Instance.playerData.divineSensePoint += todaySs2;
  606. }
  607. }
  608. EventManager.Instance.Dispatch(CustomEventType.DivineSensePointChange, null);
  609. AccountFileInfo.Instance.playerData.ExitTime = 0;
  610. AccountFileInfo.Instance.SavePlayerData();
  611. }
  612. public void AddTestHeroInfo(TestCombatHeroConfig.TestHeroInfoConfig testHeroInfoConfig)
  613. {
  614. isTest = true;
  615. GongFaControl.allSkill.Clear();
  616. SkillConfig[] allSkillConfig = ConfigComponent.Instance.GetAll<SkillConfig>();
  617. for (int i = 0; i < allSkillConfig.Length; i++)
  618. {
  619. SkillConfig skillConfig = allSkillConfig[i];
  620. if (skillConfig.level == testHeroInfoConfig.skillStart)
  621. {
  622. SkillInfo skillInfo = new SkillInfo(skillConfig.ID, testHeroInfoConfig.skillLevel);
  623. skillInfo.index = -1;
  624. GongFaControl.AddSkillInfo(skillInfo);
  625. }
  626. }
  627. AccountFileInfo.HeroData heroData = new AccountFileInfo.HeroData();
  628. heroData.heroModelId = testHeroInfoConfig.heroID;
  629. heroData.heroPowerId = testHeroInfoConfig.level;
  630. myHero = new HeroInfo();
  631. myHero.InitHero(heroData);
  632. if (testHeroInfoConfig.skill.Count > 0)
  633. {
  634. GongFaControl.allSkill.Clear();
  635. for (int i = 0; i < testHeroInfoConfig.skill.Count; i++)
  636. {
  637. SkillInfo skillInfo = new SkillInfo(testHeroInfoConfig.skill[i], testHeroInfoConfig.skillLevel,
  638. testHeroInfoConfig.skillStart);
  639. skillInfo.index = i;
  640. GongFaControl.AddSkillInfo(skillInfo);
  641. }
  642. }
  643. else
  644. {
  645. SkillInfo[] skillInfos = GongFaControl.allUseSkill;
  646. for (int i = 0; i < skillInfos.Length; i++)
  647. {
  648. if (skillInfos[i] != null)
  649. {
  650. SkillInfo skillInfo = new SkillInfo(skillInfos[i].skillConfig.IDGroup,
  651. testHeroInfoConfig.skillLevel,
  652. testHeroInfoConfig.skillStart);
  653. skillInfo.index = i;
  654. GongFaControl.allUseSkill[i] = skillInfo;
  655. }
  656. }
  657. }
  658. if (testHeroInfoConfig.magicWeaponId.Count > 0)
  659. {
  660. int fbLevel = ((testHeroInfoConfig.level - 1) / 10) + 1;
  661. if (fbLevel <= 0)
  662. {
  663. fbLevel = 1;
  664. }
  665. for (int i = 0; i < testHeroInfoConfig.magicWeaponId.Count; i++)
  666. {
  667. FaBaoInfo faBaoInfo = new FaBaoInfo(testHeroInfoConfig.magicWeaponId[i], fbLevel);
  668. faBaoInfo.FaBaoData.useIndex = i;
  669. FaBaoControl.FightFaBao[i] = faBaoInfo;
  670. FaBaoControl.AddFaBao(faBaoInfo);
  671. }
  672. }
  673. float[] qiangDu = new float[] { 0, 35.7f, 98f, 138.7f, 199.3f, 216f };
  674. int qiangDuLevelId = Mathf.CeilToInt(testHeroInfoConfig.level / 5f);
  675. HeroQiangDuAddConfig heroQiangDuAddConfig = ConfigComponent.Instance.Get<HeroQiangDuAddConfig>(qiangDuLevelId);
  676. int index = Mathf.RoundToInt(heroQiangDuAddConfig.qiangDuZhi) - 1;
  677. myHero.hp = (EncryptionLong)(myHero.hp.Value * (qiangDu[index] / 100f + 1));
  678. myHero.attack = (EncryptionLong)(myHero.attack.Value * (qiangDu[index] / 100f + 1));
  679. myHero.defense = (EncryptionLong)(myHero.defense.Value * (qiangDu[index] / 100f + 1));
  680. // for (int i = 0; i < 4; i++)
  681. // {
  682. // FaBaoControl.FightFaBao[i] = FaBaoControl.myAllFaBao[i];
  683. // }
  684. myHero.hp += testHeroInfoConfig.hp;
  685. myHero.attack += testHeroInfoConfig.att;
  686. myHero.defense += testHeroInfoConfig.def;
  687. myHero.Metal += testHeroInfoConfig.jing;
  688. myHero.Wood += testHeroInfoConfig.mu;
  689. myHero.Water += testHeroInfoConfig.shui;
  690. myHero.Fire += testHeroInfoConfig.huo;
  691. myHero.Earth += testHeroInfoConfig.tu;
  692. myHero.TaoismSkillId = 601011;
  693. myHero.MagicWeaponID.Clear();
  694. myHero.MagicWeaponID.AddRange(FaBaoControl.FightFaBao);
  695. // for (int i = 0; i < FaBaoControl.FightFaBao.Length; i++)
  696. // {
  697. // FaBaoInfo faBaoInfo = FaBaoControl.FightFaBao[i];
  698. // if (faBaoInfo != null)
  699. // {
  700. // foreach (var VARIABLE in faBaoInfo.attriButedIC)
  701. // {
  702. // switch (VARIABLE.Key)
  703. // {
  704. // case 1:
  705. // myHero.hp += VARIABLE.Value;
  706. // break;
  707. // case 2:
  708. // myHero.defense += VARIABLE.Value;
  709. // break;
  710. // case 3:
  711. // myHero.attack += VARIABLE.Value;
  712. // break;
  713. // }
  714. // }
  715. // }
  716. // }
  717. }
  718. /// <summary>
  719. /// 保存英雄数据
  720. /// </summary>
  721. /// <param name="heroInfo"></param>
  722. public void SaveHeroData(HeroInfo heroInfo)
  723. {
  724. AccountFileInfo.Instance.playerData.heroData = heroInfo.heroData;
  725. AccountFileInfo.Instance.SavePlayerData();
  726. }
  727. /// <summary>
  728. /// 时间(秒)转换位小时分钟秒
  729. /// </summary>
  730. /// <param name="miao"></param>
  731. /// <returns></returns>
  732. public static string TimeToHSM(long miao)
  733. {
  734. long fen = miao / 60;
  735. miao = miao % 60;
  736. long xiaoShi = fen / 60;
  737. long tian = xiaoShi / 24;
  738. xiaoShi = xiaoShi % 24;
  739. fen = fen % 60;
  740. if (tian > 0)
  741. {
  742. return $"{tian}天{xiaoShi}小時";
  743. }
  744. else
  745. {
  746. if (xiaoShi <= 0 && fen <= 59)
  747. {
  748. return $"{fen}分{miao}秒";
  749. }
  750. else
  751. {
  752. return $"{xiaoShi}小時{fen}分";
  753. }
  754. }
  755. }
  756. }