Commit c51e57a9 authored by nanahira's avatar nanahira

rearrange death

parent 29861e81
...@@ -283,7 +283,7 @@ ...@@ -283,7 +283,7 @@
"public_roomlist": false, "public_roomlist": false,
"show_ip": false, "show_ip": false,
"show_info": true, "show_info": true,
"quick_death_rule": false, "quick_death_rule": 2,
"ssl": { "ssl": {
"enabled": false, "enabled": false,
"port": 7923, "port": 7923,
......
...@@ -1363,6 +1363,52 @@ class Room ...@@ -1363,6 +1363,52 @@ class Room
client.server.destroy() client.server.destroy()
return return
start_death: () ->
unless @established and @started and !@death
return false
oppo_pos = if @hostinfo.mode == 2 then 2 else 1
if !@changing_side and (!@duel_count or @turn) # Extra duel started in duel
switch settings.modules.http.quick_death_rule
when 3
@death = -2
ygopro.stoc_send_chat_to_room(this, "${death_start_phase}", ygopro.constants.COLORS.BABYBLUE)
else
@death = (if @turn then @turn + 4 else 5)
ygopro.stoc_send_chat_to_room(this, "${death_start}", ygopro.constants.COLORS.BABYBLUE)
else # Extra duel started in siding
switch settings.modules.http.quick_death_rule
when 2,3
if @scores[@dueling_players[0].name_vpass] == @scores[@dueling_players[oppo_pos].name_vpass]
if settings.modules.http.quick_death_rule == 3
@death = -1
ygopro.stoc_send_chat_to_room(this, "${death_start_quick}", ygopro.constants.COLORS.BABYBLUE)
else
@death = 5
ygopro.stoc_send_chat_to_room(this, "${death_start_siding}", ygopro.constants.COLORS.BABYBLUE)
else
win_pos = if @scores[@dueling_players[0].name_vpass] > @scores[@dueling_players[oppo_pos].name_vpass] then 0 else oppo_pos
@finished_by_death = true
ygopro.stoc_send_chat_to_room(this, "${death2_finish_part1}" + @dueling_players[win_pos].name + "${death2_finish_part2}", ygopro.constants.COLORS.BABYBLUE)
CLIENT_send_replays(@dueling_players[oppo_pos - win_pos], this) if @hostinfo.mode == 1
ygopro.stoc_send(@dueling_players[oppo_pos - win_pos], 'DUEL_END')
ygopro.stoc_send(@dueling_players[oppo_pos - win_pos + 1], 'DUEL_END') if @hostinfo.mode == 2
@scores[@dueling_players[oppo_pos - win_pos].name_vpass] = -1
CLIENT_kick(@dueling_players[oppo_pos - win_pos])
CLIENT_kick(@dueling_players[oppo_pos - win_pos + 1]) if @hostinfo.mode == 2
when 1
@death = -1
ygopro.stoc_send_chat_to_room(this, "${death_start_quick}", ygopro.constants.COLORS.BABYBLUE)
else
@death = 5
ygopro.stoc_send_chat_to_room(this, "${death_start_siding}", ygopro.constants.COLORS.BABYBLUE)
return true
cancel_death: () ->
unless @established and @started and @death
return false
@death = 0
ygopro.stoc_send_chat_to_room(this, "${death_cancel}", ygopro.constants.COLORS.BABYBLUE)
return true
# 网络连接 # 网络连接
net.createServer (client) -> net.createServer (client) ->
...@@ -3529,43 +3575,9 @@ if settings.modules.http ...@@ -3529,43 +3575,9 @@ if settings.modules.http
response.end(addCallback(u.query.callback, "['密码错误', 0]")) response.end(addCallback(u.query.callback, "['密码错误', 0]"))
return return
death_room_found = false death_room_found = false
for room in ROOM_all when room and room.established and room.started and !room.death and (u.query.death == "all" or u.query.death == room.process_pid.toString() or u.query.death == room.name) for room in ROOM_all when room and (u.query.death == "all" or u.query.death == room.process_pid.toString() or u.query.death == room.name)
death_room_found = true if room.start_death()
oppo_pos = if room.hostinfo.mode == 2 then 2 else 1 death_room_found = true
if !room.changing_side and (!room.duel_count or room.turn)
switch settings.modules.http.quick_death_rule
when 3
room.death = -2
ygopro.stoc_send_chat_to_room(room, "${death_start_phase}", ygopro.constants.COLORS.BABYBLUE)
else
room.death = (if room.turn then room.turn + 4 else 5)
ygopro.stoc_send_chat_to_room(room, "${death_start}", ygopro.constants.COLORS.BABYBLUE)
else
switch settings.modules.http.quick_death_rule
when 2,3
if room.scores[room.dueling_players[0].name_vpass] == room.scores[room.dueling_players[oppo_pos].name_vpass]
if settings.modules.http.quick_death_rule == 3
room.death = -1
ygopro.stoc_send_chat_to_room(room, "${death_start_quick}", ygopro.constants.COLORS.BABYBLUE)
else
room.death = 5
ygopro.stoc_send_chat_to_room(room, "${death_start_siding}", ygopro.constants.COLORS.BABYBLUE)
else
win_pos = if room.scores[room.dueling_players[0].name_vpass] > room.scores[room.dueling_players[oppo_pos].name_vpass] then 0 else oppo_pos
room.finished_by_death = true
ygopro.stoc_send_chat_to_room(room, "${death2_finish_part1}" + room.dueling_players[win_pos].name + "${death2_finish_part2}", ygopro.constants.COLORS.BABYBLUE)
CLIENT_send_replays(room.dueling_players[oppo_pos - win_pos], room) if room.hostinfo.mode == 1
ygopro.stoc_send(room.dueling_players[oppo_pos - win_pos], 'DUEL_END')
ygopro.stoc_send(room.dueling_players[oppo_pos - win_pos + 1], 'DUEL_END') if room.hostinfo.mode == 2
room.scores[room.dueling_players[oppo_pos - win_pos].name_vpass] = -1
CLIENT_kick(room.dueling_players[oppo_pos - win_pos])
CLIENT_kick(room.dueling_players[oppo_pos - win_pos + 1]) if room.hostinfo.mode == 2
when 1
room.death = -1
ygopro.stoc_send_chat_to_room(room, "${death_start_quick}", ygopro.constants.COLORS.BABYBLUE)
else
room.death = 5
ygopro.stoc_send_chat_to_room(room, "${death_start_siding}", ygopro.constants.COLORS.BABYBLUE)
response.writeHead(200) response.writeHead(200)
if death_room_found if death_room_found
response.end(addCallback(u.query.callback, "['death ok', '" + u.query.death + "']")) response.end(addCallback(u.query.callback, "['death ok', '" + u.query.death + "']"))
...@@ -3578,10 +3590,9 @@ if settings.modules.http ...@@ -3578,10 +3590,9 @@ if settings.modules.http
response.end(addCallback(u.query.callback, "['密码错误', 0]")) response.end(addCallback(u.query.callback, "['密码错误', 0]"))
return return
death_room_found = false death_room_found = false
for room in ROOM_all when room and room.established and room.started and room.death and (u.query.deathcancel == "all" or u.query.deathcancel == room.process_pid.toString()) for room in ROOM_all when room and (u.query.death == "all" or u.query.death == room.process_pid.toString() or u.query.death == room.name)
death_room_found = true if room.cancel_death()
room.death = 0 death_room_found = true
ygopro.stoc_send_chat_to_room(room, "${death_cancel}", ygopro.constants.COLORS.BABYBLUE)
response.writeHead(200) response.writeHead(200)
if death_room_found if death_room_found
response.end(addCallback(u.query.callback, "['death cancel ok', '" + u.query.deathcancel + "']")) response.end(addCallback(u.query.callback, "['death cancel ok', '" + u.query.deathcancel + "']"))
......
...@@ -1777,6 +1777,73 @@ ...@@ -1777,6 +1777,73 @@
} }
}; };
Room.prototype.start_death = function() {
var oppo_pos, win_pos;
if (!(this.established && this.started && !this.death)) {
return false;
}
oppo_pos = this.hostinfo.mode === 2 ? 2 : 1;
if (!this.changing_side && (!this.duel_count || this.turn)) {
switch (settings.modules.http.quick_death_rule) {
case 3:
this.death = -2;
ygopro.stoc_send_chat_to_room(this, "${death_start_phase}", ygopro.constants.COLORS.BABYBLUE);
break;
default:
this.death = (this.turn ? this.turn + 4 : 5);
ygopro.stoc_send_chat_to_room(this, "${death_start}", ygopro.constants.COLORS.BABYBLUE);
}
} else {
switch (settings.modules.http.quick_death_rule) {
case 2:
case 3:
if (this.scores[this.dueling_players[0].name_vpass] === this.scores[this.dueling_players[oppo_pos].name_vpass]) {
if (settings.modules.http.quick_death_rule === 3) {
this.death = -1;
ygopro.stoc_send_chat_to_room(this, "${death_start_quick}", ygopro.constants.COLORS.BABYBLUE);
} else {
this.death = 5;
ygopro.stoc_send_chat_to_room(this, "${death_start_siding}", ygopro.constants.COLORS.BABYBLUE);
}
} else {
win_pos = this.scores[this.dueling_players[0].name_vpass] > this.scores[this.dueling_players[oppo_pos].name_vpass] ? 0 : oppo_pos;
this.finished_by_death = true;
ygopro.stoc_send_chat_to_room(this, "${death2_finish_part1}" + this.dueling_players[win_pos].name + "${death2_finish_part2}", ygopro.constants.COLORS.BABYBLUE);
if (this.hostinfo.mode === 1) {
CLIENT_send_replays(this.dueling_players[oppo_pos - win_pos], this);
}
ygopro.stoc_send(this.dueling_players[oppo_pos - win_pos], 'DUEL_END');
if (this.hostinfo.mode === 2) {
ygopro.stoc_send(this.dueling_players[oppo_pos - win_pos + 1], 'DUEL_END');
}
this.scores[this.dueling_players[oppo_pos - win_pos].name_vpass] = -1;
CLIENT_kick(this.dueling_players[oppo_pos - win_pos]);
if (this.hostinfo.mode === 2) {
CLIENT_kick(this.dueling_players[oppo_pos - win_pos + 1]);
}
}
break;
case 1:
this.death = -1;
ygopro.stoc_send_chat_to_room(this, "${death_start_quick}", ygopro.constants.COLORS.BABYBLUE);
break;
default:
this.death = 5;
ygopro.stoc_send_chat_to_room(this, "${death_start_siding}", ygopro.constants.COLORS.BABYBLUE);
}
}
return true;
};
Room.prototype.cancel_death = function() {
if (!(this.established && this.started && this.death)) {
return false;
}
this.death = 0;
ygopro.stoc_send_chat_to_room(this, "${death_cancel}", ygopro.constants.COLORS.BABYBLUE);
return true;
};
return Room; return Room;
})(); })();
...@@ -4250,7 +4317,7 @@ ...@@ -4250,7 +4317,7 @@
return callback + "( " + text + " );"; return callback + "( " + text + " );";
}; };
requestListener = function(request, response) { requestListener = function(request, response) {
var archive_args, archive_name, archive_process, check, death_room_found, duellog, error, filename, getpath, kick_room_found, len2, len3, len4, len5, len6, m, n, o, oppo_pos, p, parseQueryString, pass_validated, player, q, ref2, replay, room, roomsjson, u, win_pos; var archive_args, archive_name, archive_process, check, death_room_found, duellog, error, filename, getpath, kick_room_found, len2, len3, len4, len5, len6, m, n, o, p, parseQueryString, pass_validated, player, q, ref2, replay, room, roomsjson, u;
parseQueryString = true; parseQueryString = true;
u = url.parse(request.url, parseQueryString); u = url.parse(request.url, parseQueryString);
if (u.pathname === '/api/getrooms') { if (u.pathname === '/api/getrooms') {
...@@ -4524,58 +4591,9 @@ ...@@ -4524,58 +4591,9 @@
death_room_found = false; death_room_found = false;
for (p = 0, len5 = ROOM_all.length; p < len5; p++) { for (p = 0, len5 = ROOM_all.length; p < len5; p++) {
room = ROOM_all[p]; room = ROOM_all[p];
if (!(room && room.established && room.started && !room.death && (u.query.death === "all" || u.query.death === room.process_pid.toString() || u.query.death === room.name))) { if (room && (u.query.death === "all" || u.query.death === room.process_pid.toString() || u.query.death === room.name)) {
continue; if (room.start_death()) {
} death_room_found = true;
death_room_found = true;
oppo_pos = room.hostinfo.mode === 2 ? 2 : 1;
if (!room.changing_side && (!room.duel_count || room.turn)) {
switch (settings.modules.http.quick_death_rule) {
case 3:
room.death = -2;
ygopro.stoc_send_chat_to_room(room, "${death_start_phase}", ygopro.constants.COLORS.BABYBLUE);
break;
default:
room.death = (room.turn ? room.turn + 4 : 5);
ygopro.stoc_send_chat_to_room(room, "${death_start}", ygopro.constants.COLORS.BABYBLUE);
}
} else {
switch (settings.modules.http.quick_death_rule) {
case 2:
case 3:
if (room.scores[room.dueling_players[0].name_vpass] === room.scores[room.dueling_players[oppo_pos].name_vpass]) {
if (settings.modules.http.quick_death_rule === 3) {
room.death = -1;
ygopro.stoc_send_chat_to_room(room, "${death_start_quick}", ygopro.constants.COLORS.BABYBLUE);
} else {
room.death = 5;
ygopro.stoc_send_chat_to_room(room, "${death_start_siding}", ygopro.constants.COLORS.BABYBLUE);
}
} else {
win_pos = room.scores[room.dueling_players[0].name_vpass] > room.scores[room.dueling_players[oppo_pos].name_vpass] ? 0 : oppo_pos;
room.finished_by_death = true;
ygopro.stoc_send_chat_to_room(room, "${death2_finish_part1}" + room.dueling_players[win_pos].name + "${death2_finish_part2}", ygopro.constants.COLORS.BABYBLUE);
if (room.hostinfo.mode === 1) {
CLIENT_send_replays(room.dueling_players[oppo_pos - win_pos], room);
}
ygopro.stoc_send(room.dueling_players[oppo_pos - win_pos], 'DUEL_END');
if (room.hostinfo.mode === 2) {
ygopro.stoc_send(room.dueling_players[oppo_pos - win_pos + 1], 'DUEL_END');
}
room.scores[room.dueling_players[oppo_pos - win_pos].name_vpass] = -1;
CLIENT_kick(room.dueling_players[oppo_pos - win_pos]);
if (room.hostinfo.mode === 2) {
CLIENT_kick(room.dueling_players[oppo_pos - win_pos + 1]);
}
}
break;
case 1:
room.death = -1;
ygopro.stoc_send_chat_to_room(room, "${death_start_quick}", ygopro.constants.COLORS.BABYBLUE);
break;
default:
room.death = 5;
ygopro.stoc_send_chat_to_room(room, "${death_start_siding}", ygopro.constants.COLORS.BABYBLUE);
} }
} }
} }
...@@ -4594,12 +4612,11 @@ ...@@ -4594,12 +4612,11 @@
death_room_found = false; death_room_found = false;
for (q = 0, len6 = ROOM_all.length; q < len6; q++) { for (q = 0, len6 = ROOM_all.length; q < len6; q++) {
room = ROOM_all[q]; room = ROOM_all[q];
if (!(room && room.established && room.started && room.death && (u.query.deathcancel === "all" || u.query.deathcancel === room.process_pid.toString()))) { if (room && (u.query.death === "all" || u.query.death === room.process_pid.toString() || u.query.death === room.name)) {
continue; if (room.cancel_death()) {
death_room_found = true;
}
} }
death_room_found = true;
room.death = 0;
ygopro.stoc_send_chat_to_room(room, "${death_cancel}", ygopro.constants.COLORS.BABYBLUE);
} }
response.writeHead(200); response.writeHead(200);
if (death_room_found) { if (death_room_found) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment