FightDataManager.cs 17 KB

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