203 lines
5.4 KiB
JavaScript
203 lines
5.4 KiB
JavaScript
var AIConfig = require("aiconfig").cfg
|
|
var AIEnum = require("aiconfig").enum
|
|
var TempV = cc.v2()
|
|
var robotai = function() {
|
|
|
|
this.setaicfg = function(data, tar) {
|
|
this.target = tar
|
|
// this.target.wudi = true
|
|
this.aicfg = AIConfig[data + ""]
|
|
this.aiidx = 0
|
|
this.aiready = true
|
|
this.bindAI()
|
|
|
|
}
|
|
|
|
|
|
|
|
this.bindAI = function() {
|
|
|
|
this.AIFTB = {
|
|
[AIEnum.Delay]: this.AIDelay.bind(this),
|
|
[AIEnum.MoveToPlayer]: this.AIMoveToPlayer.bind(this),
|
|
[AIEnum.Shot]: this.AIShot.bind(this),
|
|
[AIEnum.Moveby]: this.AIMoveby.bind(this),
|
|
[AIEnum.Moveto]: this.AIMoveto.bind(this),
|
|
[AIEnum.createloot]: this.AICreateloot.bind(this),
|
|
[AIEnum.Emote]: this.AIEmote.bind(this),
|
|
[AIEnum.God]: this.AIGod.bind(this),
|
|
[AIEnum.wincheck]: this.AIwincheck.bind(this),
|
|
[AIEnum.sethp]: this.AIsethp.bind(this),
|
|
[AIEnum.wudi]: this.AIwudi.bind(this),
|
|
[AIEnum.dir]: this.AIdir.bind(this),
|
|
}
|
|
|
|
}
|
|
this.AIwudi=function(data){
|
|
this.target.wudi = data.prama
|
|
this.aiready = true
|
|
}
|
|
this.AIdir = function(data){
|
|
var tectv = cc.v2(data.x,data.y)
|
|
tectv = tectv.normalize()
|
|
this.target.dashdir = tectv
|
|
this.aiready = true
|
|
}
|
|
|
|
this.stopaction = function(){
|
|
this.target.dir.x = 0
|
|
this.target.dir.y = 0
|
|
this.target.move_dir.x = this.target.move_dir.y = 0
|
|
this.target.shot_hold = false
|
|
}
|
|
this.AICreateloot = function(data) {
|
|
var cfg = data.prama
|
|
this.aiready = true
|
|
var x = cfg[1]
|
|
var y = cfg[2]
|
|
if (cfg[3] == 1) {
|
|
x += cc.clientbattle.player.x
|
|
y += cc.clientbattle.player.y
|
|
}
|
|
cc.clientbattle.createlootbyid(cfg[0], x, y)
|
|
}
|
|
this.AIEmote = function(cfg){
|
|
this.target.showEmoteNetAnimation(cfg.id)
|
|
this.AIDelay(cfg)
|
|
}
|
|
this.AIsethp = function(cfg){
|
|
this.target.health = cfg.prama
|
|
this.aiready = true
|
|
}
|
|
this.AIwincheck = function(){
|
|
cc.clientbattle.wincheck = true
|
|
this.aiready = true
|
|
}
|
|
this.AIDelay = function(cfg) {
|
|
this.stopaction()
|
|
this.time = cfg.prama
|
|
}
|
|
this.AIMoveToPlayer = function(cfg) {
|
|
this.target.shot_hold = false
|
|
this.time = cfg.prama
|
|
}
|
|
this.AIShot = function(cfg) {
|
|
this.time = cfg.prama
|
|
TempV.x = cc.clientbattle.player.x - this.target.pos.x
|
|
TempV.y = cc.clientbattle.player.y - this.target.pos.y
|
|
this.target.attack_dir = TempV.normalize();
|
|
this.target.dir.x = this.target.attack_dir.x
|
|
this.target.dir.y = this.target.attack_dir.y
|
|
this.target.move_dir.x = this.target.move_dir.y = 0
|
|
this.target.shot_hold = true
|
|
}
|
|
this.AIMoveto = function(cfg) {
|
|
this.MovetoXY(cfg.x, cfg.y)
|
|
}
|
|
this.AIMoveby = function(cfg) {
|
|
this.MovetoXY(this.target.pos.x + cfg.x, this.target.pos.y + cfg.y)
|
|
}
|
|
this.AIGod = function(cfg) {
|
|
this.time = cfg.prama/100
|
|
}
|
|
|
|
|
|
this.MovetoXY = function(x, y) {
|
|
this.target.shot_hold = false
|
|
this.tarpos = cc.v2(x, y)
|
|
TempV.x = this.tarpos.x - this.target.pos.x
|
|
TempV.y = this.tarpos.y - this.target.pos.y
|
|
this.target.move_dir = TempV.normalize();
|
|
this.target.dir.x = this.target.move_dir.x
|
|
this.target.dir.y = this.target.move_dir.y
|
|
}
|
|
|
|
|
|
this.donext = function() {
|
|
if (this.aiidx == this.aicfg.length ) {
|
|
this.target.wudi = false
|
|
return true
|
|
}
|
|
|
|
this.aiready = false
|
|
var cfg = this.aicfg[this.aiidx]
|
|
this.nowType = cfg.tp
|
|
this.AIFTB[this.nowType](cfg)
|
|
this.aiidx++;
|
|
return false
|
|
|
|
}
|
|
|
|
this.update = function(dt) {
|
|
if (this.aiready) {
|
|
return this.donext()
|
|
} else {
|
|
this.updateAI(dt)
|
|
}
|
|
return false
|
|
}
|
|
this.updateAI = function(dt) {
|
|
|
|
var dx = Math.abs(this.target.pos.x - cc.clientbattle.player.x)
|
|
var dy = Math.abs(this.target.pos.y - cc.clientbattle.player.y)
|
|
|
|
if (dx > 600 || dy > 600) {
|
|
this.target.notpz = true
|
|
} else {
|
|
this.target.notpz = false
|
|
}
|
|
|
|
if (this.nowType == AIEnum.Delay || this.nowType == AIEnum.Shot || this.nowType == AIEnum.Emote) {
|
|
this.time -= dt
|
|
if (this.time <= 0) {
|
|
this.target.shot_hold = false
|
|
this.aiready = true
|
|
}
|
|
} else if (this.nowType == AIEnum.MoveToPlayer) {
|
|
TempV.x = cc.clientbattle.player.x - this.target.pos.x
|
|
TempV.y = cc.clientbattle.player.y - this.target.pos.y
|
|
this.target.move_dir = TempV.normalize();
|
|
this.target.dir.x = this.target.move_dir.x
|
|
this.target.dir.y = this.target.move_dir.y
|
|
|
|
if (dx <= this.time && dy <= this.time) {
|
|
this.aiready = true
|
|
}
|
|
} else if (this.nowType == AIEnum.Moveto || this.nowType == AIEnum.Moveby) {
|
|
var offx = Math.abs(this.target.pos.x - this.tarpos.x)
|
|
var offy = Math.abs(this.target.pos.y - this.tarpos.y)
|
|
if (offx < 5 && offy < 5) {
|
|
this.aiready = true
|
|
}
|
|
|
|
}else if(this.nowType == AIEnum.God){
|
|
TempV.x = cc.clientbattle.player.x - this.target.pos.x
|
|
TempV.y = cc.clientbattle.player.y - this.target.pos.y
|
|
this.target.move_dir = TempV.normalize();
|
|
this.target.dir.x = this.target.move_dir.x
|
|
this.target.dir.y = this.target.move_dir.y
|
|
if(dx<100&&dy<100){
|
|
this.target.attack_dir.x = this.target.dir.x
|
|
this.target.attack_dir.y = this.target.dir.y
|
|
this.target.move_dir.x = 0
|
|
this.target.move_dir.y = 0
|
|
this.target.shot_hold = true
|
|
|
|
}
|
|
else if(dx<200&&dy<200){
|
|
this.target.attack_dir.x = this.target.dir.x
|
|
this.target.attack_dir.y = this.target.dir.y
|
|
this.target.shot_hold = true
|
|
}
|
|
else{
|
|
this.target.shot_hold = false
|
|
}
|
|
if(cc.clientbattle.player.health/cc.clientbattle.player.max_health<this.time){
|
|
this.aiready = true
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
module.exports = robotai; |