This commit is contained in:
libccy 2016-04-17 14:00:26 +08:00
parent a6c47ad582
commit af9fa6d3b8
2 changed files with 122 additions and 28 deletions

View File

@ -7148,15 +7148,29 @@
delete this.avatar; delete this.avatar;
}, },
initRoom:function(info,info2){ initRoom:function(info,info2){
if(!info){ if(!this.node.gaming){
this.node.gaming=ui.create.div('.gaming','游戏中',this);
this.node.gaming.dataset.nature='fire';
}
if(!this.node.serving){
this.node.serving=ui.create.div('.gaming','服务器',this);
this.node.serving.dataset.nature='water';
}
this.serving=false;
if(!info||info=='server'){
this.roomempty=true; this.roomempty=true;
this.initOL('空房间',info2||'room'); this.initOL('空房间',info2||'room');
this.node.hp.innerHTML=''; this.node.hp.innerHTML='';
if(this.node.gaming){
this.node.gaming.hide();
}
this.roomfull=false; this.roomfull=false;
this.roomgaming=false; this.roomgaming=false;
if(info=='server'){
this.serving=true;
this.node.serving.show();
}
else{
this.node.serving.hide();
}
this.node.gaming.hide();
} }
else{ else{
this.roomempty=false; this.roomempty=false;
@ -7177,16 +7191,13 @@
modetrans=get.cnNumber(parseInt(config.number))+'人'+get.translation(config.mode); modetrans=get.cnNumber(parseInt(config.number))+'人'+get.translation(config.mode);
} }
this.initOL(modetrans,info[1]); this.initOL(modetrans,info[1]);
if(!this.node.gaming){
this.node.gaming=ui.create.div('.gaming','游戏中',this);
this.node.gaming.dataset.nature='fire';
}
if(config.gameStarted){ if(config.gameStarted){
this.node.gaming.show(); this.node.gaming.show();
} }
else{ else{
this.node.gaming.hide(); this.node.gaming.hide();
} }
this.node.serving.hide();
this.setNickname(info[0]); this.setNickname(info[0]);
this.maxHp=parseInt(config.number); this.maxHp=parseInt(config.number);
this.hp=info[3]; this.hp=info[3];
@ -9129,7 +9140,7 @@
bar.style.width=0; bar.style.width=0;
}, },
hideTimer:function(){ hideTimer:function(){
if(_status.connectMode&&!game.online){ if(_status.connectMode&&!game.online&&this.playerid){
game.broadcast(function(player){ game.broadcast(function(player){
player.hideTimer(); player.hideTimer();
},this); },this);
@ -12022,7 +12033,7 @@
this.closed=true; this.closed=true;
} }
} }
else if(lib.node.clients.length>=parseInt(lib.configOL.number)){ else if(lib.node.clients.length-(window.isNonameServer?1:0)>=parseInt(lib.configOL.number)){
this.send('denied','number'); this.send('denied','number');
lib.node.clients.remove(this); lib.node.clients.remove(this);
this.closed=true; this.closed=true;
@ -12059,6 +12070,11 @@
player.unwait(result); player.unwait(result);
} }
}, },
startGame:function(){
if(this.id==game.onlinezhu){
game.resume();
}
},
changeRoomConfig:function(config){ changeRoomConfig:function(config){
if(this.id==game.onlinezhu){ if(this.id==game.onlinezhu){
game.broadcastAll(function(config){ game.broadcastAll(function(config){
@ -12158,11 +12174,21 @@
lib.wsOL[id].onclose(); lib.wsOL[id].onclose();
} }
}, },
createroom:function(){ reloadroom:function(){
if(window.isNonameServer){
game.reload();
}
},
createroom:function(config,mode){
game.online=false; game.online=false;
game.onlineroom=true; game.onlineroom=true;
lib.node={}; lib.node={};
game.switchMode(lib.configOL.mode); if(config&&mode&&window.isNonameServer){
game.switchMode(mode,config);
}
else{
game.switchMode(lib.configOL.mode);
}
}, },
enterroomfailed:function(){ enterroomfailed:function(){
alert('请稍后再试'); alert('请稍后再试');
@ -12202,8 +12228,7 @@
},true); },true);
if(window.isNonameServer){ if(window.isNonameServer){
lib.configOL.mode='identity'; game.send('server','server');
game.send('server','enter',ui.rooms[0].roomindex,lib.config.connect_nickname,lib.config.connect_avatar);
} }
} }
if(_status.event.getParent()){ if(_status.event.getParent()){
@ -12583,6 +12608,9 @@
if(ui.roomInfo){ if(ui.roomInfo){
ui.roomInfo.innerHTML='房间设置'; ui.roomInfo.innerHTML='房间设置';
} }
if(ui.connectStartButton){
ui.connectStartButton.innerHTML='开始游戏';
}
} }
} }
else{ else{
@ -12678,6 +12706,9 @@
ui.arena.classList.add('playerhidden'); ui.arena.classList.add('playerhidden');
} }
game.prepareArena(); game.prepareArena();
if(window.isNonameServer){
game.me=ui.create.player();
}
var list=[]; var list=[];
for(var i=0;i<game.players.length;i++){ for(var i=0;i<game.players.length;i++){
if(game.players[i]!=game.me){ if(game.players[i]!=game.me){
@ -12693,9 +12724,11 @@
current.nickname=current.ws.nickname; current.nickname=current.ws.nickname;
current.setNickname(); current.setNickname();
} }
game.me.playerid=get.id(); if(!window.isNonameServer){
game.me.nickname=lib.config.connect_nickname; game.me.playerid=get.id();
game.me.setNickname(); game.me.nickname=lib.config.connect_nickname;
game.me.setNickname();
}
for(var i=0;i<game.players.length;i++){ for(var i=0;i<game.players.length;i++){
if(!game.players[i].playerid){ if(!game.players[i].playerid){
game.players[i].playerid=get.id(); game.players[i].playerid=get.id();
@ -15675,6 +15708,9 @@
if(game.addRecord){ if(game.addRecord){
game.addRecord(resultbool); game.addRecord(resultbool);
} }
if(window.isNonameServer){
setTimeout(game.reload,5000);
}
}, },
loop:function(){ loop:function(){
var event=_status.event; var event=_status.event;
@ -16336,7 +16372,7 @@
callback(mode[name]); callback(mode[name]);
}); });
}, },
switchMode:function(name){ switchMode:function(name,configx){
window.mode={}; window.mode={};
var script=lib.init.js(lib.assetURL+'mode',name,function(){ var script=lib.init.js(lib.assetURL+'mode',name,function(){
script.remove(); script.remove();
@ -16436,9 +16472,16 @@
if(_status.connectMode&&lib.mode[name].connect){ if(_status.connectMode&&lib.mode[name].connect){
game.saveConfig('connect_mode',name); game.saveConfig('connect_mode',name);
game.clearConnect(); game.clearConnect();
for(var i in lib.mode[name].connect){ if(configx){
if(i=='update') continue; for(var i in configx){
lib.configOL[i.slice(8)]=get.config(i); lib.configOL[i]=configx[i];
}
}
else{
for(var i in lib.mode[name].connect){
if(i=='update') continue;
lib.configOL[i.slice(8)]=get.config(i);
}
} }
lib.configOL.mode=name; lib.configOL.mode=name;
lib.configOL.characterPack=lib.connectCharacterPack.slice(0); lib.configOL.characterPack=lib.connectCharacterPack.slice(0);
@ -17841,7 +17884,17 @@
} }
else if(_status.enteringroom){ else if(_status.enteringroom){
lib.configOL.mode=active.mode; lib.configOL.mode=active.mode;
game.send('server','enter',_status.roomindex,lib.config.connect_nickname,lib.config.connect_avatar); if(_status.enteringroomserver){
var config={};
for(var i in lib.mode[lib.configOL.mode].connect){
if(i=='update') continue;
config[i.slice(8)]=get.config(i,lib.configOL.mode);
}
game.send('server','enter',_status.roomindex,lib.config.connect_nickname,lib.config.connect_avatar,config,active.mode);
}
else{
game.send('server','enter',_status.roomindex,lib.config.connect_nickname,lib.config.connect_avatar);
}
} }
else{ else{
localStorage.setItem(lib.configprefix+'directstart',true); localStorage.setItem(lib.configprefix+'directstart',true);
@ -22128,8 +22181,13 @@
var button=ui.create.div('.menubutton.large.highlight.connectbutton',game.online?'退出联机':'开始游戏',ui.window,function(){ var button=ui.create.div('.menubutton.large.highlight.connectbutton',game.online?'退出联机':'开始游戏',ui.window,function(){
if(button.clicked) return; if(button.clicked) return;
if(game.online){ if(game.online){
game.saveConfig('reconnect_info'); if(game.onlinezhu){
game.reload(); game.send('startGame');
}
else{
game.saveConfig('reconnect_info');
game.reload();
}
} }
else{ else{
game.resume(); game.resume();
@ -23884,6 +23942,7 @@
else if(this.hasOwnProperty('roomindex')){ else if(this.hasOwnProperty('roomindex')){
if(!_status.enteringroom){ if(!_status.enteringroom){
_status.enteringroom=true; _status.enteringroom=true;
_status.enteringroomserver=this.serving;
if(this.roomempty){ if(this.roomempty){
_status.roomindex=this.roomindex; _status.roomindex=this.roomindex;
ui.click.connectMenu(); ui.click.connectMenu();

View File

@ -5,7 +5,7 @@
var rooms=[{},{},{},{},{},{}]; var rooms=[{},{},{},{},{},{}];
var clients={}; var clients={};
var messages={ var messages={
enter:function(index,nickname,avatar){ enter:function(index,nickname,avatar,config,mode){
this.nickname=nickname; this.nickname=nickname;
this.avatar=avatar; this.avatar=avatar;
var room=rooms[index]; var room=rooms[index];
@ -15,7 +15,13 @@
} }
this.room=room; this.room=room;
if(room.owner){ if(room.owner){
if(!room.config){ if(room.servermode&&!room.owner._onconfig&&config&&mode){
room.owner.sendl('createroom',config,mode);
room.owner._onconfig=this;
room.owner.nickname=nickname;
room.owner.avatar=avatar;
}
else if(!room.config){
this.sendl('enterroomfailed'); this.sendl('enterroomfailed');
} }
else{ else{
@ -29,9 +35,31 @@
this.sendl('createroom'); this.sendl('createroom');
} }
}, },
server:function(){
for(var i=0;i<rooms.length;i++){
if(!rooms[i].owner){
rooms[i].owner=this;
rooms[i].servermode=true;
this.room=rooms[i];
this.servermode=true;
break;
}
}
util.updaterooms();
},
config:function(config){ config:function(config){
var room=this.room; var room=this.room;
if(room&&room.owner==this){ if(room&&room.owner==this){
if(room.servermode){
room.servermode=false;
if(this._onconfig){
if(clients[this._onconfig.wsid]){
this._onconfig.owner=this;
this.sendl('onconnection',this._onconfig.wsid);
}
delete this._onconfig;
}
}
room.config=config; room.config=config;
} }
util.updaterooms(); util.updaterooms();
@ -74,12 +102,18 @@
rooms[i]._num=0; rooms[i]._num=0;
} }
for(var i in clients){ for(var i in clients){
if(clients[i].room){ if(clients[i].room&&!clients[i].servermode){
clients[i].room._num++; clients[i].room._num++;
} }
} }
for(var i=0;i<rooms.length;i++){ for(var i=0;i<rooms.length;i++){
if(rooms[i].owner&&rooms[i].config){ if(rooms[i].servermode){
roomlist[i]='server';
}
else if(rooms[i].owner&&rooms[i].config){
if(rooms[i]._num==0){
rooms[i].owner.sendl('reloadroom');
}
roomlist[i]=[rooms[i].owner.nickname,rooms[i].owner.avatar, roomlist[i]=[rooms[i].owner.nickname,rooms[i].owner.avatar,
rooms[i].config,rooms[i]._num]; rooms[i].config,rooms[i]._num];
} }
@ -156,6 +190,7 @@
if(room&&room.owner==this){ if(room&&room.owner==this){
room.owner=null; room.owner=null;
room.config=null; room.config=null;
room.servermode=false;
for(var i in clients){ for(var i in clients){
if(clients[i].room==room&&clients[i]!=this){ if(clients[i].room==room&&clients[i]!=this){
clients[i].close(); clients[i].close();