任务:提取创建武将方法

This commit is contained in:
luying
2021-04-14 10:55:15 +08:00
parent d37d7cbb58
commit 93309f84f0
12 changed files with 117 additions and 91 deletions

View File

@@ -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)});
}

View File

@@ -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<number>) {
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<number>) {
let {role, ce, pushHeros, topLineupCe, guild, serverId } = await reCalAllHeroCe(type, roleId, update, args);
let result = await reCalAllHeroCe(type, roleId, update, args);
if(result.pushHeros.length > 0) {
return await pushCalAllHeroCe(roleId, sid, result);
} else {
return result.role;
}
}
if(pushHeros.length > 0) {
// 修改全局战力的推送
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(ce), heros: pushHeros, topLineupCe: reduceCe(topLineupCe) }), uids);
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;
}

View File

@@ -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<number>) {
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;
}

View File

@@ -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];
/**
* 计算强化次数和消耗

View File

@@ -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) {

View File

@@ -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';

View File

@@ -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 })

View File

@@ -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<number, any>();
const fiendShips = new Map<string, any>();
const comBtlLvRange = new Map<number, Array<number>>();
interface dicStar {
id: number;
quality: number;
star: number;
advanceUpFragmentNum: number;
ceAttr: Map<number, number>
}
interface dicWake {
id: number;
quality: number;
star: number;
fragmentNum: number;
consume: string;
ceAttr: Map<number, number>
}
function parseWarData() {
let result = null;
for (let filename of wars) {

View File

@@ -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<Figure>(), frames: new Array<Figure>(), spines: new Array<Figure>() };
for(let {type, paramHid, paramFavourLv, paramSkinId } of conditions) {
let canUnLockList = gameData.figureCondition.get(type);
if(canUnLockList) {
@@ -215,3 +215,33 @@ 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<number>();
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 }
}

View File

@@ -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 }>();

View File

@@ -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,39 +301,22 @@ 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<number>();
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);

View File

@@ -40,7 +40,7 @@ export default (appInfo: EggAppInfo) => {
},
};
config.decodeParm = true;
config.decodeParm = false;
config.static = {
prefix: '/',