From cefc6d8ba4e8030b12a7c42d9fb5e13366db25b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=AB=E8=B0=B7=E5=89=91=E4=BB=99?= Date: Sat, 28 Dec 2019 21:50:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E4=BD=BF=E7=94=A8=E4=BD=8D?= =?UTF-8?q?=E7=9A=84=E6=96=B9=E5=BC=8F=E6=9D=A5=E5=8E=8B=E7=BC=A9=E6=BD=9C?= =?UTF-8?q?=E8=A7=89=EF=BC=8C=E4=BD=86=E6=98=AF=E5=8F=91=E7=8E=B0=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E4=BA=86=EF=BC=8C=E6=97=A0=E6=B3=95=E6=8A=8A8?= =?UTF-8?q?=E4=B8=AA=E6=BD=9C=E8=A7=89=E5=8E=8B=E7=BC=A9=E5=88=B01?= =?UTF-8?q?=E4=B8=AA=E6=95=B0=E5=AD=97=E9=87=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script.js | 54 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/script.js b/script.js index 5a048894..6f38869a 100644 --- a/script.js +++ b/script.js @@ -32,9 +32,25 @@ Member.prototype.outObj = function(){ var obj = [m.id]; if (m.level != undefined) obj[1] = m.level; if (m.awoken != undefined) obj[2] = m.awoken; - if (m.plus != undefined && m.plus instanceof Array && m.plus.length>=3 && (m.plus[0]+m.plus[1]+m.plus[2])>0) obj[3] = m.plus; - if (m.latent != undefined && m.latent instanceof Array && m.latent.length>=1) obj[4] = m.latent; - if (m.sawoken != undefined) obj[5] = m.sawoken; + if (m.plus != undefined && m.plus instanceof Array && m.plus.length>=3 && (m.plus[0]+m.plus[1]+m.plus[2])!==0) + { + if (m.plus[0] === m.plus[1] && m.plus[0] === m.plus[2]) + { //当3个加值一样时只生成第一个减少长度 + obj[3] = m.plus[0]; + }else + { + obj[3] = m.plus; + } + } + if (m.latent != undefined && m.latent instanceof Array && m.latent.length>=1) + { + //obj[4] = m.latent; + //潜觉为1-33,5位可以表示0-31,6位才能表示0-63 + obj[4] = m.latent.reduce((previousValue, currentValue, idx) => { + return previousValue | currentValue << 6*idx; + },m.latent[0]); + } + if (m.sawoken != undefined && m.sawoken>=0) obj[5] = m.sawoken; return obj; } Member.prototype.loadObj = function(m,dataVersion){ @@ -46,9 +62,35 @@ Member.prototype.loadObj = function(m,dataVersion){ this.id = dataVersion>1 ? m[0] : m.id; this.level = dataVersion>1 ? m[1] : m.level; this.awoken = dataVersion>1 ? m[2] : m.awoken; - this.plus = dataVersion>1 ? m[3] : m.plus; - if (!(this.plus instanceof Array)) this.plus = [0,0,0]; //如果潜觉不是数组,则改变 - this.latent = dataVersion>1 ? m[4] : m.latent; + const singlePlus = parseInt(m[3],10);//如果只有一个数字时,复制3份 + this.plus = dataVersion>1 ? (isNaN(m[3])||m[3]==null ? m[3] : [singlePlus,singlePlus,singlePlus]) : m.plus; + if (!(this.plus instanceof Array)) this.plus = [0,0,0]; //如果加值不是数组,则改变 + if (dataVersion>1) + { + if (isNaN(m[4])) + { + this.latent = m[4]; + } + else if(m[4] != null) + { + const binNum = m[4].toString(2); + const latentCount = Math.ceil(binNum.length/6); + const startSubStr = binNum.length % 6; + let latentArray = []; + + latentArray.push(parseInt(binNum.substr(0,startSubStr),2)); //从最后一个潜觉开始添加 + for (let i=0;i<(latentCount-1);i++) + { + latentArray.push(parseInt(binNum.substr(startSubStr+6*i,6),2)); + } + latentArray.reverse(); //数组反向 + this.latent = latentArray; + } + }else + { + this.latent = m.latent; + } + //this.latent = dataVersion>1 ? m[4] : m.latent; if (!(this.latent instanceof Array)) this.latent = []; //如果潜觉不是数组,则改变 this.sawoken = dataVersion>1 ? m[5] : m.sawoken; }