var Utils = require("Utils") var ItemConfig = require("gameConfig").itemConfig var lootFrame = {} var lootreadyFrame = {} var deltay = 20 var GameLoot = cc.Class({ extends: cc.Node, properties: { // foo: { // // ATTRIBUTES: // default: null, // The default value will be used only when the component attaching // // to a node for the first time // type: cc.SpriteFrame, // optional, default is typeof default // serializable: true, // optional, default is true // }, // bar: { // get () { // return this._bar; // }, // set (value) { // this._bar = value; // } // }, }, setDebugFrame(frameName, sprite) { if (!cc.battledebug) { return } var self = this sprite.sizeMode = 0 cc.loader.loadRes("btn1", cc.SpriteFrame, function(err, res) { if (!err && self.isValid) { sprite.spriteFrame = res; } }); }, setFrame(sprite, frameName, dir) { if (lootFrame[frameName]) { sprite.spriteFrame = lootFrame[frameName]; } else { var self = this if (lootreadyFrame[frameName] == undefined) { lootreadyFrame[frameName] = [] cc.loader.loadRes(dir + "/" + frameName, cc.SpriteFrame, function(err, res) { if (!err && self.isValid) { lootFrame[frameName] = res for (var i = lootreadyFrame[frameName].length - 1; i >= 0; i--) { try { lootreadyFrame[frameName][i].spriteFrame = res } catch (e) {} } lootreadyFrame[frameName] = null } }); } lootreadyFrame[frameName].push(sprite) } }, checkshakeani() { // if (this.spani) { // this.spani.stop() // } // if (this.isdead) { // return // } // if (!this.istree) { // return // } // if (this.spani) { // if (this.istree == 1) { // this.spani.play("grasswave1") // } else { // this.spani.play("grasswave2") // } // } }, preinit(istree) { var self = this if (!this.sprite) { var spnode = new cc.Node() spnode.anchorY = 0 var sprite11 = spnode.addComponent('cc.Sprite') // spnode.rotation = -45 spnode.scaleY = cc.hdscale spnode.scaleX = cc.hdscale this.addChild(spnode) this.sprite = sprite11; if (cc.battledebug) { var debugnode = new cc.Node() debugnode.zIndex = 32767 this.addChild(debugnode) var sprite = debugnode.addComponent('cc.Sprite') this.debugnode = debugnode } // this.spani = spnode.addComponent(cc.Animation) // spnode.getComponent(cc.Animation).addClip(cc.battleCache.grasswave1, "grasswave1"); // spnode.getComponent(cc.Animation).addClip(cc.battleCache.grasswave2, "grasswave1"); if (istree) { this.grassshader = spnode.addComponent(cc.battlegrass) this.grassshader.init() } } this.event = null }, initdata(data, netdata, pos) { this.isloot = true this.active = true this.opacity = 255 this.is_door = false; this.fadeadd = 0 this.isdead = false; this.hidemode = 0 this.birth = netdata.born_frameno this.preinit(false) //this.preinit(data.is_tree == 2) var iheight = data.height var iwidth = data.width var itpye = data.type this.sprite.node.y = -iheight / 2 - deltay if (netdata.collider) { iwidth = netdata.collider.width iheight = netdata.collider.height itpye = netdata.collider.shape } if (data.xiuzheng) { this.sprite.node.y = 0 } if (cc.battledebug) { var sprite = this.debugnode.getComponent('cc.Sprite') sprite.sizeMode = 0; this.setDebugFrame(data.img, sprite) if (netdata.dead) { sprite.node.color = cc.Color.RED } else { sprite.node.color = cc.Color.WHITE } this.debugnode.width = iwidth; this.debugnode.height = iheight; this.debugnode.opacity = 160 } this.sprite.spriteFrame = null this.deadImg = data.dead_img if (data.delay_destroy) { this.daedfadetime = data.delay_destroy / 1000 } else { this.daedfadetime = 0 } if (netdata.dead == false) { this.sprite.spriteFrame = cc.atlMgr.mapthingatlas.getSpriteFrame(data.img) // this.setFrame(this.sprite,data.img,"textures/game/mapthing") this.build_transparent = data.build_transparent } else { this.sprite.spriteFrame = cc.atlMgr.mapthingatlas.getSpriteFrame(data.dead_img) if(data.prefab){ this.sprite.node.y = 0 } // this.setFrame(this.sprite,this.deadImg,"textures/game/mapthing") this.isdead = true this.zIndex = -32767 if (this.daedfadetime > 0) { this.opacity = 0 } this.build_transparent = null } if (data.layer_layering) { this.zplus = data.layer_layering - 30 } else { this.zplus = 0 } this.tp = itpye; this.width = iwidth; this.height = iheight; this.prebattle_hide = data.prebattle_hide this.istree = data.is_tree // if (this.istree == 2) { // this.grassshader.setree(pos.x, pos.y + this.sprite.node.y, this) // } this.viewWidth = this.width this.viewHeight = this.height if (data.object_vision) { var numarrv = data.object_vision.split('|') this.viewWidth = Number(numarrv[0]) this.viewHeight = Number(numarrv[1]) } if (data.viewtest) { var numarr = data.viewtest.split('|') this.viewtest = { x: pos.x + Number(numarr[0]), y: pos.y + Number(numarr[1]), width: Number(numarr[2]), height: Number(numarr[3]) } } else { this.viewtest = null } this.deadani = data.dead_ani this.hit_sound = data.hit_sound this.hit_sound2 = data.hit_sound2 this.dead_sound = data.dead_sound this.event = data.event // this.attack_type = data.attack_type this.bullet_hit = data.bullet_hit this.prefab_range = data.prefab_range this.thing_type = data.thing_type this.pbres = data.prefab this.viewhit = { x: pos.x, y: pos.y, width: this.viewWidth, height: this.viewHeight } if (this.prefab_range) { this.hitobj2 = { x: pos.x, y: pos.y, width: data.prefab_range, height: data.prefab_range } } // this.pbnode.active = true if (this.effani) { this.effani.destroy() this.effani = null } if (data.prefab && netdata.dead == false) { this.prefabname = data.prefab var self = this var cb = function(res) { if (self && self.isValid && self.sprite && self.sprite.isValid && self.sprite.node) { res.birth = self.birth self.effani = res if (self.prefab_range) { self.effani.opacity = 0 } else { self.effani.opacity = 255 } res.fnode = self self.sprite.node.addChild(res) res.scale = 1/cc.hdscale } else { console.log("!11111111111111") } } cc.gameMgr.effectManager.createlooteff(data.prefab, cb) } this.checkshakeani() }, doout() { this.hidemode = 0 if (this.effani) { cc.gameMgr.effectManager.huishoulooteff(this.prefabname, this.effani) this.effani = null this.prefabname = null } }, deadfake() { this.hidemode = 0 this.opacity = 255 this.fadeadd = 255 / this.daedfadetime // var self = this // var cb = cc.callFunc(function() { // self.doout() // }); // this.runAction(cc.sequence(cc.fadeOut(this.daedfadetime), cb)); }, refreshNetData(netdata, isquanliang) { // if(netdata.is_door){ // this.position = cc.v2(netdata.pos.x,netdata.pos.y) // if(netdata.door_width){ // this.width = netdata.door_width; // this.height = netdata.door_height; // this.refreshdoor(netdata); // } // } if (isquanliang) { if (netdata.button_name) { this.button_name = netdata.button_name // cc.gameMgr.uic.btn_name.string = netdata.button_name } else { this.button_name = undefined } } if (netdata.dead == true && this.isdead == false) { if (cc.battledebug) { var sprite = this.debugnode.getComponent('cc.Sprite') sprite.node.color = cc.Color.RED } if (this.sonobj) { this.sonobj.needDelete = true this.sonobj = null } this.isdead = true; var self = this if (netdata.dead_at_thisframe) { if (this.daedfadetime == 0) { this.doout() } if (this.active) { if (this.deadani) { cc.gameMgr.effectManager.createBreak(this.position, this.deadani) } cc.gameMgr.playSound(this.dead_sound) if (this.daedfadetime > 0) { this.deadfake() } } else { this.doout() } netdata.dead_at_thisframe = false } else { this.doout() } // if (this.spani) { // this.spani.stop() // } // this.stopAllActions() if (this.deadImg) { this.sprite.spriteFrame = cc.atlMgr.mapthingatlas.getSpriteFrame(this.deadImg) if(this.pbres){ this.sprite.node.y = 0 } self.zIndex = -32767 } else { self.sprite.spriteFrame = null; } } }, playShake() { if (this.active == false || this.isdead) { return } var ac = new cc.ShakeAction() ac.initWithDuration(0.3, 1, 0.5) this.stopAllActions() this.runAction(ac) }, update2(dt) { if (!cc.gameMgr.nditem.active && this.prebattle_hide) { this.opacity = 0 return } if (!this.isdead && this.istree != 4) { if (this.isson) { if (Utils.hitTestRectangle(cc.gameMgr.watchPlayer, this.viewhit)) { // this.opacity = 150 this.hidemode = 3 } else { // this.opacity = 255 this.hidemode = 2 } } else { this.opacity = 255 } } if (this.fadeadd > 0 && this.isdead) { this.opacity -= this.fadeadd * dt if (this.opacity <= 0) { this.opacity = 0 this.doout() } } if (this.effani && this.prefab_range && this.opacity != 0) { var ishit = false for (var i = cc.gameMgr.playerarr.length - 1; i >= 0; i--) { ishit = Utils.hitTestCircle(this.hitobj2, cc.gameMgr.playerarr[i]) if (ishit) { break } } if (ishit) { this.effani.opacity += dt * 30 } else { this.effani.opacity -= dt * 30 } } if (this.hidemode == 3 && this.opacity > 150) { this.opacity -= dt * 700 } else if (this.hidemode == 1 && this.opacity > 0) { this.opacity -= dt * 700 } else if (this.hidemode == 2 && this.opacity < 255) { this.opacity += dt * 700 } } }); GameLoot.getData = function(id) { return ItemConfig[id] } module.exports = GameLoot;