feat(稷下学宫): c67747d87到5ff932e83

This commit is contained in:
luying
2023-09-04 14:48:16 +08:00
parent 9b391ef61f
commit 58e58a8a38
16 changed files with 10586 additions and 9645 deletions

View File

@@ -44,7 +44,7 @@ export class HandleAddCard {
cards.push({ index, cardCode, cardId });
}
let charaCode = genCode(8);
this.addCharas.push({ ...this.getCommonParam(), cards, charaCode, charaId: id, maxHp, hp: maxHp, ap: 0, shield: 0, roundSkill: 0, apSkill: 0 });
this.addCharas.push({ ...this.getCommonParam(), cards, charaCode, charaId: id, maxHp, hp: maxHp, ap: 0, shield: 0, others: '', roundSkill: 0, apSkill: 0 });
return charaCode;
}
@@ -71,7 +71,7 @@ export class HandleAddCard {
public pushHolyCard(id: number) {
let cardCode = genCode(8);
this.addHolyCards.push({
...this.getCommonParam(), cardCode, cardId: id, type: ROUGE_LIKE_CARD_TYPE.HOLY, useCount: this.getHolyUseCount(id)
...this.getCommonParam(), cardCode, cardId: id, type: ROUGE_LIKE_CARD_TYPE.HOLY, useCount: 0
});
return cardCode
}
@@ -138,7 +138,8 @@ export class HandleAddCard {
await RougelikeCharaModel.bulkWriteUpdate([...charas.values()]);
charasMap = new Map([...charasMap, ...charas])
}
if (cards && Object.entries(cards).length > 0) {
if (cards && cards.size > 0) {
await RougelikeCardModel.bulkWriteUpdate([...cards.values()])
cardsMap = new Map([...cardsMap, ...cards])
}
}

View File

@@ -9,6 +9,7 @@ import { getRandEelm } from "../../pubUtils/util";
import { RougelikeTechModel } from "../../db/RougelikeTech";
import { getAuthorTypeCardNum } from "./rougeService";
import * as util from 'util';
import { DicRougePassiveCard } from "../../pubUtils/dictionary/DicRougePassiveCard";
@@ -98,6 +99,7 @@ export class RougeEffect {
ROUGE_EFFECT_TYPE.HOLY_PASSIVE_UPDATE_RAND, //2006
ROUGE_EFFECT_TYPE.HOLY_UPDATE_PASSIVE_BY_LV, //2012
ROUGE_EFFECT_TYPE.HOLY_REPAIRE_HOLY, //2015
ROUGE_EFFECT_TYPE.HOLY_CHARA_SLOT_UNLOCK_POINT,//2023
], holyIds)
await this.getCharaSlot();
@@ -110,6 +112,8 @@ export class RougeEffect {
await this.getRecoveryHoly();
await this.getSlotUnlockPoint()
result = { charas: this.updateCharaMap, cards: this.updateCardMap };
return result;
@@ -119,9 +123,14 @@ export class RougeEffect {
// 获得该圣物时所有学员立刻解锁X个特性槽 2002
private async getCharaSlot() {
if (this.newEffect.length == 0 || this.dbCharas.length == 0) return;
for (const { effectParam, effectType } of this.newEffect) {
for (const { effectParam, effectType, cardCode } of this.newEffect) {
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;
@@ -133,18 +142,32 @@ export class RougeEffect {
cards.push({ index, cardCode: '', cardId: 0 });
this.updateCharaMap.set(charaCode, val);
unlockNum--;
isUseCount = true;
}
}
}
if (isUseCount) this.updateHolyMapUseCount(this.holyMap.get(cardCode));
}
}
private updateHolyMapUseCount(holy: { cardCode: string, cardId: number, useCount: number }) {
let { cardCode, useCount = 0, cardId } = (holy || {});
if (!cardId || !cardCode) return;
let val = this.dbCards.find(cur => cur.cardCode == cardCode);
if (val == undefined) return;
useCount = (useCount + 1) >= 0 ? (useCount + 1) : 0
this.updateCardMap.set(cardCode, { ...val, useCount });
this.holyMap.set(cardCode, { cardCode, cardId, useCount });
}
// 获得该圣物时随机解锁X个学员的Y个特性槽 2003
private async getRandCharaSlot() {
if (this.newEffect.length == 0 || this.dbCharas.length == 0) return;
for (const { effectParam, effectType } of this.newEffect) {
for (const { effectParam, effectType, cardCode } of this.newEffect) {
if (effectType != ROUGE_EFFECT_TYPE.HOLY_CHARA_SLOT_UNLOCK_RAND) continue;
if (effectParam.length == 0) continue;
let isUseCount = false;
if (!getHolyCardIsUse(this.holyMap.get(cardCode))) continue;
const randomNum = effectParam[0] || 0;
let unlockNum = effectParam[1] || 0;
let charas = getRandEelm(this.dbCharas.filter(cur => cur.cards.length < ROUGE_SLOT_LIMIT), randomNum);
@@ -156,8 +179,10 @@ export class RougeEffect {
cards.push({ index, cardCode: '', cardId: 0 });
this.updateCharaMap.set(charaCode, val);
unlockNum--;
isUseCount = true;
}
}
if (isUseCount) this.updateHolyMapUseCount(this.holyMap.get(cardCode));
}
}
@@ -165,61 +190,129 @@ export class RougeEffect {
private async getRandomCardLv() {
let cards: RougelikeCardType[] = [];
if (this.newEffect.length == 0 || this.dbCards.length == 0) return cards;
for (const { effectParam, effectType } of this.newEffect) {
for (const { effectParam, effectType, cardCode } of this.newEffect) {
if (effectType != ROUGE_EFFECT_TYPE.HOLY_PASSIVE_UPDATE_RAND) continue;
if (effectParam.length == 0) continue;
if (!getHolyCardIsUse(this.holyMap.get(cardCode))) continue;
const randomNum = effectParam[0] || 0;
let random = this.dbCards.filter(cur => cur.type == ROUGE_LIKE_CARD_TYPE.PASSIVE && cur.charaId != 0 && cur.lv < (gameData.rougePassiveCard.get(cur.cardId)?.lv || 0))
let cards = getRandEelm(random, randomNum);
cards.forEach(cur => {
cur.lv += 1;
this.updateCardMap.set(cur.cardCode, cur);
});
let random = this.dbCards.filter(cur => cur.type == ROUGE_LIKE_CARD_TYPE.PASSIVE && cur.charaId && cur.charaId != 0 && cur.lv < (gameData.rougePassiveCard.get(cur.cardId)?.lv || 0))
for (let cur of this.dbCards) {
if (cur.type != ROUGE_LIKE_CARD_TYPE.PASSIVE || cur.charaId == 0) continue;
let passiveCardDataMap = this.getPassiveData(cur.cardId);
if (!passiveCardDataMap.has(cur.lv + 1)) continue;
random.push({ ...cur, cardId: passiveCardDataMap.get(cur.lv + 1).id, lv: cur.lv + 1 })
}
if (random && random.length > 0) {
let cards = getRandEelm(random, randomNum);
cards.forEach(async cur => { this.updateCardMap.set(cur.cardCode, cur), await this.updateCharaCards(cur, cardCode, cur.cardId); });
this.updateHolyMapUseCount(this.holyMap.get(cardCode));
}
}
}
private getPassiveData(cardId: number) {
let passiveCardDataMap = new Map<number, DicRougePassiveCard>()
const passiveCardData = gameData.rougePassiveCard.get(cardId);
if (!passiveCardData) return passiveCardDataMap;
const passiveCardByGroupData = gameData.rougePassiveCardByGroup.get(passiveCardData.group || 0);
if (passiveCardByGroupData.length == 0 || passiveCardByGroupData.length == 1) return passiveCardDataMap;
passiveCardDataMap = passiveCardByGroupData.reduce((result, cur) => { result.set(cur.lv, cur); return result; }, new Map<number, DicRougePassiveCard>());
return passiveCardDataMap;
}
// 获得该圣物时立即升级所有X星特性卡 2012
private async getPassiveLv() {
if (this.newEffect.length == 0) return;
for (const { effectParam, effectType } of this.newEffect) {
for (const { effectParam, effectType, cardCode } of this.newEffect) {
if (effectType != ROUGE_EFFECT_TYPE.HOLY_UPDATE_PASSIVE_BY_LV) continue;
if (effectParam.length == 0) continue;
let isUseCount = false;
if (!getHolyCardIsUse(this.holyMap.get(cardCode))) continue;
const level = effectParam[0] || 0;
for (let val of this.dbCards) {
let { lv, cardId, cardCode } = val;
const passiveCardData = gameData.rougePassiveCard.get(cardId);
if (level != passiveCardData?.quality || 0 || lv >= passiveCardData?.lv || 0) continue;
lv += 1;
this.updateCardMap.set(cardCode, val);
if (lv != level) continue;
let passiveCardDataMap = this.getPassiveData(cardId);
if (!passiveCardDataMap.has(lv + 1)) continue;
let id = passiveCardDataMap.get(lv + 1).id;
this.updateCardMap.set(cardCode, { ...val, lv: lv + 1, cardId: passiveCardDataMap.get(lv + 1).id });
if (val.charaId && val.charaId > 0) {
await this.updateCharaCards(val, cardCode, id);
}
isUseCount = true;
}
if (isUseCount) this.updateHolyMapUseCount(this.holyMap.get(cardCode));
}
}
private async updateCharaCards(val: RougelikeCardType, cardCode: string, id: number) {
for (let obj of this.dbCharas) {
if (obj.charaId != val.charaId) continue;
for (let card of (obj.cards || [])) {
if (card.cardCode != cardCode) continue;
card.cardId = id;
}
this.updateCharaMap.set(obj.charaCode, obj);
}
}
// 获得该圣物时随机修复X个已损毁的圣物 2015
private async getRecoveryHoly() {
if (this.newEffect.length == 0) return;
for (const { effectParam, effectType } of this.newEffect) {
for (const { effectParam, effectType, cardCode } of this.newEffect) {
if (effectType != ROUGE_EFFECT_TYPE.HOLY_REPAIRE_HOLY) continue;
if (effectParam.length == 0) continue;
let isUseCount = false;
if (!getHolyCardIsUse(this.holyMap.get(cardCode))) continue;
const num = effectParam[0] || 0;
let canRandomCards: RougelikeCardType[] = []
this.dbCards.forEach(cur => {
const { cardCode, cardId, useCount = 0, type } = cur;
const holyCardData = gameData.rougeHolyCard.get(cardId);
let tempUseCount = holyCardData?.useCount || 0;
if (tempUseCount > 0 && useCount < tempUseCount && type == ROUGE_LIKE_CARD_TYPE.HOLY) canRandomCards.push(cur);
if (tempUseCount > 0 && useCount > 0 && type == ROUGE_LIKE_CARD_TYPE.HOLY) canRandomCards.push(cur);
})
let randomCards = getRandEelm(canRandomCards, num);
for (let val of randomCards) {
let { cardCode, cardId } = val;
val.useCount += 1;
// if (this.holyMap.has(cardCode)) this.holyMap.set(cardCode, { cardCode, cardId, useCount });
this.updateCardMap.set(cardCode, val)
val.useCount -= 1;
this.updateCardMap.set(cardCode, val);
if (this.holyMap.has(cardCode)) this.holyMap.set(cardCode, { cardCode, cardId, useCount: val.useCount });
isUseCount = true;
}
if (isUseCount) this.updateHolyMapUseCount(this.holyMap.get(cardCode));
}
}
//2023
private async getSlotUnlockPoint() {
if (this.newEffect.length == 0) return;
for (const { effectParam, effectType, cardCode } of this.newEffect) {
if (effectType != ROUGE_EFFECT_TYPE.HOLY_CHARA_SLOT_UNLOCK_POINT) continue;
if (effectParam.length == 0) continue;
let isUseCount = false;
if (!getHolyCardIsUse(this.holyMap.get(cardCode))) continue;
const num = effectParam[0] || 0;
const index = effectParam[0] || 0;
for (let val of this.dbCharas) {
let { cards = [], charaCode } = val
if (cards.find(cur => cur.index == index) == undefined) {
cards.push({ index, cardCode: '', cardId: 0 });
this.updateCharaMap.set(charaCode, val);
isUseCount = true;
}
}
if (isUseCount) this.updateHolyMapUseCount(this.holyMap.get(cardCode));
}
}
// 和圣物相关maxhp
@@ -235,6 +328,9 @@ export class RougeEffect {
addRatio += await this.getMaxHpByBase();
await updateCards([...this.updateCardMap.values()]);
return addRatio;
}
@@ -244,7 +340,8 @@ export class RougeEffect {
const dbRecord = await RougelikeRecordModel.findByGameCode(this.gameCode);
let coinTotal = dbRecord?.coin || 0;
if (this.newEffect.length == 0) return addRatio;
for (const { effectParam, effectType } of this.newEffect) {
for (const { effectParam, effectType, cardCode } of this.newEffect) {
if (!getHolyCardIsUse(this.holyMap.get(cardCode))) continue;
if (effectType != ROUGE_EFFECT_TYPE.HOLY_CHARA_MAIN_ATTR_UP_BY_COIN) continue;
if (effectParam.length == 0) continue;
const count = effectParam[0] || 0;
@@ -252,6 +349,9 @@ export class RougeEffect {
const value = effectParam[2] || 0;
if (count == 0 || id != ABI_TYPE.ABI_HP || value == 0) continue;
addRatio += Math.floor(coinTotal / count * value)
this.updateHolyMapUseCount(this.holyMap.get(cardCode));
}
return addRatio;
@@ -261,13 +361,15 @@ export class RougeEffect {
private async getMaxHpByBase() {
let addRatio = 0;
if (this.newEffect.length == 0) return addRatio;
for (const { effectParam, effectType } of this.newEffect) {
for (const { effectParam, effectType, cardCode } of this.newEffect) {
if (effectType != ROUGE_EFFECT_TYPE.HOLY_CHARA_MAIN_ATTR_UP && effectType != ROUGE_EFFECT_TYPE.TECH_CHARA_MAIN_ATTR_UP) continue;
if (effectParam.length == 0) continue;
if (!getHolyCardIsUse(this.holyMap.get(cardCode))) continue;
const id = effectParam[0] || 0;
const value = effectParam[1] || 0;
if (id != ABI_TYPE.ABI_HP || value == 0) continue;
addRatio += value;
this.updateHolyMapUseCount(this.holyMap.get(cardCode));
}
return addRatio;
}
@@ -283,9 +385,11 @@ export async function getCharaHp(roleId: string, gameCode: string) {
ROUGE_EFFECT_TYPE.HOLY_CHARA_HP_RECOVERY_UP,// 2001
]);
if (newEffect.length == 0) return hpRatio;
for (const { effectType, effectParam } of newEffect) {
for (const { effectType, effectParam, cardCode } of newEffect) {
if (effectParam.length == 0) continue;
if (!getHolyCardIsUse(holyMap.get(cardCode))) continue;
hpRatio += (effectParam[0] || 0);
await updateHolyUseCount(holyMap.get(cardCode), gameCode)
}
return hpRatio;
}
@@ -300,17 +404,19 @@ export async function getAddCoin(roleId: string, gameCode: string, nodeType: num
ROUGE_EFFECT_TYPE.TECH_COIN_UP_BY_NODE_TYPE, //3007
]);
if (newEffect.length == 0) return { coinRatio, coinAdd };
for (const { effectType, effectParam } of newEffect) {
for (const { effectType, effectParam, cardCode } of newEffect) {
if (effectParam.length == 0) continue;
if (!getHolyCardIsUse(holyMap.get(cardCode))) continue;
if (effectType == ROUGE_EFFECT_TYPE.HOLY_COIN_UP) {
const type = effectParam[0] || 0;
const value = effectParam[1] || 0;
if (type == 1) coinAdd += value;
else if (type == 2) coinRatio += value;
await updateHolyUseCount(holyMap.get(cardCode), gameCode)
}
if (effectType == ROUGE_EFFECT_TYPE.TECH_COIN_UP_BY_NODE_TYPE) {
let [targetNodeType = 0, value = 0] = effectParam;
if (targetNodeType == nodeType) coinRatio += value;
let [value = 0, ...targetNodeType] = effectParam;
if (targetNodeType && targetNodeType.includes(nodeType)) coinRatio += value;
}
}
@@ -318,7 +424,6 @@ export async function getAddCoin(roleId: string, gameCode: string, nodeType: num
}
// 获得圣物后X流派特性卡的权重增加Y 2007
export async function getAddPassiveWeight(roleId: string, gameCode: string, authorType: number) {
let addPassiveWeight = 0;
@@ -327,12 +432,14 @@ export async function getAddPassiveWeight(roleId: string, gameCode: string, auth
ROUGE_EFFECT_TYPE.HOLY_PASSIVE_WEIGHT_UP_BY_AUTHOR,//2007
]);
if (newEffect.length == 0) return addPassiveWeight;
for (const { effectParam } of newEffect) {
for (const { effectParam, cardCode } of newEffect) {
if (effectParam.length == 0) continue;
if (!getHolyCardIsUse(holyMap.get(cardCode))) continue;
const type = effectParam[0] || 0;
const value = effectParam[1] || 0;
if (type != authorType) continue;
addPassiveWeight += value;
await updateHolyUseCount(holyMap.get(cardCode), gameCode)
}
return addPassiveWeight;
}
@@ -344,6 +451,12 @@ export async function getNoBossRecoveryHp(roleId: string, gameCode: string) {
ROUGE_EFFECT_TYPE.HOLY_REVIVE_ALL,//2009
]);
if (newEffect.length == 0) return false;
for (const { effectParam, cardCode } of newEffect) {
if (!getHolyCardIsUse(holyMap.get(cardCode))) continue;
await updateHolyUseCount(holyMap.get(cardCode), gameCode)
}
return true; // 拿到true 将所有学员更新和hp=maxHp
}
@@ -357,9 +470,11 @@ export async function getBattleRecoveryNum(roleId: string, gameCode: string) {
]);
if (newEffect.length == 0) return recoveryNum;
for (const { effectParam } of newEffect) {
for (const { effectParam, cardCode } of newEffect) {
if (effectParam.length == 0) continue;
if (!getHolyCardIsUse(holyMap.get(cardCode))) continue;
recoveryNum += (effectParam[0] || 0)
await updateHolyUseCount(holyMap.get(cardCode), gameCode)
}
return recoveryNum;
}
@@ -373,10 +488,12 @@ export async function getShopDiscount(roleId: string, gameCode: string) {
ROUGE_EFFECT_TYPE.HOLY_SHOP_DISCOUNT,//2011
]);
if (newEffect.length == 0) return discount;
for (const { effectParam } of newEffect) {
for (const { effectParam, cardCode } of newEffect) {
if (effectParam.length == 0) continue;
if (!getHolyCardIsUse(holyMap.get(cardCode))) continue;
const tempDiscount = effectParam[0] || 0;
discount *= (tempDiscount / 100);
await updateHolyUseCount(holyMap.get(cardCode), gameCode)
}
return Math.floor(discount);
}
@@ -390,15 +507,20 @@ export async function getChooseQualityPassives(roleId: string, gameCode: string,
ROUGE_EFFECT_TYPE.HOLY_PASSIVE_CHOOSE_FIX,//2013
]);
if (newEffect.length == 0) return targetPassives;
for (const { effectParam } of newEffect) {
for (const { effectParam, cardCode } of newEffect) {
let isUseCount = false;
if (effectParam.length == 0) continue;
if (!getHolyCardIsUse(holyMap.get(cardCode))) continue;
const level = effectParam[0] || 0;
for (let val of passiveCards) {
const { cardId } = val;
const passiveCardData = gameData.rougePassiveCard.get(cardId);
if (level != passiveCardData?.lv || 0) continue;
targetPassives.push(val);
isUseCount = true;
}
if (isUseCount) await updateHolyUseCount(holyMap.get(cardCode), gameCode);
}
return targetPassives;
}
@@ -410,10 +532,12 @@ export async function getAddChoosePassive(roleId: string, gameCode: string) {
let { newEffect, holyMap } = await rougeEffect.getEffectData([
ROUGE_EFFECT_TYPE.HOLY_PASSIVE_CHOOSE_NUM_UP,//2014
]);
for (const { effectParam } of newEffect) {
for (const { effectParam, cardCode } of newEffect) {
if (effectParam.length == 0) continue;
if (!getHolyCardIsUse(holyMap.get(cardCode))) continue;
const num = effectParam[0] || 0;
addChooseNum += num;
await updateHolyUseCount(holyMap.get(cardCode), gameCode);
}
return addChooseNum
}
@@ -425,27 +549,26 @@ export async function getSlotUnlockPoint(roleId: string, gameCode: string, dbCha
let { newEffect, holyMap } = await rougeEffect.getEffectData([
ROUGE_EFFECT_TYPE.HOLY_CHARA_SLOT_UNLOCK_POINT,//2023
]);
for (const { effectParam } of newEffect) {
for (const { effectParam, cardCode } of newEffect) {
if (effectParam.length == 0) continue;
let isUseCount = false;
if (!getHolyCardIsUse(holyMap.get(cardCode))) continue;
const index = effectParam[0] || 0;
for (let { cards = [] } of dbCharas) {
if (cards.length == 0) {
cards.push({ index, cardCode: '', cardId: 0 });
isUpdate = true;
continue;
}
if (cards.find(cur => cur.index == index) == undefined) {
isUpdate = true
cards.push({ index, cardCode: '', cardId: 0 });
isUseCount = true;
}
}
if (isUseCount) await updateHolyUseCount(holyMap.get(cardCode), gameCode);
}
return { isUpdate, dbCharas };
}
// 休整点额外恢复X%的生命 2017 3006
// 休整点额外恢复上限X%的生命 2017 3006
export async function getRecoveryExtendHp(roleId: string, gameCode: string) {
let hpRatio = 0;
let rougeEffect = new RougeEffect(roleId, gameCode);
@@ -454,9 +577,11 @@ export async function getRecoveryExtendHp(roleId: string, gameCode: string) {
ROUGE_EFFECT_TYPE.TECH_RECOVERY_POINT_UP, // 3006
]);
if (newEffect.length == 0) return hpRatio;
for (const { effectType, effectParam } of newEffect) {
for (const { effectType, effectParam, cardCode } of newEffect) {
if (effectParam.length == 0) continue;
if (!getHolyCardIsUse(holyMap.get(cardCode))) continue;
hpRatio += (effectParam[0] || 0);
await updateHolyUseCount(holyMap.get(cardCode), gameCode);
}
return hpRatio;
}
@@ -471,10 +596,13 @@ export async function getTrainCardDiscount(roleId: string, gameCode: string) {
ROUGE_EFFECT_TYPE.TECH_TRAIN_POINT_DISCOUNT, // 3009
]);
if (newEffect.length == 0) return discount;
for (const { effectParam } of newEffect) {
for (const { effectParam, cardCode } of newEffect) {
if (effectParam.length == 0) continue;
if (!getHolyCardIsUse(holyMap.get(cardCode))) continue;
const tempDiscount = effectParam[0] || 0;
discount *= (tempDiscount / 100);
await updateHolyUseCount(holyMap.get(cardCode), gameCode);
}
return Math.floor(discount);
}
@@ -533,4 +661,25 @@ export async function checkCanReRandomReward(roleId: string, gameCode: string, r
});
if (!curParam) return { canReRandom: false, costCoin: 0 }
return { canReRandom: true, costCoin: curParam.effectParam[1] || 0 };
}
export function getHolyCardIsUse(holy: { cardId: number, useCount: number }) {
const { useCount = 0, cardId } = (holy || {});
if (!cardId) return;
const holyCardData = gameData.rougeHolyCard.get(cardId)
if (!holyCardData) return;
if ((holyCardData?.useCount || 0) <= useCount) return;
return true
}
export async function updateHolyUseCount(holy: { cardId: number, useCount: number, cardCode: string }, gameCode: string) {
const { cardId, cardCode } = (holy || {});
if (!cardId || !cardCode) return;
await RougelikeCardModel.updateByCode(gameCode, cardCode, { $inc: { useCount: 1 } })
}
export async function updateCards(updateCards: RougelikeCardPara[]) {
if (updateCards.length == 0) return;
await RougelikeCardModel.bulkWriteUpdate(updateCards)
}

View File

@@ -41,7 +41,7 @@ export async function getRougeData(roleId: string) {
const dbExtends = await RougelikeExtendModel.findByRoleId(roleId);
const limitIds = dbExtends.map(cur => cur.limitId);
return { isPlaying, gameCode, weeklyScore: dbScore?.score || 0, receivedScore: dbScore?.received || [], ...techData, collections, limitIds }
return { isPlaying, gameCode, weeklyScore: dbScore?.score || 0, receivedScore: dbScore?.received || [], ...techData, collections, limitIds, takeoutRewardCnt: dbScore?.takeoutRewardCnt }
}
/*
@@ -283,18 +283,24 @@ export async function chooseNode(dbRecord: RougelikeRecordType, layerChooseNode:
}
}
let weightRecords = [];
if ((!dbDetail || !dbDetail.shops || dbDetail.shops.length == 0) && isShop) {
shops = await getLayerShopReward(roleId, gameCode, authorType, nodeId, layerPlanData.shopPlan);
dbPara.shops = shops;
let result = await getLayerShopReward(roleId, gameCode, authorType, nodeId, layerPlanData.shopPlan);
dbPara.shops = shops = result.shops;
weightRecords = dbPara.weightRecords = (result?.weightRecords || [])
}
if (dbDetail && dbDetail.shops) shops = dbDetail.shops || shops;
if (dbDetail && dbDetail.shops) { shops = dbDetail.shops || shops; weightRecords = dbDetail.weightRecords }
if ((!dbDetail || !dbDetail.rewards || dbDetail.rewards.length == 0) && isReward) {
let result = await getLayerNodeReward(roleId, gameCode, authorType, nodeId, layerPlanData.rewardPlan, layer, dbPara.questType);
if (result) {
if (result && result.rewards) {
reward = result;
dbPara.rewards = result.rewards;
}
// TODO正式环境屏蔽
weightRecords = dbPara.weightRecords = (result?.weightRecords || []);
}
if (dbDetail && dbDetail.rewards) {
let tempType = (dbDetail?.questType || 0) > 0 ? dbDetail?.questType : nodeType
@@ -302,6 +308,8 @@ export async function chooseNode(dbRecord: RougelikeRecordType, layerChooseNode:
if (!layerRewardData) return;
let { coin, score, tech } = layerRewardData;
reward = { rewards: dbDetail.rewards || [], score: score || 0, techScore: tech || 0, takeoutReward: layerPlanData.takeoutReward || [] };
// TODO正式环境屏蔽
weightRecords = dbDetail.weightRecords
}
if (!dbDetail) {
@@ -311,7 +319,7 @@ export async function chooseNode(dbRecord: RougelikeRecordType, layerChooseNode:
await RougelikeLayerModel.updateByGameCodeAndLayer(gameCode, layer, detailCode, ROUGE_LIKE_CHOOSE_REWARD.CHOOSE)
}
let curNode = { detailCode, nodeId, nodeType, status, warId, reward, shops, challenge, question, restPoints, }
let curNode = { detailCode, nodeId, nodeType, status, warId, reward, shops, challenge, question, restPoints, weightRecords }
// console.log('-x-x--x-x-x-x-x-x-x-x-x- curNode', util.inspect(curNode, { depth: null }));
return curNode;
}
@@ -356,55 +364,79 @@ export async function getLayerNodeReward(roleId: string, gameCode: string, type:
options: tempOptions,
groupStatus: charaChooseNum > 0 ? ROUGE_LIKE_CHOOSE_REWARD.NOCHOOSE : ROUGE_LIKE_CHOOSE_REWARD.CHOOSE,
chooseNum: charaChooseNum,
reRandRewardCnt: 0,
});
}
let passiveCards = await getPassiveCardPlan(passiveCardPlan, passiveCardRandomNum, type, dbRougelikeCards, gameCode, roleId);
passiveCardRandomNum = await getPassiveCardRandom(passiveCardChooseNum, passiveCardRandomNum, gameCode, layer, roleId);
let { passiveCards, passiveWeightRecords } = await getPassiveCardPlan(passiveCardPlan, passiveCardRandomNum, type, dbRougelikeCards, gameCode, roleId);
if (passiveCards && passiveCards.length > 0) {
let chooseNum = await getPassiveCardChooseNum(passiveCardChooseNum, passiveCardRandomNum, gameCode, layer, roleId);
rewards.push({
groupIndex: rewards.length + 1,
rewardType: ROUGE_LIKE_CARD_TYPE.PASSIVE,
options: passiveCards.map((ele, index) => { return { optionIndex: index++, rewardId: ele.cardId, optionStatus: ROUGE_LIKE_CHOOSE_REWARD.NOCHOOSE, weightRecord: ele.weightRecord } }),
options: passiveCards.map((ele, index) => { return { optionIndex: index++, rewardId: ele.cardId, optionStatus: ROUGE_LIKE_CHOOSE_REWARD.NOCHOOSE } }),
groupStatus: chooseNum > 0 ? ROUGE_LIKE_CHOOSE_REWARD.NOCHOOSE : ROUGE_LIKE_CHOOSE_REWARD.CHOOSE,
chooseNum
chooseNum,
reRandRewardCnt: 0,
});
}
let holyCards = await getHolyCardPlan(holyCardPlan, holyCardRandomNum, dbRougelikeCards, gameCode, roleId);
let { holyCards, holyWeightRecords } = await getHolyCardPlan(holyCardPlan, holyCardRandomNum, dbRougelikeCards, gameCode, roleId);
if (holyCards && holyCards.length > 0) {
rewards.push({
groupIndex: rewards.length + 1,
rewardType: ROUGE_LIKE_CARD_TYPE.HOLY,
options: holyCards.map((ele, index) => { return { optionIndex: index++, rewardId: ele.cardId, optionStatus: ROUGE_LIKE_CHOOSE_REWARD.NOCHOOSE, weightRecord: ele.weightRecord } }),
options: holyCards.map((ele, index) => { return { optionIndex: index++, rewardId: ele.cardId, optionStatus: ROUGE_LIKE_CHOOSE_REWARD.NOCHOOSE } }),
groupStatus: holyCardChooseNum > 0 ? ROUGE_LIKE_CHOOSE_REWARD.NOCHOOSE : ROUGE_LIKE_CHOOSE_REWARD.CHOOSE,
chooseNum: holyCardChooseNum,
reRandRewardCnt: 0,
});
}
// rewards.push({ groupIndex: rewards.length + 1, rewardType: 0, groupStatus: (coin || 0) > 0 ? ROUGE_LIKE_CHOOSE_REWARD.NOCHOOSE : ROUGE_LIKE_CHOOSE_REWARD.CHOOSE, chooseNum: coin || 0 })
return { rewards, score, techScore: tech };
return { rewards, score, techScore: tech, weightRecords: [...(passiveWeightRecords || []), ...(holyWeightRecords || [])] };
}
// 处理挑战类型中 接下来X次选择特性卡时可选择的卡片数量少1
export async function getPassiveCardRandom(passiveCardChooseNum: number, passiveCardRandomNum: number, gameCode: string, layer: number, roleId: string) {
let num = passiveCardRandomNum;
let dbDetails = await RougelikeRecordDetailModel.findByGameCodeAndLtLayer(gameCode, layer);
if (dbDetails.length == 0) return num;
for (let { challenge } of dbDetails) {
if (challenge && Object.entries(challenge).length != 0 && challenge.status == 1) {
let { challengeId } = challenge;
const rougeChallengeData = gameData.rougeChallenge.get(challengeId);
if (!rougeChallengeData) return num;
for (let effectId of (rougeChallengeData.effectId || [])) {
const rougeEffectTypeData = gameData.rougeEffect.get(effectId);
if (rougeEffectTypeData.effectType != ROUGE_EFFECT_TYPE.CHALLENGE_PASSIVE_CARD_REDUCE) continue;
num -= (rougeEffectTypeData.effectParam[1] || 0);
}
}
}
return num >= 0 ? num : 0;
}
export async function getPassiveCardChooseNum(passiveCardChooseNum: number, passiveCardRandomNum: number, gameCode: string, layer: number, roleId: string) {
let chooseNum = passiveCardChooseNum;
let dbDetails = await RougelikeRecordDetailModel.findByGameCodeAndLtLayer(gameCode, layer);
if (dbDetails.length == 0) return chooseNum;
for (let { challenge } of dbDetails) {
if (challenge && Object.entries(challenge).length != 0 && challenge.status == 1) {
let { challengeId } = challenge;
const rougeChallengeData = gameData.rougeChallenge.get(challengeId);
if (!rougeChallengeData) return chooseNum;
for (let effectId of (rougeChallengeData.effectId || [])) {
const rougeEffectTypeData = gameData.rougeEffect.get(effectId);
if (rougeEffectTypeData.effectType != ROUGE_EFFECT_TYPE.CHALLENGE_PASSIVE_CARD_REDUCE) continue;
chooseNum -= (rougeEffectTypeData.effectParam[1] || 0);
}
}
}
// for (let { challenge } of dbDetails) {
// if (challenge && Object.entries(challenge).length != 0 && challenge.status == 1) {
// let { challengeId } = challenge;
// const rougeChallengeData = gameData.rougeChallenge.get(challengeId);
// if (!rougeChallengeData) return chooseNum;
// for (let effectId of (rougeChallengeData.effectId || [])) {
// const rougeEffectTypeData = gameData.rougeEffect.get(effectId);
// if (rougeEffectTypeData.effectType != ROUGE_EFFECT_TYPE.CHALLENGE_PASSIVE_CARD_REDUCE) continue;
// chooseNum -= (rougeEffectTypeData.effectParam[1] || 0);
// }
// }
// }
chooseNum += await getAddChoosePassive(roleId, gameCode);
if (chooseNum < 0) chooseNum = 0;
@@ -427,7 +459,7 @@ export async function getSelfPassiveCards(charaId: number, passiveCardPlan: numb
let charaData = gameData.rougeChara.get(charaId);
if (!charaData) return result;
if (charaData.charaType != ROUGE_CHARA_TYPE.HIGH) return result;
let passiveCards = await getPassiveCardPlan(passiveCardPlan, charaData.initCardCnt, type, dbRougelikeCards, gameCode, roleId);
let { passiveCards } = await getPassiveCardPlan(passiveCardPlan, charaData.initCardCnt, type, dbRougelikeCards, gameCode, roleId);
if (passiveCards && passiveCards.length > 0) result.push(...passiveCards.map((ele) => { return ele.cardId }),);
return result;
@@ -446,12 +478,12 @@ export async function getLayerShopReward(roleId: string, gameCode: string, type:
let shopPlanData = gameData.rougeShopPlan.get(shopPlan);
// let nodeData = gameData.rougeNode.get(nodeId);
if (!shopPlanData) return shops;
if (!shopPlanData) return { shops };
let dbRougelikeCards = await RougelikeCardModel.findByGameCodeAndType(gameCode, ROUGE_LIKE_CARD_TYPE.PASSIVE);
let passiveCards = await getPassiveCardPlan(shopPlanData.passivecardPlanId, shopPlanData.passiveCardRandomNum, type || 0, dbRougelikeCards, gameCode, roleId);
let { passiveCards, passiveWeightRecords } = await getPassiveCardPlan(shopPlanData.passivecardPlanId, shopPlanData.passiveCardRandomNum, type || 0, dbRougelikeCards, gameCode, roleId);
let index = 0, discount = await getShopDiscount(roleId, gameCode);
if (passiveCards && passiveCards.length > 0) {
for (let ele of passiveCards) {
@@ -468,7 +500,7 @@ export async function getLayerShopReward(roleId: string, gameCode: string, type:
}
}
let holyCards = await getHolyCardPlan(shopPlanData?.holyCardPlanId, shopPlanData?.holyCardRandomNum, dbRougelikeCards, gameCode, roleId);
let { holyCards, holyWeightRecords } = await getHolyCardPlan(shopPlanData?.holyCardPlanId, shopPlanData?.holyCardRandomNum, dbRougelikeCards, gameCode, roleId);
if (holyCards && holyCards.length > 0) {
for (let ele of holyCards) {
let price = gameData.rougeHolyCard.get(ele.cardId)?.purchasePrice || 0;
@@ -483,7 +515,7 @@ export async function getLayerShopReward(roleId: string, gameCode: string, type:
}
}
return shops;
return { shops, weightRecords: [...(passiveWeightRecords || []), ...(holyWeightRecords || [])] };
}
@@ -533,7 +565,7 @@ export function getCharaCardPlan(planId: number, charaRandomNum: number) {
*/
export async function getPassiveCardPlan(passiveCardPlan: number, passiveCardRandomNum: number, type: number, dbRougelikeCards: RougelikeCardType[], gameCode: string, roleId: string) {
let cards = checkRandomLimit(passiveCardPlan, passiveCardRandomNum, ROUGE_LIKE_CARD_TYPE.PASSIVE);
if (cards.length <= passiveCardRandomNum) return cards;
if (cards.length <= passiveCardRandomNum) return { passiveCards: cards };
// 计算变化权重
let lableMap = new Map<number, number>(); //统计lable数量
@@ -582,9 +614,11 @@ export async function getPassiveCardPlan(passiveCardPlan: number, passiveCardRan
weight += await getAddPassiveWeight(roleId, gameCode, type);
if ((passiveCardData?.authorType || 0) == type) weight += ROUGELIKE.AUTHOR_ADD_RANDOM;
if ((passiveCardData?.authorType || 0) == type) {
weight += ROUGELIKE.AUTHOR_ADD_RANDOM;
weightRecord.authorAddWeight = ROUGELIKE.AUTHOR_ADD_RANDOM;
}
weightRecord.authorAddWeight = ROUGELIKE.AUTHOR_ADD_RANDOM;
let labelNum = lableMap.get(cardId) || 0;
if (labelNum >= ROUGELIKE.PASSIVE_LABLE_NUM) {
@@ -611,7 +645,7 @@ export async function getPassiveCardPlan(passiveCardPlan: number, passiveCardRan
let randResult = getRandEelmWithWeightAndNum(newCards, passiveCardRandomNum - result.length);
return [...result, ...randResult.map(cur => cur.dic)]
return { passiveCards: [...result, ...randResult.map(cur => cur.dic)], passiveWeightRecords: newCards }
}
export async function getIsChooseCard(gameCode: string) {
@@ -650,7 +684,7 @@ export async function getCardCount(gameCode: string, type: number) {
export async function getHolyCardPlan(holyCardPlan: number, holyCardRandomNum: number, dbRougelikeCards: RougelikeCardType[], gameCode: string, roleId: string) {
let cards = checkRandomLimit(holyCardPlan, holyCardRandomNum, ROUGE_LIKE_CARD_TYPE.HOLY);
if (cards.length <= holyCardRandomNum) return cards;
if (cards.length <= holyCardRandomNum) return { holyCards: cards };
let lableMap = new Map<number, number>();//统计lable数量
if (dbRougelikeCards && dbRougelikeCards.length > ROUGELIKE.HOLY_LABLE_NUM) {
@@ -720,7 +754,7 @@ export async function getHolyCardPlan(holyCardPlan: number, holyCardRandomNum: n
}
let randResult = getRandEelmWithWeightAndNum(newCards, holyCardRandomNum);
return randResult.map(cur => cur.dic);
return { holyCards: randResult.map(cur => cur.dic), holyWeightRecords: newCards }
}
@@ -755,8 +789,6 @@ export function getChallengePlan(planId: number) {
export async function updateChalleng(dbRecord: RougelikeRecordType, roleId: string, sid: string, gameCode: string, curLayer: number, rougeDamage, isAp?: boolean, isRound?: boolean) {
let len = rougeDamage.length;
const minHp = rougeDamage.reduce((min, cur) => { return Math.min(min, cur.hp); }, Infinity);
let challenges: { challengeId: number, status: number, progress: number, detailCode: string }[] = [];
const { authorType, type, grade } = dbRecord;
let dbDetails = await RougelikeRecordDetailModel.findByGameCodeAndLtLayer(gameCode, curLayer);
@@ -778,8 +810,18 @@ export async function updateChalleng(dbRecord: RougelikeRecordType, roleId: stri
if (rougeEffectTypeData.effectType == ROUGE_EFFECT_TYPE.CHALLENGE_PASSIVE_CARD_REDUCE) continue;
if (rougeEffectTypeData.effectType == ROUGE_EFFECT_TYPE.CHALLENGE_CHARA_NO_AP_SKILL && isAp) continue;
if (rougeEffectTypeData.effectType == ROUGE_EFFECT_TYPE.CHALLENGE_CHARA_NO_ROUND_SKILL && isRound) continue;
if (rougeEffectTypeData.effectType == ROUGE_EFFECT_TYPE.CHALLENGE_CHARA_HP_LIMIT && (rougeEffectTypeData.effectParam[1] || 0) > minHp) continue;
if (rougeEffectTypeData.effectType == ROUGE_EFFECT_TYPE.CHALLENGE_CHARA_NUM_LIMIT && (rougeEffectTypeData.effectParam[1] || 0) != len) continue;//接下来X场战斗每场战斗只能上阵2名学员
if (rougeEffectTypeData.effectType == ROUGE_EFFECT_TYPE.CHALLENGE_CHARA_HP_LIMIT) {
let isNext = true;
for (let obj of rougeDamage) {
const { maxHp = 0, hp = 0 } = (obj || {});
if (maxHp == 0 || hp == 0) { isNext = false; break; }
if (maxHp * (rougeEffectTypeData.effectParam[1] || 0) / 100 > hp) { isNext = false; break; }
}
if (!isNext) continue;
}
if (rougeEffectTypeData.effectType == ROUGE_EFFECT_TYPE.CHALLENGE_CHARA_NUM_LIMIT && (rougeEffectTypeData.effectParam[1] || 0) < len) continue;//接下来X场战斗每场战斗不超过上阵2名学员
}
challenge.progress += 1;
@@ -892,14 +934,17 @@ 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) {
export async function updateMaxHp(roleId: string, gameCode: string, type: number, grade: number, updateCharasMap) {
let dbCharas = await RougelikeCharaModel.findByGameCode(gameCode);
if (dbCharas.length == 0) return [];
let result: RougelikeCharaType[] = [];
for (let val of dbCharas) {
if (updateCharasMap.has(val.charaCode)) {
val = { ...val, ...updateCharasMap.get(val.charaCode) }
}
let tempMaxHp = await getMaxHp(roleId, gameCode, val.charaId, type, grade);
if (tempMaxHp == val.maxHp) continue;
if (tempMaxHp == val.maxHp && !updateCharasMap.has(val.charaCode)) continue;
val.maxHp = tempMaxHp;
result.push(val);
}
@@ -947,7 +992,7 @@ export async function getGame(roleId: string) {
const charas: CommonChara[] = formateCharasOrCards(await RougelikeCharaModel.findByGameCode(gameCode), ROUGE_LIKE_CARD_TYPE.CHARA)?.charas || [];
const cards: CommonCard[] = formateCharasOrCards(await RougelikeCardModel.findByGameCode(gameCode), ROUGE_LIKE_CARD_TYPE.PASSIVE | ROUGE_LIKE_CARD_TYPE.HOLY)?.cards || [];
console.log("x-x-x-x-x-x-x-x- dbCurLayerChooseNode", dbCurLayerChooseNode)
// console.log("x-x-x-x-x-x-x-x- dbCurLayerChooseNode", dbCurLayerChooseNode)
if (Object.entries(dbCurLayerChooseNode).length != 0) curNode = await chooseNode(dbRecord, dbCurLayerChooseNode, curLayer)
return {

View File

@@ -913,10 +913,10 @@ export function checkRouteParam(route: string, msg: any) {
case "battle.rougeHandler.battleEnd":
{
let { gameCode, detailCode, battleCode, warId, status, round, rougeDamage, isAp, isRound } = msg;
let { gameCode, detailCode, battleCode, warId, status, round, rougeDamage } = msg;
if (!checkNaturalStrings(gameCode, detailCode, battleCode)) return false;
if (!checkNaturalNumbers(warId, round, status)) return false;
if (!checkBooleanIfExist(isAp, isRound)) return false;
// if (!checkBooleanIfExist(isAp, isRound)) return false;
if (!isArray(rougeDamage) || rougeDamage.length == 0) return false;
let charaCodes: string[] = [];
for (let { charaCode } of rougeDamage) {