feat(地图): 根据主角属性倾向调整任务卡牌权重
在获取任务卡牌选项时,查询主角已拥有的永久属性Buff,将对应属性的卡牌权重提高一倍,使卡牌选择更符合角色成长方向。
This commit is contained in:
@@ -248,8 +248,9 @@ function getDefaultPool(type: CardType, level: number = 1): IPoolItem[] {
|
||||
* @param count 选项数量 (默认3个)
|
||||
* @param excludeUuids 排除的卡牌UUID列表 (用于去重或排除已拥有)
|
||||
* @param forcedType 强制指定卡牌类型 (用于特殊获取,如商店、技能书等)
|
||||
* @param preferredAttrs 偏好的属性类型列表 (用于增加权重)
|
||||
*/
|
||||
export function getCardOptions(level: number, count: number = 3, excludeUuids: number[] = [], forcedType?: CardType): ICardInfo[] {
|
||||
export function getCardOptions(level: number, count: number = 3, excludeUuids: number[] = [], forcedType?: CardType, preferredAttrs: number[] = []): ICardInfo[] {
|
||||
// 1. 确定类型:强制指定 > 默认为属性
|
||||
const type = forcedType !== undefined ? forcedType : CardType.Attr;
|
||||
|
||||
@@ -267,6 +268,16 @@ export function getCardOptions(level: number, count: number = 3, excludeUuids: n
|
||||
const info = getCardBaseInfo(type, item.id);
|
||||
if (info) {
|
||||
info.weight = item.weight;
|
||||
|
||||
// 如果是属性卡,且该属性在偏好列表中,增加权重
|
||||
if (type === CardType.Attr && preferredAttrs.length > 0) {
|
||||
// AttrCards 的 payload 就是 AttrInfo,包含 attr 字段
|
||||
if (info.payload && preferredAttrs.includes(info.payload.attr)) {
|
||||
// 增加权重,这里设置为 2 倍
|
||||
info.weight *= 2;
|
||||
}
|
||||
}
|
||||
|
||||
candidates.push(info);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -259,9 +259,21 @@ export class MissionCardComp extends CCComp {
|
||||
* @param forcedType 强制类型 (可选)
|
||||
*/
|
||||
fetchCards(level: number, forcedType?: CardType){
|
||||
// 获取主角已有的属性倾向 (已拥有的永久属性Buff)
|
||||
let preferredAttrs: number[] = [];
|
||||
// @ts-ignore
|
||||
const entities = ecs.query(ecs.allOf(HeroMasterComp));
|
||||
if (entities.length > 0) {
|
||||
const role = entities[0];
|
||||
const heroAttrs = role.get(HeroAttrsComp);
|
||||
if (heroAttrs && heroAttrs.BUFFS) {
|
||||
preferredAttrs = Object.keys(heroAttrs.BUFFS).map(Number);
|
||||
}
|
||||
}
|
||||
|
||||
// 使用 CardSet 的 getCardOptions 获取卡牌
|
||||
// 这里我们要获取 4 张卡牌
|
||||
const options = getCardOptions(level, 4, [], forcedType);
|
||||
const options = getCardOptions(level, 4, [], forcedType, preferredAttrs);
|
||||
mLogger.log(this.debugMode, 'MissionCard', `[MissionCard] 获取到的卡牌选项: ${JSON.stringify(options)}`);
|
||||
// 更新卡片数据
|
||||
if (options.length > 0) this.updateCardData(1, options[0]);
|
||||
|
||||
Reference in New Issue
Block a user