FightDataManager.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using cfg.GfgCfg;
  5. using ET;
  6. using UnityEngine;
  7. namespace GFGGame
  8. {
  9. public class FightDataManager : SingletonBase<FightDataManager>
  10. {
  11. //public byte[] FightRoleRes { get; set; }
  12. //public Texture2D RoleTextuex { get; set; }
  13. //角色基础分+部件基础分
  14. // private int _score;
  15. // public int score
  16. // {
  17. // get
  18. // {
  19. // return _score;
  20. // }
  21. // set
  22. // {
  23. // _score = value;
  24. // EventAgent.DispatchEvent(ConstMessage.DRESS_UP_SCORE_CHANGED, _score);
  25. // }
  26. // }
  27. public void Clear()
  28. {
  29. maxFightSpeed = 3;
  30. _fightSpeed = 1;
  31. _autoPlay = false;
  32. _storyDialogSpeed = 1;
  33. _totalScore = 0;
  34. _targetTotalScore = 0;
  35. }
  36. public int GetScore(FightData roleData)
  37. {
  38. float score = 0;
  39. for (int i = 0; i < roleData.itemList.Count; i++)
  40. {
  41. score += ItemDataManager.GetArenaScore(roleData.itemList[i], roleData.scoreType, roleData.tags);
  42. }
  43. if (InstanceZonesDataManager.FightScene == ConstInstanceZonesType.Arena ||
  44. InstanceZonesDataManager.FightScene == ConstInstanceZonesType.FieldWork)
  45. {
  46. int tagCount = ArenaDataManager.Instance.GetTagsCount(roleData.itemList, roleData.tags);
  47. ;
  48. tagCount = Math.Min(CommonDataManager.Tables.TblArenaTagCfg.DataList.Count, tagCount);
  49. float addition = 0;
  50. if (tagCount > 0)
  51. {
  52. int additionCfg = CommonDataManager.Tables.TblArenaTagCfg.GetOrDefault(tagCount).Addition;
  53. addition = additionCfg / 10000f;
  54. }
  55. score = score * (1 + addition);
  56. }
  57. return (int)Math.Ceiling(score);
  58. }
  59. //最终得分
  60. private int _totalScore;
  61. public int totalScore
  62. {
  63. get { return _totalScore; }
  64. set { _totalScore = value; }
  65. }
  66. //战斗对象最终得分
  67. private int _targetTotalScore;
  68. public int npcTotalScore
  69. {
  70. get { return _targetTotalScore; }
  71. set { _targetTotalScore = value; }
  72. }
  73. private bool _autoPlay = false;
  74. public bool autoPlay
  75. {
  76. get { return _autoPlay; }
  77. set
  78. {
  79. _autoPlay = value;
  80. if (!_autoPlay) fightSpeed = 1;
  81. StorageSProxy.ReqSetClientValue(ConstStorageId.STORAGE_AUTO_PLAY, _autoPlay == true ? 1 : 0)
  82. .Coroutine();
  83. }
  84. }
  85. public int maxFightSpeed = 3;
  86. private int _fightSpeed = 1;
  87. public int fightSpeed
  88. {
  89. get { return _fightSpeed; }
  90. set
  91. {
  92. _fightSpeed = value;
  93. StorageSProxy.ReqSetClientValue(ConstStorageId.STORAGE_FIGHT_AUTO_PLAY_SPEED, _fightSpeed).Coroutine();
  94. }
  95. }
  96. private int _storyDialogSpeed = 1;
  97. public int dialogSpeed
  98. {
  99. get { return _storyDialogSpeed; }
  100. set
  101. {
  102. _storyDialogSpeed = value;
  103. StorageSProxy.ReqSetClientValue(ConstStorageId.STORAGE_DIALOG_AUTO_PLAY_SPEED, _storyDialogSpeed)
  104. .Coroutine();
  105. }
  106. }
  107. //根据位置原点和随机范围获取评分位置
  108. public void GetCirclePos(Vector2 pos, int range, out float x, out float y)
  109. {
  110. int numX = UnityEngine.Random.Range(0, 2);
  111. int signX = numX % 2 == 0 ? 1 : -1;
  112. float rangeX = UnityEngine.Random.Range(0, range);
  113. x = pos.x + signX * (rangeX);
  114. int numY = UnityEngine.Random.Range(0, 2);
  115. int signY = numY % 2 == 0 ? 1 : -1;
  116. float rangeY = UnityEngine.Random.Range(0, range);
  117. y = pos.y + signY * (rangeY);
  118. }
  119. //public Texture2D GetPrintscreenNTexture(Camera camera)
  120. //{
  121. // RenderTexture rt = new RenderTexture(UnityEngine.Screen.width, UnityEngine.Screen.height, 0);//渲染一张1920*1080的图
  122. // camera.targetTexture = rt;//传到主摄像机上
  123. // camera.Render();//渲染
  124. // RenderTexture.active = rt;
  125. // Texture2D screenShot = new Texture2D(UnityEngine.Screen.width, UnityEngine.Screen.height, TextureFormat.ARGB32, false);
  126. // screenShot.ReadPixels(new Rect(0, 0, UnityEngine.Screen.width, UnityEngine.Screen.height), 0, 0);//读像素
  127. // screenShot.Apply();
  128. // camera.targetTexture = null;
  129. // RenderTexture.active = null;
  130. // UnityEngine.Object.Destroy(rt);
  131. // return screenShot;
  132. //}
  133. /// <summary>
  134. /// 获取标签总分数
  135. /// </summary>
  136. /// <param name="itemList">服装列表</param>
  137. /// <param name="tags">标签</param>
  138. /// <returns></returns>
  139. public int GetTagsScore(List<int> itemList, List<string> tags)
  140. {
  141. int score = 0;
  142. for (int i = 0; i < itemList.Count; i++)
  143. {
  144. score += ItemDataManager.GetItemTagScore(itemList[i], tags);
  145. }
  146. return score;
  147. }
  148. public void SetItemScoreList(FightData _roleData)
  149. {
  150. _roleData.itemScoreList.Clear();
  151. _roleData.itemScoreDic.Clear();
  152. for (int i = 0; i < _roleData.itemList.Count; i++)
  153. {
  154. int score = ItemDataManager.GetArenaScore(_roleData.itemList[i], _roleData.scoreType);
  155. _roleData.itemScoreList.Add(score);
  156. _roleData.itemScoreDic[_roleData.itemList[i]] = score;
  157. }
  158. }
  159. public float GetDressListAllScore(List<int> itemList, int scoreType)
  160. {
  161. float itemSum = 0;
  162. for (int i = 0; i < itemList.Count; i++)
  163. {
  164. itemSum += ItemDataManager.GetArenaScore(itemList[i], scoreType);
  165. }
  166. return itemSum;
  167. }
  168. /// <summary>
  169. /// 0失败1优秀2完美
  170. /// </summary>
  171. /// <param name="scale"></param>
  172. /// <returns></returns>
  173. public int GetClickType(float scale)
  174. {
  175. // float scaleX = _ui.m_comClick.m_comResult.m_imgCircle.scale.x;
  176. int clickType = ClickType.MISS_CLICK;
  177. if (FightDataManager.Instance.autoPlay == true)
  178. {
  179. return ClickType.PERFECT_CLICK;
  180. }
  181. if (scale <= 0.55f && scale > 0.45f)
  182. {
  183. clickType = ClickType.PERFECT_CLICK;
  184. }
  185. else if (scale <= 0.05f)
  186. {
  187. clickType = ClickType.MISS_CLICK;
  188. }
  189. else
  190. {
  191. clickType = ClickType.GOOD_CLICK;
  192. }
  193. return clickType;
  194. }
  195. /// <summary>
  196. /// 词牌列表按竞技战力排序
  197. /// </summary>
  198. /// <param name="arrayList"></param>
  199. /// <returns></returns>
  200. public List<CardData> SortCardList(List<CardData> cardList, double itemSum, int scoreType)
  201. {
  202. int baseScore = CommonDataManager.Tables.TblRoleLevelCfg.GetOrDefault(RoleDataManager.lvl).BaseScore;
  203. int leagueSkillScore = LeagueDataManager.Instance.GetAllSkillScore(scoreType);
  204. cardList.Sort((CardData a, CardData b) =>
  205. {
  206. List<int> skillLvsA = SkillDataManager.Instance.GetCardSkillLvs(a.id);
  207. List<int> skillLvsB = SkillDataManager.Instance.GetCardSkillLvs(b.id);
  208. //start===============================
  209. //double addA = a.scores[scoreType] * ConstScoreSystem.PERFECT_SCORE * ConstScoreSystem.CLICK_SCORE / ConstScoreSystem.PART_SCORE * 6d;
  210. //double addB = b.scores[scoreType] * ConstScoreSystem.PERFECT_SCORE * ConstScoreSystem.CLICK_SCORE / ConstScoreSystem.PART_SCORE * 6d;
  211. //因为这里只是排序,不需要计算完整分数
  212. //end=================================
  213. double addA = a.scores[scoreType];
  214. double addB = b.scores[scoreType];
  215. double scoreA = GetSkillFightScore(itemSum, baseScore, leagueSkillScore, a.id, a.scores[scoreType],
  216. skillLvsA) + addA;
  217. double scoreB = GetSkillFightScore(itemSum, baseScore, leagueSkillScore, b.id, b.scores[scoreType],
  218. skillLvsB) + addB;
  219. if (scoreA < scoreB)
  220. {
  221. return 1;
  222. }
  223. else if (scoreA > scoreB)
  224. {
  225. return -1;
  226. }
  227. return string.Compare(a.itemCfg.Res, b.itemCfg.Res);
  228. });
  229. return cardList;
  230. }
  231. /// <summary>
  232. /// 获取技能战力
  233. /// </summary>
  234. /// <param name="itemScoreSum"></param>
  235. /// <param name="baseScore"></param>
  236. /// <param name="cardId"></param>
  237. /// <param name="cardScore"></param>
  238. /// <param name="skillLvs"></param>
  239. /// <returns></returns>
  240. public long GetSkillFightScore(double itemScoreSum, int baseScore, long leagueSkillScore, int cardId,
  241. int cardScore, List<int> skillLvs)
  242. {
  243. float skillScore = 0;
  244. if (skillLvs.Count == 0) return (long)skillScore;
  245. float skillBaseScore = (long)itemScoreSum + cardScore + baseScore + leagueSkillScore;
  246. List<PassivitySkillCfg> skillCfgs = CommonDataManager.Tables.TblPassivitySkillCfg.DataList
  247. .Where(a => a.CardId == cardId).ToList();
  248. //容错处理,防止两个长度不一致
  249. var count = Mathf.Min(skillLvs.Count, skillCfgs.Count);
  250. for (int j = 0; j < count; j++)
  251. {
  252. PassivitySkillLvlCfg skillLvlCfg =
  253. CommonDataManager.Tables.TblPassivitySkillLvlCfg.Get(skillLvs[j], skillCfgs[j].SkillId);
  254. if (skillLvlCfg == null) continue;
  255. skillScore += skillBaseScore * ((float)skillLvlCfg.FightPowerParam / 10000f);
  256. }
  257. // ET.Log.Debug("cardId:" + cardId);
  258. // ET.Log.Debug("skillScore:" + skillScore);
  259. return (long)Math.Ceiling(skillScore);
  260. ;
  261. }
  262. /// <summary>
  263. /// 获取快速挑战结果
  264. /// </summary>
  265. /// <param name="myRoleData"></param>
  266. /// <param name="targetType"></param>
  267. /// <param name="targetRoleData"></param>
  268. /// <param name="targetRobotData"></param>
  269. /// <param name="_score"></param>
  270. /// <param name="_targetScore"></param>
  271. public void GetQuickFightResult(int roundIndex, FightData myRoleData, FightData targetRoleData, out long _score,
  272. out long _targetScore)
  273. {
  274. double score = 0;
  275. double targetScore = 0;
  276. int cardId = myRoleData.cardId;
  277. double mainScore = ScoreSystemData.Instance.GetMainScore(myRoleData);
  278. List<int> skillLvs = myRoleData.skillLvs;
  279. int targetCardId;
  280. double targetMainScore;
  281. List<int> targetSkillLvs;
  282. List<int> targetRoundTime;
  283. List<int> roundTime = ScoreSystemData.Instance.GetRoundTime(myRoleData.cardId, myRoleData.skillLvs);
  284. targetCardId = targetRoleData.cardId;
  285. targetSkillLvs = targetRoleData.skillLvs;
  286. targetRoundTime = ScoreSystemData.Instance.GetRoundTime(targetRoleData.cardId, targetRoleData.skillLvs);
  287. if (targetRoleData.type == FightTargetType.PLAYER)
  288. {
  289. targetMainScore = ScoreSystemData.Instance.GetMainScore(targetRoleData);
  290. }
  291. else
  292. {
  293. targetMainScore = ScoreSystemData.Instance.GetRobotMainScore(targetRoleData);
  294. }
  295. if (InstanceZonesDataManager.FightScene == ConstInstanceZonesType.Arena ||
  296. InstanceZonesDataManager.FightScene == ConstInstanceZonesType.FieldWork)
  297. {
  298. ArenaDataManager.Instance.roundTime = roundTime;
  299. ArenaDataManager.Instance.targetRoundTime = targetRoundTime;
  300. if (!ArenaDataManager.Instance.vaildSkills.ContainsKey(roundIndex))
  301. ArenaDataManager.Instance.vaildSkills[roundIndex] =
  302. new Dictionary<int, Dictionary<int, List<PassivitySkillLvlCfg>>>();
  303. if (!ArenaDataManager.Instance.targetVaildSkills.ContainsKey(roundIndex))
  304. ArenaDataManager.Instance.targetVaildSkills[roundIndex] =
  305. new Dictionary<int, Dictionary<int, List<PassivitySkillLvlCfg>>>();
  306. }
  307. int roundId = 0;
  308. int currentTime = SkillBeginTime.FIGHT_BEGIN;
  309. GetSkillScore(FightRoleType.MINE, roundIndex, currentTime, roundId, mainScore, cardId, skillLvs, roundTime,
  310. ref score, targetMainScore, targetCardId, targetSkillLvs, targetRoundTime, ref targetScore);
  311. GetSkillScore(FightRoleType.TAEGET, roundIndex, currentTime, roundId, targetMainScore, targetCardId,
  312. targetSkillLvs, targetRoundTime, ref targetScore, mainScore, cardId, skillLvs, roundTime, ref score);
  313. for (int i = 0; i < CommonDataManager.Tables.TblFightScoreCfg.DataList.Count; i++)
  314. {
  315. roundId++;
  316. currentTime = SkillBeginTime.ERVERY_ROUND_BEGIN;
  317. GetSkillScore(FightRoleType.MINE, roundIndex, currentTime, roundId, mainScore, cardId, skillLvs,
  318. roundTime, ref score, targetMainScore, targetCardId, targetSkillLvs, targetRoundTime,
  319. ref targetScore);
  320. GetSkillScore(FightRoleType.TAEGET, roundIndex, currentTime, roundId, targetMainScore, targetCardId,
  321. targetSkillLvs, targetRoundTime, ref targetScore, mainScore, cardId, skillLvs, roundTime,
  322. ref score);
  323. score += ScoreSystemData.Instance.GetRoundScore(myRoleData, roundId, ClickType.PERFECT_CLICK, 0);
  324. if (targetRoleData.type == FightTargetType.PLAYER)
  325. {
  326. targetScore +=
  327. ScoreSystemData.Instance.GetRoundScore(targetRoleData, roundId, ClickType.PERFECT_CLICK, 0);
  328. }
  329. else
  330. {
  331. targetScore +=
  332. ScoreSystemData.Instance.GetRobotRoundScore(targetRoleData, roundId, ClickType.PERFECT_CLICK,
  333. 0);
  334. }
  335. currentTime = SkillBeginTime.PERFECT_CLICK;
  336. GetSkillScore(FightRoleType.MINE, roundIndex, currentTime, roundId, mainScore, cardId, skillLvs,
  337. roundTime, ref score, targetMainScore, targetCardId, targetSkillLvs, targetRoundTime,
  338. ref targetScore);
  339. GetSkillScore(FightRoleType.TAEGET, roundIndex, currentTime, roundId, targetMainScore, targetCardId,
  340. targetSkillLvs, targetRoundTime, ref targetScore, mainScore, cardId, skillLvs, roundTime,
  341. ref score);
  342. currentTime = SkillBeginTime.ERVERY_ROUND_END;
  343. GetSkillScore(FightRoleType.MINE, roundIndex, currentTime, roundId, mainScore, cardId, skillLvs,
  344. roundTime, ref score, targetMainScore, targetCardId, targetSkillLvs, targetRoundTime,
  345. ref targetScore);
  346. GetSkillScore(FightRoleType.TAEGET, roundIndex, currentTime, roundId, targetMainScore, targetCardId,
  347. targetSkillLvs, targetRoundTime, ref targetScore, mainScore, cardId, skillLvs, roundTime,
  348. ref score);
  349. // Debug.Log(" targetScore444:" + targetScore);
  350. }
  351. roundId++;
  352. currentTime = SkillBeginTime.ALL_PERFECT_START;
  353. GetSkillScore(FightRoleType.MINE, roundIndex, currentTime, roundId, mainScore, cardId, skillLvs, roundTime,
  354. ref score, targetMainScore, targetCardId, targetSkillLvs, targetRoundTime, ref targetScore);
  355. GetSkillScore(FightRoleType.TAEGET, roundIndex, currentTime, roundId, targetMainScore, targetCardId,
  356. targetSkillLvs, targetRoundTime, ref targetScore, mainScore, cardId, skillLvs, roundTime, ref score);
  357. score += ScoreSystemData.Instance.GetAllCircleAddScore(myRoleData);
  358. targetScore += ScoreSystemData.Instance.GetAllCircleAddScore(targetRoleData);
  359. Debug.Log(" targetScore666:" + targetScore);
  360. _score = Mathf.CeilToInt((float)score);
  361. _targetScore = Mathf.CeilToInt((float)targetScore);
  362. }
  363. private void GetSkillScore(int roleType, int roundIndex, int currentTime, int partId, double mainScore,
  364. int cardId, List<int> skillLvs, List<int> roundTime, ref double score, double targetMainScore,
  365. int targetCardId, List<int> targetSkillLvs, List<int> targetRoundTime, ref double targetScore)
  366. {
  367. List<PassivitySkillLvlCfg> vaildSkills = ScoreSystemData.Instance.GetValidSkills(currentTime, partId,
  368. cardId, skillLvs, targetCardId, targetSkillLvs, roundTime, targetRoundTime);
  369. ScoreSystemData.Instance.GetRoundItemSkillScore(vaildSkills, mainScore, targetMainScore, out int skillScore,
  370. out int targetSkillScore, out Dictionary<int, int> skillScoreDic);
  371. score += skillScore;
  372. targetScore += targetSkillScore;
  373. if (InstanceZonesDataManager.FightScene == ConstInstanceZonesType.Arena ||
  374. InstanceZonesDataManager.FightScene == ConstInstanceZonesType.FieldWork)
  375. {
  376. ArenaDataManager dataManager = ArenaDataManager.Instance;
  377. if (roleType == FightRoleType.MINE)
  378. {
  379. if (!dataManager.vaildSkills[roundIndex].ContainsKey(partId))
  380. dataManager.vaildSkills[roundIndex][partId] = new Dictionary<int, List<PassivitySkillLvlCfg>>();
  381. dataManager.vaildSkills[roundIndex][partId][currentTime] = vaildSkills;
  382. }
  383. else
  384. {
  385. if (!dataManager.targetVaildSkills[roundIndex].ContainsKey(partId))
  386. dataManager.targetVaildSkills[roundIndex][partId] =
  387. new Dictionary<int, List<PassivitySkillLvlCfg>>();
  388. dataManager.targetVaildSkills[roundIndex][partId][currentTime] = vaildSkills;
  389. }
  390. }
  391. }
  392. }
  393. }