diff --git a/game-server/app/servers/battle/handler/rougeHandler.ts b/game-server/app/servers/battle/handler/rougeHandler.ts index a9881d06e..4b8707710 100644 --- a/game-server/app/servers/battle/handler/rougeHandler.ts +++ b/game-server/app/servers/battle/handler/rougeHandler.ts @@ -817,7 +817,7 @@ export class RougeHandler { let dbCard = await RougelikeCardModel.findByCode(gameCode, cardCode); if (!dbCard) return resResult(STATUS.NO_CARD); - let { type, cardId, charaId, lv = 0 } = dbCard; + let { type, cardId, charaId = 0, lv = 0 } = dbCard; const passiveCardData = gameData.rougePassiveCard.get(cardId); if (!passiveCardData) return resResult(STATUS.NO_CARD); @@ -855,6 +855,21 @@ export class RougeHandler { const newDbCard = await RougelikeCardModel.updateByCode(gameCode, cardCode, { $set: { cardId: id }, $inc: { lv: 1 } }); const cards: CommonCard[] = formateCharasOrCards([newDbCard], ROUGE_LIKE_CARD_TYPE.PASSIVE)?.cards || []; + if (charaId > 0) { + const dbCharas = await RougelikeCharaModel.findByGameCodeAndCharaId(gameCode, charaId); + let isEnd = false; + for (let { cards = [], charaCode } of dbCharas) { + for (let obj of cards) { + if (cardCode != obj.cardCode) continue; + obj.cardId = id; + await RougelikeCharaModel.findOneAndUpdate({ gameCode, charaCode, 'cards.cardCode': cardCode }, { 'cards.$.cardId': cardId }, { new: true, upsert: true }).lean(true); + isEnd = true; + break; + } + if (isEnd) break; + } + } + return resResult(STATUS.SUCCESS, { restPoints, cards, reward: { rewards }, redCoin: -realConsume, }) } diff --git a/game-server/app/services/battle/rougeCollectService.ts b/game-server/app/services/battle/rougeCollectService.ts index 251648936..7fb4f5218 100644 --- a/game-server/app/services/battle/rougeCollectService.ts +++ b/game-server/app/services/battle/rougeCollectService.ts @@ -11,6 +11,8 @@ import { clone } from 'underscore'; import { RougeEffect, getSlotUnlockPoint } from './rougeEffectService'; import { BackendSession } from 'pinus'; import { checkTask } from '../task/taskService'; +import { RougelikeRecordModel } from '../../db/RougelikeRecord'; +import { updateMaxHp } from './rougeService'; export class HandleAddCard { roleId: string; @@ -120,11 +122,11 @@ export class HandleAddCard { passiveCardMap.set(passiveCardData.authorType, count + 1); } for (const [authorType, count] of passiveCardMap) { - await checkTask(this.serverId, this.roleId, this.sid, TASK_TYPE.ROUGE_AUTHOR_CARD_COLLECT, { authorType, cardType: TASK_ROUGE_CARD_TYPE.PASSIVE, cardIds:this.addPassiveCards.map(cur => cur.cardId) }); + await checkTask(this.serverId, this.roleId, this.sid, TASK_TYPE.ROUGE_AUTHOR_CARD_COLLECT, { authorType, cardType: TASK_ROUGE_CARD_TYPE.PASSIVE, cardIds: this.addPassiveCards.map(cur => cur.cardId) }); } } if (this.addHolyCards.length > 0) { - await checkTask(this.serverId, this.roleId, this.sid, TASK_TYPE.ROUGE_HOLY_COLLECT, {cardIds:this.addHolyCards.map(cur => cur.cardId)}); + await checkTask(this.serverId, this.roleId, this.sid, TASK_TYPE.ROUGE_HOLY_COLLECT, { cardIds: this.addHolyCards.map(cur => cur.cardId) }); } if (this.addCharas.length > 0) { @@ -166,6 +168,8 @@ export class HandleAddCard { result.addCharas = [...charasMap.values()].map(param => new CommonChara(param)); result.addCards = [...cardsMap.values()].map(param => new CommonCard(param)); + const dbRecord = await RougelikeRecordModel.findByGameCode(this.gameCode); + result.addCharas = await updateMaxHp(this.roleId, this.gameCode, (dbRecord?.type || 0), (dbRecord?.grade || 0), charasMap) return result; } } diff --git a/game-server/app/services/battle/rougeEffectService.ts b/game-server/app/services/battle/rougeEffectService.ts index 02e2e41b3..219815d31 100644 --- a/game-server/app/services/battle/rougeEffectService.ts +++ b/game-server/app/services/battle/rougeEffectService.ts @@ -127,10 +127,7 @@ export class RougeEffect { if (effectType != ROUGE_EFFECT_TYPE.HOLY_CHARA_SLOT_UNLOCK_ALL) continue; if (effectParam.length == 0) continue; let isUseCount = false; - console.log("xx-x-x-x-x-x-x-x-11111-x-xx-x-x- cardCode", cardCode) - console.log("xx-x-x-x-x-x-x-x-11111-x-xx-x-x- this.holyMap", this.holyMap) if (!getHolyCardIsUse(this.holyMap.get(cardCode))) continue; - console.log("xx-x-x-x-x-x-x-x--x-xx-x-x- this.holyMap", this.holyMap) for (let val of this.dbCharas) { let { charaCode, cards = [] } = val; let unlockNum = effectParam[0] || 0; diff --git a/game-server/app/services/battle/rougeService.ts b/game-server/app/services/battle/rougeService.ts index a74574c85..132f1d342 100644 --- a/game-server/app/services/battle/rougeService.ts +++ b/game-server/app/services/battle/rougeService.ts @@ -1,6 +1,6 @@ import { clone, result } from "underscore"; import { ROUGE_CHARA_INITIAL, ROUGE_CHARA_TYPE, ROUGE_EFFECT_TYPE, ROUGE_LIKE_CARD_TYPE, ROUGE_LIKE_CHOOSE_REWARD, ROUGE_LIKE_NODE_TYPE, ROUGE_LIKE_STATUS, SHOP_REFRESH_TYPE } from "../../consts"; -import { Card, RougelikeCharaModel, RougelikeCharaType } from "../../db/RougelikeChara"; +import { Card, RougelikeCharaModel, RougelikeCharaPara, RougelikeCharaType } from "../../db/RougelikeChara"; import { RougelikeLayerModel, RougelikeLayerType } from "../../db/RougelikeLayer"; import { RougelikeRecordModel, RougelikeRecordType } from "../../db/RougelikeRecord"; import { gameData } from "../../pubUtils/data"; @@ -299,8 +299,8 @@ export async function chooseNode(dbRecord: RougelikeRecordType, layerChooseNode: reward = result; dbPara.rewards = result.rewards; } - - if(isDevelopEnv){ + + if (isDevelopEnv) { weightRecords = dbPara.weightRecords = (result?.weightRecords || []); } } @@ -311,7 +311,7 @@ export async function chooseNode(dbRecord: RougelikeRecordType, layerChooseNode: let { coin, score, tech } = layerRewardData; reward = { rewards: dbDetail.rewards || [], score: score || 0, techScore: tech || 0, takeoutReward: layerPlanData.takeoutReward || [] }; - if(isDevelopEnv){ + if (isDevelopEnv) { weightRecords = dbDetail.weightRecords } } @@ -603,7 +603,7 @@ export async function getPassiveCardPlan(passiveCardPlan: number, passiveCardRan if (!passiveCardData) continue; const getLimit = cardsMap.get(cardId) || 0; if (getLimit >= (passiveCardData?.getLimit || 0)) continue; //处理限制获取数量 - + weightRecord.originalWight = weight; if (chooseCardsMap.has(cardId)) { @@ -739,12 +739,14 @@ export async function getHolyCardPlan(holyCardPlan: number, holyCardRandomNum: n } if (!holyCardData.label) { newCards.push({ ...obj }); + weightRecord.finalWeight = weight; continue; }; let labelNum = lableMap.get(holyCardData.label) || 0; if (labelNum < ROUGELIKE.HOLY_LABLE_NUM || ROUGELIKE.HOLY_LABLE_NUM == 0) { newCards.push({ ...obj }); + weightRecord.finalWeight = weight; continue; }; @@ -938,7 +940,7 @@ export async function getMaxHp(roleId: string, gameCode: string, charaId: number return Math.floor(maxHp); } -export async function updateMaxHp(roleId: string, gameCode: string, type: number, grade: number, updateCharasMap?: Map) { +export async function updateMaxHp(roleId: string, gameCode: string, type: number, grade: number, updateCharasMap?: Map) { let dbCharas = await RougelikeCharaModel.findByGameCode(gameCode); if (dbCharas.length == 0) return []; @@ -949,7 +951,9 @@ export async function updateMaxHp(roleId: string, gameCode: string, type: number } let tempMaxHp = await getMaxHp(roleId, gameCode, val.charaId, type, grade); if (tempMaxHp == val.maxHp && updateCharasMap && !updateCharasMap.has(val.charaCode)) continue; + let preMaxHp = val.maxHp; val.maxHp = tempMaxHp; + val.hp = Math.min(val.hp + tempMaxHp - preMaxHp, tempMaxHp); result.push(val); } await RougelikeCharaModel.bulkWriteUpdate(result); diff --git a/shared/db/RougelikeChara.ts b/shared/db/RougelikeChara.ts index 0f5331342..bf0106c6e 100644 --- a/shared/db/RougelikeChara.ts +++ b/shared/db/RougelikeChara.ts @@ -71,12 +71,12 @@ export default class RougelikeChara extends BaseModel { if (updateArr.length == 0) return []; let num = await CounterModel.getNewCounterNum(COUNTER.ROUGE_CHARA, updateArr.length); let resultArr: RougelikeCharaType[] = []; - for(let index = 0; index < updateArr.length; index++) { + for (let index = 0; index < updateArr.length; index++) { let param = updateArr[index]; let seqId = num - updateArr.length + index + 1; const { gameCode, charaCode } = param; - let data = await RougelikeCharaModel.findOneAndUpdate({ gameCode, charaCode }, { $set: { ...param, seqId }}, { new: true, upsert: true }).lean(); - if(data) resultArr.push(data) + let data = await RougelikeCharaModel.findOneAndUpdate({ gameCode, charaCode }, { $set: { ...param, seqId } }, { new: true, upsert: true }).lean(); + if (data) resultArr.push(data) } return resultArr } @@ -113,6 +113,11 @@ export default class RougelikeChara extends BaseModel { } } + public static async findByGameCodeAndCharaId(gameCode: string, charaId: number, lean = true) { + const result: RougelikeCharaType[] = await RougelikeCharaModel.find({ gameCode, charaId }).lean(lean); + return result; + } + public static async bulkWriteUpdate(updateArr: RougelikeCharaPara[]) { if (updateArr.length == 0) return; await RougelikeCharaModel.bulkWrite(updateArr.map((param) => { diff --git a/shared/db/RougelikeRecordDetail.ts b/shared/db/RougelikeRecordDetail.ts index af4452f7b..dfbcdf03e 100644 --- a/shared/db/RougelikeRecordDetail.ts +++ b/shared/db/RougelikeRecordDetail.ts @@ -127,7 +127,7 @@ export class RandomRec { @prop({ required: false, default: 0 }) weight?: number; // 权重 @prop({ required: false, type: WeightRecord, default: {}, _id: false }) - weightRecords?: WeightRecord; + weightRecord?: WeightRecord; } export class Option {