Commit 800ae2d7 authored by JoyJ's avatar JoyJ

update(incompleted)

parent 40f29241
function GetRankByScore(score) {
var rank="";
var rankScore = 0;
if (score < 0) {
return "阿兹卡班";
}
else if (score < 5001) {
rank = "青铜";
rankScore = rank;
}
else if (score < 10001) {
rank = "白银";
rankScore = rank - 5000;
}
else if (score < 15001) {
rank = "黄金";
rankScore = rank - 10000;
}
else if (score < 20001) {
rank = "白金";
rankScore = rank - 15000;
}
else if (score < 25001) {
rank = "钻石";
rankScore = rank - 20000;
}
else if (score < 30001) {
rank = "传奇";
rankScore = rank - 25000;
}
else if (score < 35001) {
rank = "大师";
rankScore = rank - 30000;
}
else {
rank = "决斗王";
}
if (rankScore <= 1000){
rank = rank + "V";
}
else if (rankScore <= 2000){
rank = rank + "IV";
}
else if (rankScore <= 3000){
rank = rank + "III";
}
else if (rankScore <= 4000){
rank = rank + "II";
}
else {
rank = rank + "I";
}
}
//CREATE TABLE ChronicleRank(name varchar(255), pass varchar(255), score int, lastscore int, ip varchar(255), lastLogin varchar(255));
function CreateAccount(name,ip,pass) {
var sql = "INSERT IGNORE INTO ChronicleRank VALUES(?,'',?,?,?,DATE_SUB(NOW(), INTERVAL 1 DAY))";
var score = 1000;
var lastscore = 0;
var sqlParams = [name, pass, score, lastscore, ip];
mysqldb.query(sql, sqlParams, function(err, result) {
if (err) {
return;
}
var sql2="UPDATE ChronicleRank SET pass=MD5(?) WHERE name=?";
var sqlParams2=[pass,name];
mysqldb.query(sql, sqlParams, function(_, _) {});
});
}
//CREATE TABLE ChronicleRank(name varchar(255), pass varchar(255), score int, lastscore int, ip varchar(255), lastLogin varchar(255));
function AddScore(name,add,ip) {
var sql = "UPDATE ChronicleRank SET score=score+? WHERE name=? AND ip=?";
var sqlParams = [add, name, ip];
mysqldb.query(sql, sqlParams, function(err, result) {
});
}
ygopro.ctos_follow_after("CHAT", true, async (buffer, info, client, server, datas) => {
var room = ROOM_all[client.rid];
var msg = _.trim(info.msg);
if (msg == "/rank") {
for(var i=0;i<room.players.length;i++){
var player=room.players[i];
var name = player.name;
var sql="SELECT name, score FROM ChronicleRank WHERE name=?";
var sqlParams = [name];
mysqldb.query(sql, sqlParams, function(err, result) {
if (err) {
global.mysqldb=mysql.createConnection(global.settings.modules.cloud_replay.mysql);
log.info(err);
ygopro.stoc_send_chat(client, "数据库连接失败!", ygopro.constants.COLORS.RED);
return;
}
var score = 1000;
if (result != null && result[0]!=null){
score = result[0].score;
}
else {
CreateAccount(name,player.ip,"");
}
ygopro.stoc_send_chat_to_room(
room,
result[0].name+"的当前命运力为【"+score+"】点("+GetRankByScore(score)+"",
ygopro.constants.COLORS.YELLOW
);
});
}
return null;
}
if (msg.substring(0, 5) == "/login") {
if (msg.length<6) {
ygopro.stoc_send_chat(client, "请以【/login 密码】的格式进行登录", ygopro.constants.COLORS.YELLOW);
return;
}
var pass=msg.substring(6);
var sql="SELECT name,ip FROM ChronicleRank WHERE name=? AND (ip=? OR pass='')"
var sqlParams=[pass,client.name,client.ip];
}
if (msg.substring(0, 5) == "/lock") {
var sql="UPDATE "
}
});
//初始命运力:1000
//胜场:+100 ±30
//负场:-80 ±30
//完成1场决斗(每22小时1次):+500 ± 50
//CREATE TABLE ChronicleRank(name varchar(255), pass varchar(255), score int, lastscore int, ip varchar(255), lastDaily varchar(255));
ygopro.stoc_follow_after('DUEL_END', true, async function(buffer, info, client, server, datas) {
var room = ROOM_all[client.rid];
var winnerscore = 0;
for (var i=0;i<room.dueling_players.length;i++) {
var player = room.dueling_players[i];
var vname = player.name_vpass;
if (room.scores[vname] && room.scores[vname]>winnerscore) {
winnerscore = room.scores[vname];
}
}
for (var i=0;i<room.dueling_players.length;i++) {
var player = room.dueling_players[i];
var vname = player.name_vpass;
if (room.scores[vname] && room.scores[vname]==winnerscore) {
var sql = "SELECT name, score, lastDaily FROM ChronicleRank WHERE name=?";
var sqlParams = [name];
}
}
});
\ No newline at end of file
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