FightDataManager.cs 17 KB

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