RewardMnr.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. console.error(this.HasPropName);
  37. LocalData.getInstance().setGold(Count, '+')
  38. cc.systemEvent.emit(EventName.Tips, `您获得了 ${Count} 枚金币`)
  39. }
  40. }
  41. //#region 使用道具
  42. //道具使用辅助线次数
  43. PropUseParabola(Count: number) {
  44. if (LocalData.getInstance().getParabolaCount() > 0) {
  45. LocalData.getInstance().setParabolaCount(Count, '-')
  46. this.ParabolaCount += Count
  47. cc.systemEvent.emit(EventName.Tips, `您获得了 ${Count} 次完整辅助线机会`)
  48. } else {
  49. }
  50. }
  51. //道具使用超级跳次数
  52. PropUseSupjump(Count: number) {
  53. if (LocalData.getInstance().getSupjumpCount() > 0) {
  54. LocalData.getInstance().setSupjumpCount(Count, '-')
  55. cc.systemEvent.emit(EventName.Tips, `超级跳咯~`)
  56. cc.systemEvent.emit(EventName.UseSupjump)
  57. } else {
  58. }
  59. }
  60. //道具使用超级跳次数
  61. PropFlyjump(Count: number) {
  62. if (LocalData.getInstance().getFlyCount() > 0) {
  63. LocalData.getInstance().setFlyCount(Count, '-')
  64. cc.systemEvent.emit(EventName.Tips, `起飞咯~`)
  65. cc.systemEvent.emit(EventName.UseFly)
  66. } else {
  67. }
  68. }
  69. //#endregion
  70. isEnable(name: string) {
  71. if (!this.HasPropName.includes(name)) {
  72. return true
  73. }
  74. return false
  75. }
  76. useOnceParabola() {
  77. if (this.ParabolaCount > 0) {
  78. this.ParabolaCount--
  79. }
  80. }
  81. // 1虚线 2超级跳 3 飞
  82. PopAward(num: AwardType) {
  83. (async () => {
  84. const url = "res/Pop/Award"
  85. let Prefab = await LoadManager.instance.LoadAssets<cc.Prefab>(url);
  86. if (cc.isValid(Prefab)) {
  87. let a = cc.instantiate(Prefab);
  88. a.getComponent(Award).setSp(num)
  89. cc.Camera.main.node.addChild(a)
  90. setTimeout(() => {
  91. a.setPosition(cc.v2(0, 0))
  92. }, 1);
  93. }
  94. })();
  95. }
  96. // update (dt) {}
  97. }