TowerHuan.ts 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. import towerManger from "./towerManger";
  2. import { TowerType } from "../../configData/Enum";
  3. import gameUI from "../UIFace/gameUI";
  4. import monsterManger from "../monster/monsterManger";
  5. import gameData from "../../configData/gameData";
  6. import TapNode from "../UIFace/TapNode";
  7. const { ccclass, property } = cc._decorator;
  8. @ccclass
  9. export default class TowerHuan extends cc.Component {
  10. /**环点击区域 */
  11. @property(cc.Node)
  12. private tapSqrt: cc.Node = null;
  13. /**预警范围 */
  14. @property(cc.Sprite)
  15. private lanse: cc.Sprite = null;
  16. /**预警范围 */
  17. @property(cc.Sprite)
  18. private redquan: cc.Sprite = null;
  19. /** 圆环底座*/
  20. @property(cc.Sprite)
  21. private huan: cc.Sprite = null;
  22. /**不可升级标志 */
  23. @property(cc.Sprite)
  24. private nosele: cc.Sprite = null;
  25. /**升级金币数量 */
  26. @property(cc.Label)
  27. private sale: cc.Label = null;
  28. /**升级底座 */
  29. @property(cc.Sprite)
  30. private shengji: cc.Sprite = null;
  31. /**插旗底座 */
  32. @property(cc.Sprite)
  33. private chaqi: cc.Sprite = null;
  34. /**卖掉塔底座 */
  35. @property(cc.Sprite)
  36. private towerdestory: cc.Sprite = null;
  37. /**升级标志 */
  38. @property(cc.Sprite)
  39. private uptip: cc.Sprite = null;
  40. /**升级勾 */
  41. @property(cc.Sprite)
  42. private upgou: cc.Sprite = null;
  43. /**卖钱标志 */
  44. @property(cc.Sprite)
  45. private saletip: cc.Sprite = null;
  46. /**卖钱勾 */
  47. @property(cc.Sprite)
  48. private salegou: cc.Sprite = null;
  49. /**圆环是否打开 */
  50. public isOpen = false;
  51. /**是否可以插旗 */
  52. public isCanChaqi = false;
  53. /**升四级塔选项 */
  54. private upfor1: cc.Node = null;
  55. private upfor2: cc.Node = null;
  56. /**技能升级选项 */
  57. private skillupbg1: cc.Node = null;
  58. private skillupbg2: cc.Node = null;
  59. private skillupbg3: cc.Node = null;
  60. private skillLv = [0, 0, 0];
  61. private GoPos: cc.Vec3[] = [];
  62. private norMaterial: cc.Material = cc.Material.getBuiltinMaterial('2d-sprite');
  63. private grayMaterial: cc.Material = cc.Material.getBuiltinMaterial('2d-gray-sprite');
  64. private tower = null;
  65. private towerType: TowerType = 1;
  66. onLoad() {
  67. this.tapSqrt.on(cc.Node.EventType.TOUCH_START, this.touchNode, this);
  68. this.initSpr();
  69. this.GoPos = gameUI.instance.getGoPos();
  70. }
  71. private initSpr() {
  72. this.redquan.node.active = false;
  73. this.huan.node.active = false;
  74. this.chaqi.node.on(cc.Node.EventType.TOUCH_START, this.chaqiclick, this);
  75. this.towerdestory.node.on(cc.Node.EventType.TOUCH_START, this.destoryclick, this);
  76. }
  77. public setTowerType(type: TowerType) {
  78. this.towerType = type;
  79. this.chaqi.node.active = (type == TowerType.Enum_Barrack);
  80. if (type == TowerType.Enum_Barrack) {
  81. this.redquan.spriteFrame = this.lanse.spriteFrame;
  82. }
  83. }
  84. /**设置塔 */
  85. public setTower(tower) {
  86. this.tower = tower;
  87. this.sale.string = tower.myDataObj.TowerData.up_gold[0].toString();
  88. // console.log("------");
  89. this.initModel();
  90. }
  91. /**设置塔环类型 */
  92. private initModel() {
  93. let level = this.tower.myDataObj.TowerData.tower_level;
  94. this.shengji.node.active = false;
  95. this.upfor1 = this.huan.node.getChildByName('tower_upFour_1');
  96. this.upfor2 = this.huan.node.getChildByName('tower_upFour_2');
  97. this.skillupbg1 = this.huan.node.getChildByName('skillupbg1');
  98. this.skillupbg2 = this.huan.node.getChildByName('skillupbg2');
  99. this.skillupbg3 = this.huan.node.getChildByName('skillupbg3');
  100. this.upfor1.active = false;
  101. this.upfor2.active = false;
  102. this.skillupbg1.active = false;
  103. this.skillupbg2.active = false;
  104. this.skillupbg3.active = false;
  105. if (this.towerType == TowerType.Enum_Barrack) {
  106. this.skillupbg1.setPosition(-139, 16);
  107. this.skillupbg2.setPosition(-32, 134);
  108. this.skillupbg3.setPosition(124, 98);
  109. }
  110. if (level < 3) {
  111. this.shengji.node.active = true;
  112. this.shengji.node.on(cc.Node.EventType.TOUCH_START, () => {
  113. this.shengjiclick(0);
  114. }, this);
  115. }
  116. if (level == 3) {
  117. this.upfor1.active = true;
  118. this.upfor2.active = true;
  119. this.upfor1.on(cc.Node.EventType.TOUCH_START, this.seleTower1click, this);
  120. this.upfor2.on(cc.Node.EventType.TOUCH_START, this.seleTower2click, this);
  121. let sale1 = this.upfor1.getChildByName('sale').getComponent(cc.Label);
  122. let sale2 = this.upfor2.getChildByName('sale').getComponent(cc.Label);
  123. sale1.string = this.tower.myDataObj.TowerData.up_gold[0].toString();
  124. sale2.string = this.tower.myDataObj.TowerData.up_gold[0].toString();
  125. let self = this;
  126. cc.resources.load("game/skill/tower_icon_" + this.towerType+"_0", cc.SpriteFrame, function (err, myspriteFrame: cc.SpriteFrame) {
  127. self.upfor1.getChildByName('iconspr').getComponent(cc.Sprite).spriteFrame = myspriteFrame;
  128. });
  129. cc.resources.load("game/skill/tower_icon_" + this.towerType+"_1", cc.SpriteFrame, function (err, myspriteFrame: cc.SpriteFrame) {
  130. self.upfor2.getChildByName('iconspr').getComponent(cc.Sprite).spriteFrame = myspriteFrame;
  131. });
  132. }
  133. if (level >= 4) {
  134. this.skillupbg1.active = true;
  135. this.skillupbg2.active = true;
  136. if (this.towerType == TowerType.Enum_Barrack) {
  137. this.skillupbg3.active = true;
  138. }
  139. this.skillupbg1.on(cc.Node.EventType.TOUCH_START, this.upSkill1click, this);
  140. this.skillupbg2.on(cc.Node.EventType.TOUCH_START, this.upSkill2click, this);
  141. this.skillupbg3.on(cc.Node.EventType.TOUCH_START, this.upSkill3click, this);
  142. this.resetSkillTap();
  143. }
  144. }
  145. /**设置技能升级按钮 金币数 和图片 */
  146. private resetSkillTap() {
  147. let sale1 = this.skillupbg1.getChildByName('sale').getComponent(cc.Label);
  148. let sale2 = this.skillupbg2.getChildByName('sale').getComponent(cc.Label);
  149. let sale3 = this.skillupbg3.getChildByName('sale').getComponent(cc.Label);
  150. let self = this;
  151. if (this.skillLv[0] == 0) {
  152. sale1.string = this.tower.myDataObj.TowerData.up_gold[0].toString();
  153. let idd = this.tower.myDataObj.TowerData.next_skill[0];
  154. this.tower.myDataObj.writeSkill_Config(idd);
  155. cc.resources.load("game/skill/" + this.tower.myDataObj.SkillData.skill_icon, cc.SpriteFrame, function (err, myspriteFrame: cc.SpriteFrame) {
  156. self.skillupbg1.getChildByName('iconspr').getComponent(cc.Sprite).spriteFrame = myspriteFrame;
  157. });
  158. }
  159. else {
  160. this.tower.myDataObj.writeSkill_Config(this.tower.SkillIDL);
  161. sale1.string = this.tower.myDataObj.SkillData.up_gold.toString();
  162. for (let i = 1; i <= this.skillLv[0]; i++) {
  163. this.skillupbg1.getChildByName('skilllv' + i).opacity = 255;
  164. }
  165. cc.resources.load("game/skill/" + this.tower.myDataObj.SkillData.skill_icon, cc.SpriteFrame, function (err, myspriteFrame: cc.SpriteFrame) {
  166. self.skillupbg1.getChildByName('iconspr').getComponent(cc.Sprite).spriteFrame = myspriteFrame;
  167. });
  168. }
  169. if (this.skillLv[1] == 0) {
  170. sale2.string = this.tower.myDataObj.TowerData.up_gold[1].toString();
  171. let idd = this.tower.myDataObj.TowerData.next_skill[1];
  172. this.tower.myDataObj.writeSkill_Config(idd);
  173. cc.resources.load("game/skill/" + this.tower.myDataObj.SkillData.skill_icon, cc.SpriteFrame, function (err, myspriteFrame: cc.SpriteFrame) {
  174. self.skillupbg2.getChildByName('iconspr').getComponent(cc.Sprite).spriteFrame = myspriteFrame;
  175. });
  176. }
  177. else {
  178. this.tower.myDataObj.writeSkill_Config(this.tower.SkillIDR);
  179. sale2.string = this.tower.myDataObj.SkillData.up_gold.toString();
  180. for (let i = 1; i <= this.skillLv[1]; i++) {
  181. this.skillupbg2.getChildByName('skilllv' + i).opacity = 255;
  182. }
  183. cc.resources.load("game/skill/" + this.tower.myDataObj.SkillData.skill_icon, cc.SpriteFrame, function (err, myspriteFrame: cc.SpriteFrame) {
  184. self.skillupbg2.getChildByName('iconspr').getComponent(cc.Sprite).spriteFrame = myspriteFrame;
  185. });
  186. }
  187. if (this.towerType == TowerType.Enum_Barrack) {
  188. if (this.skillLv[2] == 0) {
  189. sale3.string = this.tower.myDataObj.TowerData.up_gold[2].toString();
  190. let idd = this.tower.myDataObj.TowerData.next_skill[2];
  191. this.tower.myDataObj.writeSkill_Config(idd);
  192. cc.resources.load("game/skill/" + this.tower.myDataObj.SkillData.skill_icon, cc.SpriteFrame, function (err, myspriteFrame: cc.SpriteFrame) {
  193. self.skillupbg3.getChildByName('iconspr').getComponent(cc.Sprite).spriteFrame = myspriteFrame;
  194. });
  195. }
  196. else {
  197. this.tower.myDataObj.writeSkill_Config(this.tower.SkillIDT);
  198. sale3.string = this.tower.myDataObj.SkillData.up_gold.toString();
  199. for (let i = 1; i <= this.skillLv[2]; i++) {
  200. this.skillupbg3.getChildByName('skilllv' + i).opacity = 255;
  201. }
  202. cc.resources.load("game/skill/" + this.tower.myDataObj.SkillData.skill_icon, cc.SpriteFrame, function (err, myspriteFrame: cc.SpriteFrame) {
  203. self.skillupbg3.getChildByName('iconspr').getComponent(cc.Sprite).spriteFrame = myspriteFrame;
  204. });
  205. }
  206. }
  207. }
  208. /**设置环的大小 */
  209. public setRedHuanScale(scale: number) {
  210. this.redquan.node.scale = scale / 275;
  211. }
  212. /**选择左技能塔 */
  213. private seleTower1click() {
  214. this.shengjiclick(0);
  215. }
  216. /**选择右技能塔 */
  217. private seleTower2click() {
  218. this.shengjiclick(1);
  219. }
  220. /**升级左边技能 */
  221. private upSkill1click() {
  222. if (this.skillLv[0] < 3) {
  223. this.shengjiclick(0);
  224. }
  225. }
  226. /**升级右边技能 */
  227. private upSkill2click() {
  228. if (this.skillLv[1] < 3) {
  229. this.shengjiclick(1);
  230. }
  231. }
  232. /**升级3边技能 */
  233. private upSkill3click() {
  234. if (this.skillLv[2] < 3) {
  235. this.shengjiclick(2);
  236. }
  237. }
  238. /**升级塔 */
  239. private shengjiclick(dex: number) {
  240. let level = this.tower.myDataObj.TowerData.tower_level;
  241. let upgold = this.tower.myDataObj.TowerData.up_gold[dex];
  242. if (level == 3) {
  243. upgold = this.tower.myDataObj.TowerData.up_gold[0];
  244. }
  245. let isgoldMore = upgold <= gameUI.instance.getGold();
  246. if (level >= 4 && this.skillLv[dex] > 0) {
  247. if (dex == 0) {
  248. this.tower.myDataObj.writeSkill_Config(this.tower.SkillIDL);
  249. isgoldMore = this.tower.myDataObj.SkillData.up_gold <= gameUI.instance.getGold();
  250. }
  251. if (dex == 1) {
  252. this.tower.myDataObj.writeSkill_Config(this.tower.SkillIDR);
  253. isgoldMore = this.tower.myDataObj.SkillData.up_gold <= gameUI.instance.getGold();
  254. }
  255. if (dex == 2) {
  256. this.tower.myDataObj.writeSkill_Config(this.tower.SkillIDT);
  257. isgoldMore = this.tower.myDataObj.SkillData.up_gold <= gameUI.instance.getGold();
  258. }
  259. }
  260. let canUpTower = gameUI.instance.getLevelLimit().indexOf(this.tower.myDataObj.TowerData.next_tower_id[dex]) < 0;
  261. let dagou = this.upgou;
  262. if (level == 3) {
  263. if (dex == 0) {
  264. dagou = this.upfor1.getChildByName('build_1').getComponent(cc.Sprite);
  265. }
  266. if (dex == 1) {
  267. dagou = this.upfor2.getChildByName('build_1').getComponent(cc.Sprite);
  268. }
  269. }
  270. if (level >= 4) {
  271. if (dex == 0) {
  272. dagou = this.skillupbg1.getChildByName('build_1').getComponent(cc.Sprite);
  273. }
  274. if (dex == 1) {
  275. dagou = this.skillupbg2.getChildByName('build_1').getComponent(cc.Sprite);
  276. }
  277. if (dex == 2) {
  278. dagou = this.skillupbg3.getChildByName('build_1').getComponent(cc.Sprite);
  279. }
  280. }
  281. if (isgoldMore && canUpTower) {
  282. if (dagou.node.opacity == 0) {
  283. dagou.node.opacity = 255;
  284. if (level < 3) {
  285. this.uptip.node.opacity = 0;
  286. }
  287. if (level == 3) {
  288. if (dex == 0) {
  289. this.upfor2.getChildByName('build_1').opacity = 0;
  290. }
  291. if (dex == 1) {
  292. this.upfor1.getChildByName('build_1').opacity = 0;
  293. }
  294. }
  295. if (level >= 4) {
  296. if (dex == 0) {
  297. this.skillupbg2.getChildByName('build_1').opacity = 0;
  298. this.skillupbg3.getChildByName('build_1').opacity = 0;
  299. }
  300. if (dex == 1) {
  301. this.skillupbg1.getChildByName('build_1').opacity = 0;
  302. this.skillupbg3.getChildByName('build_1').opacity = 0;
  303. }
  304. if (dex == 2) {
  305. this.skillupbg1.getChildByName('build_1').opacity = 0;
  306. this.skillupbg2.getChildByName('build_1').opacity = 0;
  307. }
  308. }
  309. }
  310. else {
  311. if (level <= 3) {
  312. towerManger.instance.delateTower(this.tower);
  313. towerManger.instance.UpTower(this.tower, this.tower.myDataObj.TowerData.next_tower_id[dex]);
  314. gameUI.instance.AddGold(-this.tower.myDataObj.TowerData.up_gold[0]);
  315. this.scheduleOnce(function () {
  316. this.tower.node.destroy();
  317. }, 0);
  318. }
  319. else {
  320. this.tower.setandUpSkillId(dex + 1);
  321. if (this.skillLv[dex] == 0) {
  322. gameUI.instance.AddGold(-this.tower.myDataObj.TowerData.up_gold[0]);
  323. }
  324. else {
  325. gameUI.instance.AddGold(-this.tower.myDataObj.SkillData.up_gold);
  326. }
  327. this.skillLv[dex]++;
  328. this.resetSkillTap();
  329. this.turnsmall();
  330. }
  331. }
  332. }
  333. }
  334. /**插旗 */
  335. private chaqiclick() {
  336. this.redquan.node.active = true;
  337. this.isCanChaqi = true;
  338. TapNode.instance.node.active = true;
  339. this.turnsmall();
  340. }
  341. /**插旗 */
  342. public chaqiTap(location: cc.Vec2) {
  343. if (this.isCanChaqi) {
  344. if (this.getIsInGopos(location) && this.tower.getIsInSqrt(location)) {
  345. this.isCanChaqi = false;
  346. this.redquan.node.active = false;
  347. TapNode.instance.node.active = false;
  348. this.tower.chaqiWalk(location);
  349. monsterManger.instance.chaqidian(location);
  350. }
  351. else {
  352. monsterManger.instance.updatest(location);
  353. }
  354. }
  355. }
  356. /**插旗位置判断 */
  357. private getIsInGopos(location: cc.Vec2): boolean {
  358. let leth = Number(gameData.instance().game_Const[7][2]);
  359. let laca = cc.v3(location.x, location.y);
  360. for (let i = 0; i < this.GoPos.length; i++) {
  361. const element = this.GoPos[i];
  362. if (element.sub(laca).mag() < leth) {
  363. return true;
  364. }
  365. }
  366. return false;
  367. }
  368. /**销毁塔卖钱*/
  369. private destoryclick() {
  370. if (this.salegou.node.opacity == 0) {
  371. this.salegou.node.opacity = 255;
  372. this.saletip.node.opacity = 0;
  373. }
  374. else {
  375. this.tower._taside.openTouchOn();
  376. towerManger.instance.delateTower(this.tower);
  377. let value_gold = this.tower.myDataObj.TowerData.value_gold;
  378. if (this.tower.SkillIDL > 0) {
  379. this.tower.myDataObj.writeSkill_Config(this.tower.SkillIDL);
  380. value_gold += this.tower.myDataObj.SkillData.up_gold;
  381. this.tower._taside.addtowerGold(this.tower.myDataObj.SkillData.up_gold);
  382. }
  383. if (this.tower.SkillIDR > 0) {
  384. this.tower.myDataObj.writeSkill_Config(this.tower.SkillIDR);
  385. value_gold += this.tower.myDataObj.SkillData.up_gold;
  386. this.tower._taside.addtowerGold(this.tower.myDataObj.SkillData.up_gold);
  387. }
  388. if (this.towerType == TowerType.Enum_Barrack) {
  389. if (this.tower.SkillIDT > 0) {
  390. this.tower.myDataObj.writeSkill_Config(this.tower.SkillIDT);
  391. value_gold += this.tower.myDataObj.SkillData.up_gold;
  392. this.tower._taside.addtowerGold(this.tower.myDataObj.SkillData.up_gold);
  393. }
  394. }
  395. if (towerManger.instance.talantData[0].length > 0 && this.towerType == TowerType.Enum_Arrow) {
  396. value_gold = this.tower._taside.gettowerGold() * towerManger.instance.talantData[0][0];
  397. this.tower._taside.settowerGold(0);
  398. }
  399. gameUI.instance.AddGold(value_gold);
  400. this.tower.node.destroy();
  401. }
  402. }
  403. //iconspr
  404. /**显示金币不足时状态 */
  405. private showNosele() {
  406. let isgoldMore = this.tower.myDataObj.TowerData.up_gold[0] <= gameUI.instance.getGold();
  407. let canUpTower = gameUI.instance.getLevelLimit().indexOf(this.tower.myDataObj.TowerData.next_tower_id[0]) < 0;
  408. let level = this.tower.myDataObj.TowerData.tower_level;
  409. if (level < 3) {
  410. this.uptip.node.opacity = 255;
  411. if (canUpTower) {
  412. this.nosele.node.opacity = 0;
  413. this.shengji.node.getChildByName('skillupbg3').opacity = 255;
  414. this.shengji.node.getChildByName('iconspr').opacity = 255;
  415. this.sale.node.opacity = 255;
  416. }
  417. else {
  418. this.nosele.node.opacity = 255;
  419. this.shengji.node.getChildByName('iconspr').opacity = 0;
  420. this.sale.node.opacity = 0;
  421. this.shengji.node.getChildByName('skillupbg3').opacity = 0;
  422. }
  423. if (isgoldMore) {
  424. this.shengji.node.getChildByName('iconspr').getComponent(cc.Sprite).setMaterial(0, this.norMaterial);
  425. this.sale.node.color = cc.color(235, 255, 6);
  426. }
  427. else {
  428. this.shengji.node.getChildByName('iconspr').getComponent(cc.Sprite).setMaterial(0, this.grayMaterial);
  429. this.sale.node.color = cc.color(102, 91, 91);
  430. }
  431. }
  432. if (level == 3) {
  433. if (canUpTower) {
  434. this.upfor1.getChildByName('build_2').opacity = 0;
  435. this.upfor1.getChildByName('iconspr').opacity = 255;
  436. this.upfor1.getChildByName('sale').opacity = 255;
  437. this.upfor1.getChildByName('skillupbg3').opacity = 255;
  438. }
  439. else {
  440. this.upfor1.getChildByName('build_2').opacity = 255;
  441. this.upfor1.getChildByName('iconspr').opacity = 0;
  442. this.upfor1.getChildByName('sale').opacity = 0;
  443. this.upfor1.getChildByName('skillupbg3').opacity = 0;
  444. }
  445. let canUpTower1 = gameUI.instance.getLevelLimit().indexOf(this.tower.myDataObj.TowerData.next_tower_id[1]) < 0;
  446. if (canUpTower1) {
  447. this.upfor2.getChildByName('build_2').opacity = 0;
  448. this.upfor2.getChildByName('iconspr').opacity = 255;
  449. this.upfor2.getChildByName('sale').opacity = 255;
  450. this.upfor2.getChildByName('skillupbg3').opacity = 255;
  451. }
  452. else {
  453. this.upfor2.getChildByName('build_2').opacity = 255;
  454. this.upfor2.getChildByName('iconspr').opacity = 0;
  455. this.upfor2.getChildByName('sale').opacity = 0;
  456. this.upfor2.getChildByName('skillupbg3').opacity = 0;
  457. }
  458. if (isgoldMore) {
  459. this.upfor1.getChildByName('iconspr').getComponent(cc.Sprite).setMaterial(0, this.norMaterial);
  460. this.upfor2.getChildByName('iconspr').getComponent(cc.Sprite).setMaterial(0, this.norMaterial);
  461. this.upfor1.getChildByName('sale').color = cc.color(235, 255, 6);
  462. this.upfor2.getChildByName('sale').color = cc.color(235, 255, 6);
  463. }
  464. else {
  465. this.upfor1.getChildByName('iconspr').getComponent(cc.Sprite).setMaterial(0, this.grayMaterial);
  466. this.upfor2.getChildByName('iconspr').getComponent(cc.Sprite).setMaterial(0, this.grayMaterial);
  467. this.upfor1.getChildByName('sale').color = cc.color(102, 91, 91);
  468. this.upfor2.getChildByName('sale').color = cc.color(102, 91, 91);
  469. }
  470. }
  471. if (level >= 4) {
  472. if (this.tower.SkillIDL == 0) {
  473. let isgoldMore = this.tower.myDataObj.TowerData.up_gold[0] <= gameUI.instance.getGold();
  474. if (isgoldMore) {
  475. this.skillupbg1.getChildByName('iconspr').getComponent(cc.Sprite).setMaterial(0, this.norMaterial);
  476. this.skillupbg1.getChildByName('sale').color = cc.color(235, 255, 6);
  477. }
  478. else {
  479. this.skillupbg1.getChildByName('iconspr').getComponent(cc.Sprite).setMaterial(0, this.grayMaterial);
  480. this.skillupbg1.getChildByName('sale').color = cc.color(102, 91, 91);
  481. }
  482. }
  483. else {
  484. if (this.skillLv[0] < 3) {
  485. this.tower.myDataObj.writeSkill_Config(this.tower.SkillIDL);
  486. let isgoldMore = this.tower.myDataObj.SkillData.up_gold <= gameUI.instance.getGold();
  487. if (isgoldMore) {
  488. this.skillupbg1.getChildByName('iconspr').getComponent(cc.Sprite).setMaterial(0, this.norMaterial);
  489. this.skillupbg1.getChildByName('sale').color = cc.color(235, 255, 6);
  490. }
  491. else {
  492. this.skillupbg1.getChildByName('iconspr').getComponent(cc.Sprite).setMaterial(0, this.grayMaterial);
  493. this.skillupbg1.getChildByName('sale').color = cc.color(102, 91, 91);
  494. }
  495. }
  496. else {
  497. this.skillupbg1.getChildByName('sale').opacity = 0;
  498. this.skillupbg1.getChildByName('skillupbg3').opacity = 0;
  499. }
  500. }
  501. if (this.tower.SkillIDR == 0) {
  502. let isgoldMore = this.tower.myDataObj.TowerData.up_gold[1] <= gameUI.instance.getGold();
  503. if (isgoldMore) {
  504. this.skillupbg2.getChildByName('iconspr').getComponent(cc.Sprite).setMaterial(0, this.norMaterial);
  505. this.skillupbg2.getChildByName('sale').color = cc.color(235, 255, 6);
  506. }
  507. else {
  508. this.skillupbg2.getChildByName('iconspr').getComponent(cc.Sprite).setMaterial(0, this.grayMaterial);
  509. this.skillupbg2.getChildByName('sale').color = cc.color(102, 91, 91);
  510. }
  511. }
  512. else {
  513. if (this.skillLv[1] < 3) {
  514. this.tower.myDataObj.writeSkill_Config(this.tower.SkillIDR);
  515. let isgoldMore = this.tower.myDataObj.SkillData.up_gold <= gameUI.instance.getGold();
  516. if (isgoldMore) {
  517. this.skillupbg2.getChildByName('iconspr').getComponent(cc.Sprite).setMaterial(0, this.norMaterial);
  518. this.skillupbg2.getChildByName('sale').color = cc.color(235, 255, 6);
  519. }
  520. else {
  521. this.skillupbg2.getChildByName('iconspr').getComponent(cc.Sprite).setMaterial(0, this.grayMaterial);
  522. this.skillupbg2.getChildByName('sale').color = cc.color(102, 91, 91);
  523. }
  524. }
  525. else {
  526. this.skillupbg2.getChildByName('sale').opacity = 0;
  527. this.skillupbg2.getChildByName('skillupbg3').opacity = 0;
  528. }
  529. }
  530. if (this.towerType == TowerType.Enum_Barrack) {
  531. if (this.tower.SkillIDT == 0) {
  532. let isgoldMore = this.tower.myDataObj.TowerData.up_gold[2] <= gameUI.instance.getGold();
  533. if (isgoldMore) {
  534. this.skillupbg3.getChildByName('iconspr').getComponent(cc.Sprite).setMaterial(0, this.norMaterial);
  535. this.skillupbg3.getChildByName('sale').color = cc.color(235, 255, 6);
  536. }
  537. else {
  538. this.skillupbg3.getChildByName('iconspr').getComponent(cc.Sprite).setMaterial(0, this.grayMaterial);
  539. this.skillupbg3.getChildByName('sale').color = cc.color(102, 91, 91);
  540. }
  541. }
  542. else {
  543. if (this.skillLv[2] < 3) {
  544. this.tower.myDataObj.writeSkill_Config(this.tower.SkillIDT);
  545. let isgoldMore = this.tower.myDataObj.SkillData.up_gold <= gameUI.instance.getGold();
  546. if (isgoldMore) {
  547. this.skillupbg3.getChildByName('iconspr').getComponent(cc.Sprite).setMaterial(0, this.norMaterial);
  548. this.skillupbg3.getChildByName('sale').color = cc.color(235, 255, 6);
  549. }
  550. else {
  551. this.skillupbg3.getChildByName('iconspr').getComponent(cc.Sprite).setMaterial(0, this.grayMaterial);
  552. this.skillupbg3.getChildByName('sale').color = cc.color(102, 91, 91);
  553. }
  554. }
  555. else {
  556. this.skillupbg3.getChildByName('sale').opacity = 0;
  557. this.skillupbg3.getChildByName('skillupbg3').opacity = 0;
  558. }
  559. }
  560. }
  561. }
  562. }
  563. /**打开圆环 */
  564. private turnbig() {
  565. this.showNosele();
  566. towerManger.instance.closedHuan();
  567. this.huan.node.scale = 0.5;
  568. this.huan.node.opacity = 0;
  569. this.huan.node.active = true;
  570. this.redquan.node.active = true;
  571. this.huan.node.stopAllActions();
  572. this.node.zIndex = 1007;
  573. cc.tween(this.huan.node)
  574. .to(0.1, { scale: 1, opacity: 255 })
  575. .call(() => {
  576. this.isOpen = true;
  577. })
  578. .start();
  579. }
  580. /**关闭圆环 */
  581. public turnsmall() {
  582. if (this.isOpen) {
  583. this.node.zIndex = 1006;
  584. this.huan.node.stopAllActions();
  585. cc.tween(this.huan.node)
  586. .to(0.1, { scale: 0.5, opacity: 0 })
  587. .call(() => {
  588. this.huan.node.active = false;
  589. this.isOpen = false;
  590. if (!this.isCanChaqi) {
  591. this.redquan.node.active = false;
  592. }
  593. this.upgou.node.opacity = 0;
  594. this.salegou.node.opacity = 0;
  595. this.saletip.node.opacity = 255;
  596. this.upfor1.getChildByName('build_1').opacity = 0;
  597. this.upfor2.getChildByName('build_1').opacity = 0;
  598. this.skillupbg1.getChildByName('build_1').opacity = 0;
  599. this.skillupbg2.getChildByName('build_1').opacity = 0;
  600. this.skillupbg3.getChildByName('build_1').opacity = 0;
  601. })
  602. .start();
  603. }
  604. }
  605. /**点击泥土 */
  606. private touchNode() {
  607. this.turnbig();
  608. }
  609. }