FightDataManager.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  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. List<CardData> arrayList = new List<CardData>(cardList);
  208. for (int i = arrayList.Count - 1; i >= 0; i--)
  209. {
  210. List<int> skillLvs = SkillDataManager.Instance.GetCardSkillLvs(arrayList[i].id);
  211. if (skillLvs.Count == 0)
  212. {
  213. ET.Log.Error("卡牌:" + arrayList[i].id + " 未配置技能");
  214. arrayList.RemoveAt(i);
  215. }
  216. }
  217. int baseScore = RoleLevelCfgArray.Instance.GetCfg(RoleDataManager.lvl).baseScore;
  218. int leagueSkillScore = LeagueDataManager.Instance.GetAllSkillScore(scoreType);
  219. arrayList.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. 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. double scoreA = GetSkillFightScore(itemSum, baseScore, leagueSkillScore, a.id, a.scores[scoreType], skillLvsA) + addA;
  226. double scoreB = GetSkillFightScore(itemSum, baseScore, leagueSkillScore, b.id, b.scores[scoreType], skillLvsB) + addB;
  227. if (scoreA < scoreB)
  228. {
  229. return 1;
  230. }
  231. else if (scoreA > scoreB)
  232. {
  233. return -1;
  234. }
  235. return string.Compare(a.itemCfg.res, b.itemCfg.res);
  236. });
  237. return arrayList;
  238. }
  239. /// <summary>
  240. /// 获取技能战力
  241. /// </summary>
  242. /// <param name="itemScoreSum"></param>
  243. /// <param name="baseScore"></param>
  244. /// <param name="cardId"></param>
  245. /// <param name="cardScore"></param>
  246. /// <param name="skillLvs"></param>
  247. /// <returns></returns>
  248. public long GetSkillFightScore(double itemScoreSum, int baseScore, long leagueSkillScore, int cardId, int cardScore, List<int> skillLvs)
  249. {
  250. float skillScore = 0;
  251. float skillBaseScore = (long)itemScoreSum + cardScore + baseScore + leagueSkillScore;
  252. List<PassivitySkillCfg> skillCfgs = PassivitySkillCfgArray.Instance.GetCfgsBycardId(cardId);
  253. for (int j = 0; j < skillCfgs.Count; j++)
  254. {
  255. if (skillLvs.Count == 0) continue;
  256. PassivitySkillLvlCfg skillLvlCfg = PassivitySkillLvlCfgArray.Instance.GetCfgByskilllvlAndskillId(skillLvs[j], skillCfgs[j].skillId);
  257. if (skillLvlCfg == null) continue;
  258. skillScore += skillBaseScore * ((float)skillLvlCfg.fightPowerParam / 10000f);
  259. }
  260. // ET.Log.Debug("cardId:" + cardId);
  261. // ET.Log.Debug("skillScore:" + skillScore);
  262. return (long)Math.Ceiling(skillScore); ;
  263. }
  264. /// <summary>
  265. /// 获取快速挑战结果
  266. /// </summary>
  267. /// <param name="myRoleData"></param>
  268. /// <param name="targetType"></param>
  269. /// <param name="targetRoleData"></param>
  270. /// <param name="targetRobotData"></param>
  271. /// <param name="_score"></param>
  272. /// <param name="_targetScore"></param>
  273. public void GetQuickFightResult(int roundIndex, FightData myRoleData, FightData targetRoleData, out long _score, out long _targetScore)
  274. {
  275. double score = 0;
  276. double targetScore = 0;
  277. int cardId = myRoleData.cardId;
  278. double mainScore = ScoreSystemData.Instance.GetMainScore(myRoleData);
  279. List<int> skillLvs = myRoleData.skillLvs;
  280. int targetCardId;
  281. double targetMainScore;
  282. List<int> targetSkillLvs;
  283. List<int> targetRoundTime;
  284. List<int> roundTime = ScoreSystemData.Instance.GetRoundTime(myRoleData.cardId, myRoleData.skillLvs);
  285. targetCardId = targetRoleData.cardId;
  286. targetSkillLvs = targetRoleData.skillLvs;
  287. targetRoundTime = ScoreSystemData.Instance.GetRoundTime(targetRoleData.cardId, targetRoleData.skillLvs);
  288. if (targetRoleData.type == FightTargetType.PLAYER)
  289. {
  290. targetMainScore = ScoreSystemData.Instance.GetMainScore(targetRoleData);
  291. }
  292. else
  293. {
  294. targetMainScore = ScoreSystemData.Instance.GetRobotMainScore(targetRoleData);
  295. }
  296. if (InstanceZonesDataManager.FightScene == ConstInstanceZonesType.Arena)
  297. {
  298. ArenaDataManager.Instance.roundTime = roundTime;
  299. ArenaDataManager.Instance.targetRoundTime = targetRoundTime;
  300. if (!ArenaDataManager.Instance.vaildSkills.ContainsKey(roundIndex)) ArenaDataManager.Instance.vaildSkills[roundIndex] = new Dictionary<int, Dictionary<int, List<PassivitySkillLvlCfg>>>();
  301. if (!ArenaDataManager.Instance.targetVaildSkills.ContainsKey(roundIndex)) ArenaDataManager.Instance.targetVaildSkills[roundIndex] = new Dictionary<int, Dictionary<int, List<PassivitySkillLvlCfg>>>();
  302. }
  303. int partId = 0;
  304. int currentTime = BeginTime.PART_ALL_FIGHT_BEGIN;
  305. GetSkillScore(FightRoleType.MINE, roundIndex, currentTime, partId, mainScore, cardId, skillLvs, roundTime, ref score, targetMainScore, targetCardId, targetSkillLvs, targetRoundTime, ref targetScore);
  306. GetSkillScore(FightRoleType.TAEGET, roundIndex, currentTime, partId, targetMainScore, targetCardId, targetSkillLvs, targetRoundTime, ref targetScore, mainScore, cardId, skillLvs, roundTime, ref score);
  307. for (int i = 0; i < FightScoreCfgArray.Instance.dataArray.Length; i++)
  308. {
  309. partId++;
  310. currentTime = BeginTime.PART_FIGHT_BEGIN;
  311. GetSkillScore(FightRoleType.MINE, roundIndex, currentTime, partId, mainScore, cardId, skillLvs, roundTime, ref score, targetMainScore, targetCardId, targetSkillLvs, targetRoundTime, ref targetScore);
  312. GetSkillScore(FightRoleType.TAEGET, roundIndex, currentTime, partId, targetMainScore, targetCardId, targetSkillLvs, targetRoundTime, ref targetScore, mainScore, cardId, skillLvs, roundTime, ref score);
  313. score += ScoreSystemData.Instance.GetPartScore(myRoleData, partId, ClickType.PREFACT_CLICK, 0);
  314. if (targetRoleData.type == FightTargetType.PLAYER)
  315. {
  316. targetScore += ScoreSystemData.Instance.GetPartScore(targetRoleData, partId, ClickType.PREFACT_CLICK, 0);
  317. }
  318. else
  319. {
  320. targetScore += ScoreSystemData.Instance.GetRobotPartScore(targetRoleData, partId, ClickType.PREFACT_CLICK, 0);
  321. }
  322. currentTime = BeginTime.PART_PREFACT_CLICK;
  323. GetSkillScore(FightRoleType.MINE, roundIndex, currentTime, partId, mainScore, cardId, skillLvs, roundTime, ref score, targetMainScore, targetCardId, targetSkillLvs, targetRoundTime, ref targetScore);
  324. GetSkillScore(FightRoleType.TAEGET, roundIndex, currentTime, partId, targetMainScore, targetCardId, targetSkillLvs, targetRoundTime, ref targetScore, mainScore, cardId, skillLvs, roundTime, ref score);
  325. currentTime = BeginTime.PART_FIGHT_END;
  326. GetSkillScore(FightRoleType.MINE, roundIndex, currentTime, partId, mainScore, cardId, skillLvs, roundTime, ref score, targetMainScore, targetCardId, targetSkillLvs, targetRoundTime, ref targetScore);
  327. GetSkillScore(FightRoleType.TAEGET, roundIndex, currentTime, partId, targetMainScore, targetCardId, targetSkillLvs, targetRoundTime, ref targetScore, mainScore, cardId, skillLvs, roundTime, ref score);
  328. // Debug.Log(" targetScore444:" + targetScore);
  329. }
  330. partId++;
  331. currentTime = BeginTime.ALL_PERFECT_START;
  332. GetSkillScore(FightRoleType.MINE, roundIndex, currentTime, partId, mainScore, cardId, skillLvs, roundTime, ref score, targetMainScore, targetCardId, targetSkillLvs, targetRoundTime, ref targetScore);
  333. GetSkillScore(FightRoleType.TAEGET, roundIndex, currentTime, partId, targetMainScore, targetCardId, targetSkillLvs, targetRoundTime, ref targetScore, mainScore, cardId, skillLvs, roundTime, ref score);
  334. score += ScoreSystemData.Instance.GetAllCircleAddScore(mainScore);
  335. targetScore += ScoreSystemData.Instance.GetAllCircleAddScore(targetMainScore);
  336. Debug.Log(" targetScore666:" + targetScore);
  337. _score = Mathf.CeilToInt((float)score);
  338. _targetScore = Mathf.CeilToInt((float)targetScore);
  339. }
  340. 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)
  341. {
  342. List<PassivitySkillLvlCfg> vaildSkills = ScoreSystemData.Instance.GetValidSkills(currentTime, partId, cardId, skillLvs, targetCardId, targetSkillLvs, roundTime, targetRoundTime);
  343. ScoreSystemData.Instance.GetPartItemSkillScore(vaildSkills, mainScore, targetMainScore, out int skillScore, out int targetSkillScore, out Dictionary<int, int> skillScoreDic);
  344. score += skillScore;
  345. targetScore += targetSkillScore;
  346. if (InstanceZonesDataManager.FightScene == ConstInstanceZonesType.Arena)
  347. {
  348. ArenaDataManager dataManager = ArenaDataManager.Instance;
  349. if (roleType == FightRoleType.MINE)
  350. {
  351. if (!dataManager.vaildSkills[roundIndex].ContainsKey(partId)) dataManager.vaildSkills[roundIndex][partId] = new Dictionary<int, List<PassivitySkillLvlCfg>>();
  352. dataManager.vaildSkills[roundIndex][partId][currentTime] = vaildSkills;
  353. }
  354. else
  355. {
  356. if (!dataManager.targetVaildSkills[roundIndex].ContainsKey(partId)) dataManager.targetVaildSkills[roundIndex][partId] = new Dictionary<int, List<PassivitySkillLvlCfg>>();
  357. dataManager.targetVaildSkills[roundIndex][partId][currentTime] = vaildSkills;
  358. }
  359. }
  360. }
  361. }
  362. }