FightDataManager.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  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. //获取玩家战斗数据
  150. private FightRoleData GetMyFightRoleData()
  151. {
  152. _roleData.name = RoleDataManager.roleName;
  153. _roleData.headId = RoleDataManager.headId;
  154. // _roleData.headBorderId = RoleDataManager.headBorderId;
  155. _roleData.baseScore = RoleLevelCfgArray.Instance.GetCfg(RoleDataManager.lvl).baseScore;//角色等级分数
  156. if (InstanceZonesDataManager.FightScene == ConstInstanceZonesType.Arena)
  157. {
  158. if (ArenaDataManager.Instance.CurFightIndex == 0)
  159. {
  160. _roleData.tags = new string[1] { ArenaDataManager.Instance.Tag };
  161. }
  162. _roleData.scoreType = ArenaDataManager.Instance.DressupList[ArenaDataManager.Instance.CurFightIndex].scoreType;
  163. _roleData.cardId = ArenaDataManager.Instance.DressupList[ArenaDataManager.Instance.CurFightIndex].cardId;
  164. _roleData.cardScore = ItemDataManager.GetItemAdditionScore(_roleData.cardId, _roleData.scoreType, _roleData.tags);
  165. _roleData.itemList = ArenaDataManager.Instance.DressupList[ArenaDataManager.Instance.CurFightIndex].itemList;
  166. }
  167. else
  168. {
  169. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(InstanceZonesDataManager.currentLevelCfgId);
  170. // roleData.fightScene = levelCfg.type;
  171. if (!string.IsNullOrEmpty(levelCfg.fightID))
  172. {
  173. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  174. _roleData.tags = fightCfg.needTagsArr;////本次战斗要求的标签
  175. }
  176. _roleData.scoreType = InstanceZonesDataManager.currentScoreType; //本次战斗的主题
  177. _roleData.cardId = InstanceZonesDataManager.currentCardId; ;//卡牌id
  178. _roleData.cardScore = _roleData.cardId == 0 ? 0 : CardDataManager.GetCardDataById(_roleData.cardId).scores[_roleData.scoreType];//卡牌对应主题的属性分数
  179. _roleData.itemList = MyDressUpHelper.dressUpObj.itemList;
  180. }
  181. if (_roleData.cardId > 0)
  182. {
  183. _roleData.skillLvs = SkillDataManager.Instance.GetSkillLvs(_roleData.cardId);
  184. }
  185. SetItemScoreList(_roleData);
  186. ScoreSystemData.Instance.SetEquipScoresWithPartId(_roleData);
  187. return _roleData;
  188. }
  189. public void SetItemScoreList(FightRoleData _roleData)
  190. {
  191. _roleData.itemScoreList.Clear();
  192. for (int i = 0; i < _roleData.itemList.Count; i++)
  193. {
  194. int score = ItemDataManager.GetItemAdditionScore(_roleData.itemList[i], _roleData.scoreType);
  195. _roleData.itemScoreList.Add(score);
  196. }
  197. }
  198. //获取副本机器人战斗数据
  199. public FightRobotData GetFightRobotData()
  200. {
  201. FightRobotData robotData = new FightRobotData();
  202. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(InstanceZonesDataManager.currentLevelCfgId);
  203. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  204. robotData.res = fightCfg.targetRes;
  205. robotData.name = fightCfg.targetName;
  206. robotData.scoreType = InstanceZonesDataManager.currentScoreType; //本次战斗的主题
  207. robotData.baseScore = fightCfg.targetBaseScore;
  208. robotData.cardId = fightCfg.targetCardId;
  209. robotData.cardScore = fightCfg.targetCardScore;
  210. robotData.skillLvs = new List<int>(fightCfg.targetSkillLvsArr);
  211. robotData.itemScoreList = new List<int>(fightCfg.targetPartsScoreArr);
  212. return robotData;
  213. }
  214. /// <summary>
  215. /// 0失败1优秀2完美
  216. /// </summary>
  217. /// <param name="scale"></param>
  218. /// <returns></returns>
  219. public int GetClickType(float scale)
  220. {
  221. // float scaleX = _ui.m_comClick.m_comResult.m_imgCircle.scale.x;
  222. int clickType = ClickType.MISS_CLICK;
  223. if (FightDataManager.Instance.autoPlay == true)
  224. {
  225. return ClickType.PREFACT_CLICK;
  226. }
  227. if (scale <= 0.866f && scale > 0.65f)
  228. {
  229. clickType = ClickType.PREFACT_CLICK;
  230. }
  231. else if (scale <= 0.216f)
  232. {
  233. clickType = ClickType.MISS_CLICK;
  234. }
  235. else
  236. {
  237. clickType = ClickType.GREAT_CLICK;
  238. }
  239. return clickType;
  240. }
  241. /// <summary>
  242. /// 卡牌列表按竞技战力排序
  243. /// </summary>
  244. /// <param name="arrayList"></param>
  245. /// <returns></returns>
  246. public List<CardData> SortCardList(List<CardData> cardList, List<int> itemList, int scoreType)
  247. {
  248. double itemSum = 0;
  249. for (int i = 0; i < itemList.Count; i++)
  250. {
  251. itemSum += ItemDataManager.GetItemAdditionScore(itemList[i], scoreType);
  252. }
  253. List<CardData> arrayList = new List<CardData>(cardList);
  254. for (int i = arrayList.Count - 1; i >= 0; i--)
  255. {
  256. List<int> skillLvs = SkillDataManager.Instance.GetSkillLvs(arrayList[i].id);
  257. if (skillLvs.Count == 0)
  258. {
  259. ET.Log.Error("卡牌:" + arrayList[i].id + " 未配置技能");
  260. arrayList.RemoveAt(i);
  261. }
  262. }
  263. int baseScore = RoleLevelCfgArray.Instance.GetCfg(RoleDataManager.lvl).baseScore;
  264. arrayList.Sort((CardData a, CardData b) =>
  265. {
  266. double scoreA = GetSkillFightScore(itemSum, baseScore, a.id, a.scores[scoreType], SkillDataManager.Instance.GetSkillLvs(a.id));
  267. double scoreB = GetSkillFightScore(itemSum, baseScore, b.id, b.scores[scoreType], SkillDataManager.Instance.GetSkillLvs(b.id));
  268. if (scoreA < scoreB)
  269. {
  270. return 1;
  271. }
  272. else if (scoreA > scoreB)
  273. {
  274. return -1;
  275. }
  276. return string.Compare(a.itemCfg.res, b.itemCfg.res);
  277. });
  278. return arrayList;
  279. }
  280. /// <summary>
  281. /// 获取技能战力
  282. /// </summary>
  283. /// <param name="itemScoreSum"></param>
  284. /// <param name="baseScore"></param>
  285. /// <param name="cardId"></param>
  286. /// <param name="cardScore"></param>
  287. /// <param name="skillLvs"></param>
  288. /// <returns></returns>
  289. public long GetSkillFightScore(double itemScoreSum, int baseScore, int cardId, int cardScore, List<int> skillLvs)
  290. {
  291. // double itemSum = itemScoreSum;
  292. long skillScore = 0;
  293. long skillBaseScore = (long)itemScoreSum + cardScore + baseScore;
  294. List<PassivitySkillCfg> skillCfgs = PassivitySkillCfgArray.Instance.GetCfgsBycardId(cardId);
  295. for (int j = 0; j < skillCfgs.Count; j++)
  296. {
  297. // ET.Log.Debug("cardId:" + cardId + " skillLvs:" + skillLvs.Count + " skillCfgs:" + skillCfgs.Count + " index:" + j);
  298. PassivitySkillLvlCfg skillLvlCfg = PassivitySkillLvlCfgArray.Instance.GetCfgByskilllvlAndskillId(skillLvs[j], skillCfgs[j].skillId);
  299. if (skillLvlCfg == null) continue;
  300. skillScore += skillBaseScore * skillLvlCfg.fightPowerParam / 10000;
  301. }
  302. return skillScore;
  303. }
  304. /// <summary>
  305. /// 获取快速挑战结果
  306. /// </summary>
  307. /// <param name="myRoleData"></param>
  308. /// <param name="targetType"></param>
  309. /// <param name="targetRoleData"></param>
  310. /// <param name="targetRobotData"></param>
  311. /// <param name="_score"></param>
  312. /// <param name="_targetScore"></param>
  313. public void GetQuickFightResult(FightRoleData myRoleData, int targetType, FightRoleData targetRoleData, FightRobotData targetRobotData, out int _score, out int _targetScore)
  314. {
  315. double score = 0;
  316. double targetScore = 0;
  317. int cardId = myRoleData.cardId;
  318. double mainScore = ScoreSystemData.Instance.GetMainScore(myRoleData);
  319. List<int> skillLvs = myRoleData.skillLvs;
  320. int targetCardId;
  321. double targetMainScore;
  322. List<int> targetSkillLvs;
  323. List<int> targetRoundTime;
  324. List<int> roundTime = ScoreSystemData.Instance.GetRoundTime(myRoleData.cardId, myRoleData.skillLvs);
  325. if (targetType == ArenaFightTargetType.PLAYER)
  326. {
  327. targetCardId = targetRoleData.cardId;
  328. targetSkillLvs = targetRoleData.skillLvs;
  329. targetMainScore = ScoreSystemData.Instance.GetMainScore(targetRoleData);
  330. targetRoundTime = ScoreSystemData.Instance.GetRoundTime(targetRoleData.cardId, targetRoleData.skillLvs);
  331. }
  332. else
  333. {
  334. targetCardId = targetRobotData.cardId;
  335. targetSkillLvs = targetRobotData.skillLvs;
  336. targetMainScore = ScoreSystemData.Instance.GetRobotMainScore(targetRobotData);
  337. targetRoundTime = ScoreSystemData.Instance.GetRoundTime(targetRobotData.cardId, targetRobotData.skillLvs);
  338. }
  339. int partId = 0;
  340. int currentTime = BeginTime.PART_ALL_FIGHT_BEGIN;
  341. GetSkillScore(currentTime, partId, mainScore, cardId, skillLvs, roundTime, ref score, targetMainScore, targetCardId, targetSkillLvs, targetRoundTime, ref targetScore);
  342. GetSkillScore(currentTime, partId, targetMainScore, targetCardId, targetSkillLvs, targetRoundTime, ref targetScore, mainScore, cardId, skillLvs, roundTime, ref score);
  343. for (int i = 0; i < FightScoreCfgArray.Instance.dataArray.Length; i++)
  344. {
  345. partId++;
  346. currentTime = BeginTime.PART_FIGHT_BEGIN;
  347. GetSkillScore(currentTime, partId, mainScore, cardId, skillLvs, roundTime, ref score, targetMainScore, targetCardId, targetSkillLvs, targetRoundTime, ref targetScore);
  348. GetSkillScore(currentTime, partId, targetMainScore, targetCardId, targetSkillLvs, targetRoundTime, ref targetScore, mainScore, cardId, skillLvs, roundTime, ref score);
  349. score += ScoreSystemData.Instance.GetPartScore(myRoleData, partId, ClickType.PREFACT_CLICK, 0);
  350. if (targetType == ArenaFightTargetType.PLAYER)
  351. {
  352. targetScore += ScoreSystemData.Instance.GetPartScore(targetRoleData, partId, ClickType.PREFACT_CLICK, 0);
  353. }
  354. else
  355. {
  356. targetScore += ScoreSystemData.Instance.GetRobotPartScore(targetRobotData, partId, ClickType.PREFACT_CLICK, 0);
  357. }
  358. currentTime = BeginTime.PART_PREFACT_CLICK;
  359. GetSkillScore(currentTime, partId, mainScore, cardId, skillLvs, roundTime, ref score, targetMainScore, targetCardId, targetSkillLvs, targetRoundTime, ref targetScore);
  360. GetSkillScore(currentTime, partId, targetMainScore, targetCardId, targetSkillLvs, targetRoundTime, ref targetScore, mainScore, cardId, skillLvs, roundTime, ref score);
  361. currentTime = BeginTime.PART_FIGHT_END;
  362. GetSkillScore(currentTime, partId, mainScore, cardId, skillLvs, roundTime, ref score, targetMainScore, targetCardId, targetSkillLvs, targetRoundTime, ref targetScore);
  363. GetSkillScore(currentTime, partId, targetMainScore, targetCardId, targetSkillLvs, targetRoundTime, ref targetScore, mainScore, cardId, skillLvs, roundTime, ref score);
  364. }
  365. score += ScoreSystemData.Instance.GetAllCircleAddScore(mainScore);
  366. targetScore += ScoreSystemData.Instance.GetAllCircleAddScore(targetMainScore);
  367. _score = Mathf.CeilToInt((float)score);
  368. _targetScore = Mathf.CeilToInt((float)targetScore);
  369. }
  370. 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)
  371. {
  372. List<PassivitySkillLvlCfg> vaildSkills = ScoreSystemData.Instance.GetValidSkills(currentTime, partId, cardId, skillLvs, targetCardId, targetSkillLvs, roundTime, targetRoundTime);
  373. ScoreSystemData.Instance.GetPartItemSkillScore(vaildSkills, mainScore, targetMainScore, out int skillScore, out int targetSkillScore, out Dictionary<int, int> skillScoreDic);
  374. score += skillScore;
  375. targetMainScore += targetSkillScore;
  376. }
  377. }
  378. }