FightDataManager.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. namespace GFGGame
  4. {
  5. public class FightDataManager : SingletonBase<FightDataManager>
  6. {
  7. public byte[] FightRoleRes { get; set; }
  8. public Texture2D RoleTextuex { get; set; }
  9. //角色基础分+部件基础分
  10. private int _score;
  11. public int score
  12. {
  13. get
  14. {
  15. return _score;
  16. }
  17. set
  18. {
  19. _score = value;
  20. EventAgent.DispatchEvent(ConstMessage.DRESS_UP_SCORE_CHANGED, _score);
  21. }
  22. }
  23. //最终得分
  24. private int _totalScore;
  25. public int totalScore
  26. {
  27. get
  28. {
  29. return _totalScore;
  30. }
  31. set
  32. {
  33. _totalScore = value;
  34. }
  35. }
  36. //战斗对象最终得分
  37. private int _targetTotalScore;
  38. public int npcTotalScore
  39. {
  40. get
  41. {
  42. return _targetTotalScore;
  43. }
  44. set
  45. {
  46. _targetTotalScore = value;
  47. }
  48. }
  49. private bool _autoPlay = false;
  50. public bool autoPlay
  51. {
  52. get
  53. {
  54. return _autoPlay;
  55. }
  56. set
  57. {
  58. _autoPlay = value;
  59. if (!_autoPlay) fightSpeed = 1;
  60. StorageSProxy.ReqSetClientValue(ConstStorageId.STORAGE_AUTO_PLAY, _autoPlay == true ? 1 : 0).Coroutine();
  61. }
  62. }
  63. public int maxFightSpeed = 2;
  64. private int _fightSpeed = 1;
  65. public int fightSpeed
  66. {
  67. get
  68. {
  69. return _fightSpeed;
  70. }
  71. set
  72. {
  73. _fightSpeed = value;
  74. StorageSProxy.ReqSetClientValue(ConstStorageId.STORAGE_FIGHT_AUTO_PLAY_SPEED, _fightSpeed).Coroutine();
  75. }
  76. }
  77. private int _storyDialogSpeed = 1;
  78. public int dialogSpeed
  79. {
  80. get
  81. {
  82. return _storyDialogSpeed;
  83. }
  84. set
  85. {
  86. _storyDialogSpeed = value;
  87. StorageSProxy.ReqSetClientValue(ConstStorageId.STORAGE_DIALOG_AUTO_PLAY_SPEED, _storyDialogSpeed).Coroutine();
  88. }
  89. }
  90. //根据位置原点和随机范围获取评分位置
  91. public void GetCirclePos(Vector2 pos, int range, out float x, out float y)
  92. {
  93. int numX = UnityEngine.Random.Range(0, 2);
  94. int signX = numX % 2 == 0 ? 1 : -1;
  95. float rangeX = UnityEngine.Random.Range(0, range);
  96. x = pos.x + signX * (rangeX);
  97. int numY = UnityEngine.Random.Range(0, 2);
  98. int signY = numY % 2 == 0 ? 1 : -1;
  99. float rangeY = UnityEngine.Random.Range(0, range);
  100. y = pos.y + signY * (rangeY);
  101. }
  102. public Texture2D GetPrintscreenNTexture(Camera camera)
  103. {
  104. RenderTexture rt = new RenderTexture(UnityEngine.Screen.width, UnityEngine.Screen.height, 0);//渲染一张1920*1080的图
  105. camera.targetTexture = rt;//传到主摄像机上
  106. camera.Render();//渲染
  107. RenderTexture.active = rt;
  108. Texture2D screenShot = new Texture2D(UnityEngine.Screen.width, UnityEngine.Screen.height, TextureFormat.ARGB32, false);
  109. screenShot.ReadPixels(new Rect(0, 0, UnityEngine.Screen.width, UnityEngine.Screen.height), 0, 0);//读像素
  110. screenShot.Apply();
  111. camera.targetTexture = null;
  112. RenderTexture.active = null;
  113. Object.Destroy(rt);
  114. return screenShot;
  115. }
  116. //获取玩家战斗数据
  117. public FightRoleData GetMyFightRoleData()
  118. {
  119. FightRoleData roleData = new FightRoleData();
  120. roleData.name = RoleDataManager.roleName;
  121. roleData.headId = RoleDataManager.headId;
  122. roleData.headBorderId = RoleDataManager.headBorderId;
  123. roleData.scoreType = InstanceZonesDataManager.currentScoreType; //本次战斗的主题
  124. roleData.baseScore = RoleLevelCfgArray.Instance.GetCfg(RoleDataManager.lvl).baseScore;//角色等级分数
  125. roleData.cardId = InstanceZonesDataManager.currentCardId; ;//卡牌id
  126. roleData.cardScore = CardDataManager.GetCardDataById(roleData.cardId).scores[roleData.scoreType];//卡牌对应主题的属性分数
  127. if (InstanceZonesDataManager.FightScene == ConstInstanceZonesType.Arena)
  128. {
  129. // roleData.fightScene = ConstInstanceZonesType.Arena;
  130. roleData.tags = new string[1] { ArenaDataManager.Instance.Tag };
  131. }
  132. else
  133. {
  134. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(InstanceZonesDataManager.currentLevelCfgId);
  135. // roleData.fightScene = levelCfg.type;
  136. if (!string.IsNullOrEmpty(levelCfg.fightID))
  137. {
  138. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  139. roleData.tags = fightCfg.needTagsArr;////本次战斗要求的标签
  140. }
  141. }
  142. if (roleData.cardId > 0)
  143. {
  144. roleData.skillLvs = SkillDataManager.Instance.GetSkillLvs(roleData.cardId);
  145. }
  146. roleData.itemList = MyDressUpHelper.dressUpObj.itemList;
  147. for (int i = 0; i < roleData.itemList.Count; i++)
  148. {
  149. int score = ItemDataManager.GetItemAdditionScore(roleData.itemList[i], roleData.scoreType);
  150. roleData.itemScoreList.Add(score);
  151. }
  152. return roleData;
  153. }
  154. //获取副本机器人战斗数据
  155. public FightRobotData GetFightRobotData()
  156. {
  157. FightRobotData robotData = new FightRobotData();
  158. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(InstanceZonesDataManager.currentLevelCfgId);
  159. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  160. robotData.res = fightCfg.targetRes;
  161. robotData.name = fightCfg.targetName;
  162. robotData.scoreType = InstanceZonesDataManager.currentScoreType; //本次战斗的主题
  163. robotData.baseScore = fightCfg.targetBaseScore;
  164. robotData.cardId = fightCfg.targetCardId;
  165. robotData.cardScore = fightCfg.targetCardScore;
  166. robotData.skillLvs = new List<int>(fightCfg.targetSkillLvsArr);
  167. robotData.targetPareScorList = new List<int>(fightCfg.targetPartsScoreArr);
  168. return robotData;
  169. }
  170. //获取竞技场对手角色战斗数据
  171. public FightRoleData GetArenaRoleData(int index, ArenaTargetData arenaTarget)
  172. {
  173. return arenaTarget.RoleDressupList[index];
  174. }
  175. //获取竞技场机器人战斗数据
  176. public FightRobotData GetArenaRobotData(int index, ArenaTargetData arenaTarget)
  177. {
  178. return arenaTarget.RobotDressupList[index];
  179. }
  180. /// <summary>
  181. /// 0失败1优秀2完美
  182. /// </summary>
  183. /// <param name="scale"></param>
  184. /// <returns></returns>
  185. public int GetClickType(float scale)
  186. {
  187. // float scaleX = _ui.m_comClick.m_comResult.m_imgCircle.scale.x;
  188. int clickType = ClickType.MISS_CLICK;
  189. if (FightDataManager.Instance.autoPlay == true)
  190. {
  191. return ClickType.PREFACT_CLICK;
  192. }
  193. if (scale <= 0.866f && scale > 0.65f)
  194. {
  195. clickType = ClickType.PREFACT_CLICK;
  196. }
  197. else if (scale <= 0.216f)
  198. {
  199. clickType = ClickType.MISS_CLICK;
  200. }
  201. else
  202. {
  203. clickType = ClickType.GREAT_CLICK;
  204. }
  205. return clickType;
  206. }
  207. }
  208. }