|
@@ -24,26 +24,11 @@ export default class AIBase extends cc.Component {
|
|
|
displayName: '灵敏度(毫秒)'
|
|
|
})
|
|
|
public AI_CD:number = 1000;
|
|
|
- /**
|
|
|
- * 攻击间隔 ms
|
|
|
- * 一次攻击后间隔多久开始下次攻击
|
|
|
- */
|
|
|
- @property({
|
|
|
- displayName: '攻击间隔(毫秒)'
|
|
|
- })
|
|
|
- public atk_CD = 3000;
|
|
|
- /**
|
|
|
- * 每次攻击几颗子弹
|
|
|
- */
|
|
|
- @property({
|
|
|
- displayName: '每次攻击子弹数量'
|
|
|
- })
|
|
|
- public atk_count = 1;
|
|
|
/**
|
|
|
* 移动速度
|
|
|
*/
|
|
|
@property({
|
|
|
- displayName: '移动速度'
|
|
|
+ displayName: '角色移动速度'
|
|
|
})
|
|
|
public speed = 50;
|
|
|
/**
|
|
@@ -117,41 +102,43 @@ export default class AIBase extends cc.Component {
|
|
|
if(!this.canSkill){
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
- let time = new Date().getTime();
|
|
|
let target = this.checkTarget();
|
|
|
if(target){
|
|
|
if(this.skills.length > 0){
|
|
|
- let skill = this.checkSkill(target);
|
|
|
+ let skill:SkillBase = this.checkSkill(target);
|
|
|
if(skill){
|
|
|
- // cc.log('开始使用技能 :',skill)
|
|
|
- this.canSkill = false;
|
|
|
- skill.exe(target,()=>{
|
|
|
- this.canSkill = true;
|
|
|
- // cc.log('技能使用结束 :',skill)
|
|
|
- });
|
|
|
- }else{
|
|
|
- if(this.AI_Time == 0){
|
|
|
- this.AI_Time = time;
|
|
|
- }else if(time - this.AI_Time > this.AI_CD){
|
|
|
- this.AI_Time = time;
|
|
|
- this.walk(this.sprite.mButtleDis);
|
|
|
+ if(this.speed <= 0){
|
|
|
+ this.canSkill = false;
|
|
|
+ skill.exe(target,()=>{
|
|
|
+ this.canSkill = true;
|
|
|
+ // cc.log('技能使用结束 :',skill)
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ let p1 = this.sprite.node.getPosition()
|
|
|
+ let p2 = target.node.getPosition()
|
|
|
+ let dis = CMath.getDistance(p1,p2);
|
|
|
+ if(dis < skill.range){
|
|
|
+ this.canSkill = false;
|
|
|
+ skill.exe(target,()=>{
|
|
|
+ this.canSkill = true;
|
|
|
+ // cc.log('技能使用结束 :',skill)
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ this.walk(skill.range);
|
|
|
+ // this.moveToTarget(target)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- } else{
|
|
|
- if(time - this.atk_Time > this.atk_CD){
|
|
|
- this.atk_Time = time;
|
|
|
- this.fire(target);
|
|
|
- }
|
|
|
- }
|
|
|
- }else{
|
|
|
- if(this.AI_Time == 0){
|
|
|
- this.AI_Time = time;
|
|
|
- }else if(time - this.AI_Time > this.AI_CD){
|
|
|
- this.AI_Time = time;
|
|
|
- this.walk(this.sprite.mButtleDis);
|
|
|
}
|
|
|
}
|
|
|
+ // else{
|
|
|
+ // if(this.AI_Time == 0){
|
|
|
+ // this.AI_Time = time;
|
|
|
+ // }else if(time - this.AI_Time > this.AI_CD){
|
|
|
+ // this.AI_Time = time;
|
|
|
+ // this.walk(0);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
}
|
|
|
/**
|
|
|
* 查询可用技能
|
|
@@ -167,24 +154,27 @@ export default class AIBase extends cc.Component {
|
|
|
if(lists.length <= 0){
|
|
|
return null;
|
|
|
}else{
|
|
|
- let p1 = this.node.getPosition();
|
|
|
- let p2 = target.node.getPosition();
|
|
|
- let dis = cc.Vec2.distance(p1,p2);
|
|
|
- let fList = [];
|
|
|
- for (let i = 0; i < lists.length; i++) {
|
|
|
- const element = lists[i];
|
|
|
- if(dis < element.range){
|
|
|
- fList.push(element);
|
|
|
- }
|
|
|
- }
|
|
|
- if(fList.length <= 0){
|
|
|
- this.moveToTarget(target);
|
|
|
- return null;
|
|
|
- }else{
|
|
|
- this.sprite.playAction(SpriteActionType.stand,true)
|
|
|
- let index = CMath.getRandom(0,fList.length-1);
|
|
|
- return fList[index];
|
|
|
- }
|
|
|
+ let index = CMath.getRandom(0,lists.length-1);
|
|
|
+ return lists[index];
|
|
|
+
|
|
|
+ // let p1 = this.node.getPosition();
|
|
|
+ // let p2 = target.node.getPosition();
|
|
|
+ // let dis = cc.Vec2.distance(p1,p2);
|
|
|
+ // let fList = [];
|
|
|
+ // for (let i = 0; i < lists.length; i++) {
|
|
|
+ // const element = lists[i];
|
|
|
+ // if(dis < element.range){
|
|
|
+ // fList.push(element);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // if(fList.length <= 0){
|
|
|
+ // this.moveToTarget(target);
|
|
|
+ // return null;
|
|
|
+ // }else{
|
|
|
+ // this.sprite.playAction(SpriteActionType.stand,true)
|
|
|
+ // let index = CMath.getRandom(0,fList.length-1);
|
|
|
+ // return fList[index];
|
|
|
+ // }
|
|
|
}
|
|
|
}
|
|
|
/**
|
|
@@ -219,44 +209,25 @@ export default class AIBase extends cc.Component {
|
|
|
this.sprite.setDir(tmp);
|
|
|
}
|
|
|
|
|
|
- public fire(target:FSprite){
|
|
|
- //判断是否在攻击范围内
|
|
|
- let mts = this.sprite.mButtleDis;
|
|
|
- let p1 = target.node.getPosition();
|
|
|
- let p2 = this.sprite.node.getPosition();
|
|
|
- let dis = cc.Vec2.distance(p1,p2);
|
|
|
-
|
|
|
- if(dis > mts){
|
|
|
- this.moveToTarget(target);
|
|
|
- }else{
|
|
|
- this.sprite.setDir({x:0,y:0});
|
|
|
- this.sprite.setShooting(true);
|
|
|
- let count = 0;
|
|
|
- this.canSkill = false;
|
|
|
- this.sprite.setFireCallback(()=>{
|
|
|
- count ++;
|
|
|
- if(count >= this.atk_count){
|
|
|
- this.sprite.setShooting(false);
|
|
|
- this.sprite.setFireCallback(null);
|
|
|
- cc.tween(this).delay(0.7).call(()=>{
|
|
|
- this.walk(this.sprite.mButtleDis);
|
|
|
- }).start();
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
/**
|
|
|
* 远程怪物的闲逛
|
|
|
*/
|
|
|
public walk(distance){
|
|
|
- cc.tween(this).delay(0).call(()=>{
|
|
|
+ if(this.speed > 0){
|
|
|
+ this.canSkill = false;
|
|
|
this.sprite.setDir(this.getRandState(distance));
|
|
|
this.sprite.playAction(SpriteActionType.move,true)
|
|
|
- }).delay(0.5).call(()=>{
|
|
|
+ cc.tween(this).delay(0.5).call(()=>{
|
|
|
+ this.sprite.setDir({x:0,y:0});
|
|
|
+ this.sprite.playAction(SpriteActionType.stand,true)
|
|
|
+ }).delay(1).call(()=>{
|
|
|
+ this.canSkill = true;
|
|
|
+ }).start()
|
|
|
+ }else{
|
|
|
this.canSkill = true;
|
|
|
this.sprite.setDir({x:0,y:0});
|
|
|
this.sprite.playAction(SpriteActionType.stand,true)
|
|
|
- }).start();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public getRandState(distance){
|
|
@@ -264,10 +235,8 @@ export default class AIBase extends cc.Component {
|
|
|
let p1 = this.target.node.getPosition();
|
|
|
let p2 = this.sprite.node.getPosition();
|
|
|
|
|
|
- let distance = this.sprite.mButtleDis;
|
|
|
-
|
|
|
let dis = CMath.getDistance(p1,p2);
|
|
|
- if(dis > 150){
|
|
|
+ if(dis > distance){
|
|
|
let tmp = {
|
|
|
x:0,
|
|
|
y:0
|