zhuguoqing 62d8fb825e update
2022-05-28 11:15:04 +08:00

1303 lines
39 KiB
JavaScript

var smap = null
var spawn = null
var spawnmap = {}
var newbiepoint = null
var gameConfig = require("gameConfig")
var Utils = require("Utils")
var quadtree = require("quadtree")
var dropcfg = gameConfig.dropConfig
var safecfg = gameConfig.safeConfig
var airConfig = gameConfig.airConfig
var praconfig = gameConfig.parameterConfig
var rankPointConfig = gameConfig.rankPointConfig
var killPointConfig = gameConfig.killPointConfig
var rankRewardConfig = gameConfig.rankRewardConfig
var killRewardConfig = gameConfig.killRewardConfig
var mapconfig = gameConfig.mapConfig
var chacheobj = require("battleobjcache")
var buffobj = require("buffobj")
var dropobj = require("dropobj")
var lootobj = require("lootobj")
var playerobj = require("playerobj")
var SDKManage = require("SDKManage")
var bnewbieCfg = require("battleNewbieConfig")
var bNewbieEnum = bnewbieCfg.enu
var gird = 1024
var housegird = 1024
var dtoh = 0.0174528
var totalalive = 40
var totalalivezombie = 10
var killrobottime = 5
var robotcreatetime = 5
var tongpingfudong = 3
var objgas = function() {
this.init = function(p, isnewbie) {
this.step = [30001, 30002, 30003, 30004, 30005, 30006, 30007]
this.idx = 0
this.mode = 0
this.pos_old = cc.v2(cc.clientbattle.mapsize / 2, cc.clientbattle.mapsize / 2)
this.pos_new = cc.v2()
this.statedu = 0
this.pausetime = 0
this.canreport = true
this.duration = 3 + Utils.randintSeed(5)
if (cc.clientbattle.battlecount == 1) {
this.duration = Number(praconfig.newbie_gas_inactive_time.param_value)
}
var tal = totalalive
cc.clientbattle.alive_count = Utils.randintSeed(10) + 10
if (cc.clientbattle.zombie) {
tal = totalalivezombie
cc.clientbattle.alive_count = 5
}
this.totalalive = tal
this.alivecount = cc.clientbattle.alive_count + 1
this.preadd = (tal - cc.clientbattle.alive_count) / (this.duration - 3)
this.isnewbie = isnewbie
if (this.isnewbie) {
this.duration = 0
}
}
this.GenSmallCircle = function() {
var dir = cc.v2(0, 1)
dir = Utils.dirRotate(dir, Utils.randintSeed(360) * dtoh)
var rad = Utils.randintSeed(this.rad_old - this.rad_new);
if (rad <= 0.001) {
rad = 0.001;
}
this.pos_new.x = this.pos_old.x + dir.x * rad
this.pos_new.y = this.pos_old.y + dir.y * rad
}
this.newduquan = function() {
this.canreport = true
if (this.statedu == 0) {
if (this.idx == this.step.length - 1) {
this.mode = -1
this.canreport = false
return
}
this.mode = 1
this.statedu = 1
var tcfg = safecfg[this.step[this.idx]]
this.duration = tcfg.wait_time
this.rad_old = tcfg.rad
// this.suoquanspeed= tcfg.shrink_speed
this.hurt = tcfg.hurt
this.idx++;
this.rad_new = safecfg[this.step[this.idx]].rad
this.suoquanspeed = (this.rad_old - this.rad_new) / tcfg.shrink_speed
this.GenSmallCircle()
} else if (this.statedu == 1) {
this.mode = 2
this.statedu = 0
this.duration = this.suoquanspeed
this.radfps = (this.rad_old - this.rad_new) / this.duration
this.movedir = {
x: (this.pos_old.x - this.pos_new.x) / this.duration,
y: (this.pos_old.y - this.pos_new.y) / this.duration,
}
}
}
this.update = function(dt) {
if (cc.jietumode || this.isnewbie) {
return
}
if (this.mode == -1) {
return
}
this.duration -= dt
if (this.mode == 0) {
this.alivecount += dt * this.preadd
if (Math.floor(this.alivecount) > cc.clientbattle.alive_count) {
cc.clientbattle.alive_count = Math.floor(this.alivecount)
if (cc.clientbattle.alive_count > this.totalalive) {
cc.clientbattle.alive_count = this.totalalive
}
cc.clientbattle.refreshalive()
}
}
if (this.duration <= 0) {
this.duration = 0
if (this.mode == 0) {
cc.gameMgr.dogamestart()
//cc.clientbattle.gamestart = true
cc.clientbattle.dogamestart()
this.pausetime = 1
if (cc.clientbattle.zombie) {
this.mode = -1
return
}
}
this.newduquan()
}
if (this.mode == 2) {
this.rad_old -= this.radfps * dt
this.pos_old.x -= this.movedir.x * dt
this.pos_old.y -= this.movedir.y * dt
}
}
}
var clientserver = function(bcount) {
this.battlecount = bcount
this.createloot = function(maparr, needspawn, px, py) {
for (var i = maparr.length - 1; i >= 0; i--) {
var dat = maparr[i]
if (needspawn) {
if (dat.param1) {
spawn.push(dat)
if (dat.name == praconfig.newbie_born_point.param_value) {
newbiepoint = dat
}
continue
} else {
dat.xidx = Math.floor((dat.x + px) / gird)
dat.yidx = Math.floor((dat.y + py) / gird)
if (!dat.kongqiqiang) {
dat.obstacle_id = dat.things.split('\n')[0].split(':')[0]
} else {
dat.weight = 10000
dat.obstacle_id = 100003
}
// dat.obstacle_id = dat.things.split('\n')[0].split(':')[0]
}
}
//if(true){
if (Utils.randintSeed(10000) < Number(dat.weight)) {
if (!this.lootarr[dat.xidx + "-" + dat.yidx]) {
this.lootarr[dat.xidx + "-" + dat.yidx] = []
}
var loot = new lootobj()
if (loot.init(dat, this.obj_uniid++)) {
loot.pos.x += px
loot.pos.y += py
loot.x = loot.pos.x
loot.y = loot.pos.y
// this.lootarr[dat.xidx+"-"+dat.yidx].push(loot)
if (loot.object_type == 3) {
this.createloot(loot.lootarr, needspawn, loot.pos.x - loot.tilewidth, loot.pos.y - loot.tileheight)
this.housearr.push(loot)
} else {
this.lootarr[dat.xidx + "-" + dat.yidx].push(loot)
if (loot.needpz) {
this.myTree.insert({
xx: loot.x,
yy: loot.y,
x: loot.x - loot.width / 2,
y: loot.y - loot.height / 2,
width: loot.width,
height: loot.height,
loot: loot
});
}
}
}
}
}
}
this.dogamestart = function() {
this.gamestart = true
this.memberarr = {
}
if (this.zudui) {
for (var i = 0; i < 3; i++) {
let robot = new playerobj(this.obj_uniid++, this)
robot.init(null, true)
this.playerarr.push(robot)
this.memberarr[robot.obj_uniid] = robot
}
this.memberarr[this.player.obj_uniid] = this.player
}
}
this.clean = function() {
cc.Notifier.off('jiantingbattle', this);
chacheobj.objmapplayer = {}
chacheobj.objmaploot = {}
chacheobj.objdrop = {}
chacheobj.shotarr.length = 0
chacheobj.bulletarr.length = 0
cc.clientbattle = null
this.myTree.clear();
cc.Notifier.cleankey('ondesloot')
}
this.initmap = function() {
this.myTree = new quadtree({
x: 0,
y: 0,
width: this.mapsize,
height: this.mapsize
}, 6);
chacheobj.objmapplayer = {}
chacheobj.objmaploot = {}
chacheobj.objdrop = {}
chacheobj.shotarr.length = 0
chacheobj.bulletarr.length = 0
this.lootarr = {}
this.dropitemmap = {}
this.playerarr = []
this.mapthingarr = []
this.needpush = []
this.housearr = []
this.boomarr = []
this.smokearr = []
this.obj_uniid = 1
this.chged_buff_list = []
this.zuoqiarr = []
this.eventarr = []
this.eventarrtemp = []
this.emitarr = []
this.airtime = 0
this.aircfgarr = [1, 2, 3, 4, 5, 6]
this.airidx = 0
this.rbotidx = 0
this.killtime = 0
this.nameidx = []
var needspawn = false
if (!spawnmap[this.mapdataname]) {
spawnmap[this.mapdataname] = []
needspawn = true
}
spawn = spawnmap[this.mapdataname]
if (smap) {
this.createloot(smap, needspawn, 0, 0)
}
}
this.getaair = function() {
return airConfig[this.aircfgarr[this.airidx]]
}
this.randpos = function(player) {
if (!player) {
player = this.player
}
//var idx = Utils.randintSeed(spawn.length)
// this.player.setposition(spawn[idx].x, spawn[idx].y)
if (this.isnewbie) { //jjtest
this.player.setposition(500, 1168)
this.createlootbyid("160001", 500, 1168)
this.createlootbyid("160002", 1330, 943) //
this.createlootbyid("160002", 1330, 1380) //
this.createlootbyid("160003", 400, 1168) //
this.createlootbyid("160003", 2030, 1168) //
this.createlootbyid("160004", 1070, 1134) //
//this.createlootbyid("160005", 1720, 1179) //
this.createlootbyid("160006", 1070, 1134) //
//this.createlootbyid("160007", 1720, 1179) //
}
}
this.init = function(cfg) {
cfg.newbiemode = true
this.frameno = 0
if (cc.jietumode) {
gird = 30000
housegird = 51200
}
// if (!cfg.mapid) {
// cfg.mapid = 1000
// }
cfg.team_mode = 0
cfg.mapid = 1000
mapconfig[1000] = {
airdrops: "1|2|3|4|5|6",
color: "#514849",
map_height: 2432,
map_id: 1000,
map_mode: 99,
map_name: "map",
map_pic: 2,
map_width: 2432,
player: 10,
refresh_robot: "2-3|1-2",
safearea: 30001,
template_list: "1001:1000",
}
cfg.baseskin[0] = 1
// cfg.skill_list = [{key: 10301, value: 0},{key: 20301, value: 0}]
var mapjs = "map" + mapconfig[cfg.mapid].template_list.split(':')[0]
//smap = require("newbiemap")
this.mapdataname = mapjs
if (cfg.newbiemode) {
this.isnewbie = true
cc.Notifier.on('jiantingbattle', this, this.jiantingbattle.bind(this));
} else {
this.isnewbie = false
}
this.robotnamearr = cc.language.getrobot()
this.radgunarr = cc.language.getrangun()
for (var i = 0; i < this.robotnamearr.length; i++) {
var s = this.robotnamearr[i]
var cidx = Math.floor(Math.random() * this.robotnamearr.length)
this.robotnamearr[i] = this.robotnamearr[cidx]
this.robotnamearr[cidx] = s
}
cc.clientbattle = this
this.team_data = []
if (cfg.team_mode == 1) {
this.zudui = true
}
if (cfg.room_mode == 1) {
this.zudui = false
this.zombie = true
}
this.mapsize = mapconfig[cfg.mapid].map_width
totalalive = mapconfig[cfg.mapid].player
this.gamestart = false
this.fixdrop = []
if (this.battlecount == 1) {
this.fixdrop = praconfig.newbie_drop.param_value.split(':')
}
this.newbiebaohu = 30
this.initmap()
this.player = new playerobj(this.obj_uniid++, this)
this.player.name = SDKManage.nickName
this.player.init(cfg)
this.active_player_id = this.player.obj_uniid
this.playerarr.push(this.player)
this.gas = new objgas()
this.gas.init(this.alive_count, this.isnewbie)
this.time_alive = 0
this.randpos()
this.aitime = 0
if (!this.zombie) {
this.robotcount = totalalive - 1
} else {
this.robotcount = totalalivezombie - 1
}
this.aliverobot = 0
if (this.zudui) {
this.robotcount -= 3
}
if (this.battlecount == 1) {
this.canrefreshrobot = false
this.aitime = robotcreatetime - Number(praconfig.newbie_first_robot_appeartime.param_value)
} else {
this.canrefreshrobot = true
}
this.tongping = 1
if (this.isnewbie) {
this.dogamestart()
}
}
this.createdropitem = function(k, pos, plus, notmove, gunlv, player) {
if (k == 0) {
return
}
var rx = Utils.randintSeed(100) - 50
var ry = Utils.randintSeed(100) - 50
if (notmove) {
rx = ry = plus = 0
}
var x = pos.x + rx
var y = pos.y + ry
if (plus) {
var dir = cc.v2(rx, ry)
dir = dir.normalize()
x = pos.x + dir.x * plus
y = pos.y + dir.y * plus
}
var xidx = Math.floor(x / gird)
var yidx = Math.floor(y / gird)
var xykey = xidx + "-" + yidx
if (!this.dropitemmap[xykey]) {
this.dropitemmap[xykey] = []
}
var dobj = new dropobj()
dobj.init(this.obj_uniid++, k, x, y, gunlv, player)
if (dobj.dead == false) {
this.dropitemmap[xykey].push(dobj)
if (dobj.equip_type == 9) {
this.zuoqiarr.push(dobj)
this.needzuoqi = true
}
}
}
this.createdrop = function(dropid, pos) {
if (dropid) {
if (this.fixdrop.length > 0) {
dropid = this.fixdrop.shift()
}
var data = dropcfg[dropid]
if (!data.inited) {
data.inited = true
var itemarr = data.item_id.split('|')
var numarr = data.num.split('|')
var weightarr = data.weight.split('|')
data.item = []
for (var i = 0; i < itemarr.length; i++) {
data.item.push({
k: itemarr[i],
v: numarr[i],
w: Number(weightarr[i])
})
}
}
for (var i = data.item.length - 1; i >= 0; i--) {
if (Utils.randintSeed(10000) < data.item[i].w) {
this.createdropitem(data.item[i].k, pos)
}
}
// this.createdropitem(15048,pos)
// this.createdropitem(13014,pos)
// this.createdropitem(17001,pos)
}
}
this.dohit = function(gun, uuid, tp, pos, atkerid) {
if (this.gamestart == false) {
return
}
if (gun.explosion_range) {
if (gun.atk) {
this.createboom(gun.atk, gun.explosion_range, pos, gun.explosion_effect, true, atkerid, gun)
} else if (gun.equip_type == 3) {
this.createsmoke(pos)
}
} else {
if (tp == 2) {
var drop = chacheobj.objmaploot[uuid].hurt(gun.atk, atkerid)
this.createdrop(drop, pos)
} else if (tp == 1) {
chacheobj.objmapplayer[uuid].hurt(gun.atk, atkerid, gun)
}
}
}
this.createsmoke = function(pos) {
this.smokearr.push({
pos: {
x: pos.x,
y: pos.y
},
})
}
this.dobaoxiang = function() {
var player = this.player
player.backpack = 12701
player.refreshbag()
player.getitem(7)
player.getitem(8)
player.needreport = true
}
this.createboom = function(atk, rag, pos, eff, skipplayer, atkerid, gun) {
var xidx = Math.floor(pos.x / gird)
var yidx = Math.floor(pos.y / gird)
var xykey = xidx + "-" + yidx
var bom = {
x: pos.x,
y: pos.y,
width: rag * 2
}
var oar = this.lootarr[xykey]
if (oar) {
for (var j = oar.length - 1; j >= 0; j--) {
if (Utils.hitTestCircle(bom, oar[j])) {
var drop = oar[j].hurt(atk, atkerid)
this.createdrop(drop, pos)
}
}
}
for (var j = this.playerarr.length - 1; j >= 0; j--) {
// if (skipplayer && this.playerarr[j] == this.player) {
// continue
// }
if (atkerid == this.playerarr[j].obj_uniid) {
continue
}
if (Utils.hitTestCircle(bom, this.playerarr[j])) {
this.playerarr[j].hurt(atk, atkerid, gun)
}
}
this.boomarr.push({
pos: {
x: pos.x,
y: pos.y
},
effect: eff,
})
}
this.pushcgbuff = function(buff, player, chg) {
this.chged_buff_list.push({
obj_id: player.obj_uniid,
chg: chg,
buff: {
buff_id: buff.buff_id,
left_time: buff.left_time,
lasting_time: buff.lasting_time,
}
})
}
this.sendupdate = function() {
if (this.gameover) {
return null
}
var out_objids = []
var full_objects = []
var airdrop = this.airdrop
this.airdrop = null
var xidx = Math.floor(this.player.pos.x / gird)
var yidx = Math.floor(this.player.pos.y / gird)
var xykey = xidx + "-" + yidx
var outarea = []
var emotes = []
var deletarr = []
if (this.area != xykey) {
var sx = xidx - 1
var mx = xidx + 1
var sy = yidx - 1
var my = yidx + 1
var temp = [
xidx + "-" + yidx,
xidx + "-" + sy,
xidx + "-" + my,
sx + "-" + yidx,
sx + "-" + sy,
sx + "-" + my,
mx + "-" + yidx,
mx + "-" + sy,
mx + "-" + my,
]
for (var i = 0; i < this.needpush.length; i++) {
var baoliu = false
for (var j = 0; j < temp.length; j++) {
if (this.needpush[i] == temp[j]) {
baoliu = true
break
}
}
if (!baoliu) {
outarea.push(this.needpush[i])
}
}
this.needpush = temp
this.area = xykey
}
for (var i = outarea.length - 1; i >= 0; i--) {
var oar = this.lootarr[outarea[i]]
if (oar) {
for (var j = oar.length - 1; j >= 0; j--) {
out_objids.push(oar[j].obj_uniid)
}
}
var oar2 = this.dropitemmap[outarea[i]]
if (oar2) {
for (var j = oar2.length - 1; j >= 0; j--) {
out_objids.push(oar2[j].obj_uniid)
}
}
}
for (var i = this.needpush.length - 1; i >= 0; i--) {
var oar = this.lootarr[this.needpush[i]]
if (oar) {
for (var j = oar.length - 1; j >= 0; j--) {
var onedata = oar[j]
full_objects.push({
object_type: onedata.object_type,
["union_obj_" + onedata.object_type]: onedata,
})
}
}
var oar2 = this.dropitemmap[this.needpush[i]]
if (oar2) {
for (var j = oar2.length - 1; j >= 0; j--) {
var onedata = oar2[j]
full_objects.push({
object_type: onedata.object_type,
["union_obj_" + onedata.object_type]: onedata
})
if (onedata.dead) {
if (onedata.equip_type == 9) {
this.needzuoqi = true
}
deletarr.push(onedata.obj_uniid)
chacheobj.objdrop[onedata.obj_uniid] = null
oar2.splice(j, 1);
}
}
}
}
for (var i = this.housearr.length - 1; i >= 0; i--) {
var onedata = this.housearr[i]
if (Math.abs(onedata.pos.x - this.player.pos.x) < housegird && Math.abs(onedata.pos.y - this.player.pos.y) < housegird) {
full_objects.push({
object_type: onedata.object_type,
["union_obj_" + onedata.object_type]: onedata
})
this.housearr.splice(i, 1);
}
}
for (var i = this.playerarr.length - 1; i >= 0; i--) {
var oneplayer = this.playerarr[i]
var px = Math.floor(oneplayer.pos.x / gird)
var py = Math.floor(oneplayer.pos.y / gird)
var key = px + "-" + py
var canpush = false
for (var j = this.needpush.length - 1; j >= 0; j--) {
if (key == this.needpush[j]) {
canpush = true
break
}
}
if (canpush) {
full_objects.push({
object_type: 1,
["union_obj_1"]: oneplayer
})
if (oneplayer.emote) {
emotes.push(oneplayer.emote)
}
} else {
var needout = false
for (var j = outarea.length - 1; j >= 0; j--) {
if (key == outarea[j]) {
needout = true
break
}
}
if (needout) {
out_objids.push(oneplayer.obj_uniid)
}
}
oneplayer.emote = null
}
var bulletarr2 = []
for (var i = chacheobj.bulletarr.length - 1; i >= 0; i--) {
bulletarr2.push(chacheobj.bulletarr[i])
}
chacheobj.bulletarr.length = 0
var shotarr2 = []
for (var i = chacheobj.shotarr.length - 1; i >= 0; i--) {
shotarr2.push(chacheobj.shotarr[i])
}
chacheobj.shotarr.length = 0
var boomarr2 = []
for (var i = this.boomarr.length - 1; i >= 0; i--) {
boomarr2.push(this.boomarr[i])
}
this.boomarr.length = 0
var smokearr2 = []
for (var i = this.smokearr.length - 1; i >= 0; i--) {
smokearr2.push(this.smokearr[i])
}
this.smokearr.length = 0
var chged_buff_list2 = []
for (var i = this.chged_buff_list.length - 1; i >= 0; i--) {
chged_buff_list2.push(this.chged_buff_list[i])
}
this.chged_buff_list.length = 0
var ropp = null
if (this.player.needreport) {
this.player.needreport = false
ropp = this.player
ropp.action_frameno = this.frameno
}
var chged_property_list = null
if (this.player.propertyarr.length > 0) {
chged_property_list = this.player.propertyarr
this.player.propertyarr = []
}
var gas = null
if (this.gas.canreport) {
gas = this.gas
this.gas.canreport = false
}
var gas_progress = null
var gas_pos_old = null
if (this.gas.mode == 2) {
gas_progress = this.gas.rad_old
gas_pos_old = this.gas.pos_old
}
if (this.team_data) {
for (var i = this.team_data.length - 1; i >= 0; i--) {
this.team_data[i].health = this.memberarr[this.team_data[i].player_id].health
this.team_data[i].max_health = this.memberarr[this.team_data[i].player_id].max_health
}
}
if (cc.jietumode) {
out_objids = []
}
var skillani = []
if (this.nowskill) {
skillani.push({
skill_id: this.nowskill,
obj_uniid: this.player.obj_uniid
})
this.nowskill = null
}
var req = {
airdrop: airdrop,
frameno: this.frameno,
active_player_id: this.player.obj_uniid,
alive_count: this.alive_count,
active_player_data: ropp,
bullets: bulletarr2,
chged_buff_list: chged_buff_list2,
del_objids: deletarr,
emotes: emotes,
explosions: boomarr2,
full_objects: full_objects,
gas_data: gas,
gas_pos_old: gas_pos_old,
gas_progress: gas_progress,
out_objids: out_objids,
part_objects: [],
shots: shotarr2,
smokes: smokearr2,
team_data: this.team_data,
chged_property_list: chged_property_list,
play_skill_list: skillani,
}
this.frameno++;
return req
}
this.createlootbyid = function(oid, ox, oy) {
var loot = new lootobj()
var dat = {
x: ox,
y: oy,
obstacle_id: oid
}
dat.xidx = Math.floor(dat.x / gird)
dat.yidx = Math.floor(dat.y / gird)
if (loot.init(dat, this.obj_uniid++, this)) {
if (!this.lootarr[dat.xidx + "-" + dat.yidx]) {
this.lootarr[dat.xidx + "-" + dat.yidx] = []
}
this.lootarr[dat.xidx + "-" + dat.yidx].push(loot)
this.myTree.insert({
xx: loot.x,
yy: loot.y,
x: loot.x - loot.width / 2,
y: loot.y - loot.height / 2,
width: loot.width,
height: loot.height,
loot: loot
});
}
return loot
}
this.createair = function() {
this.createlootbyid(this.aironjid, this.airx, this.airy)
}
this.createnewbieenemy = function(data) {
let robot = new playerobj(this.obj_uniid++, this)
robot.init(undefined, undefined, data[4])
if (data[3] == 1) {
robot.setposition(this.player.x + data[1], this.player.y + data[2])
} else {
robot.setposition(data[1], data[2])
}
robot.setaicfg(data[5])
this.playerarr.push(robot)
this.aliverobot++;
this.refreshalive()
}
this.donewbiewin = function() {
setTimeout(() => {
this.gameover = true
}, 100);
cc.gameMgr.uic.newbiewin()
}
this.update = function(dt) {
if (this.wincheck) {
if (this.aliverobot == 0) {
this.wincheck = false
cc.Notifier.emit("jiantingbattle","newbieover")
}
}
if (this.gamestart && this.aitime > robotcreatetime && this.robotcount > 0 && this.aliverobot < this.tongping && !this.player.tiaosan && !this.isnewbie) {
this.tongping = Utils.randintSeed(tongpingfudong) + 1
this.aitime = 0
let robot = new playerobj(this.obj_uniid++, this)
robot.init()
var dir = cc.v2(0, 1)
dir = Utils.dirRotate(dir, Utils.randintSeed(360) * dtoh)
if (this.battlecount > 1) {
robot.setposition(this.player.x + dir.x * 400, this.player.y + dir.y * 400)
} else {
if (!this.fistbobot) {
this.fistbobot = true
dir.x = 0
dir.y = 1
dir = Utils.dirRotate(dir, 280 * dtoh)
var dis = Number(praconfig.newbie_first_robot_distance.param_value)
robot.setposition(this.player.x + dir.x * dis, this.player.y + dir.y * dis)
} else {
robot.setposition(this.player.x + dir.x * 400, this.player.y + dir.y * 400)
}
}
this.playerarr.push(robot)
this.robotcount--;
this.aliverobot++;
}
for (var i = 0; i < this.playerarr.length; i++) {
this.playerarr[i].update(dt, this.gas)
}
this.gas.update(dt)
this.time_alive += dt
if (this.gamestart && !this.isnewbie) {
if (this.newbiebaohu > 0) {
this.newbiebaohu -= dt
if (this.newbiebaohu <= 0) {
this.canrefreshrobot = true
}
}
if (this.canrefreshrobot) {
this.aitime += dt
}
if (this.airidx < this.aircfgarr.length) {
this.airtime += dt
var airdata = this.getaair()
if (this.airtime > airdata.time) {
this.aironjid = airdata.drop_id
this.airx = this.gas.pos_old.x + Utils.randintSeed(this.gas.rad_new) - this.gas.rad_new / 2
this.airy = this.gas.pos_old.y + Utils.randintSeed(this.gas.rad_new) - this.gas.rad_new / 2
this.airdroptime = 5
this.airdrop = {
pos: {
x: this.airx,
y: this.airy,
},
appear_time: airdata.appear_time,
box_id: aironjid,
}
this.airidx++
}
}
if (this.robotcount > 0 && this.canrefreshrobot && !this.zombie) {
this.killtime += dt
if (this.killtime > killrobottime) {
this.killtime = 0
this.robotcount--;
this.showkiiltip()
this.alive_count--;
this.refreshalive()
}
}
}
if (this.airdroptime > 0) {
this.airdroptime -= dt
if (this.airdroptime <= 0) {
this.createair()
}
}
var pd = 1
if (this.zudui) {
pd = 4
}
if (this.alive_count == pd && !this.isnewbie) {
this.dogameover()
}
this.updateevent(dt)
}
this.move = function(data) {
if (this.gameover) {
return
}
var dt = 0.09
if (this.gas.pausetime > 0) {
this.gas.pausetime -= dt
if (this.gas.pausetime <= 0) {
if (this.battlecount > 1) {
this.randpos()
} else {
this.player.setposition(newbiepoint.x, newbiepoint.y)
}
if (this.zudui) {
for (var k in this.memberarr) {
if (this.memberarr[k] != this.player) {
this.memberarr[k].setposition(this.player.x + Utils.randintSeed(50), this.player.y + Utils.randintSeed(50))
this.team_data.push({
player_id: this.memberarr[k].obj_uniid,
max_health: 200,
health: 200,
name: this.robotnamearr[this.rbotidx],
dead: false,
downed: false,
pos: this.memberarr[k].pos,
account_id: "",
vip_lv: this.memberarr[k].vip_lv,
head: this.memberarr[k].head,
user_data: this.memberarr[k].user_data,
avatar_url: this.memberarr[k].avatar_url,
})
this.memberarr[k].name = this.robotnamearr[this.rbotidx]
this.rbotidx++
}
}
}
for (var i = 0; i < this.playerarr.length; i++) {
this.playerarr[i].daduanaction()
this.playerarr[i].addbuff(7002)
}
}
return
}
this.player.onreport(data)
this.update(dt)
if (this.needzuoqi) {
this.zuoqiui()
}
}
this.sendRevive = function() {
this.player.revive()
}
this.dogameover = function(killname) {
this.gameover = true
var rank = this.alive_count
if (this.zudui) {
rank -= 3
}
var gold = killRewardConfig[this.player.killcount].parameter * Number(praconfig.kill_parameter.param_value) + rankRewardConfig[rank].parameter * Number(praconfig.rank_parameter.param_value)
var jifen = rankPointConfig[rank].parameter2 + killPointConfig[this.player.killcount].parameter2
var itemget = []
for (var k in this.player.battleitemmap) {
itemget.push({
values: [Number(k), this.player.battleitemmap[k]]
})
}
cc.gameMgr.uic.netGameOver({
team_data: this.team_data,
team_rank: rank,
offline: true,
player_stats: [{
items: [], //{key:18005,value:1},{key:18004,value:2}
time_alive: Math.floor(this.time_alive) * 1000,
damage_amount: Math.floor(this.player.dmg),
kills: this.player.killcount,
killer_account_id: 10086,
killer_name: killname,
gold: gold,
rank_score: jifen,
}],
spoils_items: itemget
})
}
this.sendGameOver = function() {
this.player.dodead()
}
this.showkiiltip = function(name, gunname) {
if (!gunname) {
gunname = this.radgunarr[Utils.randintSeed(this.radgunarr.length)]
}
var atker = cc.language.stringformat("morenmingzi")
var deader = cc.language.stringformat("morenmingzi")
if (Utils.randintSeed(100) > 10) {
deader = this.robotnamearr[this.rbotidx]
this.rbotidx++
}
if (name) {
atker = name
} else {
if (Utils.randintSeed(100) > 10) {
atker = this.robotnamearr[this.rbotidx]
}
}
var str = cc.language.stringformat("fighttips1", [atker, gunname, deader]) //atker + " " + gunname + " " + deader
// cc.gameMgr.uic.showbattletip(str)
}
this.dokillmsg = function(name, gun) {
this.alive_count--;
this.refreshalive()
if (gun) {
this.showkiiltip(name, gun.name)
}
}
this.refreshalive = function() {
var count = this.alive_count
if (this.isnewbie) {
count = this.aliverobot + 1
}
cc.gameMgr.uic.refreshAlive({
alive_count: count,
kill_count: this.player.killcount
})
}
this.zuoqiui = function() {
var out = []
for (var i = this.zuoqiarr.length - 1; i >= 0; i--) {
if (this.zuoqiarr[i].dead) {
this.zuoqiarr.splice(i, 1);
} else {
out.push({
pos: {
x: this.zuoqiarr[i].pos.x,
y: this.zuoqiarr[i].pos.y
}
})
}
}
cc.gameMgr.uic.refreshTank(out)
this.needzuoqi = false
}
this.getpzobjs = function(data) {
return this.myTree.retrieve(data)
}
this.updateevent = function(dt) {
for (var i = this.eventarrtemp.length - 1; i >= 0; i--) {
this.eventarr.push(this.eventarrtemp[i])
}
this.eventarrtemp.length = 0
for (var i = this.eventarr.length - 1; i >= 0; i--) {
var onedata = this.eventarr[i]
if (onedata.lifetime) {
onedata.lifetime -= dt
if (onedata.lifetime <= 0) {
onedata.target.donext()
this.eventarr.splice(i, 1);
}
}
}
}
this.addevent = function(tar, dat) {
var tp = dat[0]
if (tp == bNewbieEnum.delay) {
this.eventarrtemp.push({
target: tar,
lifetime: dat[1]
})
} else if (tp == bNewbieEnum.waitforemit) {
this.emitarr.push({
target: tar,
emit: dat[1]
})
}
// else if (tp == bNewbieEnum.touch) {
// cc.bnewbiemgr.ntouch(tar,dat[1])
// }
}
this.jiantingbattle = function(v) {
for (var i = this.emitarr.length - 1; i >= 0; i--) {
var onedata = this.emitarr[i]
if (onedata.emit == v) {
onedata.target.donext()
this.emitarr.splice(i, 1);
}
}
}
}
module.exports = clientserver;