JG0106_2.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import BaseEvent from "../../fight/evnet/base/BaseEvent";
  2. import AIPet from "../../fight/object/AI/AIPet";
  3. import { SpriteActionType } from "../../fight/object/FSprite";
  4. import PSprite from "../../fight/object/PSprite";
  5. const { ccclass, property } = cc._decorator;
  6. /**
  7. * 采集浆果。
  8. 直到采集4个给小鹿吃,小鹿才起身,跟着角色走。
  9. */
  10. @ccclass
  11. export default class JG0106_2 extends BaseEvent {
  12. @property({
  13. type: cc.SpriteFrame,
  14. displayName: '图标'
  15. })
  16. public mTipsIcon: cc.SpriteFrame = null;
  17. /**
  18. * 主角进入碰撞区域
  19. * @param tag 碰撞组件编号
  20. */
  21. public onBegin(tag: number) {
  22. this.showOpt(this.mTipsIcon, () => {
  23. let head = this.ff.mFFheader;
  24. let count = head.getTmpCount(5001);
  25. this.closeOpt()
  26. if(count >= 4){
  27. head.removeTmpGood(5001,4)
  28. this.dialog()
  29. }else{
  30. let sprite:PSprite = this.getPet() as PSprite;
  31. let text = [
  32. '饿饿..饿饿..',
  33. ]
  34. this.showDialog(sprite.node, text, () => {
  35. })
  36. }
  37. })
  38. }
  39. public onEnd(tag: number) {
  40. this.closeOpt()
  41. }
  42. private dialog(){
  43. this.pause()
  44. let sprite:PSprite = this.getPet() as PSprite;
  45. let text = [
  46. '嗷嗷..嗷嗷..',
  47. ]
  48. this.showDialog(sprite.node, text, () => {
  49. this.resume()
  50. this.petBack()
  51. this.node.destroy()
  52. })
  53. }
  54. /**
  55. * 宠物脱离队伍
  56. */
  57. private petBack(){
  58. let sprite:PSprite = this.getPet() as PSprite;
  59. sprite.inFront = this.ff.mainSprite
  60. sprite.playAction(SpriteActionType.stand,true)
  61. sprite.node.addComponent(AIPet)
  62. }
  63. private getPet(){
  64. let sprites = this.ff.getGroupBy('A')
  65. for (let i = 0; i < sprites.length; i++) {
  66. const element = sprites[i];
  67. if(element != this.ff.mainSprite){
  68. return element
  69. }
  70. }
  71. }
  72. }