FightDataManager.cs 18 KB

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