RewardMnr.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // Learn TypeScript:
  2. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
  3. // Learn Attribute:
  4. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
  5. // Learn life-cycle callbacks:
  6. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html
  7. import EventName from "../EventName/EventName";
  8. import LoadManager from "../LoadManager";
  9. import LocalData from "../LocalData";
  10. import Award, { AwardType } from "../Pop/Award";
  11. export default class RewardMnr {
  12. private static _instance: RewardMnr = null;
  13. public static getInstance() {
  14. if (!this._instance) {
  15. this._instance = new RewardMnr();
  16. }
  17. return this._instance;
  18. }
  19. //还原
  20. Reset() {
  21. this.HasPropName = []
  22. }
  23. HasPropName: string[] = []
  24. ParabolaCount = 0
  25. //添加辅助线次数
  26. addParabola(name: string, Count: number) {
  27. if (!this.HasPropName.includes(name)) {
  28. this.HasPropName.push(name)
  29. this.ParabolaCount += Count
  30. this.PopAward(AwardType.XuXian)
  31. }
  32. }
  33. addGold(name: string, Count: number) {
  34. if (!this.HasPropName.includes(name)) {
  35. this.HasPropName.push(name)
  36. LocalData.getInstance().setGold(Count, '+')
  37. cc.systemEvent.emit(EventName.Tips, `您获得了 ${Count} 枚金币`)
  38. }
  39. }
  40. //#region 使用道具
  41. //道具使用辅助线次数
  42. PropUseParabola(Count: number) {
  43. if (LocalData.getInstance().getParabolaCount() > 0) {
  44. LocalData.getInstance().setParabolaCount(Count, '-')
  45. this.ParabolaCount += Count
  46. cc.systemEvent.emit(EventName.Tips, `您获得了 ${Count} 次完整辅助线机会`)
  47. } else {
  48. }
  49. }
  50. //道具使用超级跳次数
  51. PropUseSupjump(Count: number) {
  52. if (LocalData.getInstance().getSupjumpCount() > 0) {
  53. LocalData.getInstance().setSupjumpCount(Count, '-')
  54. cc.systemEvent.emit(EventName.Tips, `超级跳咯~`)
  55. cc.systemEvent.emit(EventName.UseSupjump)
  56. } else {
  57. }
  58. }
  59. //道具使用超级跳次数
  60. PropFlyjump(Count: number) {
  61. if (LocalData.getInstance().getFlyCount() > 0) {
  62. LocalData.getInstance().setFlyCount(Count, '-')
  63. cc.systemEvent.emit(EventName.Tips, `起飞咯~`)
  64. cc.systemEvent.emit(EventName.UseFly)
  65. } else {
  66. }
  67. }
  68. //#endregion
  69. isEnable(name: string) {
  70. if (!this.HasPropName.includes(name)) {
  71. return true
  72. }
  73. return false
  74. }
  75. useOnceParabola() {
  76. if (this.ParabolaCount > 0) {
  77. this.ParabolaCount--
  78. }
  79. }
  80. // 1虚线 2超级跳 3 飞
  81. PopAward(num: AwardType) {
  82. (async () => {
  83. const url = "res/Pop/Award"
  84. let Prefab = await LoadManager.instance.LoadAssets<cc.Prefab>(url);
  85. if (cc.isValid(Prefab)) {
  86. let a = cc.instantiate(Prefab);
  87. a.getComponent(Award).setSp(num)
  88. cc.Camera.main.node.addChild(a)
  89. setTimeout(() => {
  90. a.setPosition(cc.v2(0, 0))
  91. }, 1);
  92. }
  93. })();
  94. }
  95. // update (dt) {}
  96. }