var gameConfig = require("gameConfig") var lootcfg = gameConfig.itemConfig var chacheobj = require("battleobjcache") var praconfig = gameConfig.parameterConfig var bnewbieCfg = require("battleNewbieConfig") var bNewbieEnum = bnewbieCfg.enu var SDKManage = require("SDKManage") // var functionTb={}; // functionTb[bNewbieEnum.createloot] = function(){ // } var lootobj = function() { this.ondes = function(v) { if (this.destroykey == v) { this.dodead() cc.Notifier.off('ondesloot', this); } } this.dodead = function() { this.dead = true var nloot = null if (this.nextloot) { nloot = cc.clientbattle.createlootbyid(this.nextloot, this.x, this.y) } return nloot } this.dodakai = function(v) { var nloot = this.dodead() if (nloot.event) { nloot.doevent() } } this.init = function(data, uuid) { this.dead = false this.dead_at_thisframe = false this.obj_uniid = uuid this.obstacle_id = data.obstacle_id this.pos = { x: data.x, y: data.y } var cfg = lootcfg[this.obstacle_id] if (!cfg) { if (data.obstacle_id == "12803") { cc.clientbattle.createdropitem(data.obstacle_id, this.pos) } return false } if (cc.clientbattle.battlecount > 1 && data.obstacle_id == praconfig.level0room_spec_things.param_value) { return false } this.nextloot = cfg.nextloot if (cfg.destroykey) { this.destroykey = cfg.destroykey cc.Notifier.on('ondesloot', this, this.ondes.bind(this)); } // this.pos.x-=cfg.width / 2 // this.pos.y-=cfg.height / 2 this.event = cfg.event this.button_name = cfg.button_name this.x = this.pos.x this.y = this.pos.y if (cfg.hp) { this.health = cfg.hp this.candestroy = true } else { this.candestroy = false } if (cfg.is_tree != 2) { this.needpz = true } if (cfg.is_house) { this.building_id = cfg.house_id this.object_type = 3 var hcfg = gameConfig.houseConfig[this.building_id] this.lootarr = hcfg.lootObj this.tilewidth = hcfg.tilewidth / 2 this.tileheight = hcfg.tileheight / 2 this.createwall() } else { this.object_type = 2 chacheobj.objmaploot[uuid] = this } this.dropid = cfg.drop this.width = cfg.width this.height = cfg.height if (data.kongqiqiang) { this.width = data.width this.height = data.height this.collider = { width: data.width, height: data.height } } else { this.collider = null // if(data.height){ // this.pos.y = this.pos.y -data.height/2 // this.y = this.pos.y // } } if (cfg.collision_hit == 1) { this.width = this.height = 0 this.needpz = false } this.dmg = cfg.damage this.damage_dia = cfg.damage_dia return true } this.createwall = function() { this.objChildren = [] var hcfg = gameConfig.houseConfig[this.building_id] for (var i = hcfg.staticObj.length - 1; i >= 0; i--) { var p = hcfg.staticObj[i] var child = { x: p.x - this.tilewidth + this.x - p.width / 2, y: p.y - this.tileheight + this.y - p.height / 2, width: p.width, height: p.height, xx: p.x - this.tilewidth + this.x, yy: p.y - this.tileheight + this.y, } cc.clientbattle.myTree.insert(child); this.objChildren.push(child) } } this.hurt = function(dmg, atkerid) { if (this.candestroy && this.health > 0) { this.health -= dmg if (this.health <= 0) { this.dodead() this.dead_at_thisframe = true if (this.dmg && this.damage_dia) { cc.clientbattle.createboom(this.dmg, this.damage_dia, this.pos, 0, false, atkerid) } if (this.dropid) { cc.clientbattle.canrefreshrobot = true return this.dropid } } } return false } this.donext = function() { var nowstp = this.eventcfg[this.step] if (nowstp) { var tp = nowstp[0] var isquick = false if (tp == bNewbieEnum.createloot || tp == bNewbieEnum.createdrop || tp == bNewbieEnum.createair) { isquick = true var x = nowstp[2] var y = nowstp[3] if (nowstp[4] == 1) { x += cc.clientbattle.player.x y += cc.clientbattle.player.y } if (tp == bNewbieEnum.createloot) { cc.clientbattle.createlootbyid(nowstp[1], x, y) } else if (tp == bNewbieEnum.createdrop) { var pppp = null if (nowstp[5]) { pppp = cc.clientbattle.player } cc.clientbattle.createdropitem(nowstp[1], { x: x, y: y }, 0, true, undefined, pppp) } else if (tp == bNewbieEnum.createair) { cc.clientbattle.airdroptime = 5 cc.clientbattle.airdrop = { pos: { x: x, y: y, }, appear_time: 5000, box_id: nowstp[1], } cc.clientbattle.airx = x cc.clientbattle.airy = y cc.clientbattle.aironjid = nowstp[1] } } else if (tp == bNewbieEnum.gamepause) { isquick = true cc.battlepause = true } else if (tp == bNewbieEnum.gameresume) { isquick = true cc.battlepause = false } else if (tp == bNewbieEnum.playerpause) { isquick = true cc.clientbattle.player.dopause(nowstp[1]) } else if (tp == bNewbieEnum.tipsPosAndRotation) { isquick = true cc.bnewbiemgr.settipsPosAndRotation(nowstp) } else if (tp == bNewbieEnum.handPosAndRotation) { isquick = true cc.bnewbiemgr.sethandPosAndRotation(nowstp) } else if (tp == bNewbieEnum.showHand) { isquick = true cc.bnewbiemgr.showHand() } else if (tp == bNewbieEnum.hideHand) { isquick = true cc.bnewbiemgr.hideHand() } else if (tp == bNewbieEnum.setText) { if (nowstp[1] == "" || !nowstp[2]) { isquick = true } cc.bnewbiemgr.setText(this, nowstp) } else if (tp == bNewbieEnum.createnewbieenemy) { isquick = true cc.clientbattle.createnewbieenemy(nowstp) } else if (tp == bNewbieEnum.touch) { cc.bnewbiemgr.ntouch(this, nowstp[1]) } else if (tp == bNewbieEnum.emit) { isquick = true cc.Notifier.emit("newbieanimation", nowstp[1]) } else if (tp == bNewbieEnum.destroyloot) { isquick = true cc.Notifier.emit("ondesloot", nowstp[1]) } else if (tp == bNewbieEnum.timescale) { isquick = true cc.mytimescale = nowstp[1] } else if (tp == bNewbieEnum.dir) { isquick = true var tectv = cc.v2(nowstp[1], nowstp[2]) cc.clientbattle.player.dashdir = tectv } else if (tp == bNewbieEnum.maidian) { isquick = true SDKManage.logEvent(nowstp[1]) } else if (tp == bNewbieEnum.hidenode) { isquick = true cc.find(nowstp[1]).active = false } else if (tp == bNewbieEnum.shownode) { isquick = true cc.find(nowstp[1]).active = true } else if (tp == bNewbieEnum.dowin) { isquick = true cc.clientbattle.donewbiewin() } else { cc.clientbattle.addevent(this, nowstp) } this.step++; if (isquick) { this.donext() } } } this.doevent = function() { this.dodead() var enu = bnewbieCfg.enu this.step = 0 this.eventcfg = bnewbieCfg.cfg[this.event] this.donext() } } module.exports = lootobj;