FightDataManager.cs 18 KB

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