FightDataManager.cs 18 KB

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