皮肤:修改存储逻辑
This commit is contained in:
@@ -78,7 +78,8 @@ export const ITEM_TABLE = {
|
||||
EQUIP: 'equip',
|
||||
ITEM: 'item',
|
||||
ROLE: 'role',
|
||||
HERO: 'hero'
|
||||
HERO: 'hero',
|
||||
SKIN: 'skin'
|
||||
}
|
||||
|
||||
const itid_array = [
|
||||
@@ -127,7 +128,7 @@ const itid_array = [
|
||||
{ id: 33, name: '神兵', table: 'equip', type: EQUIP_TYPE.WEAPON },
|
||||
{ id: 34, name: '代币', table: 'item', type: CONSUME_TYPE.POINT },
|
||||
{ id: 53, name: '武将招募券', table: 'item', type: CONSUME_TYPE.POINT },
|
||||
{ id: 39, name: '时装', table: 'hero', type: CONSUME_TYPE.SKIN },
|
||||
{ id: 39, name: '时装', table: 'skin', type: CONSUME_TYPE.SKIN },
|
||||
{ id: 40, name: '装备碎片', table: 'item', type: CONSUME_TYPE.PIECE },
|
||||
{ id: 41, name: '图纸', table: 'item', type: CONSUME_TYPE.CONSUME },
|
||||
{ id: 42, name: '神兵宝石', table: 'item', type: CONSUME_TYPE.JEWEL },
|
||||
|
||||
@@ -4,6 +4,7 @@ import Equip, { } from './Equip';
|
||||
import { CounterModel } from './Counter';
|
||||
import { COUNTER, EQUIP_TYPE } from '../consts';
|
||||
import { reduceCe } from '../pubUtils/util';
|
||||
import Skin from './Skin';
|
||||
|
||||
class CeAttrData {
|
||||
@prop({ required: true })
|
||||
@@ -33,9 +34,11 @@ export class Connect {
|
||||
level: number;
|
||||
}
|
||||
|
||||
class Skin {
|
||||
export class HeroSkin {
|
||||
@prop({ required: true })
|
||||
id: number;
|
||||
@prop({ ref: 'Skin', type: mongoose.Schema.Types.ObjectId })
|
||||
skin: Ref<Skin>;
|
||||
@prop({ required: true })
|
||||
enable: boolean;
|
||||
}
|
||||
@@ -131,8 +134,8 @@ export default class Hero extends BaseModel {
|
||||
favourLv: number; // 好感等级
|
||||
@prop({ required: true, type: Connect, default: [], _id: false })
|
||||
connections: Connect[]; // 羁绊
|
||||
@prop({ required: true, type: Skin, default: [], _id: false })
|
||||
skins: Skin[]; // 皮肤
|
||||
@prop({ required: true, type: HeroSkin, default: [], _id: false })
|
||||
skins: HeroSkin[]; // 皮肤
|
||||
|
||||
@prop({ required: true, type: EPlace, default: getInitialEplace(), _id: false })
|
||||
ePlace: EPlace[]; // 武将装备引用数组
|
||||
|
||||
41
shared/db/Skin.ts
Normal file
41
shared/db/Skin.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType, modelOptions } from '@typegoose/typegoose';
|
||||
@index({ roleId: 1, id: 1 })
|
||||
@index({ seqId: 1 })
|
||||
@modelOptions({ schemaOptions: { id: false } })
|
||||
export default class Skin extends BaseModel {
|
||||
@prop({ required: true, default: '' })
|
||||
roleId: string; // 角色 id
|
||||
@prop({ required: true, default: '' })
|
||||
roleName: string; // 角色名称
|
||||
|
||||
@prop({ required: true, default: '' })
|
||||
id: number; // 皮肤id
|
||||
@prop({ required: true, default: '', select: false})
|
||||
skinName: string; // 皮肤名称
|
||||
@prop({ required: true, default: 0 })
|
||||
hid: number;
|
||||
|
||||
public static async findbyRole(roleId: string) {
|
||||
const rec: SkinType[] = await SkinModel.find({ roleId }).select('id').lean();
|
||||
return rec;
|
||||
}
|
||||
|
||||
public static async findbyRoleAndHid(roleId: string, hid: number) {
|
||||
const rec: SkinType[] = await SkinModel.find({ roleId, hid }).select('id').lean();
|
||||
return rec;
|
||||
}
|
||||
|
||||
public static async increaseSkin(roleId: string, id: number, info: { roleId: string, roleName: string, id: number, skinName: string, hid: number }, lean = true) {
|
||||
const doc = new SkinModel();
|
||||
const setOnInsert = Object.assign(doc.toJSON(), info);
|
||||
const items: SkinType = await SkinModel.findOneAndUpdate({ roleId, id }, { $setOnInsert: setOnInsert }, { new: true, upsert: true }).lean(lean);
|
||||
return items;
|
||||
}
|
||||
}
|
||||
|
||||
export const SkinModel = getModelForClass(Skin);
|
||||
|
||||
export interface SkinType extends Pick<DocumentType<Skin>, keyof Skin> {
|
||||
id: number;
|
||||
};
|
||||
@@ -5,6 +5,8 @@ import { FILENAME } from '../../consts';
|
||||
export interface DicFashions {
|
||||
// 时装id
|
||||
readonly id: number;
|
||||
// 皮肤装名
|
||||
readonly name: string;
|
||||
// 指向heroSkill表
|
||||
readonly skillId: number;
|
||||
// 全局加成
|
||||
|
||||
@@ -15,19 +15,37 @@ import { getTimeFun, nowSeconds } from './timeUtil';
|
||||
import { calPlayerCeAndSave, reCalAllHeroCe } from './playerCe';
|
||||
import { checkTask, checkTaskWithHeroes, checkTaskWithEquip, accomplishTask } from './taskUtil';
|
||||
import { CreateHeroParam } from '../domain/roleField/hero';
|
||||
import { SkinModel } from '../db/Skin';
|
||||
|
||||
export async function addSkins(roleId: string, id: number) {
|
||||
let skinInfo = gameData.fashion.get(id);
|
||||
if (!skinInfo)
|
||||
return false;
|
||||
let hero = await HeroModel.findByHidAndRole(skinInfo.actorId, roleId);
|
||||
if (!hero)
|
||||
return false;
|
||||
if (!!findWhere(hero.skins, { id }))
|
||||
return false;
|
||||
hero.skins.push({ id, enable: false });
|
||||
await HeroModel.updateHeroInfo(roleId, hero.hid, hero);
|
||||
return { skins: hero.skins, hid: hero.hid };
|
||||
/**
|
||||
* 添加皮肤
|
||||
* @param roleId 玩家id
|
||||
* @param roleName 玩家名
|
||||
* @param id 皮肤id
|
||||
* @param hero 武将,如果已经查询过这个武将就不用再查询一次,主意要select skins字段
|
||||
* @returns {{ hero, figureInfo, calAllHeroResult }} hero:添加皮肤后的武将 figureInfo: 触发头像添加信息 calAllHeroResult:全局战力加成后结果
|
||||
*/
|
||||
export async function addSkin(roleId: string, roleName: string, skinId: number, enable: boolean, hero?: HeroType) {
|
||||
let dicSkin = gameData.fashion.get(skinId);
|
||||
if (!dicSkin) return false;
|
||||
|
||||
let skin = await SkinModel.increaseSkin(roleId, skinId, { roleId, roleName, id: skinId, skinName: dicSkin.name, hid: dicSkin.actorId });
|
||||
if(!skin) return false; // 插入失败
|
||||
|
||||
if(dicSkin.actorId && !hero) hero = await HeroModel.findByHidAndRole(dicSkin.actorId, roleId);
|
||||
let condition = { type: FIGURE_UNLOCK_CONDITION.GET_SKIN, paramSkinId: skinId };
|
||||
let figureInfo = await unlockFigure(roleId, [condition]); // 解锁头像
|
||||
let calAllHeroResult = await reCalAllHeroCe(HERO_SYSTEM_TYPE.ADD_SKIN, roleId, {}, [skinId]); // 全局加成
|
||||
|
||||
if (hero) { // 有武将的,将皮肤链接到武将上
|
||||
if (!findWhere(hero.skins, { id: skinId })) {
|
||||
hero.skins.push({ id: skinId, skin: skin._id, enable });
|
||||
await HeroModel.updateHeroInfo(roleId, hero.hid, hero);
|
||||
}
|
||||
return { hero, figureInfo, calAllHeroResult };
|
||||
} else {
|
||||
return { hero: null, figureInfo, calAllHeroResult }
|
||||
}
|
||||
}
|
||||
|
||||
export async function addBags(roleId: string, roleName: string, data: BagInter) {
|
||||
@@ -230,35 +248,61 @@ function unlockSingleFigure(dbFigures: Figure[], id: number, unlockDirect = fals
|
||||
return figure
|
||||
}
|
||||
|
||||
async function linkOldSkins(roleId: string, hero: HeroType) {
|
||||
let allSkins = await SkinModel.findbyRoleAndHid(roleId, hero.hid);
|
||||
let skins = hero.skins||[];
|
||||
for(let skin of allSkins) {
|
||||
let index = skins.findIndex(cur => cur.id == skin.id);
|
||||
if(index == -1) {
|
||||
skins.push({ id: skin.id, skin: skin._id, enable: false });
|
||||
}
|
||||
}
|
||||
return await HeroModel.updateHeroInfo(roleId, hero.hid, { skins })
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建武将
|
||||
* @param roleId 玩家id
|
||||
* @param roleName 玩家名
|
||||
* @param serverId 服务器id
|
||||
* @param {CreateHeroParam} heroInfo 创建武将所需信息
|
||||
* @param funcs 玩家开启了的功能,主要用于任务
|
||||
*/
|
||||
export async function createHero(roleId: string, roleName: string, serverId: number, heroInfo: CreateHeroParam, funcs?: number[]) {
|
||||
let { role, figureInfo, heroes, calHeroResults, calAllHeroResults, taskPushMessage, activityTaskPushMessage } = await createHeroes(roleId, roleName, serverId, [heroInfo], funcs)
|
||||
return { hero: heroes[0], role, figureInfo, calHeroResult: calHeroResults[0], calAllHeroResult: calAllHeroResults[0], taskPushMessage, activityTaskPushMessage }
|
||||
let { role, figureInfo, heroes, calHeroResults, calAllHeroResult, taskPushMessage, activityTaskPushMessage } = await createHeroes(roleId, roleName, serverId, [heroInfo], funcs)
|
||||
return { hero: heroes[0], role, figureInfo, calHeroResult: calHeroResults[0], calAllHeroResult, taskPushMessage, activityTaskPushMessage }
|
||||
}
|
||||
|
||||
export async function createHeroes(roleId: string, roleName: string, serverId: number, heroInfos: CreateHeroParam[], funcs?: number[]) {
|
||||
|
||||
let heroNum = 0;
|
||||
let skinIds = new Array<number>();
|
||||
let conditions = new Array<{ type: number, paramHid?: number, paramFavourLv?: number, paramSkinId?: number }>();
|
||||
let heroes: HeroType[] = [], calHeroResults = [], calAllHeroResults = [];
|
||||
let heroes: HeroType[] = [], calHeroResults = [], calAllHeroResult = undefined;
|
||||
let figureInfos:{ heads: Figure[], frames: Figure[], spines: Figure[] }[] = [];
|
||||
|
||||
for (let heroInfo of heroInfos) {
|
||||
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 info = { roleId, roleName, serverId, quality, star, job, hName };
|
||||
|
||||
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);
|
||||
let addSkinResult = await addSkin(roleId, roleName, initialSkin, true, curHero); // 添加皮肤
|
||||
curHero = await linkOldSkins(roleId, curHero);
|
||||
|
||||
if(addSkinResult) { // 处理添加皮肤结果
|
||||
curHero = addSkinResult.hero;
|
||||
figureInfos.push(addSkinResult.figureInfo);
|
||||
calAllHeroResult = addSkinResult.calAllHeroResult; // 全局加成,所以同一个人的处理都是累加
|
||||
}
|
||||
// 计算初始战力
|
||||
let calHeroResult = await calPlayerCeAndSave(HERO_SYSTEM_TYPE.INIT, roleId, curHero, {});
|
||||
calHeroResults.push(calHeroResult);
|
||||
heroes.push(calHeroResult.hero);
|
||||
conditions.push({ type: FIGURE_UNLOCK_CONDITION.GET_HERO, paramHid: heroInfo.hid });
|
||||
info.skins.forEach(cur => {
|
||||
skinIds.push(cur.id);
|
||||
conditions.push({ type: FIGURE_UNLOCK_CONDITION.GET_SKIN, paramSkinId: cur.id });
|
||||
});
|
||||
heroNum++;
|
||||
}
|
||||
let figureInfo = await unlockFigure(roleId, conditions); // 解锁头像
|
||||
figureInfos.push(await unlockFigure(roleId, conditions)); // 解锁头像
|
||||
|
||||
let role = await RoleModel.incRoleInfo(roleId, { heroNum }, { heroNumUpdatedAt: nowSeconds() });
|
||||
// 任务
|
||||
@@ -271,7 +315,23 @@ export async function createHeroes(roleId: string, roleName: string, serverId: n
|
||||
let mm1 = await accomplishTask(serverId, roleId, TASK_TYPE.HERO_NUM, heroNum)
|
||||
let mm2 = await accomplishTask(serverId, roleId, TASK_TYPE.HERO_QUALITY, heroNum, { heroes })
|
||||
let activityTaskPushMessage = mm1.concat(mm2);
|
||||
return { role, figureInfo, heroes, calHeroResults, calAllHeroResults, taskPushMessage, activityTaskPushMessage }
|
||||
return { role, figureInfo: combineFigureInfo(figureInfos), heroes, calHeroResults, calAllHeroResult, taskPushMessage, activityTaskPushMessage }
|
||||
}
|
||||
|
||||
export function combineFigureInfo(figureInfos: { heads: Figure[], frames: Figure[], spines: Figure[] }[]) {
|
||||
let figureInfo = { heads: new Array<Figure>(), frames: new Array<Figure>(), spines: new Array<Figure>() };
|
||||
for(let {heads, frames, spines} of figureInfos) {
|
||||
for(let head of heads) {
|
||||
figureInfo.heads.push(head);
|
||||
}
|
||||
for(let frame of frames) {
|
||||
figureInfo.frames.push(frame);
|
||||
}
|
||||
for(let spine of spines) {
|
||||
figureInfo.spines.push(spine);
|
||||
}
|
||||
}
|
||||
return figureInfo;
|
||||
}
|
||||
|
||||
export function transPiece(hid: number) {
|
||||
|
||||
@@ -325,21 +325,23 @@ export function calHeroStarIncAttr(originHero: HeroType, update: HeroUpdate, typ
|
||||
updateHeroAttr(heroAttrs, targetAttrId, { set: { base: newBase } });
|
||||
}
|
||||
|
||||
// 解锁技能
|
||||
let curSkin = skins.find(cur => cur.enable);
|
||||
let curSeidList = getSeidListOfFashion(curSkin.id, star, colorStar);
|
||||
let preSeidList = getSeidListOfFashion(curSkin.id, isInit ? 0 : originStar, isInit ? 0 : originColorStar);
|
||||
|
||||
curSeidList.forEach((seid, type) => {
|
||||
if (!preSeidList.has(type)) {
|
||||
addSeidList.push(seid, 0);
|
||||
}
|
||||
});
|
||||
preSeidList.forEach((seid, type) => {
|
||||
if (!curSeidList.has(type)) {
|
||||
removeSeidList.push(seid, 0);
|
||||
}
|
||||
});
|
||||
// 武将被动技能,初始时候还没有皮肤,就先不算被动
|
||||
if(skins.length > 0) {
|
||||
let curSkin = skins.find(cur => cur.enable);
|
||||
let curSeidList = getSeidListOfFashion(curSkin.id, star, colorStar);
|
||||
let preSeidList = getSeidListOfFashion(curSkin.id, isInit ? 0 : originStar, isInit ? 0 : originColorStar);
|
||||
|
||||
curSeidList.forEach((seid, type) => {
|
||||
if (!preSeidList.has(type)) {
|
||||
addSeidList.push(seid, 0);
|
||||
}
|
||||
});
|
||||
preSeidList.forEach((seid, type) => {
|
||||
if (!curSeidList.has(type)) {
|
||||
removeSeidList.push(seid, 0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
originHero.attr = heroAttrs;
|
||||
return heroAttrs;//属性增量可以是多个
|
||||
|
||||
Reference in New Issue
Block a user