FightDataManager.cs 18 KB

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