🐞 fix(guild): 捐赠宝箱重复领取&领取之后展示问题修复

This commit is contained in:
dingchaolin
2023-03-16 12:42:13 +08:00
parent 739ea2da6b
commit 36c81751bd
5 changed files with 125 additions and 127 deletions

View File

@@ -4,7 +4,7 @@ import { resResult } from '../../../pubUtils/util';
import { DATA_NAME, ITEM_CHANGE_REASON, STATUS, TASK_TYPE } from '../../../consts';
import { DonationModel } from '../../../db/Donation';
import { getZeroPoint, nowSeconds } from '../../../pubUtils/timeUtil';
import { getArmyDonateBaseByLv, getArmyDonateBoxBaseById } from '../../../pubUtils/data';
import { getArmyDonateBaseByLv, getArmyDonateBoxBaseById, getArmyDonateBoxBaseByLvAndIndex } from '../../../pubUtils/data';
import { GuildModel } from '../../../db/Guild';
import { handleCost, addItems } from '../../../services/role/rewardService';
import { CHAT_SERVER, GUILD_POINT_WAYS } from '../../../consts';
@@ -16,6 +16,7 @@ import { checkTask, checkTaskInDonate } from '../../../services/task/taskService
import { guildInter } from '../../../pubUtils/interface';
import { lockData } from '../../../services/redLockService';
import { getVipDonateConsume } from '../../../services/activity/monthlyTicketService';
import { changeReceiveBoxIdByLvAndIndex } from '../../../services/donateService';
export default function (app: Application) {
new HandlerService(app, {});
@@ -44,7 +45,9 @@ export class DonationHandler {
}
const { guildCode: code, donateCnt, receiveBoxs } = userGuild;
let { donateFund, reports, donationLv } = await getDonation(code, guild);
return resResult(STATUS.SUCCESS, { receiveBoxs, donateFund, reports, donateCnt: donateCnt || 0, donationLv });
// 根据donationLv, 和index, 转化成对应的箱子id
let haveGotBoxIds: number[] = changeReceiveBoxIdByLvAndIndex(receiveBoxs, donationLv);
return resResult(STATUS.SUCCESS, { receiveBoxs: haveGotBoxIds, donateFund, reports, donateCnt: donateCnt || 0, donationLv });
}
/**
* 捐献
@@ -129,10 +132,13 @@ export class DonationHandler {
return resResult(STATUS.WRONG_PARMS);
}
// 捐献宝箱-每级有4个
const TOTAL_BOX_COUNT = 4;
// 领取限制: 一天内相同index的箱子不允许重复领取
// 当前要领取的箱子index
const {index: curBoxIndex} = getArmyDonateBoxBaseById(id);
for (let haveGotId of resReceiveBoxs) {
if ((haveGotId % TOTAL_BOX_COUNT) === (id % TOTAL_BOX_COUNT)) {
// 已领取箱子index
let {index: haveGotIndex} = getArmyDonateBoxBaseById(haveGotId);
if (haveGotIndex === curBoxIndex) {
return resResult(STATUS.GUILD_DONATE_BOXS_IS_GOT);
}
}
@@ -144,6 +150,8 @@ export class DonationHandler {
resReceiveBoxs.push(id);
let { receiveBoxs } = await UserGuildModel.updateInfo(roleId, { receiveBoxs: resReceiveBoxs }, {}, 'receiveBoxs');
let goods = await addItems(roleId, roleName, sid, boxRewards, ITEM_CHANGE_REASON.DONATE_BOX);
return resResult(STATUS.SUCCESS, { receiveBoxs, goods });
// 根据donationLv, 和index, 转化成对应的箱子id
let haveGotBoxIds: number[] = changeReceiveBoxIdByLvAndIndex(receiveBoxs, donationLv);
return resResult(STATUS.SUCCESS, { receiveBoxs: haveGotBoxIds, goods });
}
}

View File

@@ -8,6 +8,7 @@ import { gameData } from '../pubUtils/data';
import { shouldRefresh } from '../pubUtils/util';
import { recordGuildFund } from './activity/timeLimitRankService';
import { pushGuildInfoUpdate } from './guildService';
import { getArmyDonateBoxBaseById, getArmyDonateBoxBaseByLvAndIndex } from '../pubUtils/data';
/**
* 获得军团捐献,并检查是否刷新捐献数据
* @param code
@@ -66,3 +67,22 @@ export async function addFund(code: string, serverId: number, fund: number) {
}
}
/**
* 将已经领取的其他等级捐赠宝箱id转为donationLv对应等级相同index的宝箱id
*
* @export
* @param {number[]} receiveBoxs 已领取的宝箱id
* @param {number} donationLv 当前捐赠等级
*/
export function changeReceiveBoxIdByLvAndIndex(receiveBoxs: number[], donationLv: number) {
let haveGotBoxIds: number[] = [];
receiveBoxs.forEach((boxId) => {
// 获取已领取箱子的index
let { index } = getArmyDonateBoxBaseById(boxId);
// 获取donationLv等级第index个箱子的id
let { id } = getArmyDonateBoxBaseByLvAndIndex(donationLv, index);
haveGotBoxIds.push(id);
});
return haveGotBoxIds;
}

