UESubHp.ts 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. import { gameMethod } from "../../common/gameMethod";
  2. import UEBase from "../../frameWork/compment/UEBase";
  3. import { eg } from "../../frameWork/eg";
  4. import GameMath from "../../utils/GameMath";
  5. const { ccclass, property } = cc._decorator;
  6. @ccclass
  7. export default class UESubHp extends UEBase {
  8. @property(cc.Node) buffTxt: cc.Node = null
  9. @property(cc.Node) txtHP: cc.Node = null
  10. @property(cc.Font) baojiFont: cc.Font = null
  11. @property(cc.Font) lianjiFont: cc.Font = null;
  12. @property(cc.Font) pugongFont: cc.Font = null;
  13. @property(cc.Font) huifuFont: cc.Font = null;
  14. @property(cc.Font) fanjiFont: cc.Font = null;
  15. @property(cc.Font) jiansheFnt: cc.Font = null;
  16. @property(cc.Font) gedangFnt: cc.Font = null;
  17. @property(cc.Font) jinengFnt: cc.Font = null;
  18. @property(cc.Font) cxshFnt: cc.Font = null;
  19. @property(cc.SpriteAtlas) buffTxtAtlas: cc.SpriteAtlas = null;
  20. static readonly BundleKey: string = "battle";
  21. static readonly PrefabUrl: string = "UESubHp";
  22. static readonly CLS: string = "UESubHp";
  23. show(data: [string, number], hpType?: string) {
  24. let type = data[0];
  25. if (hpType) {
  26. if (hpType == 'skill') {
  27. type = 'jineng';
  28. } else if (hpType == 'cxsh') {
  29. type = 'cxsh';
  30. }
  31. }
  32. let effectData = this.getEffect(type, data[1]);
  33. if (effectData) {
  34. this.ShowHP(data[0], data[1], effectData.effectDesc);
  35. } else {
  36. console.log(`${type} is not exist`);
  37. this.unuse();
  38. }
  39. }
  40. PauseAction() {
  41. this.txtHP.pauseAllActions();
  42. }
  43. ResumAction() {
  44. this.txtHP.resumeAllActions();
  45. }
  46. ShowBuffTxt(buffType: string) {
  47. cc.Tween.stopAllByTarget(this.buffTxt)
  48. this.buffTxt.active = true;
  49. this.txtHP.active = false;
  50. this.buffTxt.scale = 1.4;
  51. this.node.zIndex = 1500;
  52. this.buffTxt.setPosition(0, 50)
  53. this.buffTxt.opacity = 255;
  54. this.buffTxt.getComponent(cc.Sprite).spriteFrame = this.buffTxtAtlas.getSpriteFrame(buffType);
  55. cc.tween(this.buffTxt)
  56. .by(0.8, { position: cc.v3(0, 40, 0) })
  57. .by(0.1, { scale: -1.2, opacity: -255, position: cc.v3(0, -10, 0) })
  58. .call(() => {
  59. this.unuse();
  60. })
  61. .start();
  62. }
  63. ShowHP(type: string, val: number, effectDesc: string) {
  64. this.buffTxt.active = false;
  65. this.txtHP.active = true;
  66. if (gameMethod.isEmpty(this.txtHP)) {
  67. this.txtHP = this.node.getChildByName("txtHP")
  68. }
  69. cc.Tween.stopAllByTarget(this.txtHP)
  70. this.txtHP.getComponent(cc.Label).string = effectDesc;
  71. this.txtHP.scale = 1;
  72. let upTime = 0.35;
  73. let upLen = 0;
  74. // if (type == 'baoji') {
  75. // this.txtHP.setPosition(0, 25);
  76. // upTime = 0.55;
  77. // upLen = 80;
  78. // } else {
  79. // this.txtHP.setPosition(0, 30);
  80. // upTime = 0.45;
  81. // upLen = 60;
  82. // }
  83. if (type == 'baoji' || type == 'lianji'
  84. || type == 'jianshe' || type == 'fanji' || type == 'canbeatback' || type == 'cxsh'
  85. || type == 'block') {
  86. if (type == 'baoji') {
  87. this.txtHP.getComponent(cc.Label).fontSize = 40;
  88. } else {
  89. this.txtHP.getComponent(cc.Label).fontSize = 36;
  90. }
  91. if (type == 'cxsh') {
  92. this.txtHP.setPosition(0, 30);
  93. upTime = 0.45;
  94. upLen = 60;
  95. } else {
  96. this.txtHP.setPosition(0, 25);
  97. upTime = 0.55;
  98. upLen = 80;
  99. }
  100. this.node.zIndex = 1000;
  101. } else {
  102. // if (val > 0) {
  103. // //回血
  104. // } else {
  105. // }
  106. this.txtHP.getComponent(cc.Label).fontSize = 32;
  107. this.node.zIndex = 500;
  108. this.txtHP.setPosition(0, 30);
  109. upTime = 0.45;
  110. upLen = 60;
  111. }
  112. this.txtHP.opacity = 255;
  113. cc.tween(this.txtHP)
  114. .by(upTime, { position: cc.v3(0, upLen, 0) })
  115. .by(0.1, { opacity: -255, position: cc.v3(0, 0, 0) })
  116. .call(() => {
  117. this.unuse();
  118. })
  119. .start();
  120. }
  121. // put() 收回对象池时会调用
  122. unuse() {
  123. cc.Tween.stopAllByTarget(this.txtHP);
  124. cc.Tween.stopAllByTarget(this.buffTxt);
  125. this.txtHP.getComponent(cc.Label).string = "";
  126. this.txtHP.y = 0;
  127. this.txtHP.x = 0;
  128. this.txtHP.scale = 1;
  129. this.txtHP.opacity = 255;
  130. eg.poolManager.GetPool("subHPPool").put(this.node);
  131. }
  132. // 飘字效果描述
  133. getEffect(type: string, val: number) {
  134. let effectDesc: string;
  135. this.txtHP.getComponent(cc.Label).fontSize = 26;
  136. let divide = "";
  137. if (val < 0) {
  138. divide = "-";
  139. }
  140. let value = val || '';
  141. switch (type) {
  142. case "hp":
  143. //普通扣血
  144. effectDesc = divide ? `${this.GetVal(Number(value))}` : `h+${this.GetVal(Number(value))}`;
  145. this.txtHP.getComponent(cc.Label).font = divide ? this.pugongFont : this.huifuFont;
  146. break;
  147. case "xixue":
  148. case "huifu":
  149. //吸血
  150. effectDesc = `h+${this.GetVal(Number(value))}`;
  151. this.txtHP.getComponent(cc.Label).font = this.huifuFont;
  152. break;
  153. case "cxsh":
  154. //持续伤害
  155. effectDesc = divide ? `c${this.GetVal(Number(value))}` : `h+${this.GetVal(Number(value))}`;
  156. this.txtHP.getComponent(cc.Label).font = divide ? this.cxshFnt : this.huifuFont;
  157. break;
  158. case "jineng":
  159. //普通扣血
  160. effectDesc = divide ? `${this.GetVal(Number(value))}` : `+${this.GetVal(Number(value))}`;
  161. this.txtHP.getComponent(cc.Label).font = divide ? this.jinengFnt : this.huifuFont;
  162. break;
  163. case "block":
  164. //格挡
  165. effectDesc = `g${this.GetVal(Number(value))}`;
  166. this.txtHP.getComponent(cc.Label).font = this.gedangFnt;
  167. break;
  168. case "baoji":
  169. //暴扣扣血
  170. effectDesc = `b${this.GetVal(Number(value))}`
  171. this.txtHP.getComponent(cc.Label).font = this.baojiFont;
  172. break;
  173. case "fanji"://反击
  174. case "canbeatback": // 技能反击
  175. // if (gameMethod.isEmpty(value)) {
  176. // effectDesc = `f`
  177. // } else {
  178. // effectDesc = `${this.GetVal(Number(value))}`
  179. // }
  180. effectDesc = `f${this.GetVal(Number(value))}`
  181. this.txtHP.getComponent(cc.Label).font = this.fanjiFont;
  182. break;
  183. case "lianji":
  184. //连击
  185. effectDesc = `l${this.GetVal(Number(value))}`
  186. this.txtHP.getComponent(cc.Label).font = this.lianjiFont;
  187. break;
  188. case "jianshe":
  189. //溅射
  190. effectDesc = `j${this.GetVal(Number(value))}`
  191. this.txtHP.getComponent(cc.Label).font = this.jiansheFnt;
  192. break;
  193. case "shanbi":
  194. //闪避
  195. effectDesc = "闪避"
  196. this.txtHP.getComponent(cc.Label).font = null;
  197. break;
  198. default:
  199. break;
  200. }
  201. if (effectDesc) {
  202. return { effectDesc: effectDesc }
  203. } else {
  204. return null;
  205. }
  206. }
  207. GetVal(value) {
  208. let divide = "";
  209. if (value < 0) {
  210. divide = "-";
  211. }
  212. return divide + GameMath.showNum(Math.abs(value));
  213. }
  214. }