武将:抽象武将创建接口
This commit is contained in:
@@ -689,4 +689,4 @@ export enum GACHA_CONTENT_TYPE {
|
||||
SUIT_PAPER = 6, // 套装图纸
|
||||
}
|
||||
|
||||
export const GACHA_OCCUPY_HID = 99; // 抽卡里占位的武将
|
||||
export const GACHA_OCCUPY_HID = 9999; // 抽卡里占位的武将
|
||||
|
||||
@@ -324,6 +324,9 @@ export const STATUS = {
|
||||
// 抽卡相关 31101-31200
|
||||
GACHA_COST_NOT_ENOUGH: { code: 31101, simStr: '招募券不足' },
|
||||
GACHA_NOT_ASSIGN: { code: 31102, simStr: '请选择武将' },
|
||||
GACHA_HOPE_NOT_GOLD: { code: 31103, simStr: '武将品质错误' },
|
||||
GACHA_CAN_NOT_PICK: { code: 31004, simStr: '不可选择该武将' },
|
||||
GACHA_TURNTABLE_POINT_NOT_ENOUGH: { code: 31005, simStr: '转盘积分不足' },
|
||||
// 社交相关状态 40000 - 49999
|
||||
SYS_CHANNEL_AUTH_NOT_ENOUGH: { code: 40000, simStr: '无法在系统频道发送消息' },
|
||||
UPDATE_PRIVATE_MSG_READ_TIME_ERR: { code: 40001, simStr: '更新私聊阅读时间失败' },
|
||||
|
||||
@@ -156,6 +156,15 @@ export default class Hero extends BaseModel {
|
||||
return hero;
|
||||
}
|
||||
|
||||
public static async findMapByHidRange(hids: Array<number>, roleId: string, select?: string, getters = false) {
|
||||
const hero = await HeroModel.findByHidRange(hids, roleId, select, getters);
|
||||
let map = new Map<number, HeroType>();
|
||||
for(let h of hero) {
|
||||
map.set(h.hid, h);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public static async findBySeqIdAndRole(seqId: number, roleId: string, lean = true) {
|
||||
const hero: HeroType = await HeroModel.findOne({ seqId, roleId }).lean(lean);
|
||||
return hero;
|
||||
@@ -241,9 +250,9 @@ export default class Hero extends BaseModel {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async updateHeroInfo(roleId: string, hid:number, heroUpdate:HeroUpdate, select?: string, lean = true) {
|
||||
public static async updateHeroInfo(roleId: string, hid:number, heroUpdate:HeroUpdate, select?: string, getters = false) {
|
||||
delete heroUpdate._id;
|
||||
let result: HeroType = await HeroModel.findOneAndUpdate({roleId, hid}, {$set:heroUpdate}, {new: true}).select(select).lean(lean);
|
||||
let result: HeroType = await HeroModel.findOneAndUpdate({roleId, hid}, {$set:heroUpdate}, {new: true}).select(select).lean({ getters });
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -92,7 +92,13 @@ export default class UserGacha extends BaseModel {
|
||||
}
|
||||
|
||||
public static async updateInfo(roleId: string, gachaId: number, activityId: number, update: UserGachaParam) {
|
||||
let rec: UserGachaType = await UserGachaModel.findOneAndUpdate({ roleId, gachaId, activityId }, { $set: update }, { new: true }).lean();
|
||||
const doc = new UserGachaModel();
|
||||
const setOnInsert = doc.toJSON();
|
||||
delete setOnInsert._id;
|
||||
for(let key in update) {
|
||||
delete setOnInsert[key];
|
||||
}
|
||||
let rec: UserGachaType = await UserGachaModel.findOneAndUpdate({ roleId, gachaId, activityId }, { $set: update, $setOnInsert: setOnInsert }, { new: true, upsert: true }).lean();
|
||||
return rec;
|
||||
}
|
||||
|
||||
|
||||
5
shared/domain/roleField/hero.ts
Normal file
5
shared/domain/roleField/hero.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
|
||||
import { HeroUpdate } from '../../db/Hero';
|
||||
export interface CreateHeroParam extends HeroUpdate {
|
||||
hid: number;
|
||||
}
|
||||
@@ -187,7 +187,10 @@ export const gameData = {
|
||||
taskBox: dicTaskBox,
|
||||
gacha: dicGacha,
|
||||
gachaContent: dicGachaContent,
|
||||
gachaContentHero: dicGachaContentHero
|
||||
gachaContentHero: dicGachaContentHero,
|
||||
gachaHope: getGachaHopePercent(),
|
||||
gachaTurntable: getGachaTurntablePercent(),
|
||||
heroTransPiece: getHeroTransPiece()
|
||||
};
|
||||
|
||||
// 在此提供一些原先在gamedata中提供的方法,以便更方便获取gameData数据
|
||||
@@ -582,4 +585,29 @@ export function getRandExpedition(cnt = 1) {
|
||||
arr.push(dicExpedition);
|
||||
}
|
||||
return getRandEelm(arr, cnt);
|
||||
}
|
||||
|
||||
// 抽卡心愿单概率
|
||||
function getGachaHopePercent() {
|
||||
let arr = decodeArrayListStr(RECRUIT.RECRUIT_WISH_LIST);
|
||||
return arr.map(cur => {
|
||||
return { id: parseInt(cur[0]), weight: parseInt(cur[1]) }
|
||||
});
|
||||
}
|
||||
|
||||
// 抽卡转盘概率
|
||||
function getGachaTurntablePercent() {
|
||||
let arr = decodeArrayListStr(RECRUIT.RECRUIT_BONUS_HERO_QUANTITY);
|
||||
return arr.map(cur => {
|
||||
return { quality: parseInt(cur[0]), weight: parseInt(cur[1]) }
|
||||
});
|
||||
}
|
||||
|
||||
function getHeroTransPiece() {
|
||||
let map = decodeIdCntArrayStr(RECRUIT.RECRUIT_CHANGE_SHARD, 1);
|
||||
let newMap = new Map<number, number>();
|
||||
for(let [id, count] of map) {
|
||||
newMap.set(parseInt(id), count);
|
||||
}
|
||||
return newMap
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import { Figure } from '../domain/dbGeneral';
|
||||
import { getBeforeDaySeconds, nowSeconds } from './timeUtil';
|
||||
import { calPlayerCeAndSave, reCalAllHeroCe } from './playerCe';
|
||||
import { checkTask, checkTaskWithHeroes, checkTaskWithEquip, accomplishTask } from './taskUtil';
|
||||
import { CreateHeroParam } from '../domain/roleField/hero';
|
||||
|
||||
export async function addSkins(roleId: string, id: number) {
|
||||
let skinInfo = gameData.fashion.get(id);
|
||||
@@ -221,12 +222,12 @@ function unlockSingleFigure(dbFigures: Figure[], id: number, unlockDirect = fals
|
||||
return figure
|
||||
}
|
||||
|
||||
export async function createHero(roleId: string, heroInfo: HeroUpdate) {
|
||||
let { role, figureInfo, heroes, calHeroResults, calAllHeroResults, taskPushMessage } = await createHeroes(roleId, [heroInfo])
|
||||
export async function createHero(roleId: string, roleName: string, serverId: number, heroInfo: CreateHeroParam) {
|
||||
let { role, figureInfo, heroes, calHeroResults, calAllHeroResults, taskPushMessage } = await createHeroes(roleId, roleName, serverId, [heroInfo])
|
||||
return { hero: heroes[0], role, figureInfo, calHeroResult: calHeroResults[0], calAllHeroResult: calAllHeroResults[0], taskPushMessage }
|
||||
}
|
||||
|
||||
export async function createHeroes(roleId: string, heroInfos: HeroUpdate[]) {
|
||||
export async function createHeroes(roleId: string, roleName: string, serverId: number, heroInfos: CreateHeroParam[]) {
|
||||
|
||||
let heroNum = 0;
|
||||
let skinIds = new Array<number>();
|
||||
@@ -234,12 +235,16 @@ export async function createHeroes(roleId: string, heroInfos: HeroUpdate[]) {
|
||||
let heroes: HeroType[] = [], calHeroResults = [], calAllHeroResults = [];
|
||||
|
||||
for (let heroInfo of heroInfos) {
|
||||
let curHero = await HeroModel.createHero(heroInfo); heroes.push(curHero);
|
||||
let dicHero = gameData.hero.get(heroInfo.hid);
|
||||
let { quality, initialStars: star, jobid: job, name: hName, initialSkin } = dicHero;
|
||||
|
||||
let info = { roleId, roleName, serverId, quality, star, job, hName, skins: [{id: initialSkin, enable: true}] };
|
||||
let curHero = await HeroModel.createHero(Object.assign(info, heroInfo));
|
||||
let calHeroResult = await calPlayerCeAndSave(HERO_SYSTEM_TYPE.INIT, roleId, curHero, {}); calHeroResults.push(calHeroResult);
|
||||
let calAllHeroResult = await reCalAllHeroCe(HERO_SYSTEM_TYPE.ADD_SKIN, roleId, {}, skinIds); calAllHeroResults.push(calAllHeroResult);
|
||||
|
||||
heroes.push(calHeroResult.hero);
|
||||
conditions.push({ type: FIGURE_UNLOCK_CONDITION.GET_HERO, paramHid: heroInfo.hid });
|
||||
heroInfo.skins.forEach(cur => {
|
||||
info.skins.forEach(cur => {
|
||||
skinIds.push(cur.id);
|
||||
conditions.push({ type: FIGURE_UNLOCK_CONDITION.GET_SKIN, paramSkinId: cur.id });
|
||||
});
|
||||
@@ -257,4 +262,10 @@ export async function createHeroes(roleId: string, heroInfos: HeroUpdate[]) {
|
||||
//成长任务
|
||||
await accomplishTask(roleId, TASK_TYPE.HERO_NUM, heroNum)
|
||||
return { role, figureInfo, heroes, calHeroResults, calAllHeroResults, taskPushMessage }
|
||||
}
|
||||
|
||||
export function transPiece(hid: number) {
|
||||
let dicHero = gameData.hero.get(hid);
|
||||
let count = gameData.heroTransPiece.get(dicHero.quality);
|
||||
return { pieceId: dicHero.pieceId, count }
|
||||
}
|
||||
@@ -37,7 +37,7 @@ export async function calPlayerCeAndSave(type: number, roleId: string, originHer
|
||||
update.attr = heroAttrs;
|
||||
update.ce = heroCe;
|
||||
if (originHero.historyCe < heroCe) update.historyCe = heroCe;
|
||||
let hero = await HeroModel.updateHeroInfo(roleId, originHero.hid, update); // 更新武将
|
||||
let hero = await HeroModel.updateHeroInfo(roleId, originHero.hid, update, null, true); // 更新武将 返回是战力缩过的
|
||||
|
||||
// 更新到角色
|
||||
let { topLineup, topLineupCe } = await calculatetopLineup(role, originHero.hid, heroCe, originHero._id); // 计算更新最强五人战力
|
||||
|
||||
Reference in New Issue
Block a user