皮肤:修改存储逻辑
This commit is contained in:
@@ -14,6 +14,7 @@ import { pushComposeOrangeHero, pushHeroQualityUpMsg, pushHeroStarMax, pushHeroW
|
|||||||
import { calculatetopLineup } from '../../../pubUtils/playerCe';
|
import { calculatetopLineup } from '../../../pubUtils/playerCe';
|
||||||
import { PvpDefenseModel } from '../../../db/PvpDefense';
|
import { PvpDefenseModel } from '../../../db/PvpDefense';
|
||||||
import { checkTaskWithHero, checkTask, checkActivityTask } from '../../../services/taskService';
|
import { checkTaskWithHero, checkTask, checkActivityTask } from '../../../services/taskService';
|
||||||
|
import { addSkin } from '../../../pubUtils/itemUtils';
|
||||||
|
|
||||||
export default function (app: Application) {
|
export default function (app: Application) {
|
||||||
return new HeroHandler(app);
|
return new HeroHandler(app);
|
||||||
@@ -24,8 +25,19 @@ export class HeroHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async test(msg: {}, session: BackendSession) {
|
public async test(msg: {}, session: BackendSession) {
|
||||||
let heroes = [...gameData.hero];
|
let sid = session.get('sid');
|
||||||
return resResult(STATUS.SUCCESS, { heroes })
|
|
||||||
|
for(let i = 0; i < 3; i++) {
|
||||||
|
let heroes = await HeroModel.find({}).sort({createdAt: 1}).limit(1000).skip(i*1000).lean();
|
||||||
|
for(let {hid, roleId, roleName, skins} of heroes) {
|
||||||
|
await HeroModel.updateHeroInfo(roleId, hid, { skins: [] });
|
||||||
|
for(let {id, enable } of skins) {
|
||||||
|
console.log(i, roleId, roleName, id);
|
||||||
|
await addSkin(roleId, roleName, id, enable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 'OK'
|
||||||
}
|
}
|
||||||
|
|
||||||
// ! 测试接口,用来测试前清理并初始化某个武将;代码抄自:gm-server/app/service/users.ts deleteHero
|
// ! 测试接口,用来测试前清理并初始化某个武将;代码抄自:gm-server/app/service/users.ts deleteHero
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { calAllHeroCe, pushCalPlayerCe, pushCalAllHeroCe } from './playerCeServi
|
|||||||
import { ItemModel } from '../db/Item';
|
import { ItemModel } from '../db/Item';
|
||||||
import { STATUS } from '../consts/statusCode';
|
import { STATUS } from '../consts/statusCode';
|
||||||
import { pinus } from 'pinus';
|
import { pinus } from 'pinus';
|
||||||
import { addEquips, addBags, addSkins, addFigure, unlockFigure as pubUnlockFigure, createHeroes as pubCreateHeroes, transPiece } from '../pubUtils/itemUtils';
|
import { addEquips, addBags, addSkin, addFigure, unlockFigure as pubUnlockFigure, createHeroes as pubCreateHeroes, transPiece } from '../pubUtils/itemUtils';
|
||||||
import { EquipInter, ItemInter, BagInter } from '../pubUtils/interface';
|
import { EquipInter, ItemInter, BagInter } from '../pubUtils/interface';
|
||||||
import { gameData } from '../pubUtils/data';
|
import { gameData } from '../pubUtils/data';
|
||||||
import { uniq, indexOf, findIndex } from 'underscore';
|
import { uniq, indexOf, findIndex } from 'underscore';
|
||||||
@@ -16,6 +16,7 @@ import { Figure } from '../domain/dbGeneral';
|
|||||||
import { Rank } from './rankService';
|
import { Rank } from './rankService';
|
||||||
import { checkActivityTask, pushActivityUpdate, pushTaskUpdate } from './taskService';
|
import { checkActivityTask, pushActivityUpdate, pushTaskUpdate } from './taskService';
|
||||||
import { CreateHeroParam } from '../domain/roleField/hero';
|
import { CreateHeroParam } from '../domain/roleField/hero';
|
||||||
|
import { HeroSkin } from '../db/Hero';
|
||||||
|
|
||||||
export async function handleCost(roleId: string, sid: string, goods: Array<ItemInter>) {
|
export async function handleCost(roleId: string, sid: string, goods: Array<ItemInter>) {
|
||||||
let currencysMap: any = {};
|
let currencysMap: any = {};
|
||||||
@@ -81,7 +82,7 @@ function sortConsumes(goods: Array<ItemInter>, bags: Array<ItemInter>, currencys
|
|||||||
} else {
|
} else {
|
||||||
bags.push(good);
|
bags.push(good);
|
||||||
}
|
}
|
||||||
} else if (table == ITEM_TABLE.HERO) {
|
} else if (table == ITEM_TABLE.SKIN) {
|
||||||
return false
|
return false
|
||||||
} else if (table == ITEM_TABLE.ROLE) {
|
} else if (table == ITEM_TABLE.ROLE) {
|
||||||
let curname = getCurNameById(goodInfo.good_id);
|
let curname = getCurNameById(goodInfo.good_id);
|
||||||
@@ -152,31 +153,44 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
|
|||||||
pinus.app.get('channelService').pushMessageByUids('onItemUpdate', resResult(STATUS.SUCCESS, { goods: bagInfos }), uids);
|
pinus.app.get('channelService').pushMessageByUids('onItemUpdate', resResult(STATUS.SUCCESS, { goods: bagInfos }), uids);
|
||||||
|
|
||||||
|
|
||||||
let figureInfo = await addFigure(roleId, figures);
|
let skinInfos: {skins: HeroSkin[], hid: number}[] = []; // 皮肤推送信息
|
||||||
for (let id of figures) {//皮肤推送
|
let figureInfos:{ heads: Figure[], frames: Figure[], spines: Figure[] }[] = []; // 头像变化推送信息
|
||||||
showItems.push({ id, count: 1 });
|
let calAllHeroResult = undefined; // 全局战力变化推送
|
||||||
}
|
|
||||||
if (!!figureInfo && (figureInfo.heads.length > 0 || figureInfo.frames.length > 0 || figureInfo.spines.length > 0)) {
|
|
||||||
pinus.app.get('channelService').pushMessageByUids('onHeadChange', resResult(STATUS.SUCCESS, { ...figureInfo }), uids);
|
|
||||||
}
|
|
||||||
|
|
||||||
let skinInfos = [];
|
|
||||||
let addSkinIds = [];
|
|
||||||
|
|
||||||
for (let skinId of skins) {//皮肤推送
|
for (let skinId of skins) {//皮肤推送
|
||||||
let result = await addSkins(roleId, skinId);
|
let result = await addSkin(roleId, roleName, skinId, false);
|
||||||
|
console.log(result)
|
||||||
if (!!result) {
|
if (!!result) {
|
||||||
showItems.push({ id: skinId, count: 1 });
|
showItems.push({ id: skinId, count: 1 });
|
||||||
skinInfos.push(result);
|
figureInfos.push(result.figureInfo);
|
||||||
addSkinIds.push(skinId);
|
if(result.hero) {
|
||||||
|
skinInfos.push({ skins: result.hero.skins, hid: result.hero.hid });
|
||||||
|
if(result.calAllHeroResult) calAllHeroResult = result.calAllHeroResult;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!!skinInfos.length) {
|
if (!!skinInfos.length) {
|
||||||
let unlockedType = addSkinIds.map(cur => { return { type: FIGURE_UNLOCK_CONDITION.GET_SKIN, paramSkinId: cur } });
|
pushHeroSkinMsg(skinInfos, uids); // 推送onHeroSkinChange
|
||||||
await unlockFigure(sid, roleId, unlockedType);
|
|
||||||
calAllHeroCe(HERO_SYSTEM_TYPE.ADD_SKIN, sid, roleId, {}, addSkinIds);
|
|
||||||
pinus.app.get('channelService').pushMessageByUids('onHeroSkinChange', resResult(STATUS.SUCCESS, { skinInfos }), uids);
|
|
||||||
}
|
}
|
||||||
|
// 推送全局加成信息
|
||||||
|
if(calAllHeroResult) await pushCalAllHeroCe(roleId, sid, calAllHeroResult);
|
||||||
|
|
||||||
|
// 获得头像和相框等
|
||||||
|
if(!!figures && figures.length > 0) {
|
||||||
|
let figureInfo = await addFigure(roleId, figures);
|
||||||
|
if(figureInfo) figureInfos.push(figureInfo);
|
||||||
|
for (let id of figures) {//皮肤推送
|
||||||
|
showItems.push({ id, count: 1 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获得头像或相框或形象推送
|
||||||
|
if(!!figureInfos && figureInfos.length > 0) {
|
||||||
|
for(let figureInfo of figureInfos) {
|
||||||
|
pinus.app.get('channelService').pushMessageByUids('onHeadChange', resResult(STATUS.SUCCESS, { ...figureInfo }), uids);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return showItems;
|
return showItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,7 +217,7 @@ function sortItems(goods: Array<ItemInter>, bags: Array<BagInter>, skins: Array<
|
|||||||
bags.push({ id: good.id, count: good.count, itemName: goodInfo.name, hid: goodInfo.hid || 0, type });
|
bags.push({ id: good.id, count: good.count, itemName: goodInfo.name, hid: goodInfo.hid || 0, type });
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (table == ITEM_TABLE.HERO) {
|
} else if (table == ITEM_TABLE.SKIN) {
|
||||||
if (type == CONSUME_TYPE.SKIN) {
|
if (type == CONSUME_TYPE.SKIN) {
|
||||||
let index = indexOf(skins, good.id);
|
let index = indexOf(skins, good.id);
|
||||||
if (index == -1) {
|
if (index == -1) {
|
||||||
@@ -333,7 +347,7 @@ export async function createHeroes(roleId: string, roleName: string, sid: string
|
|||||||
let resultHeroes: HeroType[] = [], resultItems: ItemInter[] = [];
|
let resultHeroes: HeroType[] = [], resultItems: ItemInter[] = [];
|
||||||
if (newHeroInfo.length > 0) {
|
if (newHeroInfo.length > 0) {
|
||||||
|
|
||||||
let { heroes, role, figureInfo, calHeroResults, calAllHeroResults, taskPushMessage, activityTaskPushMessage } = await pubCreateHeroes(roleId, roleName, serverId, newHeroInfo, funcs);
|
let { heroes, role, figureInfo, calHeroResults, calAllHeroResult, taskPushMessage, activityTaskPushMessage } = await pubCreateHeroes(roleId, roleName, serverId, newHeroInfo, funcs);
|
||||||
|
|
||||||
let r = new Rank(REDIS_KEY.HERO_NUM_RANK, { serverId });
|
let r = new Rank(REDIS_KEY.HERO_NUM_RANK, { serverId });
|
||||||
await r.setRankWithRoleInfo(roleId, role.heroNum, role.heroNumUpdatedAt, role);
|
await r.setRankWithRoleInfo(roleId, role.heroNum, role.heroNumUpdatedAt, role);
|
||||||
@@ -343,9 +357,7 @@ export async function createHeroes(roleId: string, roleName: string, sid: string
|
|||||||
for (let calHeroResult of calHeroResults) {
|
for (let calHeroResult of calHeroResults) {
|
||||||
await pushCalPlayerCe(roleId, sid, calHeroResult);
|
await pushCalPlayerCe(roleId, sid, calHeroResult);
|
||||||
}
|
}
|
||||||
for (let calAllHeroResult of calAllHeroResults) {
|
await pushCalAllHeroCe(roleId, sid, calAllHeroResult);
|
||||||
await pushCalAllHeroCe(roleId, sid, calAllHeroResult);
|
|
||||||
}
|
|
||||||
|
|
||||||
pushTaskUpdate(roleId, sid, null, taskPushMessage);
|
pushTaskUpdate(roleId, sid, null, taskPushMessage);
|
||||||
pushActivityUpdate(roleId, sid, null, activityTaskPushMessage);
|
pushActivityUpdate(roleId, sid, null, activityTaskPushMessage);
|
||||||
@@ -363,3 +375,25 @@ export async function createHero(roleId: string, roleName: string, sid: string,
|
|||||||
let result = await createHeroes(roleId, roleName, sid, serverId, funcs, [heroInfo]);
|
let result = await createHeroes(roleId, roleName, sid, serverId, funcs, [heroInfo]);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 皮肤数据变化去重、推送
|
||||||
|
* @param skinInfos 推送的皮肤
|
||||||
|
* @param uids 玩家
|
||||||
|
*/
|
||||||
|
function pushHeroSkinMsg(skinInfos: {skins: HeroSkin[], hid: number}[], uids: {uid: string, sid: string}[]) {
|
||||||
|
let pushSkinInfos: {skins: HeroSkin[], hid: number}[] = []; // 可能会有重复的
|
||||||
|
for(let { skins, hid } of skinInfos) {
|
||||||
|
let index = pushSkinInfos.findIndex(cur => cur.hid == hid);
|
||||||
|
if(index == -1) {
|
||||||
|
pushSkinInfos.push({skins, hid});
|
||||||
|
} else {
|
||||||
|
if(skins.length > pushSkinInfos[index].skins.length) {
|
||||||
|
pushSkinInfos[index] = {skins, hid};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(pushSkinInfos.length > 0) {
|
||||||
|
pinus.app.get('channelService').pushMessageByUids('onHeroSkinChange', resResult(STATUS.SUCCESS, { skinInfos }), uids);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -55,7 +55,7 @@ export default class UserController extends Controller {
|
|||||||
} else if (optType == 'lv') {
|
} else if (optType == 'lv') {
|
||||||
ctx.body = await ctx.service.users.levelUp(uids, lv);
|
ctx.body = await ctx.service.users.levelUp(uids, lv);
|
||||||
} else if (optType == 'skin') {
|
} else if (optType == 'skin') {
|
||||||
ctx.body = await ctx.service.users.addSkins(uids, skinid);
|
ctx.body = await ctx.service.users.addSkin(uids, skinid);
|
||||||
} else {
|
} else {
|
||||||
ctx.body = ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
ctx.body = ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Service } from 'egg';
|
import { Service } from 'egg';
|
||||||
import { addSkins, addBags, addEquips } from '@pubUtils/itemUtils';
|
import { addBags, addEquips } from '@pubUtils/itemUtils';
|
||||||
import * as pubUtils from '@pubUtils/util';
|
import * as pubUtils from '@pubUtils/util';
|
||||||
import { BagInter, EquipInter } from '@pubUtils/interface';
|
import { BagInter, EquipInter } from '@pubUtils/interface';
|
||||||
const csprng = require('csprng');
|
const csprng = require('csprng');
|
||||||
@@ -25,10 +25,6 @@ export default class Utils extends Service {
|
|||||||
return pubUtils.resResult(status, data, customMsg);
|
return pubUtils.resResult(status, data, customMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public addSkins(roleId: string, id: number) {
|
|
||||||
return addSkins(roleId, id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public addBags(roleId: string, roleName: string, data: BagInter) {
|
public addBags(roleId: string, roleName: string, data: BagInter) {
|
||||||
return addBags(roleId, roleName, data);
|
return addBags(roleId, roleName, data);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ import { isString } from 'underscore';
|
|||||||
import { FriendShipModel } from '@db/FriendShip';
|
import { FriendShipModel } from '@db/FriendShip';
|
||||||
import { FriendApplyModel } from '@db/FriendApply';
|
import { FriendApplyModel } from '@db/FriendApply';
|
||||||
import { FriendRelationModel } from '@db/FriendRelation';
|
import { FriendRelationModel } from '@db/FriendRelation';
|
||||||
import { createHero as pubCreateHero } from '@pubUtils/itemUtils';
|
import { createHero as pubCreateHero, addSkin } from '@pubUtils/itemUtils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test Service
|
* Test Service
|
||||||
@@ -372,13 +372,14 @@ export default class GMUsers extends Service {
|
|||||||
|
|
||||||
return ctx.service.utils.resResult(STATUS.SUCCESS, { uids });
|
return ctx.service.utils.resResult(STATUS.SUCCESS, { uids });
|
||||||
}
|
}
|
||||||
public async addSkins(uids: Array<string>, _id: string) {
|
public async addSkin(uids: Array<string>, _id: string) {
|
||||||
const { ctx } = this;
|
const { ctx } = this;
|
||||||
console.log('gm addSkin', uids, _id);
|
console.log('gm addSkin', uids, _id);
|
||||||
let id = parseInt(_id);
|
let id = parseInt(_id);
|
||||||
if (isNaN(id)) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
if (isNaN(id)) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||||
for (let roleId of uids) {
|
for (let roleId of uids) {
|
||||||
await ctx.service.utils.addSkins(roleId, id);
|
let role = await RoleModel.findByRoleId(roleId);
|
||||||
|
await addSkin(roleId, role.roleName, id, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ctx.service.utils.resResult(STATUS.SUCCESS, { uids });
|
return ctx.service.utils.resResult(STATUS.SUCCESS, { uids });
|
||||||
|
|||||||
@@ -78,7 +78,8 @@ export const ITEM_TABLE = {
|
|||||||
EQUIP: 'equip',
|
EQUIP: 'equip',
|
||||||
ITEM: 'item',
|
ITEM: 'item',
|
||||||
ROLE: 'role',
|
ROLE: 'role',
|
||||||
HERO: 'hero'
|
HERO: 'hero',
|
||||||
|
SKIN: 'skin'
|
||||||
}
|
}
|
||||||
|
|
||||||
const itid_array = [
|
const itid_array = [
|
||||||
@@ -127,7 +128,7 @@ const itid_array = [
|
|||||||
{ id: 33, name: '神兵', table: 'equip', type: EQUIP_TYPE.WEAPON },
|
{ id: 33, name: '神兵', table: 'equip', type: EQUIP_TYPE.WEAPON },
|
||||||
{ id: 34, name: '代币', table: 'item', type: CONSUME_TYPE.POINT },
|
{ id: 34, name: '代币', table: 'item', type: CONSUME_TYPE.POINT },
|
||||||
{ id: 53, 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: 40, name: '装备碎片', table: 'item', type: CONSUME_TYPE.PIECE },
|
||||||
{ id: 41, name: '图纸', table: 'item', type: CONSUME_TYPE.CONSUME },
|
{ id: 41, name: '图纸', table: 'item', type: CONSUME_TYPE.CONSUME },
|
||||||
{ id: 42, name: '神兵宝石', table: 'item', type: CONSUME_TYPE.JEWEL },
|
{ id: 42, name: '神兵宝石', table: 'item', type: CONSUME_TYPE.JEWEL },
|
||||||
|
|||||||
+6
-3
@@ -4,6 +4,7 @@ import Equip, { } from './Equip';
|
|||||||
import { CounterModel } from './Counter';
|
import { CounterModel } from './Counter';
|
||||||
import { COUNTER, EQUIP_TYPE } from '../consts';
|
import { COUNTER, EQUIP_TYPE } from '../consts';
|
||||||
import { reduceCe } from '../pubUtils/util';
|
import { reduceCe } from '../pubUtils/util';
|
||||||
|
import Skin from './Skin';
|
||||||
|
|
||||||
class CeAttrData {
|
class CeAttrData {
|
||||||
@prop({ required: true })
|
@prop({ required: true })
|
||||||
@@ -33,9 +34,11 @@ export class Connect {
|
|||||||
level: number;
|
level: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Skin {
|
export class HeroSkin {
|
||||||
@prop({ required: true })
|
@prop({ required: true })
|
||||||
id: number;
|
id: number;
|
||||||
|
@prop({ ref: 'Skin', type: mongoose.Schema.Types.ObjectId })
|
||||||
|
skin: Ref<Skin>;
|
||||||
@prop({ required: true })
|
@prop({ required: true })
|
||||||
enable: boolean;
|
enable: boolean;
|
||||||
}
|
}
|
||||||
@@ -131,8 +134,8 @@ export default class Hero extends BaseModel {
|
|||||||
favourLv: number; // 好感等级
|
favourLv: number; // 好感等级
|
||||||
@prop({ required: true, type: Connect, default: [], _id: false })
|
@prop({ required: true, type: Connect, default: [], _id: false })
|
||||||
connections: Connect[]; // 羁绊
|
connections: Connect[]; // 羁绊
|
||||||
@prop({ required: true, type: Skin, default: [], _id: false })
|
@prop({ required: true, type: HeroSkin, default: [], _id: false })
|
||||||
skins: Skin[]; // 皮肤
|
skins: HeroSkin[]; // 皮肤
|
||||||
|
|
||||||
@prop({ required: true, type: EPlace, default: getInitialEplace(), _id: false })
|
@prop({ required: true, type: EPlace, default: getInitialEplace(), _id: false })
|
||||||
ePlace: EPlace[]; // 武将装备引用数组
|
ePlace: EPlace[]; // 武将装备引用数组
|
||||||
|
|||||||
@@ -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 {
|
export interface DicFashions {
|
||||||
// 时装id
|
// 时装id
|
||||||
readonly id: number;
|
readonly id: number;
|
||||||
|
// 皮肤装名
|
||||||
|
readonly name: string;
|
||||||
// 指向heroSkill表
|
// 指向heroSkill表
|
||||||
readonly skillId: number;
|
readonly skillId: number;
|
||||||
// 全局加成
|
// 全局加成
|
||||||
|
|||||||
@@ -15,19 +15,37 @@ import { getTimeFun, nowSeconds } from './timeUtil';
|
|||||||
import { calPlayerCeAndSave, reCalAllHeroCe } from './playerCe';
|
import { calPlayerCeAndSave, reCalAllHeroCe } from './playerCe';
|
||||||
import { checkTask, checkTaskWithHeroes, checkTaskWithEquip, accomplishTask } from './taskUtil';
|
import { checkTask, checkTaskWithHeroes, checkTaskWithEquip, accomplishTask } from './taskUtil';
|
||||||
import { CreateHeroParam } from '../domain/roleField/hero';
|
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)
|
* @param roleId 玩家id
|
||||||
return false;
|
* @param roleName 玩家名
|
||||||
let hero = await HeroModel.findByHidAndRole(skinInfo.actorId, roleId);
|
* @param id 皮肤id
|
||||||
if (!hero)
|
* @param hero 武将,如果已经查询过这个武将就不用再查询一次,主意要select skins字段
|
||||||
return false;
|
* @returns {{ hero, figureInfo, calAllHeroResult }} hero:添加皮肤后的武将 figureInfo: 触发头像添加信息 calAllHeroResult:全局战力加成后结果
|
||||||
if (!!findWhere(hero.skins, { id }))
|
*/
|
||||||
return false;
|
export async function addSkin(roleId: string, roleName: string, skinId: number, enable: boolean, hero?: HeroType) {
|
||||||
hero.skins.push({ id, enable: false });
|
let dicSkin = gameData.fashion.get(skinId);
|
||||||
await HeroModel.updateHeroInfo(roleId, hero.hid, hero);
|
if (!dicSkin) return false;
|
||||||
return { skins: hero.skins, hid: hero.hid };
|
|
||||||
|
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) {
|
export async function addBags(roleId: string, roleName: string, data: BagInter) {
|
||||||
@@ -230,35 +248,61 @@ function unlockSingleFigure(dbFigures: Figure[], id: number, unlockDirect = fals
|
|||||||
return figure
|
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[]) {
|
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)
|
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: calAllHeroResults[0], taskPushMessage, activityTaskPushMessage }
|
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[]) {
|
export async function createHeroes(roleId: string, roleName: string, serverId: number, heroInfos: CreateHeroParam[], funcs?: number[]) {
|
||||||
|
|
||||||
let heroNum = 0;
|
let heroNum = 0;
|
||||||
let skinIds = new Array<number>();
|
|
||||||
let conditions = new Array<{ type: number, paramHid?: number, paramFavourLv?: number, paramSkinId?: 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) {
|
for (let heroInfo of heroInfos) {
|
||||||
let dicHero = gameData.hero.get(heroInfo.hid);
|
let dicHero = gameData.hero.get(heroInfo.hid);
|
||||||
let { quality, initialStars: star, jobid: job, name: hName, initialSkin } = dicHero;
|
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 curHero = await HeroModel.createHero(Object.assign(info, heroInfo));
|
||||||
let calHeroResult = await calPlayerCeAndSave(HERO_SYSTEM_TYPE.INIT, roleId, curHero, {}); calHeroResults.push(calHeroResult);
|
let addSkinResult = await addSkin(roleId, roleName, initialSkin, true, curHero); // 添加皮肤
|
||||||
let calAllHeroResult = await reCalAllHeroCe(HERO_SYSTEM_TYPE.ADD_SKIN, roleId, {}, skinIds); calAllHeroResults.push(calAllHeroResult);
|
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);
|
heroes.push(calHeroResult.hero);
|
||||||
conditions.push({ type: FIGURE_UNLOCK_CONDITION.GET_HERO, paramHid: heroInfo.hid });
|
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++;
|
heroNum++;
|
||||||
}
|
}
|
||||||
let figureInfo = await unlockFigure(roleId, conditions); // 解锁头像
|
figureInfos.push(await unlockFigure(roleId, conditions)); // 解锁头像
|
||||||
|
|
||||||
let role = await RoleModel.incRoleInfo(roleId, { heroNum }, { heroNumUpdatedAt: nowSeconds() });
|
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 mm1 = await accomplishTask(serverId, roleId, TASK_TYPE.HERO_NUM, heroNum)
|
||||||
let mm2 = await accomplishTask(serverId, roleId, TASK_TYPE.HERO_QUALITY, heroNum, { heroes })
|
let mm2 = await accomplishTask(serverId, roleId, TASK_TYPE.HERO_QUALITY, heroNum, { heroes })
|
||||||
let activityTaskPushMessage = mm1.concat(mm2);
|
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) {
|
export function transPiece(hid: number) {
|
||||||
|
|||||||
+16
-14
@@ -325,21 +325,23 @@ export function calHeroStarIncAttr(originHero: HeroType, update: HeroUpdate, typ
|
|||||||
updateHeroAttr(heroAttrs, targetAttrId, { set: { base: newBase } });
|
updateHeroAttr(heroAttrs, targetAttrId, { set: { base: newBase } });
|
||||||
}
|
}
|
||||||
|
|
||||||
// 解锁技能
|
// 武将被动技能,初始时候还没有皮肤,就先不算被动
|
||||||
let curSkin = skins.find(cur => cur.enable);
|
if(skins.length > 0) {
|
||||||
let curSeidList = getSeidListOfFashion(curSkin.id, star, colorStar);
|
let curSkin = skins.find(cur => cur.enable);
|
||||||
let preSeidList = getSeidListOfFashion(curSkin.id, isInit ? 0 : originStar, isInit ? 0 : originColorStar);
|
let curSeidList = getSeidListOfFashion(curSkin.id, star, colorStar);
|
||||||
|
let preSeidList = getSeidListOfFashion(curSkin.id, isInit ? 0 : originStar, isInit ? 0 : originColorStar);
|
||||||
|
|
||||||
curSeidList.forEach((seid, type) => {
|
curSeidList.forEach((seid, type) => {
|
||||||
if (!preSeidList.has(type)) {
|
if (!preSeidList.has(type)) {
|
||||||
addSeidList.push(seid, 0);
|
addSeidList.push(seid, 0);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
preSeidList.forEach((seid, type) => {
|
preSeidList.forEach((seid, type) => {
|
||||||
if (!curSeidList.has(type)) {
|
if (!curSeidList.has(type)) {
|
||||||
removeSeidList.push(seid, 0);
|
removeSeidList.push(seid, 0);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
originHero.attr = heroAttrs;
|
originHero.attr = heroAttrs;
|
||||||
return heroAttrs;//属性增量可以是多个
|
return heroAttrs;//属性增量可以是多个
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Service } from 'egg';
|
import { Service } from 'egg';
|
||||||
import { resResult as pubResult } from '../pubUtils/util';
|
import { resResult as pubResult } from '../pubUtils/util';
|
||||||
import { addSkins, addBags, addEquips, unlockFigure } from 'app/pubUtils/itemUtils';
|
import { addBags, addEquips, unlockFigure } from 'app/pubUtils/itemUtils';
|
||||||
import { BagInter, EquipInter } from 'app/pubUtils/interface';
|
import { BagInter, EquipInter } from 'app/pubUtils/interface';
|
||||||
import { RoleType } from '@db/Role';
|
import { RoleType } from '@db/Role';
|
||||||
const csprng = require('csprng');
|
const csprng = require('csprng');
|
||||||
@@ -43,10 +43,6 @@ export default class Utils extends Service {
|
|||||||
return pubResult(status, data, customMsg);
|
return pubResult(status, data, customMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public addSkins(roleId: string, id: number) {
|
|
||||||
return addSkins(roleId, id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public addBags(roleId: string, roleName: string, data: BagInter) {
|
public addBags(roleId: string, roleName: string, data: BagInter) {
|
||||||
return addBags(roleId, roleName, data);
|
return addBags(roleId, roleName, data);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user