//将之前生成的预制件存入数组然后将数组进行深复制 后传入第二个方法
//传入的数组根据每次加载的次数不同进入不同的if条件,选择前和后放入数组
combat:function(){
this._counter++if(this._counter % 2 == 0){
this._fightIn2Person(this._friendArr.slice(),this._enemyArr.slice())
}else{
this._fightIn2Person(this._enemyArr.slice(),this._friendArr.slice())
}
},
//根据上个方法体传入的两个数组然后进行赋值 传入第一个数组的第一个预制件和第二个数组中的第二个预制件然后取得取出来的第一二个预制件的坐标然后第一个预制件位移到第二个预制件的坐标后再位移回来 这就是回合制游戏的打中效果
var that = this
var node = personArr1.shift();
if(Math.random()<0.5)var sedNpc = personArr2[0]
else var sedNpc = personArr2[1]
var nodePo = node.getPosition();
var sedNpcPo = sedNpc.getPosition();
var actionTo1 = cc.moveBy(0.1,cc.p(100,0));
var actionTo2 = cc.moveBy(0.1,cc.p(-100,0));
node.runAction(cc.sequence(
cc.moveTo(0.2,sedNpcPo),
cc.callFunc(countAttack),
cc.moveTo(0.2,nodePo),
cc.callFunc(attackEnd),
))
//通过每一次位移到点后调用这个方法体 并且取得一个0.3的几率判断是否可以被闪避和被暴击双倍伤害不然就是普通命中 前面的两个0.3几率不闪避的情况下暴击的几率也为0.3
//在"Canvas/ui/Label"下显示战斗情况
function countAttack(){
if(Math.random()<0.3){
cc.find("Canvas/ui/Label").getComponent(cc.Label).string = "进行到第"+that._counter+"回合"+" 闪避"
that.scheduleOnce(function() {
sedNpc.runAction(cc.sequence(actionTo1,actionTo2))
}, 0.1);
}else if(Math.random()<0.3){
cc.find("Canvas/ui/Label").getComponent(cc.Label).string = "进行到第"+that._counter+"回合"+" 暴击"
sedNpc.getComponent('exercise').pub_beHit(node.getComponent('exercise').critical())
}else {
cc.find("Canvas/ui/Label").getComponent(cc.Label).string = "进行到第"+that._counter+"回合"+" 命中"
sedNpc.getComponent('exercise').pub_beHit(node.getComponent('exercise').attArr())
}
}