diff --git a/game-server/app/servers/role/handler/heroHandler.ts b/game-server/app/servers/role/handler/heroHandler.ts index 608477a26..f3d968af3 100644 --- a/game-server/app/servers/role/handler/heroHandler.ts +++ b/game-server/app/servers/role/handler/heroHandler.ts @@ -1,5 +1,5 @@ import {Application, BackendSession, ChannelService} from 'pinus'; -import { handleCost, addItems, unlockFigure } from '../../../services/rewardService'; +import { handleCost, addItems, unlockFigure, createHero } from '../../../services/rewardService'; import { calPlayerCeAndSave, calAllHeroCe } from '../../../services/playerCeService'; import { resResult, returnHeroCeRatio, deepCopy } from '../../../pubUtils/util'; import { STATUS } from '../../../consts/statusCode'; @@ -138,16 +138,10 @@ export class HeroHandler { let costResult = await handleCost(roleId, sid, [{id: pieceId, count: pieceCount}]); if(!costResult) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH); // createHero - let curHero = await HeroModel.createHero({ + let hero = await createHero(roleId, sid, serverId, { roleId, serverId, roleName, hid, hName, star, quality, job, skins:[{id: initialSkin, enable: true}] }); - let role = await RoleModel.incRoleInfo(roleId, { heroNum: 1 }, { heroNumUpdatedAt: nowSeconds() }); - let r = new Rank(REDIS_KEY.HERO_NUM_RANK, { serverId }); - await r.setRankWithRoleInfo(roleId, role.heroNum, role.heroNumUpdatedAt, role); - await unlockFigure(sid, roleId, [{ type: FIGURE_UNLOCK_CONDITION.GET_HERO, paramHid: hid }]); // 解锁头像 - let hero = await calPlayerCeAndSave(HERO_SYSTEM_TYPE.INIT, sid, roleId, curHero, {}); - await calAllHeroCe(HERO_SYSTEM_TYPE.ADD_SKIN, sid, roleId, {}, [initialSkin]) pushComposeOrangeHero(roleId, roleName, serverId, hero); return resResult(STATUS.SUCCESS, {curHero: returnHeroCeRatio(hero)}); } diff --git a/game-server/app/services/playerCeService.ts b/game-server/app/services/playerCeService.ts index 1130cf267..8d320d2c9 100644 --- a/game-server/app/services/playerCeService.ts +++ b/game-server/app/services/playerCeService.ts @@ -7,18 +7,33 @@ import { STATUS } from '../consts/statusCode'; import { resResult, reduceCe } from '../pubUtils/util'; import { calPlayerCeAndSave as pubCalPlayerCeAndSave, reCalAllHeroCe } from '../pubUtils/playerCe'; -import Hero, { HeroType, HeroUpdate } from '../db/Hero'; +import { HeroType, HeroUpdate } from '../db/Hero'; import { defaultHeroes } from './pvpService'; import { RoleUpdate, RoleType } from '../db/Role'; import { Rank } from './rankService'; import { REDIS_KEY } from '../consts'; import { updateUserInfo } from './redisService'; +import { GuildType } from '../db/Guild'; + +interface calPlayerReturn { + serverId: number; + role: RoleType; + guild?: GuildType; + hero?: HeroType; + pushHeros: {hid: number, ce: number, incHeroCe: number}[]; + topLineupCe: number +} //修改并下发战力 export async function calPlayerCeAndSave(type: number, sid: string, roleId: string, originHero: HeroType, update: HeroUpdate, args?: Array) { - let {role, pushHeros, topLineupCe, hero, guild, serverId} = await pubCalPlayerCeAndSave(type, roleId, originHero, update, args); + let result = await pubCalPlayerCeAndSave(type, roleId, originHero, update, args); + return await pushCalPlayerCe(roleId, sid, result); +} +// 修改后战力的推送 +export async function pushCalPlayerCe(roleId: string, sid: string, calResult: calPlayerReturn) { + let {role, pushHeros, topLineupCe, hero, guild, serverId} = calResult; // console.log(JSON.stringify(pushHeros)) //下发战力 let uids = [{ uid: roleId, sid }]; @@ -32,18 +47,27 @@ export async function calPlayerCeAndSave(type: number, sid: string, roleId: stri return hero; } +// 修改全局战力并下发 export async function calAllHeroCe(type:number, sid: string, roleId: string, update: RoleUpdate, args?:Array) { - let {role, ce, pushHeros, topLineupCe, guild, serverId } = await reCalAllHeroCe(type, roleId, update, args); - - if(pushHeros.length > 0) { - let uids = [{ uid: roleId, sid }]; - pinus.app.get('channelService').pushMessageByUids('onPlayerCeUpdate', resResult(STATUS.SUCCESS, { ce: reduceCe(ce), heros: pushHeros, topLineupCe: reduceCe(topLineupCe) }), uids); - - if(guild) { - await updateUserInfo(REDIS_KEY.GUILD_INFO, guild.code, [{ field: 'guildCe', value: guild.guildCe }]); - } - updateRank(roleId, serverId, topLineupCe, role, pushHeros); + let result = await reCalAllHeroCe(type, roleId, update, args); + if(result.pushHeros.length > 0) { + return await pushCalAllHeroCe(roleId, sid, result); + } else { + return result.role; } +} + +// 修改全局战力的推送 +export async function pushCalAllHeroCe(roleId: string, sid: string, calResult: calPlayerReturn) { + let {role, pushHeros, topLineupCe, guild, serverId } = calResult; + let uids = [{ uid: roleId, sid }]; + pinus.app.get('channelService').pushMessageByUids('onPlayerCeUpdate', resResult(STATUS.SUCCESS, { ce: reduceCe(role.ce), heros: pushHeros, topLineupCe: reduceCe(topLineupCe) }), uids); + + if(guild) { + await updateUserInfo(REDIS_KEY.GUILD_INFO, guild.code, [{ field: 'guildCe', value: guild.guildCe }]); + } + updateRank(roleId, serverId, topLineupCe, role, pushHeros); + return role; } diff --git a/game-server/app/services/rewardService.ts b/game-server/app/services/rewardService.ts index b7b172e0f..d27b318ae 100644 --- a/game-server/app/services/rewardService.ts +++ b/game-server/app/services/rewardService.ts @@ -1,18 +1,20 @@ -import { ITID, CONSUME_TYPE, getCurNameById, ITEM_TABLE, HERO_SYSTEM_TYPE, CURRENCY_BY_TYPE, FIGURE_UNLOCK_CONDITION } from './../consts'; +import { ITID, CONSUME_TYPE, getCurNameById, ITEM_TABLE, HERO_SYSTEM_TYPE, CURRENCY_BY_TYPE, FIGURE_UNLOCK_CONDITION, REDIS_KEY } from './../consts'; import { EquipModel } from './../db/Equip'; import { resResult, parseGoodStr } from '../pubUtils/util'; import { getGoodById } from '../pubUtils/gamedata'; import { RoleModel, RoleType } from '../db/Role'; import { setAp } from './actionPointService'; -import { calAllHeroCe } from './playerCeService'; +import { calAllHeroCe, pushCalPlayerCe, pushCalAllHeroCe } from './playerCeService'; import { ItemModel } from '../db/Item'; import { STATUS } from '../consts/statusCode'; import { pinus } from 'pinus'; -import { addEquips, addBags, addSkins, addFigure, unlockFigure as pubUnlockFigure } from '../pubUtils/itemUtils'; +import { addEquips, addBags, addSkins, addFigure, unlockFigure as pubUnlockFigure, createHero as pubCreateHero } from '../pubUtils/itemUtils'; import { EquipInter, ItemInter, BagInter } from '../pubUtils/interface'; import { gameData } from '../pubUtils/data'; import { uniq, indexOf, findIndex } from 'underscore'; import { HeroModel } from '../db/Hero'; +import { Figure } from '../domain/dbGeneral'; +import { Rank } from './rankService'; export async function handleFixedReward(roleId: string, roleName: string, sid: string, rewardStr: string, multi: number) { let reward = parseGoodStr(rewardStr); @@ -288,9 +290,26 @@ export async function checkGoods(roleId: string, goodIds: Array) { export async function unlockFigure(sid: string, roleId: string, conditions: { type: number, paramHid?: number, paramFavourLv?: number, paramSkinId?: number }[], role?: RoleType) { let figureInfo = await pubUnlockFigure(roleId, conditions, role); + await pushFigureUpdate(roleId, sid, figureInfo); +} +export async function pushFigureUpdate(roleId: string, sid: string, figureInfo: { heads: Figure[], frames: Figure[], spines: Figure[] }) { if (!!figureInfo && (figureInfo.heads.length > 0 || figureInfo.frames.length > 0 || figureInfo.spines.length > 0)) { let uids = [{uid: roleId, sid}]; pinus.app.get('channelService').pushMessageByUids('onHeadChange', resResult(STATUS.SUCCESS, { ...figureInfo }), uids); } +} + +export async function createHero(roleId: string, sid: string, serverId: number, heroInfo) { + let { hero, role, figureInfo, calHeroResult, calAllHeroResult } = await pubCreateHero(roleId, heroInfo); + + let r = new Rank(REDIS_KEY.HERO_NUM_RANK, { serverId }); + await r.setRankWithRoleInfo(roleId, role.heroNum, role.heroNumUpdatedAt, role); + + await pushFigureUpdate(roleId, sid, figureInfo); + + hero = await pushCalPlayerCe(roleId, sid, calHeroResult); + await pushCalAllHeroCe(roleId, sid, calAllHeroResult); + + return hero; } \ No newline at end of file diff --git a/game-server/app/services/roleService.ts b/game-server/app/services/roleService.ts index 04a592639..67902e3ed 100644 --- a/game-server/app/services/roleService.ts +++ b/game-server/app/services/roleService.ts @@ -4,11 +4,8 @@ import { getRandNum, getRandomArr } from '../pubUtils/util'; import { TERAPH_RANDOM } from "../consts/consts"; import { indexOf } from 'underscore'; import { DicTeraph } from '../pubUtils/dictionary/DicTeraph'; -import { Teraph, RoleType, RoleModel } from '../db/Role'; -import { ROLE_SELECT, FIGURE_UNLOCK_CONDITION, ITID, CONSUME_TYPE } from '../consts'; -import { gameData } from '../pubUtils/data'; -import { Figure } from '../domain/dbGeneral'; -import { getBeforeDaySeconds } from '../pubUtils/timeUtil'; +import { Teraph, RoleModel } from '../db/Role'; +import { ROLE_SELECT } from '../consts'; const TERAPH_STRENGTHEN = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; /** * 计算强化次数和消耗 diff --git a/gm-server/app/service/users.ts b/gm-server/app/service/users.ts index 8cd83dffa..85545a775 100644 --- a/gm-server/app/service/users.ts +++ b/gm-server/app/service/users.ts @@ -20,7 +20,7 @@ import { PvpDefenseModel } from '@db/PvpDefense'; import { Service } from 'egg'; import Counter from '@db/Counter'; -import { STATUS, HERO_SYSTEM_TYPE, FIGURE_UNLOCK_CONDITION } from '@consts'; +import { STATUS, HERO_SYSTEM_TYPE } from '@consts'; import { ITID, COUNTER } from '@consts'; import { ItemModel } from '@db/Item'; import { gameData, getHeroExpByLv } from '@pubUtils/data'; @@ -32,8 +32,7 @@ import { isString } from 'underscore'; import { FriendShipModel } from '@db/FriendShip'; import { FriendApplyModel } from '@db/FriendApply'; import { FriendRelationModel } from '@db/FriendRelation'; -import { unlockFigure } from '@pubUtils/itemUtils'; -import { nowSeconds } from '@pubUtils/timeUtil'; +import { createHero as pubCreateHero } from '@pubUtils/itemUtils'; /** * Test Service @@ -268,10 +267,7 @@ export default class GMUsers extends Service { try { for(let heroInfo of heroInfos) { - let hero = await HeroModel.createHero(heroInfo); - await RoleModel.incRoleInfo(heroInfo.roleId, { heroNum: 1 }, { heroNumUpdatedAt: nowSeconds() }); - await unlockFigure(heroInfo.roleId, [{ type: FIGURE_UNLOCK_CONDITION.GET_HERO, paramHid: heroInfo.hid }]); // 解锁头像 - await calPlayerCeAndSave(HERO_SYSTEM_TYPE.INIT, heroInfo.roleId, hero, {}); + await pubCreateHero(heroInfo.roleId, heroInfo); } return ctx.service.utils.resResult(STATUS.SUCCESS, { uids }); } catch(e) { diff --git a/shared/db/Guild.ts b/shared/db/Guild.ts index c9aea6c15..36a015bfd 100644 --- a/shared/db/Guild.ts +++ b/shared/db/Guild.ts @@ -2,7 +2,7 @@ import BaseModel from './BaseModel'; import { index, getModelForClass, prop, DocumentType, Ref } from '@typegoose/typegoose'; import Role, { RoleType } from './Role'; import { genCode } from '../pubUtils/util'; -import { GUILD_STRUCTURE, GUILD_STATUS, GUILD_PER_PAGE, GUILD_SELECT, RANK_TYPE, REDIS_KEY } from '../consts'; +import { GUILD_STRUCTURE, GUILD_STATUS, GUILD_PER_PAGE, GUILD_SELECT, REDIS_KEY } from '../consts'; import { getCurWeekTime, nowSeconds } from '../pubUtils/timeUtil'; import { reduceCe } from '../pubUtils/util'; diff --git a/shared/db/Hero.ts b/shared/db/Hero.ts index 2a73c08cf..0a8dfe86d 100644 --- a/shared/db/Hero.ts +++ b/shared/db/Hero.ts @@ -4,7 +4,6 @@ import Equip, { } from './Equip'; import { CounterModel } from './Counter'; import { COUNTER, EQUIP_TYPE } from '../consts'; import { reduceCe } from '../pubUtils/util'; -import { nowSeconds } from '../pubUtils/timeUtil'; class CeAttrData { @prop({ required: true }) diff --git a/shared/pubUtils/gamedata.ts b/shared/pubUtils/gamedata.ts index 13496da8b..c01b94e0d 100644 --- a/shared/pubUtils/gamedata.ts +++ b/shared/pubUtils/gamedata.ts @@ -1,6 +1,6 @@ import fs = require('fs'); import path = require('path'); -import { ABI_TYPE, ABI_STAGE, COM_BTL_LV_RANGE } from '../consts'; +import { ABI_TYPE, COM_BTL_LV_RANGE } from '../consts'; import { decodeIdCntArrayStr, getRandEelm } from './util'; import { IT_TYPE } from '../consts'; @@ -26,22 +26,6 @@ const blueprtCompose = new Map(); const fiendShips = new Map(); const comBtlLvRange = new Map>(); -interface dicStar { - id: number; - quality: number; - star: number; - advanceUpFragmentNum: number; - ceAttr: Map -} -interface dicWake { - id: number; - quality: number; - star: number; - fragmentNum: number; - consume: string; - ceAttr: Map -} - function parseWarData() { let result = null; for (let filename of wars) { diff --git a/shared/pubUtils/itemUtils.ts b/shared/pubUtils/itemUtils.ts index 7bf2bcf75..412629d99 100644 --- a/shared/pubUtils/itemUtils.ts +++ b/shared/pubUtils/itemUtils.ts @@ -1,6 +1,6 @@ -import { HeroModel, HeroUpdate, HeroType } from '../db/Hero'; +import { HeroModel, HeroUpdate } from '../db/Hero'; import { ItemModel } from '../db/Item'; import { EquipModel, RandSe, Holes } from './../db/Equip'; import { BagInter, EquipInter } from './interface'; @@ -11,8 +11,8 @@ import { getRandValueByMinMax, getRandEelm } from './util'; import { findWhere } from 'underscore'; import { RoleModel, RoleType } from '../db/Role'; import { Figure } from '../domain/dbGeneral'; -import { getBeforeDaySeconds } from './timeUtil'; -import { calPlayerCeAndSave } from './playerCe'; +import { getBeforeDaySeconds, nowSeconds } from './timeUtil'; +import { calPlayerCeAndSave, reCalAllHeroCe } from './playerCe'; export async function addSkins(roleId: string, id: number) { let skinInfo = gameData.fashion.get(id); @@ -98,7 +98,7 @@ export async function unlockFigure(roleId: string, conditions: { type: number, p role = await RoleModel.findByRoleId(roleId, ROLE_SELECT.GET_HEADS); } let { heads, frames, spines } = role; - let figureInfo = { heads: [], frames: [], spines: [] }; + let figureInfo = { heads: new Array
(), frames: new Array
(), spines: new Array
() }; for(let {type, paramHid, paramFavourLv, paramSkinId } of conditions) { let canUnLockList = gameData.figureCondition.get(type); if(canUnLockList) { @@ -214,4 +214,34 @@ function unlockSingleFigure(dbFigures: Figure[], id: number, unlockDirect = fals } return figure +} + +export async function createHero(roleId: string, heroInfo: HeroUpdate) { + let { role, figureInfo, heroes, calHeroResults, calAllHeroResults } = await createHeroes(roleId, [heroInfo]) + return { hero: heroes[0], role, figureInfo, calHeroResult: calHeroResults[0], calAllHeroResult: calAllHeroResults[0] } +} + +export async function createHeroes(roleId: string, heroInfos: HeroUpdate[]) { + + let heroNum = 0; + let skinIds = new Array(); + let conditions = new Array<{type: number, paramHid?: number, paramFavourLv?: number, paramSkinId?: number }>(); + let heroes = [], calHeroResults = [], calAllHeroResults = []; + + for(let heroInfo of heroInfos) { + let curHero = await HeroModel.createHero(heroInfo); heroes.push(curHero); + 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); + + conditions.push({ type: FIGURE_UNLOCK_CONDITION.GET_HERO, paramHid: heroInfo.hid }); + heroInfo.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); // 解锁头像 + + let role = await RoleModel.incRoleInfo(roleId, { heroNum }, { heroNumUpdatedAt: nowSeconds() }); + return { role, figureInfo, heroes, calHeroResults, calAllHeroResults } } \ No newline at end of file diff --git a/shared/pubUtils/playerCe.ts b/shared/pubUtils/playerCe.ts index 807a25b32..a587e88d2 100644 --- a/shared/pubUtils/playerCe.ts +++ b/shared/pubUtils/playerCe.ts @@ -61,7 +61,7 @@ export async function reCalAllHeroCe(type: number, roleId: string, update: RoleU let heros = await HeroModel.findByRole(roleId); let roleAttrs = await reCalRoleAttr(type, heros, role, update, args); - if(!roleAttrs) return {pushHeros: [], ce: role.ce, topLineupCe: role.topLineupCe}; // 无加成 + if(!roleAttrs) return {role, pushHeros: [], ce: role.ce, topLineupCe: role.topLineupCe, serverId: role.serverId}; // 无加成 let pushHeros = new Array<{ hid: number, ce: number, incHeroCe: number }>(); diff --git a/web-server/app/service/Auth.ts b/web-server/app/service/Auth.ts index 8001af3c8..4c1587548 100644 --- a/web-server/app/service/Auth.ts +++ b/web-server/app/service/Auth.ts @@ -1,5 +1,5 @@ -import { COUNTER, HERO_SYSTEM_TYPE, DEFAULT_LV, DEFAULT_ITEMS, ITID, DEFAULT_GOLD, DEFAULT_HERO_LV, DEFAULT_EQUIPS, DEFAULT_COIN, ADULT_AGE, GUEST_MAX_TIME, FIGURE_UNLOCK_CONDITION } from '@consts'; +import { COUNTER, DEFAULT_LV, DEFAULT_ITEMS, ITID, DEFAULT_GOLD, DEFAULT_HERO_LV, DEFAULT_EQUIPS, DEFAULT_COIN, ADULT_AGE, GUEST_MAX_TIME } from '@consts'; import { DEFAULT_HEROES } from '@consts'; import { HeroModel } from '@db/Hero'; import { RoleModel } from '@db/Role'; @@ -8,13 +8,13 @@ import { STATUS, GET_SMS_TYPE, ADDICTION_PREVENTION_CODE } from '@consts'; import { smsModel } from '@db/Sms'; import { Service } from 'egg'; import Counter from '@db/Counter'; -import { getHeroInfoById } from 'app/pubUtils/gamedata'; -import { calPlayerCeAndSave, reCalAllHeroCe } from 'app/pubUtils/playerCe'; -import { getExpByLv, getHeroExpByLv, gameData } from 'app/pubUtils/data'; +import { getHeroInfoById } from '../pubUtils/gamedata'; +import { getExpByLv, getHeroExpByLv, gameData } from '../pubUtils/data'; import { isString } from 'underscore'; -import { getAge, nowSeconds } from 'app/pubUtils/timeUtil'; -import { shouldRefresh, resResult } from 'app/pubUtils/util'; -import { authenticate } from 'app/pubUtils/httpUtil'; +import { getAge } from '../pubUtils/timeUtil'; +import { shouldRefresh, resResult } from '../pubUtils/util'; +import { authenticate } from '../pubUtils/httpUtil'; +import { createHeroes } from '../pubUtils/itemUtils'; /** * Test Service @@ -301,40 +301,23 @@ export default class Auth extends Service { const role = await RoleModel.createRole(uid, serverId, { roleId, code, roleName, seqId, lv: DEFAULT_LV, exp: (getExpByLv(DEFAULT_LV - 1) || { sum: 0 }).sum || 0 }); if (role) { - let skinIds = new Array(); - let conditions = new Array<{type: number, paramHid?: number, paramFavourLv?: number, paramSkinId?: number }>() - - let heroNum = 0; + let heroInfos = []; for (let hid of DEFAULT_HEROES) { let hero = await HeroModel.findByHidAndRole(hid, roleId); - if (hero) { - continue; - } + if (hero) continue let dicHero = getHeroInfoById(hid); - if (!dicHero) { - break; - } + if (!dicHero) break; + let { quality, initialStars: star, jobid: job, name: hName, initialSkin } = dicHero; - hero = await HeroModel.createHero({ + heroInfos.push({ roleId, roleName: role.roleName, hid, hName, star, quality, job, serverId: role.serverId, skins: [{ id: initialSkin, enable: true }], lv: DEFAULT_HERO_LV, exp: getHeroExpByLv(DEFAULT_HERO_LV - 1) || 0 }); - skinIds.push(initialSkin); - conditions.push({type: FIGURE_UNLOCK_CONDITION.GET_HERO, paramHid: hid}); - conditions.push({type: FIGURE_UNLOCK_CONDITION.GET_SKIN, paramSkinId: initialSkin}); - - await calPlayerCeAndSave(HERO_SYSTEM_TYPE.INIT, roleId, hero, {}); - heroNum ++; - } - await RoleModel.incRoleInfo(role.roleId, { heroNum }, { heroNumUpdatedAt: nowSeconds() }); - // 解锁形象 - await ctx.service.utils.unlockFigure(roleId, conditions, role); - - await reCalAllHeroCe(HERO_SYSTEM_TYPE.ADD_SKIN, roleId, {}, skinIds) - + await createHeroes(roleId, heroInfos); + for (let { id, count } of DEFAULT_ITEMS) { let dicGoods = gameData.goods.get(id); if (!dicGoods) continue; diff --git a/web-server/config/config.local.ts b/web-server/config/config.local.ts index 261f18707..62fa1e623 100644 --- a/web-server/config/config.local.ts +++ b/web-server/config/config.local.ts @@ -40,7 +40,7 @@ export default (appInfo: EggAppInfo) => { }, }; - config.decodeParm = true; + config.decodeParm = false; config.static = { prefix: '/',