军团活动:修改粮草先行

This commit is contained in:
luying
2022-04-30 19:19:48 +08:00
parent d9d0aad862
commit 2b737f2528
6 changed files with 160 additions and 123 deletions
+19 -10
View File
@@ -62,8 +62,9 @@ export class Rank {
break;
case REDIS_KEY.RACE_ACTIVITY:
this.valueConfig = [
new ValueConfig(true, 'score', 0, false, false),
new ValueConfig(false, 'time', 10, true, true)
new ValueConfig(true, 'distance', 0, false, false),
new ValueConfig(false, 'time', 6, true, true),
new ValueConfig(false, 'durability', 3, false, false),
];
break;
case REDIS_KEY.GUILD_LV_RANK:
@@ -83,7 +84,7 @@ export class Rank {
for(let i = 0; i < this.valueConfig.length; i++) {
let weight = 0;
for(let j = i + 1; j < this.valueConfig.length; j++) {
weight = this.valueConfig[j].len;
weight += this.valueConfig[j].len;
}
this.valueConfig[i].setWeight(weight);
}
@@ -155,8 +156,8 @@ export class Rank {
return await this.setRankWithGuildInfoArrParam(guildCode, [score, timestamp], guild, isInc);
}
public async setRankWithGuildInfo2(guildCode: string, lv: number, active: number, timestamp: number, guild?: GuildType, isInc = false) {
return await this.setRankWithGuildInfoArrParam(guildCode, [lv, active, timestamp], guild, isInc);
public async setRankWithGuildInfo2(guildCode: string, num1: number, num2: number, num3: number, guild?: GuildType, isInc = false) {
return await this.setRankWithGuildInfoArrParam(guildCode, [num1, num2, num3], guild, isInc);
}
public async setRankWithGuildInfoArrParam(guildCode: string, scores: number[], guild?: GuildType, isInc = false) {
@@ -640,7 +641,7 @@ export class Rank {
public async getRankListWithMyRank(myId: myIdInter) {
let ranks = await this.getRankByRange();
let newRanks = [], newMyRank: RoleRankInfo | GuildRankInfo;
let newRanks = [], newMyRank: any;
let myRank = ranks.find(cur => {
return cur.isMyInfo(myId);
});
@@ -714,7 +715,7 @@ export class Rank {
param = new RoleRankInfo(userInfo);
param.setInfo(Math.floor(ii / 2) + 1, myId, scores[0], scores[1]);
} else if (this.infoKey == REDIS_KEY.GUILD_INFO) {
if(this.key == REDIS_KEY.GUILD_LV_RANK) {
if(this.key == REDIS_KEY.GUILD_LV_RANK|| this.key == REDIS_KEY.RACE_ACTIVITY) {
param = new GuildRankInfo(userInfo);
param.setInfo2(Math.floor(ii / 2) + 1, myId, scores[0], scores[1], scores[2]);
} else {
@@ -847,15 +848,19 @@ export class Rank {
// 有序排行综合时间和得分排序
private encodeScore(scores: number[]) {
let encodeResult = 0;
this.valueConfig.forEach(({ reverse, isTimestamp, len, weight }, index) => {
console.log('#### decoencodeResultdeScore', this.key, scores, this.valueConfig);
this.valueConfig.forEach(({ name, reverse, isTimestamp, len, weight }, index) => {
let score = scores[index];
console.log('*** 1', name, len, weight, score, encodeResult)
if(isTimestamp) score = this.handleTimestamp(score, len);
console.log('*** 2', name, len, weight, score, encodeResult)
if(!reverse) {
encodeResult += score * Math.pow(10, weight);
} else {
let pow = Math.pow(10, len);
encodeResult += pow - 1 - score;
encodeResult += (pow - 1 - score) * Math.pow(10, weight);
}
console.log('*** 3', name, len, weight, score, encodeResult)
})
return encodeResult
}
@@ -863,17 +868,21 @@ export class Rank {
private decodeScore(num: string) {
let _num = parseInt(num);
let scores: number[] = [];
this.valueConfig.forEach(({ reverse, isTimestamp, len, weight }) => {
this.valueConfig.forEach(({ name, reverse, isTimestamp, len, weight }) => {
let pow = Math.pow(10, weight);
let score = Math.floor(_num / pow);
console.log('*** 1', name, len, weight, score)
_num -= pow * score;
if(isTimestamp) score = this.handleTimestamp(score, len);
console.log('*** 2', name, len, weight, score)
if(reverse) {
let pow = Math.pow(10, len);
score = pow - 1 - score;
}
console.log('*** 3', name, len, weight, score)
scores.push(score);
})
console.log('#### decodeScore', this.key, scores, this.valueConfig);
return scores;
}