View File

@@ -43,7 +43,7 @@ import { dicTrainSoloReward, loadTrainSoloReward } from './dictionary/DicTrainSo
import { RewardInter } from "./interface";
import { dicArmyDevelopConsume, loadArmyDevelopConsume } from './dictionary/DicArmyDevelopConsume';
import { dicArmyBossRank, loadArmyBossRank } from './dictionary/DicArmyBossRank';
import { dicArmyDonate, loadArmyDonate } from './dictionary/DicArmyDonateBoxReward';
import { dicArmyDonate, loadArmyDonate, dicArmyDonateBoxIdByIndexAndLv } from './dictionary/DicArmyDonateBoxReward';
import { dicRoleFriend, DicRoleFriend, loadRoleFriend } from "./dictionary/DicRoleFriend";
import { dicRoleFriendLv, loadRoleFriendLv } from "./dictionary/DicRoleFriendLv";
import { AttributeCal } from "../domain/roleField/attribute";
@@ -208,6 +208,7 @@ export const gameData = {
armyDevelopConsume: dicArmyDevelopConsume,
armyBossRank: dicArmyBossRank,
armyDonateBox: dicArmyDonate,
armyDonateBoxByIndexAndLv: dicArmyDonateBoxIdByIndexAndLv,
roleFriend: dicRoleFriend,
roleFriendLv: dicRoleFriendLv,
figureCondition: figureCondition,
@@ -679,6 +680,11 @@ export function getArmyDonateBaseByLv(lv: number) {
export function getArmyDonateBoxBaseById(id: number) {
return gameData.armyDonateBox.get(id);
}
export function getArmyDonateBoxBaseByLvAndIndex(lv: number, index: number) {
return gameData.armyDonateBoxByIndexAndLv.get(`${lv}_${index}`);
}
export function getFriendLvByExp(exp: number) {
let resultLv = 1;
for (let [lv, { sum }] of gameData.roleFriendLv.entries()) {

View File

@@ -6,6 +6,7 @@ const _ = require('lodash');
export interface DicArmyDonate {
readonly id: number;
readonly index: number;
readonly level: number;
readonly fund: number;
readonly boxRewards: Array<RewardInter>;
@@ -13,12 +14,14 @@ export interface DicArmyDonate {
const DicArmyDonateKeys: KeysEnum<DicArmyDonate> = {
id: true,
index: true,
level: true,
fund: true,
boxRewards: true
};
export const dicArmyDonate = new Map<number, DicArmyDonate>();
export const dicArmyDonateBoxIdByIndexAndLv = new Map<string, DicArmyDonate>();
export function loadArmyDonate() {
dicArmyDonate.clear();
let arr = readFileAndParse(FILENAME.DIC_ARMY_DONATE_BOX_REWARD);
@@ -26,6 +29,7 @@ export function loadArmyDonate() {
arr.forEach(o => {
o.boxRewards = parseGoodStr(o.boxReward);
dicArmyDonate.set(o.id, _.pick(o, Object.keys(DicArmyDonateKeys)));
dicArmyDonateBoxIdByIndexAndLv.set(`${o.level}_${o.index}`, _.pick(o, Object.keys(DicArmyDonateKeys)));
});
arr = undefined;
}

View File

@@ -1,322 +1,282 @@
[
{
"id": 1,
"index": 1,
"level": 1,
"fund": 10000,
"boxReward": "40005&500",
"__EMPTY": 0,
"__EMPTY_1": 0
"boxReward": "40005&500"
},
{
"id": 2,
"index": 2,
"level": 1,
"fund": 20000,
"boxReward": "17052&250",
"__EMPTY": 0,
"__EMPTY_1": 0
"boxReward": "17052&250"
},
{
"id": 3,
"index": 3,
"level": 1,
"fund": 40000,
"boxReward": "40005&1000",
"__EMPTY": 0,
"__EMPTY_1": 0
"boxReward": "40005&1000"
},
{
"id": 4,
"index": 4,
"level": 1,
"fund": 60000,
"boxReward": "17053&5",
"__EMPTY": 0,
"__EMPTY_1": 0
"boxReward": "17053&5"
},
{
"id": 5,
"index": 1,
"level": 2,
"fund": 10000,
"boxReward": "40005&550",
"__EMPTY": 0,
"__EMPTY_1": 0
"boxReward": "40005&550"
},
{
"id": 6,
"index": 2,
"level": 2,
"fund": 20000,
"boxReward": "17052&275",
"__EMPTY": 0,
"__EMPTY_1": 0
"boxReward": "17052&275"
},
{
"id": 7,
"index": 3,
"level": 2,
"fund": 40000,
"boxReward": "40005&1100",
"__EMPTY": 0,
"__EMPTY_1": 0
"boxReward": "40005&1100"
},
{
"id": 8,
"index": 4,
"level": 2,
"fund": 60000,
"boxReward": "17053&6",
"__EMPTY": 0,
"__EMPTY_1": 0
"boxReward": "17053&6"
},
{
"id": 9,
"index": 1,
"level": 3,
"fund": 10000,
"boxReward": "40005&600",
"__EMPTY": 0,
"__EMPTY_1": 0
"boxReward": "40005&600"
},
{
"id": 10,
"index": 2,
"level": 3,
"fund": 20000,
"boxReward": "17052&300",
"__EMPTY": 0,
"__EMPTY_1": 0
"boxReward": "17052&300"
},
{
"id": 11,
"index": 3,
"level": 3,
"fund": 40000,
"boxReward": "40005&1200",
"__EMPTY": 0,
"__EMPTY_1": 0
"boxReward": "40005&1200"
},
{
"id": 12,
"index": 4,
"level": 3,
"fund": 60000,
"boxReward": "17053&7",
"__EMPTY": 0,
"__EMPTY_1": 0
"boxReward": "17053&7"
},
{
"id": 13,
"index": 1,
"level": 4,
"fund": 10000,
"boxReward": "40005&650",
"__EMPTY": 0,
"__EMPTY_1": 0
"boxReward": "40005&650"
},
{
"id": 14,
"index": 2,
"level": 4,
"fund": 20000,
"boxReward": "17052&325",
"__EMPTY": 0,
"__EMPTY_1": 0
"boxReward": "17052&325"
},
{
"id": 15,
"index": 3,
"level": 4,
"fund": 40000,
"boxReward": "40005&1300",
"__EMPTY": 0,
"__EMPTY_1": 0
"boxReward": "40005&1300"
},
{
"id": 16,
"index": 4,
"level": 4,
"fund": 60000,
"boxReward": "17053&8",
"__EMPTY": 0,
"__EMPTY_1": 0
"boxReward": "17053&8"
},
{
"id": 17,
"index": 1,
"level": 5,
"fund": 10000,
"boxReward": "40005&700",
"__EMPTY": 0,
"__EMPTY_1": 0
"boxReward": "40005&700"
},
{
"id": 18,
"index": 2,
"level": 5,
"fund": 20000,
"boxReward": "17052&350",
"__EMPTY": 0,
"__EMPTY_1": 0
"boxReward": "17052&350"
},
{
"id": 19,
"index": 3,
"level": 5,
"fund": 40000,
"boxReward": "40005&1400",
"__EMPTY": 0,
"__EMPTY_1": 0
"boxReward": "40005&1400"
},
{
"id": 20,
"index": 4,
"level": 5,
"fund": 60000,
"boxReward": "17053&9",
"__EMPTY": 0,
"__EMPTY_1": 0
"boxReward": "17053&9"
},
{
"id": 21,
"index": 1,
"level": 6,
"fund": 10000,
"boxReward": "40005&750",
"__EMPTY": 0,
"__EMPTY_1": 0
"boxReward": "40005&750"
},
{
"id": 22,
"index": 2,
"level": 6,
"fund": 20000,
"boxReward": "17052&375",
"__EMPTY": 0,
"__EMPTY_1": 0
"boxReward": "17052&375"
},
{
"id": 23,
"index": 3,
"level": 6,
"fund": 40000,
"boxReward": "40005&1500",
"__EMPTY": 0,
"__EMPTY_1": 0
"boxReward": "40005&1500"
},
{
"id": 24,
"index": 4,
"level": 6,
"fund": 60000,
"boxReward": "17053&10",
"__EMPTY": 0,
"__EMPTY_1": 0
"boxReward": "17053&10"
},
{
"id": 25,
"index": 1,
"level": 7,
"fund": 10000,
"boxReward": "40005&800",
"__EMPTY": 0,
"__EMPTY_1": 0
"boxReward": "40005&800"
},
{
"id": 26,
"index": 2,
"level": 7,
"fund": 20000,
"boxReward": "17052&400",
"__EMPTY": 0,
"__EMPTY_1": 0
"boxReward": "17052&400"
},
{
"id": 27,
"index": 3,
"level": 7,
"fund": 40000,
"boxReward": "40005&1600",
"__EMPTY": 0,
"__EMPTY_1": 0
"boxReward": "40005&1600"
},
{
"id": 28,
"index": 4,
"level": 7,
"fund": 60000,
"boxReward": "17053&11",
"__EMPTY": 0,
"__EMPTY_1": 0
"boxReward": "17053&11"
},
{
"id": 29,
"index": 1,
"level": 8,
"fund": 10000,
"boxReward": "40005&850",
"__EMPTY": 0,
"__EMPTY_1": 0
"boxReward": "40005&850"
},
{
"id": 30,
"index": 2,
"level": 8,
"fund": 20000,
"boxReward": "17052&425",
"__EMPTY": 0,
"__EMPTY_1": 0
"boxReward": "17052&425"
},
{
"id": 31,
"index": 3,
"level": 8,
"fund": 40000,
"boxReward": "40005&1700",
"__EMPTY": 0,
"__EMPTY_1": 0
"boxReward": "40005&1700"
},
{
"id": 32,
"index": 4,
"level": 8,
"fund": 60000,
"boxReward": "17053&12",
"__EMPTY": 0,
"__EMPTY_1": 0
"boxReward": "17053&12"
},
{
"id": 33,
"index": 1,
"level": 9,
"fund": 10000,
"boxReward": "40005&900",
"__EMPTY": 0,
"__EMPTY_1": 0
"boxReward": "40005&900"
},
{
"id": 34,
"index": 2,
"level": 9,
"fund": 20000,
"boxReward": "17052&450",
"__EMPTY": 0,
"__EMPTY_1": 0
"boxReward": "17052&450"
},
{
"id": 35,
"index": 3,
"level": 9,
"fund": 40000,
"boxReward": "40005&1800",
"__EMPTY": 0,
"__EMPTY_1": 0
"boxReward": "40005&1800"
},
{
"id": 36,
"index": 4,
"level": 9,
"fund": 60000,
"boxReward": "17053&13",
"__EMPTY": 0,
"__EMPTY_1": 0
"boxReward": "17053&13"
},
{
"id": 37,
"index": 1,
"level": 10,
"fund": 10000,
"boxReward": "40005&1000",
"__EMPTY": 0,
"__EMPTY_1": 0
"boxReward": "40005&1000"
},
{
"id": 38,
"index": 2,
"level": 10,
"fund": 20000,
"boxReward": "17052&500",
"__EMPTY": 0,
"__EMPTY_1": 0
"boxReward": "17052&500"
},
{
"id": 39,
"index": 3,
"level": 10,
"fund": 40000,
"boxReward": "40005&2000",
"__EMPTY": 0,
"__EMPTY_1": 0
"boxReward": "40005&2000"
},
{
"id": 40,
"index": 4,
"level": 10,
"fund": 60000,
"boxReward": "17053&15",
"__EMPTY": 0,
"__EMPTY_1": 0
"boxReward": "17053&15"
}
]