FightDataManager.cs 15 KB

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