Browse Source

尝试使用位的方式来压缩潜觉,但是发现失败了,无法把8个潜觉压缩到1个数字里

tags/v3.5
枫谷剑仙 6 years ago
parent
commit
cefc6d8ba4
1 changed files with 48 additions and 6 deletions
  1. +48
    -6
      script.js

+ 48
- 6
script.js View File

@@ -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;
}


Loading…
Cancel
Save