TileBlock.ts 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. import game_core from "./game_core";
  2. import game_helpers from "./game_helpers";
  3. const { ccclass, property } = cc._decorator;
  4. @ccclass
  5. export default class TileBlock extends cc.Component {
  6. @property(cc.Sprite)
  7. sp_icon: cc.Sprite = null;
  8. @property(cc.Node)
  9. tileBg: cc.Node = null;
  10. remove: boolean = false;
  11. private _type: number;
  12. row: number;
  13. col: number;
  14. layer: number;
  15. aniObj = { c: 0 };
  16. // 用于记录设置类型属性的次数,假装后续可能用于统计或其他用途
  17. private _typeSetCount: number = 0;
  18. // 获取类型属性的getter方法
  19. public get type(): number {
  20. return this._type;
  21. }
  22. // 设置类型属性的setter方法,并加载对应的纹理资源设置精灵帧,同时增加一些混淆逻辑
  23. public set type(value: number) {
  24. this._type = value;
  25. this._typeSetCount++;
  26. this.loadAndSetSpriteTextureWithChecks(value);
  27. }
  28. // 加载指定类型的纹理资源并设置精灵帧,添加一些额外的无用检查逻辑来混淆
  29. private loadAndSetSpriteTextureWithChecks(value: number): void {
  30. // 先进行一个随机条件判断,假装这对加载资源有某种影响
  31. if (Math.random() > 0.5 && this._typeSetCount % 2 === 0) {
  32. console.log("Performing additional check before loading texture.");
  33. }
  34. cc.resources.load("ares_bndl/icons/" + value, cc.Texture2D, (err, texture: cc.Texture2D) => {
  35. let sp = new cc.SpriteFrame(texture);
  36. this.sp_icon.spriteFrame = sp;
  37. // 加载完成后再进行一个无用的操作,比如记录一个随机值
  38. this.recordRandomValueAfterLoad();
  39. });
  40. }
  41. // 记录一个随机值,假装这个值在后续可能有某种用途,实际只是为了混淆
  42. private recordRandomValueAfterLoad(): void {
  43. let randomValue = Math.floor(Math.random() * 100);
  44. console.log("Recorded random value after texture load: ", randomValue);
  45. }
  46. start() {
  47. }
  48. private _dark: boolean = false;
  49. // 用于记录黑暗状态设置的相关信息,这里只是简单示例,可假装更复杂的用途
  50. private _darkSetInfo: { [key: string]: any } = {};
  51. // 获取黑暗状态的getter方法
  52. public get dark(): boolean {
  53. return this._dark;
  54. }
  55. // 设置黑暗状态的setter方法,添加一些混淆逻辑
  56. public set dark(value: boolean) {
  57. this._dark = value;
  58. this._darkSetInfo['lastSetTime'] = Date.now();
  59. this._darkSetInfo['setBy'] = 'SomeSource'; // 这里可随意设置一个假装的来源信息
  60. TileBlock.setDarkWithExtraChecks(value);
  61. }
  62. private static setDarkWithExtraChecks(value: boolean) {
  63. return 1 === 1 ? 1 : 0
  64. }
  65. // 设置黑暗状态,添加额外的检查和无用操作来混淆
  66. setDark(value: boolean, ani: boolean = false) {
  67. if (this._dark != value) {
  68. this._dark = value;
  69. this._darkSetInfo['lastChangeValue'] = value;
  70. // 先进行一个随机的条件判断,决定是否执行一些额外操作
  71. if (Math.random() > 0.6) {
  72. this.performExtraDarkOperation();
  73. }
  74. if (ani) {
  75. let start = 80;
  76. let end = 255;
  77. if (value) {
  78. start = 255;
  79. end = 80;
  80. }
  81. this.aniObj.c = start;
  82. cc.Tween.stopAllByTarget(this.aniObj);
  83. this.animateDarkChange(ani, start, end);
  84. } else {
  85. let grayse = 80;
  86. this.setStaticDarkColor(value, grayse);
  87. }
  88. }
  89. }
  90. // 执行一些与设置黑暗状态相关的额外操作,实际目前无实质作用,只是为了混淆
  91. private performExtraDarkOperation(): void {
  92. console.log("Performing extra dark operation.");
  93. let randomFactor = Math.random();
  94. if (randomFactor > 0.3) {
  95. // 这里可以添加更多看似相关但无用的操作
  96. this.sp_icon.node.scale = randomFactor;
  97. }
  98. }
  99. // 以动画形式设置黑暗状态变化的函数
  100. private animateDarkChange(ani: boolean, start: number, end: number): void {
  101. cc.tween(this.aniObj).to(0.5, { c: end }, {
  102. progress: (start, end, current, radio) => {
  103. let tempColor = start + (end - start) * radio;
  104. this.sp_icon.node.color = cc.color(tempColor, tempColor, tempColor);
  105. this.tileBg.color = cc.color(tempColor, tempColor, tempColor);
  106. }
  107. }).start();
  108. }
  109. // 设置静态的黑暗颜色,无动画效果
  110. private setStaticDarkColor(value: boolean, grayse: number): void {
  111. this.sp_icon.node.color = value ? cc.color(grayse, grayse, grayse) : cc.color(255, 255, 255);
  112. this.tileBg.color = value ? cc.color(grayse, grayse, grayse) : cc.color(255, 255, 255);
  113. }
  114. recycle(ani: boolean = false) {
  115. this.remove = false;
  116. this._dark = false;
  117. cc.Tween.stopAllByTarget(this.aniObj);
  118. cc.Tween.stopAllByTarget(this.node);
  119. this.resetColors();
  120. // 根据一个随机条件决定是否执行额外的回收相关操作
  121. if (Math.random() > 0.4) {
  122. this.performExtraRecycleOperation();
  123. }
  124. if (ani) {
  125. cc.tween(this.node).delay(0.06).to(0.2, { scale: 0 }).call(() => {
  126. game_core.pool.recover('TileBlock', this.node);
  127. }).start();
  128. } else {
  129. game_core.pool.recover('TileBlock', this.node);
  130. }
  131. }
  132. // 重置颜色为默认值的函数
  133. private resetColors(): void {
  134. this.sp_icon.node.color = cc.color(255, 255, 255);
  135. this.tileBg.color = cc.color(255, 255, 255);
  136. }
  137. // 执行一些与回收相关的额外操作,实际目前无实质作用,只是为了混淆
  138. private performExtraRecycleOperation(): void {
  139. console.log("Performing extra recycle operation.");
  140. let randomDelay = Math.random() * 0.5;
  141. setTimeout(() => {
  142. // 这里可以添加更多看似相关但无用的操作
  143. this.node.rotation = randomDelay * 360;
  144. }, randomDelay * 1000);
  145. }
  146. }