|
|
@@ -0,0 +1,674 @@
|
|
|
+import towerManger from "./towerManger";
|
|
|
+import { TowerType } from "../../configData/Enum";
|
|
|
+import gameUI from "../UIFace/gameUI";
|
|
|
+
|
|
|
+import monsterManger from "../monster/monsterManger";
|
|
|
+import gameData from "../../configData/gameData";
|
|
|
+import TapNode from "../UIFace/TapNode";
|
|
|
+
|
|
|
+const { ccclass, property } = cc._decorator;
|
|
|
+
|
|
|
+@ccclass
|
|
|
+export default class TowerHuan extends cc.Component {
|
|
|
+
|
|
|
+ /**环点击区域 */
|
|
|
+ @property(cc.Node)
|
|
|
+ private tapSqrt: cc.Node = null;
|
|
|
+
|
|
|
+ /**预警范围 */
|
|
|
+ @property(cc.Sprite)
|
|
|
+ private lanse: cc.Sprite = null;
|
|
|
+ /**预警范围 */
|
|
|
+ @property(cc.Sprite)
|
|
|
+ private redquan: cc.Sprite = null;
|
|
|
+ /** 圆环底座*/
|
|
|
+ @property(cc.Sprite)
|
|
|
+ private huan: cc.Sprite = null;
|
|
|
+ /**不可升级标志 */
|
|
|
+ @property(cc.Sprite)
|
|
|
+ private nosele: cc.Sprite = null;
|
|
|
+ /**升级金币数量 */
|
|
|
+ @property(cc.Label)
|
|
|
+ private sale: cc.Label = null;
|
|
|
+
|
|
|
+ /**升级底座 */
|
|
|
+ @property(cc.Sprite)
|
|
|
+ private shengji: cc.Sprite = null;
|
|
|
+
|
|
|
+ /**插旗底座 */
|
|
|
+ @property(cc.Sprite)
|
|
|
+ private chaqi: cc.Sprite = null;
|
|
|
+ /**卖掉塔底座 */
|
|
|
+ @property(cc.Sprite)
|
|
|
+ private towerdestory: cc.Sprite = null;
|
|
|
+
|
|
|
+ /**升级标志 */
|
|
|
+ @property(cc.Sprite)
|
|
|
+ private uptip: cc.Sprite = null;
|
|
|
+ /**升级勾 */
|
|
|
+ @property(cc.Sprite)
|
|
|
+ private upgou: cc.Sprite = null;
|
|
|
+ /**卖钱标志 */
|
|
|
+ @property(cc.Sprite)
|
|
|
+ private saletip: cc.Sprite = null;
|
|
|
+ /**卖钱勾 */
|
|
|
+ @property(cc.Sprite)
|
|
|
+ private salegou: cc.Sprite = null;
|
|
|
+ /**圆环是否打开 */
|
|
|
+ public isOpen = false;
|
|
|
+ /**是否可以插旗 */
|
|
|
+ public isCanChaqi = false;
|
|
|
+
|
|
|
+ /**升四级塔选项 */
|
|
|
+ private upfor1: cc.Node = null;
|
|
|
+ private upfor2: cc.Node = null;
|
|
|
+ /**技能升级选项 */
|
|
|
+ private skillupbg1: cc.Node = null;
|
|
|
+ private skillupbg2: cc.Node = null;
|
|
|
+ private skillupbg3: cc.Node = null;
|
|
|
+
|
|
|
+ private skillLv = [0, 0, 0];
|
|
|
+ private GoPos: cc.Vec3[] = [];
|
|
|
+ private norMaterial: cc.Material = cc.Material.getBuiltinMaterial('2d-sprite');
|
|
|
+ private grayMaterial: cc.Material = cc.Material.getBuiltinMaterial('2d-gray-sprite');
|
|
|
+ private tower = null;
|
|
|
+ private towerType: TowerType = 1;
|
|
|
+ onLoad() {
|
|
|
+ this.tapSqrt.on(cc.Node.EventType.TOUCH_START, this.touchNode, this);
|
|
|
+ this.initSpr();
|
|
|
+ this.GoPos = gameUI.instance.getGoPos();
|
|
|
+ }
|
|
|
+
|
|
|
+ private initSpr() {
|
|
|
+ this.redquan.node.active = false;
|
|
|
+ this.huan.node.active = false;
|
|
|
+
|
|
|
+
|
|
|
+ this.chaqi.node.on(cc.Node.EventType.TOUCH_START, this.chaqiclick, this);
|
|
|
+ this.towerdestory.node.on(cc.Node.EventType.TOUCH_START, this.destoryclick, this);
|
|
|
+ }
|
|
|
+
|
|
|
+ public setTowerType(type: TowerType) {
|
|
|
+ this.towerType = type;
|
|
|
+ this.chaqi.node.active = (type == TowerType.Enum_Barrack);
|
|
|
+ if (type == TowerType.Enum_Barrack) {
|
|
|
+ this.redquan.spriteFrame = this.lanse.spriteFrame;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**设置塔 */
|
|
|
+ public setTower(tower) {
|
|
|
+ this.tower = tower;
|
|
|
+ this.sale.string = tower.myDataObj.TowerData.up_gold[0].toString();
|
|
|
+ // console.log("------");
|
|
|
+ this.initModel();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**设置塔环类型 */
|
|
|
+ private initModel() {
|
|
|
+ let level = this.tower.myDataObj.TowerData.tower_level;
|
|
|
+
|
|
|
+ this.shengji.node.active = false;
|
|
|
+ this.upfor1 = this.huan.node.getChildByName('tower_upFour_1');
|
|
|
+ this.upfor2 = this.huan.node.getChildByName('tower_upFour_2');
|
|
|
+ this.skillupbg1 = this.huan.node.getChildByName('skillupbg1');
|
|
|
+ this.skillupbg2 = this.huan.node.getChildByName('skillupbg2');
|
|
|
+ this.skillupbg3 = this.huan.node.getChildByName('skillupbg3');
|
|
|
+ this.upfor1.active = false;
|
|
|
+ this.upfor2.active = false;
|
|
|
+ this.skillupbg1.active = false;
|
|
|
+ this.skillupbg2.active = false;
|
|
|
+ this.skillupbg3.active = false;
|
|
|
+ if (this.towerType == TowerType.Enum_Barrack) {
|
|
|
+ this.skillupbg1.setPosition(-139, 16);
|
|
|
+ this.skillupbg2.setPosition(-32, 134);
|
|
|
+ this.skillupbg3.setPosition(124, 98);
|
|
|
+ }
|
|
|
+ if (level < 3) {
|
|
|
+ this.shengji.node.active = true;
|
|
|
+ this.shengji.node.on(cc.Node.EventType.TOUCH_START, () => {
|
|
|
+ this.shengjiclick(0);
|
|
|
+ }, this);
|
|
|
+ }
|
|
|
+ if (level == 3) {
|
|
|
+ this.upfor1.active = true;
|
|
|
+ this.upfor2.active = true;
|
|
|
+ this.upfor1.on(cc.Node.EventType.TOUCH_START, this.seleTower1click, this);
|
|
|
+ this.upfor2.on(cc.Node.EventType.TOUCH_START, this.seleTower2click, this);
|
|
|
+ let sale1 = this.upfor1.getChildByName('sale').getComponent(cc.Label);
|
|
|
+ let sale2 = this.upfor2.getChildByName('sale').getComponent(cc.Label);
|
|
|
+ sale1.string = this.tower.myDataObj.TowerData.up_gold[0].toString();
|
|
|
+ sale2.string = this.tower.myDataObj.TowerData.up_gold[0].toString();
|
|
|
+ let self = this;
|
|
|
+ cc.resources.load("game/skill/tower_icon_" + this.towerType+"_0", cc.SpriteFrame, function (err, myspriteFrame: cc.SpriteFrame) {
|
|
|
+ self.upfor1.getChildByName('iconspr').getComponent(cc.Sprite).spriteFrame = myspriteFrame;
|
|
|
+ });
|
|
|
+ cc.resources.load("game/skill/tower_icon_" + this.towerType+"_1", cc.SpriteFrame, function (err, myspriteFrame: cc.SpriteFrame) {
|
|
|
+ self.upfor2.getChildByName('iconspr').getComponent(cc.Sprite).spriteFrame = myspriteFrame;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (level >= 4) {
|
|
|
+ this.skillupbg1.active = true;
|
|
|
+ this.skillupbg2.active = true;
|
|
|
+ if (this.towerType == TowerType.Enum_Barrack) {
|
|
|
+ this.skillupbg3.active = true;
|
|
|
+ }
|
|
|
+ this.skillupbg1.on(cc.Node.EventType.TOUCH_START, this.upSkill1click, this);
|
|
|
+ this.skillupbg2.on(cc.Node.EventType.TOUCH_START, this.upSkill2click, this);
|
|
|
+ this.skillupbg3.on(cc.Node.EventType.TOUCH_START, this.upSkill3click, this);
|
|
|
+ this.resetSkillTap();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**设置技能升级按钮 金币数 和图片 */
|
|
|
+ private resetSkillTap() {
|
|
|
+ let sale1 = this.skillupbg1.getChildByName('sale').getComponent(cc.Label);
|
|
|
+ let sale2 = this.skillupbg2.getChildByName('sale').getComponent(cc.Label);
|
|
|
+ let sale3 = this.skillupbg3.getChildByName('sale').getComponent(cc.Label);
|
|
|
+ let self = this;
|
|
|
+ if (this.skillLv[0] == 0) {
|
|
|
+ sale1.string = this.tower.myDataObj.TowerData.up_gold[0].toString();
|
|
|
+ let idd = this.tower.myDataObj.TowerData.next_skill[0];
|
|
|
+ this.tower.myDataObj.writeSkill_Config(idd);
|
|
|
+ cc.resources.load("game/skill/" + this.tower.myDataObj.SkillData.skill_icon, cc.SpriteFrame, function (err, myspriteFrame: cc.SpriteFrame) {
|
|
|
+ self.skillupbg1.getChildByName('iconspr').getComponent(cc.Sprite).spriteFrame = myspriteFrame;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this.tower.myDataObj.writeSkill_Config(this.tower.SkillIDL);
|
|
|
+ sale1.string = this.tower.myDataObj.SkillData.up_gold.toString();
|
|
|
+
|
|
|
+ for (let i = 1; i <= this.skillLv[0]; i++) {
|
|
|
+ this.skillupbg1.getChildByName('skilllv' + i).opacity = 255;
|
|
|
+ }
|
|
|
+
|
|
|
+ cc.resources.load("game/skill/" + this.tower.myDataObj.SkillData.skill_icon, cc.SpriteFrame, function (err, myspriteFrame: cc.SpriteFrame) {
|
|
|
+ self.skillupbg1.getChildByName('iconspr').getComponent(cc.Sprite).spriteFrame = myspriteFrame;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.skillLv[1] == 0) {
|
|
|
+ sale2.string = this.tower.myDataObj.TowerData.up_gold[1].toString();
|
|
|
+ let idd = this.tower.myDataObj.TowerData.next_skill[1];
|
|
|
+ this.tower.myDataObj.writeSkill_Config(idd);
|
|
|
+ cc.resources.load("game/skill/" + this.tower.myDataObj.SkillData.skill_icon, cc.SpriteFrame, function (err, myspriteFrame: cc.SpriteFrame) {
|
|
|
+ self.skillupbg2.getChildByName('iconspr').getComponent(cc.Sprite).spriteFrame = myspriteFrame;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this.tower.myDataObj.writeSkill_Config(this.tower.SkillIDR);
|
|
|
+ sale2.string = this.tower.myDataObj.SkillData.up_gold.toString();
|
|
|
+ for (let i = 1; i <= this.skillLv[1]; i++) {
|
|
|
+ this.skillupbg2.getChildByName('skilllv' + i).opacity = 255;
|
|
|
+ }
|
|
|
+
|
|
|
+ cc.resources.load("game/skill/" + this.tower.myDataObj.SkillData.skill_icon, cc.SpriteFrame, function (err, myspriteFrame: cc.SpriteFrame) {
|
|
|
+ self.skillupbg2.getChildByName('iconspr').getComponent(cc.Sprite).spriteFrame = myspriteFrame;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.towerType == TowerType.Enum_Barrack) {
|
|
|
+ if (this.skillLv[2] == 0) {
|
|
|
+ sale3.string = this.tower.myDataObj.TowerData.up_gold[2].toString();
|
|
|
+ let idd = this.tower.myDataObj.TowerData.next_skill[2];
|
|
|
+ this.tower.myDataObj.writeSkill_Config(idd);
|
|
|
+ cc.resources.load("game/skill/" + this.tower.myDataObj.SkillData.skill_icon, cc.SpriteFrame, function (err, myspriteFrame: cc.SpriteFrame) {
|
|
|
+ self.skillupbg3.getChildByName('iconspr').getComponent(cc.Sprite).spriteFrame = myspriteFrame;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this.tower.myDataObj.writeSkill_Config(this.tower.SkillIDT);
|
|
|
+ sale3.string = this.tower.myDataObj.SkillData.up_gold.toString();
|
|
|
+ for (let i = 1; i <= this.skillLv[2]; i++) {
|
|
|
+ this.skillupbg3.getChildByName('skilllv' + i).opacity = 255;
|
|
|
+ }
|
|
|
+ cc.resources.load("game/skill/" + this.tower.myDataObj.SkillData.skill_icon, cc.SpriteFrame, function (err, myspriteFrame: cc.SpriteFrame) {
|
|
|
+ self.skillupbg3.getChildByName('iconspr').getComponent(cc.Sprite).spriteFrame = myspriteFrame;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**设置环的大小 */
|
|
|
+ public setRedHuanScale(scale: number) {
|
|
|
+ this.redquan.node.scale = scale / 275;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**选择左技能塔 */
|
|
|
+ private seleTower1click() {
|
|
|
+ this.shengjiclick(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**选择右技能塔 */
|
|
|
+ private seleTower2click() {
|
|
|
+ this.shengjiclick(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**升级左边技能 */
|
|
|
+ private upSkill1click() {
|
|
|
+ if (this.skillLv[0] < 3) {
|
|
|
+ this.shengjiclick(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**升级右边技能 */
|
|
|
+ private upSkill2click() {
|
|
|
+ if (this.skillLv[1] < 3) {
|
|
|
+ this.shengjiclick(1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**升级3边技能 */
|
|
|
+ private upSkill3click() {
|
|
|
+ if (this.skillLv[2] < 3) {
|
|
|
+ this.shengjiclick(2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**升级塔 */
|
|
|
+ private shengjiclick(dex: number) {
|
|
|
+ let level = this.tower.myDataObj.TowerData.tower_level;
|
|
|
+ let upgold = this.tower.myDataObj.TowerData.up_gold[dex];
|
|
|
+ if (level == 3) {
|
|
|
+ upgold = this.tower.myDataObj.TowerData.up_gold[0];
|
|
|
+ }
|
|
|
+ let isgoldMore = upgold <= gameUI.instance.getGold();
|
|
|
+ if (level >= 4 && this.skillLv[dex] > 0) {
|
|
|
+ if (dex == 0) {
|
|
|
+ this.tower.myDataObj.writeSkill_Config(this.tower.SkillIDL);
|
|
|
+ isgoldMore = this.tower.myDataObj.SkillData.up_gold <= gameUI.instance.getGold();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (dex == 1) {
|
|
|
+ this.tower.myDataObj.writeSkill_Config(this.tower.SkillIDR);
|
|
|
+ isgoldMore = this.tower.myDataObj.SkillData.up_gold <= gameUI.instance.getGold();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (dex == 2) {
|
|
|
+ this.tower.myDataObj.writeSkill_Config(this.tower.SkillIDT);
|
|
|
+ isgoldMore = this.tower.myDataObj.SkillData.up_gold <= gameUI.instance.getGold();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ let canUpTower = gameUI.instance.getLevelLimit().indexOf(this.tower.myDataObj.TowerData.next_tower_id[dex]) < 0;
|
|
|
+ let dagou = this.upgou;
|
|
|
+
|
|
|
+ if (level == 3) {
|
|
|
+ if (dex == 0) {
|
|
|
+ dagou = this.upfor1.getChildByName('build_1').getComponent(cc.Sprite);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (dex == 1) {
|
|
|
+ dagou = this.upfor2.getChildByName('build_1').getComponent(cc.Sprite);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (level >= 4) {
|
|
|
+ if (dex == 0) {
|
|
|
+ dagou = this.skillupbg1.getChildByName('build_1').getComponent(cc.Sprite);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (dex == 1) {
|
|
|
+ dagou = this.skillupbg2.getChildByName('build_1').getComponent(cc.Sprite);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (dex == 2) {
|
|
|
+ dagou = this.skillupbg3.getChildByName('build_1').getComponent(cc.Sprite);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isgoldMore && canUpTower) {
|
|
|
+ if (dagou.node.opacity == 0) {
|
|
|
+ dagou.node.opacity = 255;
|
|
|
+ if (level < 3) {
|
|
|
+ this.uptip.node.opacity = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (level == 3) {
|
|
|
+ if (dex == 0) {
|
|
|
+ this.upfor2.getChildByName('build_1').opacity = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (dex == 1) {
|
|
|
+ this.upfor1.getChildByName('build_1').opacity = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (level >= 4) {
|
|
|
+ if (dex == 0) {
|
|
|
+ this.skillupbg2.getChildByName('build_1').opacity = 0;
|
|
|
+ this.skillupbg3.getChildByName('build_1').opacity = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (dex == 1) {
|
|
|
+ this.skillupbg1.getChildByName('build_1').opacity = 0;
|
|
|
+ this.skillupbg3.getChildByName('build_1').opacity = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (dex == 2) {
|
|
|
+ this.skillupbg1.getChildByName('build_1').opacity = 0;
|
|
|
+ this.skillupbg2.getChildByName('build_1').opacity = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ if (level <= 3) {
|
|
|
+ towerManger.instance.delateTower(this.tower);
|
|
|
+ towerManger.instance.UpTower(this.tower, this.tower.myDataObj.TowerData.next_tower_id[dex]);
|
|
|
+ gameUI.instance.AddGold(-this.tower.myDataObj.TowerData.up_gold[0]);
|
|
|
+ this.scheduleOnce(function () {
|
|
|
+ this.tower.node.destroy();
|
|
|
+ }, 0);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this.tower.setandUpSkillId(dex + 1);
|
|
|
+ if (this.skillLv[dex] == 0) {
|
|
|
+ gameUI.instance.AddGold(-this.tower.myDataObj.TowerData.up_gold[0]);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ gameUI.instance.AddGold(-this.tower.myDataObj.SkillData.up_gold);
|
|
|
+ }
|
|
|
+ this.skillLv[dex]++;
|
|
|
+
|
|
|
+ this.resetSkillTap();
|
|
|
+ this.turnsmall();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**插旗 */
|
|
|
+ private chaqiclick() {
|
|
|
+ this.redquan.node.active = true;
|
|
|
+ this.isCanChaqi = true;
|
|
|
+ TapNode.instance.node.active = true;
|
|
|
+ this.turnsmall();
|
|
|
+ }
|
|
|
+ /**插旗 */
|
|
|
+ public chaqiTap(location: cc.Vec2) {
|
|
|
+ if (this.isCanChaqi) {
|
|
|
+ if (this.getIsInGopos(location) && this.tower.getIsInSqrt(location)) {
|
|
|
+ this.isCanChaqi = false;
|
|
|
+ this.redquan.node.active = false;
|
|
|
+ TapNode.instance.node.active = false;
|
|
|
+ this.tower.chaqiWalk(location);
|
|
|
+ monsterManger.instance.chaqidian(location);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ monsterManger.instance.updatest(location);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**插旗位置判断 */
|
|
|
+ private getIsInGopos(location: cc.Vec2): boolean {
|
|
|
+ let leth = Number(gameData.instance().game_Const[7][2]);
|
|
|
+ let laca = cc.v3(location.x, location.y);
|
|
|
+ for (let i = 0; i < this.GoPos.length; i++) {
|
|
|
+ const element = this.GoPos[i];
|
|
|
+ if (element.sub(laca).mag() < leth) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**销毁塔卖钱*/
|
|
|
+ private destoryclick() {
|
|
|
+ if (this.salegou.node.opacity == 0) {
|
|
|
+ this.salegou.node.opacity = 255;
|
|
|
+ this.saletip.node.opacity = 0;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this.tower._taside.openTouchOn();
|
|
|
+ towerManger.instance.delateTower(this.tower);
|
|
|
+ let value_gold = this.tower.myDataObj.TowerData.value_gold;
|
|
|
+ if (this.tower.SkillIDL > 0) {
|
|
|
+ this.tower.myDataObj.writeSkill_Config(this.tower.SkillIDL);
|
|
|
+ value_gold += this.tower.myDataObj.SkillData.up_gold;
|
|
|
+ this.tower._taside.addtowerGold(this.tower.myDataObj.SkillData.up_gold);
|
|
|
+ }
|
|
|
+ if (this.tower.SkillIDR > 0) {
|
|
|
+ this.tower.myDataObj.writeSkill_Config(this.tower.SkillIDR);
|
|
|
+ value_gold += this.tower.myDataObj.SkillData.up_gold;
|
|
|
+ this.tower._taside.addtowerGold(this.tower.myDataObj.SkillData.up_gold);
|
|
|
+ }
|
|
|
+ if (this.towerType == TowerType.Enum_Barrack) {
|
|
|
+ if (this.tower.SkillIDT > 0) {
|
|
|
+ this.tower.myDataObj.writeSkill_Config(this.tower.SkillIDT);
|
|
|
+ value_gold += this.tower.myDataObj.SkillData.up_gold;
|
|
|
+ this.tower._taside.addtowerGold(this.tower.myDataObj.SkillData.up_gold);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (towerManger.instance.talantData[0].length > 0 && this.towerType == TowerType.Enum_Arrow) {
|
|
|
+ value_gold = this.tower._taside.gettowerGold() * towerManger.instance.talantData[0][0];
|
|
|
+ this.tower._taside.settowerGold(0);
|
|
|
+ }
|
|
|
+ gameUI.instance.AddGold(value_gold);
|
|
|
+ this.tower.node.destroy();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //iconspr
|
|
|
+ /**显示金币不足时状态 */
|
|
|
+ private showNosele() {
|
|
|
+ let isgoldMore = this.tower.myDataObj.TowerData.up_gold[0] <= gameUI.instance.getGold();
|
|
|
+ let canUpTower = gameUI.instance.getLevelLimit().indexOf(this.tower.myDataObj.TowerData.next_tower_id[0]) < 0;
|
|
|
+ let level = this.tower.myDataObj.TowerData.tower_level;
|
|
|
+ if (level < 3) {
|
|
|
+ this.uptip.node.opacity = 255;
|
|
|
+ if (canUpTower) {
|
|
|
+ this.nosele.node.opacity = 0;
|
|
|
+ this.shengji.node.getChildByName('skillupbg3').opacity = 255;
|
|
|
+ this.shengji.node.getChildByName('iconspr').opacity = 255;
|
|
|
+ this.sale.node.opacity = 255;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this.nosele.node.opacity = 255;
|
|
|
+ this.shengji.node.getChildByName('iconspr').opacity = 0;
|
|
|
+ this.sale.node.opacity = 0;
|
|
|
+ this.shengji.node.getChildByName('skillupbg3').opacity = 0;
|
|
|
+ }
|
|
|
+ if (isgoldMore) {
|
|
|
+ this.shengji.node.getChildByName('iconspr').getComponent(cc.Sprite).setMaterial(0, this.norMaterial);
|
|
|
+ this.sale.node.color = cc.color(235, 255, 6);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this.shengji.node.getChildByName('iconspr').getComponent(cc.Sprite).setMaterial(0, this.grayMaterial);
|
|
|
+ this.sale.node.color = cc.color(102, 91, 91);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (level == 3) {
|
|
|
+
|
|
|
+ if (canUpTower) {
|
|
|
+ this.upfor1.getChildByName('build_2').opacity = 0;
|
|
|
+ this.upfor1.getChildByName('iconspr').opacity = 255;
|
|
|
+ this.upfor1.getChildByName('sale').opacity = 255;
|
|
|
+ this.upfor1.getChildByName('skillupbg3').opacity = 255;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this.upfor1.getChildByName('build_2').opacity = 255;
|
|
|
+ this.upfor1.getChildByName('iconspr').opacity = 0;
|
|
|
+ this.upfor1.getChildByName('sale').opacity = 0;
|
|
|
+ this.upfor1.getChildByName('skillupbg3').opacity = 0;
|
|
|
+ }
|
|
|
+ let canUpTower1 = gameUI.instance.getLevelLimit().indexOf(this.tower.myDataObj.TowerData.next_tower_id[1]) < 0;
|
|
|
+ if (canUpTower1) {
|
|
|
+ this.upfor2.getChildByName('build_2').opacity = 0;
|
|
|
+ this.upfor2.getChildByName('iconspr').opacity = 255;
|
|
|
+ this.upfor2.getChildByName('sale').opacity = 255;
|
|
|
+ this.upfor2.getChildByName('skillupbg3').opacity = 255;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this.upfor2.getChildByName('build_2').opacity = 255;
|
|
|
+ this.upfor2.getChildByName('iconspr').opacity = 0;
|
|
|
+ this.upfor2.getChildByName('sale').opacity = 0;
|
|
|
+ this.upfor2.getChildByName('skillupbg3').opacity = 0;
|
|
|
+ }
|
|
|
+ if (isgoldMore) {
|
|
|
+ this.upfor1.getChildByName('iconspr').getComponent(cc.Sprite).setMaterial(0, this.norMaterial);
|
|
|
+ this.upfor2.getChildByName('iconspr').getComponent(cc.Sprite).setMaterial(0, this.norMaterial);
|
|
|
+ this.upfor1.getChildByName('sale').color = cc.color(235, 255, 6);
|
|
|
+ this.upfor2.getChildByName('sale').color = cc.color(235, 255, 6);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this.upfor1.getChildByName('iconspr').getComponent(cc.Sprite).setMaterial(0, this.grayMaterial);
|
|
|
+ this.upfor2.getChildByName('iconspr').getComponent(cc.Sprite).setMaterial(0, this.grayMaterial);
|
|
|
+ this.upfor1.getChildByName('sale').color = cc.color(102, 91, 91);
|
|
|
+ this.upfor2.getChildByName('sale').color = cc.color(102, 91, 91);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (level >= 4) {
|
|
|
+ if (this.tower.SkillIDL == 0) {
|
|
|
+ let isgoldMore = this.tower.myDataObj.TowerData.up_gold[0] <= gameUI.instance.getGold();
|
|
|
+ if (isgoldMore) {
|
|
|
+ this.skillupbg1.getChildByName('iconspr').getComponent(cc.Sprite).setMaterial(0, this.norMaterial);
|
|
|
+ this.skillupbg1.getChildByName('sale').color = cc.color(235, 255, 6);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this.skillupbg1.getChildByName('iconspr').getComponent(cc.Sprite).setMaterial(0, this.grayMaterial);
|
|
|
+ this.skillupbg1.getChildByName('sale').color = cc.color(102, 91, 91);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ if (this.skillLv[0] < 3) {
|
|
|
+ this.tower.myDataObj.writeSkill_Config(this.tower.SkillIDL);
|
|
|
+ let isgoldMore = this.tower.myDataObj.SkillData.up_gold <= gameUI.instance.getGold();
|
|
|
+ if (isgoldMore) {
|
|
|
+ this.skillupbg1.getChildByName('iconspr').getComponent(cc.Sprite).setMaterial(0, this.norMaterial);
|
|
|
+ this.skillupbg1.getChildByName('sale').color = cc.color(235, 255, 6);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this.skillupbg1.getChildByName('iconspr').getComponent(cc.Sprite).setMaterial(0, this.grayMaterial);
|
|
|
+ this.skillupbg1.getChildByName('sale').color = cc.color(102, 91, 91);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this.skillupbg1.getChildByName('sale').opacity = 0;
|
|
|
+ this.skillupbg1.getChildByName('skillupbg3').opacity = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (this.tower.SkillIDR == 0) {
|
|
|
+ let isgoldMore = this.tower.myDataObj.TowerData.up_gold[1] <= gameUI.instance.getGold();
|
|
|
+ if (isgoldMore) {
|
|
|
+ this.skillupbg2.getChildByName('iconspr').getComponent(cc.Sprite).setMaterial(0, this.norMaterial);
|
|
|
+ this.skillupbg2.getChildByName('sale').color = cc.color(235, 255, 6);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this.skillupbg2.getChildByName('iconspr').getComponent(cc.Sprite).setMaterial(0, this.grayMaterial);
|
|
|
+ this.skillupbg2.getChildByName('sale').color = cc.color(102, 91, 91);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ if (this.skillLv[1] < 3) {
|
|
|
+ this.tower.myDataObj.writeSkill_Config(this.tower.SkillIDR);
|
|
|
+ let isgoldMore = this.tower.myDataObj.SkillData.up_gold <= gameUI.instance.getGold();
|
|
|
+ if (isgoldMore) {
|
|
|
+ this.skillupbg2.getChildByName('iconspr').getComponent(cc.Sprite).setMaterial(0, this.norMaterial);
|
|
|
+ this.skillupbg2.getChildByName('sale').color = cc.color(235, 255, 6);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this.skillupbg2.getChildByName('iconspr').getComponent(cc.Sprite).setMaterial(0, this.grayMaterial);
|
|
|
+ this.skillupbg2.getChildByName('sale').color = cc.color(102, 91, 91);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this.skillupbg2.getChildByName('sale').opacity = 0;
|
|
|
+ this.skillupbg2.getChildByName('skillupbg3').opacity = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.towerType == TowerType.Enum_Barrack) {
|
|
|
+ if (this.tower.SkillIDT == 0) {
|
|
|
+ let isgoldMore = this.tower.myDataObj.TowerData.up_gold[2] <= gameUI.instance.getGold();
|
|
|
+ if (isgoldMore) {
|
|
|
+ this.skillupbg3.getChildByName('iconspr').getComponent(cc.Sprite).setMaterial(0, this.norMaterial);
|
|
|
+ this.skillupbg3.getChildByName('sale').color = cc.color(235, 255, 6);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this.skillupbg3.getChildByName('iconspr').getComponent(cc.Sprite).setMaterial(0, this.grayMaterial);
|
|
|
+ this.skillupbg3.getChildByName('sale').color = cc.color(102, 91, 91);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ if (this.skillLv[2] < 3) {
|
|
|
+ this.tower.myDataObj.writeSkill_Config(this.tower.SkillIDT);
|
|
|
+ let isgoldMore = this.tower.myDataObj.SkillData.up_gold <= gameUI.instance.getGold();
|
|
|
+ if (isgoldMore) {
|
|
|
+ this.skillupbg3.getChildByName('iconspr').getComponent(cc.Sprite).setMaterial(0, this.norMaterial);
|
|
|
+ this.skillupbg3.getChildByName('sale').color = cc.color(235, 255, 6);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this.skillupbg3.getChildByName('iconspr').getComponent(cc.Sprite).setMaterial(0, this.grayMaterial);
|
|
|
+ this.skillupbg3.getChildByName('sale').color = cc.color(102, 91, 91);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this.skillupbg3.getChildByName('sale').opacity = 0;
|
|
|
+ this.skillupbg3.getChildByName('skillupbg3').opacity = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ /**打开圆环 */
|
|
|
+ private turnbig() {
|
|
|
+ this.showNosele();
|
|
|
+ towerManger.instance.closedHuan();
|
|
|
+ this.huan.node.scale = 0.5;
|
|
|
+ this.huan.node.opacity = 0;
|
|
|
+ this.huan.node.active = true;
|
|
|
+ this.redquan.node.active = true;
|
|
|
+ this.huan.node.stopAllActions();
|
|
|
+ this.node.zIndex = 1007;
|
|
|
+ cc.tween(this.huan.node)
|
|
|
+ .to(0.1, { scale: 1, opacity: 255 })
|
|
|
+ .call(() => {
|
|
|
+ this.isOpen = true;
|
|
|
+ })
|
|
|
+ .start();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**关闭圆环 */
|
|
|
+ public turnsmall() {
|
|
|
+ if (this.isOpen) {
|
|
|
+ this.node.zIndex = 1006;
|
|
|
+ this.huan.node.stopAllActions();
|
|
|
+ cc.tween(this.huan.node)
|
|
|
+ .to(0.1, { scale: 0.5, opacity: 0 })
|
|
|
+ .call(() => {
|
|
|
+ this.huan.node.active = false;
|
|
|
+ this.isOpen = false;
|
|
|
+ if (!this.isCanChaqi) {
|
|
|
+ this.redquan.node.active = false;
|
|
|
+ }
|
|
|
+ this.upgou.node.opacity = 0;
|
|
|
+ this.salegou.node.opacity = 0;
|
|
|
+ this.saletip.node.opacity = 255;
|
|
|
+
|
|
|
+ this.upfor1.getChildByName('build_1').opacity = 0;
|
|
|
+ this.upfor2.getChildByName('build_1').opacity = 0;
|
|
|
+ this.skillupbg1.getChildByName('build_1').opacity = 0;
|
|
|
+ this.skillupbg2.getChildByName('build_1').opacity = 0;
|
|
|
+ this.skillupbg3.getChildByName('build_1').opacity = 0;
|
|
|
+ })
|
|
|
+ .start();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**点击泥土 */
|
|
|
+ private touchNode() {
|
|
|
+ this.turnbig();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|