任务:提取创建武将方法
This commit is contained in:
@@ -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)});
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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];
|
||||
/**
|
||||
* 计算强化次数和消耗
|
||||
|
||||
Reference in New Issue
Block a user