EffectNode.ts 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. // Learn TypeScript:
  2. // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
  3. // Learn Attribute:
  4. // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
  5. // Learn life-cycle callbacks:
  6. // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
  7. import Random from "../utils/Random";
  8. import UiM, { PANEL_NAME } from "../manager/UiM";
  9. import PoolMgr, { NODEPOOLPREFABTYPE } from "../manager/PoolMgr";
  10. import Sciencen_M from "../utils/Sciencen_M";
  11. import Task from "./Task";
  12. import UsualCaidanNode from "./UsualCaidanNode";
  13. const { ccclass, property } = cc._decorator;
  14. @ccclass
  15. export default class EffectNode extends cc.Component {
  16. static instance: EffectNode;
  17. @property(cc.Prefab)
  18. eftPrefabs: cc.Prefab[] = [];
  19. //@property(cc.Prefab)
  20. //coinPrefab: cc.Prefab = null;
  21. //@property(cc.Prefab)
  22. //goldPrefab: cc.Prefab = null;
  23. //@property(cc.Prefab)
  24. //expPrefab:cc.Prefab=null;
  25. @property(cc.Prefab)
  26. eftScreenCoin: cc.Prefab = null;
  27. @property(cc.Node)
  28. public eftTargets: cc.Node[] = [];
  29. //@property(cc.Node)
  30. //public goldTarget: cc.Node = null;
  31. //@property(cc.Node)
  32. //public coinTarget: cc.Node = null;
  33. //@property(cc.Node)
  34. //public expTarget:cc.Node=null;
  35. @property(cc.Camera)
  36. public mainCamera: cc.Camera = null;
  37. /**元宝icon*/
  38. @property(cc.Node)
  39. redMoneyIcon: cc.Node = null;
  40. /**金币icon*/
  41. @property(cc.Node)
  42. coinIcon: cc.Node = null;
  43. /**金币icon*/
  44. @property(cc.Node)
  45. expIcon: cc.Node = null;
  46. /**提示节点*/
  47. @property(cc.Node)
  48. tipNode: cc.Node = null;
  49. @property(cc.Node)
  50. carPosNode: cc.Node = null;
  51. @property(cc.Label)
  52. tipTxt: cc.Label = null;
  53. @property(sp.Skeleton)
  54. carDesAni: sp.Skeleton = null;
  55. @property(cc.Node)
  56. carDesTxtNode: cc.Node = null;
  57. @property(cc.Label)
  58. carDesTxt: cc.Label = null;
  59. @property(cc.Node)
  60. danBg: cc.Node = null;
  61. @property(sp.Skeleton)
  62. egg1: sp.Skeleton = null;
  63. @property(cc.Node)
  64. tipNode1: cc.Node = null;
  65. @property(cc.Label)
  66. tipTxt1: cc.Label = null;
  67. // LIFE-CYCLE CALLBACKS:
  68. onLoad() {
  69. EffectNode.instance = this;
  70. }
  71. start() {
  72. if (cc.winSize.height > 1500) {
  73. this.eftTargets[0].y += 90
  74. this.eftTargets[1].y += 90
  75. }
  76. }
  77. // update (dt) {}
  78. /**
  79. * @param type 类型,0 金币,1 红包币 5 活跃 6 骰子 7 遥控卡 8 双倍卡 9 经书 10 加速卡 11 抽奖券 12 夺宝券 13 天赋石 14 红包
  80. * @param num 特效数量
  81. * @param pos 起始位置
  82. * @param fly 是否飞行
  83. * @param endpos 飞行的目标坐标 只对 6-13 有效
  84. * @param cb 动画结束回调
  85. */
  86. public PlayCoinAnim(type: number = 0, num: number, pos: cc.Vec2, fly: boolean = true, endpos: cc.Vec2 = null, cb: Function = null) {
  87. let cam_pos;
  88. let tempPos3D = this.mainCamera.getWorldToScreenPoint(pos, cam_pos);
  89. pos = cc.v2(tempPos3D.x, tempPos3D.y);
  90. for (let i = 0; i < num; i++) {
  91. //FC:-
  92. //let copyCoin = cc.instantiate(this.eftPrefabs[type]);//type == 0 ? this.coinPrefab : this.goldPrefab);
  93. //FC:+ 对象池
  94. let copyCoin = null;
  95. if (type == 0) {
  96. copyCoin = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.Coin);
  97. } else if (type == 1) {
  98. copyCoin = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.Gold);
  99. } else if (type == 5) {
  100. copyCoin = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.ActiveV);
  101. } else if (type == 6) {
  102. copyCoin = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.Dice);
  103. } else if (type == 7) {
  104. copyCoin = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.CtrlCard);
  105. } else if (type == 8) {
  106. copyCoin = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.DoubleCard);
  107. } else if (type == 9) {
  108. copyCoin = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.Book);
  109. } else if (type == 10) {
  110. copyCoin = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.SpeedCard);
  111. } else if (type == 11) {
  112. copyCoin = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.DrawCard);
  113. } else if (type == 12) {
  114. copyCoin = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.BaoCard);
  115. } else if (type == 13) {
  116. copyCoin = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.Talent);
  117. } else if (type == 14) {
  118. copyCoin = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.RedPackage);
  119. }
  120. copyCoin.setParent(this.node);
  121. copyCoin.scale = Random.Range(0.8, 1.2, false);
  122. copyCoin.angle = Random.Range(-45, 45, false);
  123. let dir = cc.v2(Random.Range(-1, 1, false), Random.Range(-1, 1, false));
  124. dir = dir.normalize();
  125. let deltaInit = cc.v2(Random.Range(10, 160, false) * dir.x, Random.Range(10, 160, false) * dir.y);
  126. //FC:-无效计算
  127. //let deltaEnd = cc.v2(Random.Range(250, 800, false) * dir.x, Random.Range(250, 800, false) * dir.y);
  128. let initPos = pos.add(deltaInit);
  129. //copyCoin.setPosition(initPos);
  130. copyCoin.setPosition(pos);
  131. this.FlyIn(type, copyCoin, initPos, fly, endpos, cb);
  132. }
  133. if (type == 5) {
  134. this.scheduleOnce(() => {
  135. UiM.Instance.taskNode.getComponent(Task).addActiveNum(num)
  136. }, 2)
  137. }
  138. }
  139. FlyIn(type: number = 0, target: cc.Node, end: cc.Vec2, fly: boolean, endpos: cc.Vec2 = null, cb: Function = null) {
  140. let ac1
  141. if (fly) {
  142. ac1 = cc.moveTo(Random.Range(0.3, 1, false), end).easing(cc.easeSineOut());
  143. }
  144. else {
  145. ac1 = cc.moveTo(Random.Range(0.3, 0.6, false), end).easing(cc.easeSineOut());
  146. }
  147. let callback = cc.callFunc(() => {
  148. //target.destroy();
  149. if (fly) {
  150. this.scheduleOnce(() => {
  151. if (type < 6 || type > 13) {
  152. if (endpos != null)
  153. this.FlyOut(type, target, endpos, cb);
  154. else
  155. this.FlyOut(type, target, (this.eftTargets[type]).getPosition(), cb);
  156. } else {
  157. if (endpos != null)
  158. this.FlyOut(type, target, endpos, cb);
  159. else
  160. this.FlyOut(type, target, (this.eftTargets[0]).getPosition(), cb);
  161. }
  162. }, 0);
  163. }
  164. else {
  165. if (type == 0) {
  166. //FC:+ 对象池
  167. PoolMgr.Inst.recyclePoolPrefab(NODEPOOLPREFABTYPE.Coin, target);
  168. this.CoinIconAni();
  169. }
  170. else if (type == 1) {
  171. //FC:+ 对象池
  172. PoolMgr.Inst.recyclePoolPrefab(NODEPOOLPREFABTYPE.Gold, target);
  173. this.RedMoneyIconAni();
  174. }
  175. else if (type == 5) {
  176. //FC:+ 对象池
  177. PoolMgr.Inst.recyclePoolPrefab(NODEPOOLPREFABTYPE.ActiveV, target);
  178. }
  179. }
  180. });
  181. let total = cc.sequence(ac1, callback);
  182. target.runAction(total);
  183. }
  184. FlyOut(type: number = 0, target: cc.Node, end: cc.Vec2, cb: Function = null) {
  185. let dur = Random.Range(0.3, 1, false);
  186. target.runAction(cc.scaleTo(dur, 0.8));
  187. let ac1 = cc.moveTo(dur, end).easing(cc.easeSineOut());
  188. let callback = cc.callFunc(() => {
  189. //FC:-
  190. //target.destroy();
  191. if (type == 0) {
  192. //FC:+ 对象池
  193. PoolMgr.Inst.recyclePoolPrefab(NODEPOOLPREFABTYPE.Coin, target);
  194. this.CoinIconAni();
  195. }
  196. else if (type == 1) {
  197. //FC:+ 对象池
  198. PoolMgr.Inst.recyclePoolPrefab(NODEPOOLPREFABTYPE.Gold, target);
  199. this.RedMoneyIconAni();
  200. }
  201. else if (type == 5) {
  202. //FC:+ 对象池
  203. PoolMgr.Inst.recyclePoolPrefab(NODEPOOLPREFABTYPE.ActiveV, target);
  204. }
  205. else if (type == 6) {
  206. //FC:+ 对象池
  207. PoolMgr.Inst.recyclePoolPrefab(NODEPOOLPREFABTYPE.Dice, target);
  208. }
  209. else if (type == 7) {
  210. //FC:+ 对象池
  211. PoolMgr.Inst.recyclePoolPrefab(NODEPOOLPREFABTYPE.CtrlCard, target);
  212. }
  213. else if (type == 8) {
  214. //FC:+ 对象池
  215. PoolMgr.Inst.recyclePoolPrefab(NODEPOOLPREFABTYPE.DoubleCard, target);
  216. }
  217. else if (type == 9) {
  218. //FC:+ 对象池
  219. PoolMgr.Inst.recyclePoolPrefab(NODEPOOLPREFABTYPE.Book, target);
  220. }
  221. else if (type == 10) {
  222. //FC:+ 对象池
  223. PoolMgr.Inst.recyclePoolPrefab(NODEPOOLPREFABTYPE.SpeedCard, target);
  224. }
  225. else if (type == 11) {
  226. //FC:+ 对象池
  227. PoolMgr.Inst.recyclePoolPrefab(NODEPOOLPREFABTYPE.DrawCard, target);
  228. }
  229. else if (type == 12) {
  230. //FC:+ 对象池
  231. PoolMgr.Inst.recyclePoolPrefab(NODEPOOLPREFABTYPE.BaoCard, target);
  232. }
  233. else if (type == 13) {
  234. //FC:+ 对象池
  235. PoolMgr.Inst.recyclePoolPrefab(NODEPOOLPREFABTYPE.Talent, target);
  236. }
  237. else if (type == 14) {
  238. //FC:+ 对象池
  239. PoolMgr.Inst.recyclePoolPrefab(NODEPOOLPREFABTYPE.RedPackage, target);
  240. }
  241. //type == 0 ? this.CoinIconAni() : this.RedMoneyIconAni();
  242. if (cb != null) {
  243. cb();
  244. }
  245. });
  246. let total = cc.sequence(ac1, callback);
  247. target.runAction(total);
  248. }
  249. /**
  250. * 经验特效
  251. * @param type 1 经验 2 每日提现
  252. */
  253. PlayExpEffect(pos: cc.Vec2, type = 1) {
  254. //FC:-
  255. //let eftcopy = cc.instantiate(this.expPrefab);
  256. //FC:+ 对象池
  257. let eftcopy = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.CarExpEft);
  258. eftcopy.setParent(this.node);
  259. eftcopy.setPosition(pos);
  260. eftcopy.scale = 1.5;
  261. //eftcopy.getComponent(cc.ParticleSystem).playOnLoad = true;
  262. //FC:+
  263. eftcopy.getComponent(cc.ParticleSystem).resetSystem();
  264. // console.log("ExpPOS:", pos);
  265. let tarPos = null
  266. if (type == 1) {
  267. tarPos = this.eftTargets[2]
  268. }
  269. else if (type == 2) {
  270. tarPos = this.eftTargets[4]
  271. }
  272. cc.tween(eftcopy).to(0.7, { position: cc.v2(tarPos.x, tarPos.y) })
  273. .call(() => {
  274. //FC:-
  275. //eftcopy.destroy()
  276. //FC:+ 对象池
  277. PoolMgr.Inst.recyclePoolPrefab(NODEPOOLPREFABTYPE.CarExpEft, eftcopy);
  278. })
  279. .start();
  280. }
  281. redIconAniEnd: boolean = true;
  282. /**
  283. * 获取元宝 元宝icon动画
  284. */
  285. RedMoneyIconAni() {
  286. if (this.redIconAniEnd) {
  287. this.redIconAniEnd = false;
  288. cc.tween(this.redMoneyIcon).to(0.1, { scale: 1.2 }).to(0.05, { scale: 1 }).call(() => this.redIconAniEnd = true).start();
  289. }
  290. }
  291. coinIconAniEnd: boolean = true;
  292. /**
  293. * 获取金币 金币icon动画
  294. */
  295. CoinIconAni() {
  296. if (this.coinIconAniEnd) {
  297. this.coinIconAniEnd = false;
  298. cc.tween(this.coinIcon).to(0.1, { scale: 1.2 }).to(0.05, { scale: 1 }).call(() => this.coinIconAniEnd = true).start();
  299. }
  300. }
  301. expIconAniEnd: boolean = true;
  302. /**
  303. * 获取经验值 经验头像动画
  304. */
  305. ExpIconAni() {
  306. if (this.expIconAniEnd) {
  307. this.expIconAniEnd = false;
  308. cc.tween(this.expIcon).to(0.1, { scale: 1.2 }).to(0.05, { scale: 1 }).call(() => this.expIconAniEnd = true).start();
  309. }
  310. }
  311. /**
  312. * 提示语显示
  313. */
  314. PlayTip(content: string) {
  315. this.tipNode.stopAllActions();
  316. this.tipNode.setPosition(cc.v2(0, 0));
  317. this.tipNode.active = true;
  318. this.tipNode.opacity = 255;
  319. this.tipTxt.string = content;
  320. let ac1 = cc.moveTo(0.35, cc.v2(0, this.node.height / 4)).easing(cc.easeSineOut());
  321. let wait = cc.delayTime(1.5);
  322. let fade = cc.fadeOut(1).easing(cc.easeQuinticActionIn());
  323. let backcall = cc.callFunc(() => this.tipNode.active = false);
  324. let total = cc.sequence(ac1, wait, fade, backcall);
  325. this.tipNode.runAction(total);
  326. }
  327. PlayTipSimple(content: string) {
  328. this.tipTxt1.string = content
  329. this.tipNode1.active = true
  330. this.tipNode1.scale = 0
  331. this.tipNode1.opacity = 0
  332. cc.tween(this.tipNode1)
  333. .to(0.35, { scale: 1, opacity: 255 })
  334. .delay(1.5)
  335. .to(0.35, { opacity: 0 })
  336. .start()
  337. }
  338. /**
  339. * 提示语显示
  340. */
  341. PlayProTip(content: string) {
  342. this.tipNode.stopAllActions();
  343. this.tipNode.setPosition(cc.v2(0, 0));
  344. this.tipNode.active = true;
  345. this.tipNode.opacity = 255;
  346. this.tipTxt.string = content;
  347. let ac1 = cc.moveTo(0.35, cc.v2(0, this.node.height / 4)).easing(cc.easeSineOut());
  348. let wait = cc.delayTime(1.5);
  349. let fade = cc.fadeOut(1).easing(cc.easeQuinticActionIn());
  350. let backcall = cc.callFunc(() => this.tipNode.active = false);
  351. let total = cc.sequence(ac1, wait, fade, backcall);
  352. this.tipNode.runAction(total);
  353. }
  354. /**垃圾回收动画*/
  355. PlayTrashAni(num: number) {
  356. //FC:-
  357. //let eft = cc.instantiate(this.carDesEft);
  358. //FC:+
  359. let eft = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.CarDesEft);
  360. eft.scale = 1.2;
  361. eft.setParent(this.node);
  362. eft.setPosition(this.carPosNode.getPosition());
  363. eft.getComponent(sp.Skeleton).setAnimation(0, 'animation', false);
  364. this.carDesAni.node.setPosition(this.carPosNode.getPosition());
  365. this.carDesAni.node.active = true;
  366. this.carDesAni.setAnimation(0, 'animation', false);
  367. this.scheduleOnce(() => {
  368. //FC:-
  369. //eft.destroy();
  370. //FC:+
  371. PoolMgr.Inst.recyclePoolPrefab(NODEPOOLPREFABTYPE.CarDesEft, eft);
  372. this.carDesAni.node.active = false;
  373. }, 1);
  374. this.carDesTxtNode.setPosition(this.carPosNode.getPosition());
  375. this.carDesTxtNode.active = true;
  376. this.carDesTxt.string = Sciencen_M.instance.format(num.toString());
  377. cc.tween(this.carDesTxtNode).to(0.5, { position: cc.v2(0, this.carPosNode.getPosition().y + 110) }).call(() => this.carDesTxtNode.active = false).start();
  378. }
  379. /**播放全屏金币例子特效*/
  380. PlayScreenCoin() {
  381. let eft = cc.instantiate(this.eftScreenCoin);
  382. eft.parent = this.node;
  383. eft.setPosition(0, cc.winSize.height / 2);
  384. }
  385. /** 彩蛋进入 */
  386. playEggIn() {
  387. this.danBg.active = true
  388. // this.egg.active = true
  389. // this.egg.setPosition(cc.v2(-600, 76))
  390. // cc.tween(this.egg)
  391. // // .bezierTo(1, cc.v2(-600, 300), cc.v2(-170, 1200), cc.v2(-170, 300))
  392. // // .to(0.1, { angle: 10 })
  393. // // .to(0.2, { angle: -10 })
  394. // // .to(0.2, { angle: 10 })
  395. // // .to(0.1, { angle: 0 })
  396. // // .delay(0.5)
  397. // .bezierTo(1, cc.v2(-600, 76), cc.v2(0, 1000), cc.v2(0, 76))
  398. // .to(0.1, { angle: 10 })
  399. // .to(0.2, { angle: -10 })
  400. // .to(0.2, { angle: 10 })
  401. // .to(0.1, { angle: 0 })
  402. // .delay(0.5)
  403. // .call(() => {
  404. // this.danBg.active = false
  405. // UiM.Instance.onPanel(PANEL_NAME.UsualCaidanNode, false, () => {
  406. // UiM.Instance.usualCaidanNode.getComponent(UsualCaidanNode).init()
  407. // this.egg.active = false
  408. // })
  409. // })
  410. // .start()
  411. this.egg1.node.active = true
  412. this.egg1.setAnimation(0, 'animation', false)
  413. this.scheduleOnce(() => {
  414. // this.danBg.active = false
  415. this.egg1.node.active = false
  416. UiM.Instance.onPanel(PANEL_NAME.UsualCaidanNode, false, () => {
  417. UiM.Instance.usualCaidanNode.getComponent(UsualCaidanNode).init()
  418. this.danBg.active = false
  419. })
  420. }, 1.5)
  421. }
  422. }