抽卡:添加抽卡接口
This commit is contained in:
@@ -1,10 +1,17 @@
|
||||
import { Application, BackendSession } from "pinus";
|
||||
import { resResult } from "../../../pubUtils/util";
|
||||
import { STATUS, GACHA_ID } from "../../../consts";
|
||||
import { resResult, getRandomWithWeight } from "../../../pubUtils/util";
|
||||
import { STATUS, GACHA_ID, GACHA_CONTENT_TYPE, GACHA_OCCUPY_HID } from "../../../consts";
|
||||
import { gameData } from "../../../pubUtils/data";
|
||||
import { GachaListReturn } from "../../../domain/activityField/gachaField";
|
||||
import { GachaListReturn, Floor, Hope, GachaResult } from "../../../domain/activityField/gachaField";
|
||||
import { UserGachaModel } from "../../../db/UserGacha";
|
||||
import { refreshFreeCount } from "../../../services/gachaService";
|
||||
import { refreshGacha, getFloorResult, getResultFromContentId, transPiece } from "../../../services/gachaService";
|
||||
import { RoleModel } from "../../../db/Role";
|
||||
import { HeroModel, HeroUpdate } from "../../../db/Hero";
|
||||
import { RewardInter } from "../../../pubUtils/interface";
|
||||
import { handleCost, createHeroes, addItems } from "../../../services/rewardService";
|
||||
import { CounterModel } from "../../../db/Counter";
|
||||
import { getNextTime, getAfterDateByDay } from "../../../pubUtils/timeUtil";
|
||||
import { UserGachaRecModel } from "../../../db/UserGachaRec";
|
||||
|
||||
|
||||
export default function (app: Application) {
|
||||
@@ -31,7 +38,8 @@ export class GachaHandler {
|
||||
if(id == GACHA_ID.TIMELIMIT) continue; // 不包括限时
|
||||
|
||||
let userGacha = userGachaList.find(cur => cur.gachaId == id);
|
||||
userGacha = await refreshFreeCount(dicGacha, userGacha);
|
||||
userGacha = await refreshGacha(dicGacha, userGacha);
|
||||
console.log(JSON.stringify(userGacha))
|
||||
let param = new GachaListReturn(dicGacha, userGacha);
|
||||
list.push(param);
|
||||
}
|
||||
@@ -47,9 +55,81 @@ export class GachaHandler {
|
||||
*/
|
||||
async pull(msg: { gachaId: number, activityId: number, count: number }, session: BackendSession) {
|
||||
const { gachaId, activityId, count } = msg;
|
||||
if(gachaId == undefined|| activityId == undefined || count == undefined) return resResult(STATUS.WRONG_PARMS);
|
||||
const roleId: string = session.get('roleId');
|
||||
const roleName: string = session.get('roleName');
|
||||
const sid: string = session.get('sid');
|
||||
const serverId: number = session.get('serverId');
|
||||
|
||||
return resResult(STATUS.SUCCESS);
|
||||
let { lv } = await RoleModel.findByRoleId(roleId);
|
||||
|
||||
let dicGacha = gameData.gacha.get(gachaId);
|
||||
if(!dicGacha) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
if(!dicGacha.count.includes(count)) return resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
let userGacha = await UserGachaModel.findByRole(roleId, gachaId, activityId);
|
||||
let { floor, freeCount, hope, point, pickHero, refFreeTime } = await refreshGacha(dicGacha, userGacha);
|
||||
if((gachaId == GACHA_ID.ASSIGN|| gachaId == GACHA_ID.TIMELIMIT) && pickHero) return resResult(STATUS.GACHA_NOT_ASSIGN);
|
||||
|
||||
let userHeroes = await HeroModel.findByRole(roleId);
|
||||
|
||||
let items: RewardInter[] = [], heroInfo: HeroUpdate[] = [], resultList: GachaResult[] = [];
|
||||
for(let i = 0; i < count; i++) {
|
||||
// 按照一般概率抽出
|
||||
let { dic: { id: base } } = getRandomWithWeight(dicGacha.percent);
|
||||
let contentId = getFloorResult(gachaId, base, floor);
|
||||
if(contentId == false) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
let result = getResultFromContentId(contentId, lv, hope);
|
||||
|
||||
if(result.hid > 0) {
|
||||
result.setSetPickHero(pickHero);
|
||||
let hasHero = userHeroes.find(cur => cur.hid == result.hid);
|
||||
if(hasHero) { // 已有转换为碎片
|
||||
let { pieceId, count } = transPiece(result.hid);
|
||||
result.transferToPiece(pieceId, count);
|
||||
items.push({ id: pieceId, count });
|
||||
} else {
|
||||
let { heroId: hid, name: hName, initialStars: star, quality, jobid: job, initialSkin } = gameData.hero.get(result.hid);
|
||||
heroInfo.push({ roleId, serverId, roleName, hid, hName, star, quality, job, skins:[{id: initialSkin, enable: true}] })
|
||||
}
|
||||
} else {
|
||||
items.push({ id: result.id, count });
|
||||
}
|
||||
resultList.push(result);
|
||||
}
|
||||
console.log('***', dicGacha.free.count, dicGacha.free.day, freeCount, count);
|
||||
let costNum = count;
|
||||
if(dicGacha.free.count > 0) {
|
||||
if(count > dicGacha.free.count - freeCount) {
|
||||
costNum = count - dicGacha.free.count + freeCount;
|
||||
freeCount = dicGacha.free.count;
|
||||
} else {
|
||||
costNum = 0;
|
||||
freeCount += count;
|
||||
}
|
||||
}
|
||||
// 消耗东西
|
||||
if(costNum > 0) {
|
||||
let cost = dicGacha.cost.map(cur => { return { id: cur.id, count: cur.count * costNum }});
|
||||
let costResult = await handleCost(roleId, sid, cost);
|
||||
if(!costResult) return resResult(STATUS.GACHA_COST_NOT_ENOUGH);
|
||||
}
|
||||
// 给东西
|
||||
let heroes = await createHeroes(roleId, sid, serverId, heroInfo);
|
||||
await addItems(roleId, roleName, sid, items);
|
||||
// 更新数据
|
||||
point += count;
|
||||
userGacha = await UserGachaModel.updateInfo(roleId, gachaId, activityId, {
|
||||
freeCount, hope, floor, count, point
|
||||
});
|
||||
|
||||
await UserGachaRecModel.createRec(roleId, gachaId, activityId, count, resultList);
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
gachaId, activityId,
|
||||
freeCount, refFreeTime: getAfterDateByDay(refFreeTime, dicGacha.free.day), count, point, floor,
|
||||
heroes, result: resultList
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -47,18 +47,18 @@ export class WishPoolHandler {
|
||||
let goodInfo = getGoodById(goodId)
|
||||
if (!goodInfo)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
if (!(goodInfo.goodType == IT_TYPE.HERO_PIECE && type == 2 ) && !(goodInfo.goodType == IT_TYPE.EQUIP_PIECE && type == 1 ))
|
||||
if (!(goodInfo.itid == IT_TYPE.HERO_PIECE && type == 2 ) && !(goodInfo.itid == IT_TYPE.EQUIP_PIECE && type == 1 ))
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
let userGuild = await getUserGuildWithRefActive(roleId, ' wishDntCnt wishGoods guildCode wishGoods');
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
let result = await checkGoods(roleId, [goodId]);
|
||||
if (!result) {
|
||||
if (goodInfo.goodType == IT_TYPE.HERO_PIECE ) {
|
||||
if (goodInfo.itid == IT_TYPE.HERO_PIECE ) {
|
||||
result = await checkGoods(roleId, [goodInfo.hid]);
|
||||
if (!result)
|
||||
return resResult(STATUS.GUILD_WISH_POOL_NOT_OWN_HERO);
|
||||
} else if (goodInfo.goodType == IT_TYPE.EQUIP_PIECE ) {
|
||||
} else if (goodInfo.itid == IT_TYPE.EQUIP_PIECE ) {
|
||||
result = await checkGoods(roleId, [goodInfo.equipId]);
|
||||
if (!result)
|
||||
return resResult(STATUS.GUILD_WISH_POOL_NOT_OWN_EQUIP);
|
||||
|
||||
@@ -200,8 +200,8 @@ export class RoleHandler {
|
||||
let school = new Array<SclResultInter>();
|
||||
gameData.school.forEach((dicSchool) => {
|
||||
let position = new Array<SclPosInter>();
|
||||
dicPosition.forEach((isOpen, id) => {
|
||||
id = parseInt(id);
|
||||
dicPosition.forEach((isOpen, dicId) => {
|
||||
let id = parseInt(dicId);
|
||||
|
||||
let userSchool = userSchoolList.find(cur => cur.schoolId == dicSchool.id && cur.positionId == id);
|
||||
if (userSchool) {
|
||||
|
||||
@@ -5,7 +5,7 @@ import { HANG_UP_CONSTS, TOWER_TASK_CONST, REDIS_KEY, TASK_TYPE } from './../con
|
||||
import { BattleRecordModel } from './../db/BattleRecord';
|
||||
import { TowerRecordModel } from './../db/TowerRecord';
|
||||
import { RoleModel } from './../db/Role';
|
||||
import { getHeroInfoById, getJobInfoById, getTowerDataByLv, getTaskById, getGamedata, getRandExpedition, getWarById, getWarJsons } from "../pubUtils/gamedata"
|
||||
import { getHeroInfoById, getJobInfoById, getTowerDataByLv, getTaskById, getGamedata, getWarJsons } from "../pubUtils/gamedata"
|
||||
import { decodeArrayStr, shouldRefresh, resResult, decodeStr, cal, getRandomWithWeight, getRefTime, decodeStrSingle, genCode } from '../pubUtils/util';
|
||||
import { STATUS } from '../consts/statusCode';
|
||||
import { HangUpSpdUpRecModel } from '../db/HangUpSpdUpRec';
|
||||
@@ -13,6 +13,7 @@ import { TowerTaskRecModel } from '../db/TowerTaskRec';
|
||||
import { cloneDeep } from 'lodash';
|
||||
import { Rank } from './rankService';
|
||||
import { checkTask } from './taskService';
|
||||
import { getRandExpedition } from '../pubUtils/data';
|
||||
|
||||
export async function checkTowerWar(roleId: string, battleId: number, heroes: Array<number>) {
|
||||
const battleIdStr = `${battleId}`;
|
||||
|
||||
@@ -432,7 +432,8 @@ export function randEquipPrintId(warInfo) {
|
||||
if (!warInfo || !warInfo['jackpotReward']) {
|
||||
return null;
|
||||
}
|
||||
const result = getRandomWithWeight(decodeStr('possibility', warInfo['jackpotReward']));
|
||||
let jackpotReward: { id: number, weight: number}[] = decodeStr('possibility', warInfo['jackpotReward']);
|
||||
const result = getRandomWithWeight(jackpotReward);
|
||||
if (!result || !result.dic || !result.dic.id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import { genCode, decodeStrSingle, decodeStr, getRandomWithWeight, resResult } f
|
||||
import { EVENT_STATUS, EVENT_RECORD_STATUS, EVENT_TYPE, EVENT_RANDOM_TYPE_ONE_OPEN, EVENT_QUIZ_NUM, EVENT_ANSWER_STATUS, FUNCS_ID } from '../consts';
|
||||
import { EVENT_REFRESH_NUM } from '../consts';
|
||||
import { STATUS } from '../consts/statusCode';
|
||||
import { gameData } from '../pubUtils/data';
|
||||
|
||||
/**
|
||||
* 从检查接口调用,检查是否有这么个战斗,顺便保存一下battleCode
|
||||
@@ -193,7 +194,7 @@ export async function refreshEvent(num: number, roleId: string, roleName: string
|
||||
}).map(cur => cur.point);
|
||||
|
||||
let event = new Array();
|
||||
let dicEvent = getGamedata('dic_zyz_event');
|
||||
let dicEvent = gameData.eventList;
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
dicEvent = dicEvent.filter(cur => { // 筛选适合等级
|
||||
let { suitLevel } = cur;
|
||||
@@ -268,8 +269,7 @@ export async function refreshEvent(num: number, roleId: string, roleName: string
|
||||
*
|
||||
* @param positionStr
|
||||
*/
|
||||
function randomPosition(positionStr: string, prePoint: Array<number>, curPoint: Array<number>) {
|
||||
let positionArr = decodeStr('point', positionStr, '&');
|
||||
function randomPosition(positionArr: number[], prePoint: Array<number>, curPoint: Array<number>) {
|
||||
let range = positionArr.filter(point => {return !prePoint.includes(point) && !curPoint.includes(point)});
|
||||
if(range.length == 0) { // 如果位置总数不够,就不管prePoint里的
|
||||
range = positionArr.filter(point => {return !curPoint.includes(point)});
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import { GachaData, Floor } from "../domain/activityField/gachaField";;
|
||||
import { GachaData, Floor, GachaResult, Hope } from "../domain/activityField/gachaField";;
|
||||
import { ActivityModelType, ActivityModel } from "../db/Activity";
|
||||
import { DicGacha } from "../pubUtils/dictionary/DicGacha";
|
||||
import { UserGachaType, UserGachaModel } from "../db/UserGacha";
|
||||
import { shouldRefresh } from "../pubUtils/util";
|
||||
import { REFRESH_HOUR, GACHA_ID, GACHA_TO_FLOOR } from "../consts";
|
||||
import { getNextDayByGap } from "../pubUtils/timeUtil";
|
||||
import { shouldRefresh, getRandEelm, decodeArrayListStr, getRandomWithWeight, decodeIdCntArrayStr } from "../pubUtils/util";
|
||||
import { REFRESH_HOUR, GACHA_ID, GACHA_TO_FLOOR, GACHA_FLOOR_TYPE, GACHA_CONTENT_TYPE, HERO_QUALITY_TYPE, GACHA_OCCUPY_HID, IT_TYPE, ITID, CONSUME_TYPE, SPECIAL_ATTR } from "../consts";
|
||||
import { getNextDayByGap, getTodayZeroDate } from "../pubUtils/timeUtil";
|
||||
import { gameData, getDicGachaFloor } from "../pubUtils/data";
|
||||
import { RECRUIT } from "../pubUtils/dicParam";
|
||||
|
||||
/**
|
||||
* 获取活动页签里的限时卡池
|
||||
@@ -39,35 +41,269 @@ export async function getLimitGacha(activityId: number) {
|
||||
* @param dicGacha
|
||||
* @param userGacha
|
||||
*/
|
||||
export async function refreshFreeCount(dicGacha: DicGacha, userGacha: UserGachaType) {
|
||||
export async function refreshGacha(dicGacha: DicGacha, userGacha: UserGachaType) {
|
||||
let { day, count } = dicGacha.free;
|
||||
if(count > 0) {
|
||||
|
||||
if(count <= 0) {
|
||||
return userGacha;
|
||||
}
|
||||
|
||||
let { roleId, gachaId, refFreeTime } = userGacha;
|
||||
let { roleId, gachaId, refFreeTime, refHopeTime } = userGacha;
|
||||
if(shouldRefresh(refFreeTime, new Date(), REFRESH_HOUR, day)) {
|
||||
let ref = getNextDayByGap(refFreeTime, new Date(), day);
|
||||
userGacha = await UserGachaModel.refreshFreeCount(roleId, gachaId, 0, ref);
|
||||
}
|
||||
if(shouldRefresh(refHopeTime, new Date(), REFRESH_HOUR)) {
|
||||
let ref = getTodayZeroDate(REFRESH_HOUR);
|
||||
userGacha = await UserGachaModel.refreshHopeCount(roleId, gachaId, 0, ref);
|
||||
}
|
||||
return userGacha
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取保底状态
|
||||
* @param type 招募类型
|
||||
* @param gachaId 招募类型
|
||||
* @param floor 玩家保底
|
||||
*/
|
||||
export function getFloorStatus(type: number, floor: Floor[]) {
|
||||
export function getFloorStatus(gachaId: number, floor: Floor[]) {
|
||||
let floorMap = new Map<number, number>();
|
||||
for(let { id, count } of floor) {
|
||||
floorMap.set(id, count);
|
||||
}
|
||||
let dicFloorType = GACHA_TO_FLOOR.get(type);
|
||||
let dicFloorType = GACHA_TO_FLOOR.get(gachaId);
|
||||
return dicFloorType.map(id => {
|
||||
return {
|
||||
id,
|
||||
count: floorMap.get(id)||0
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获得保底结果
|
||||
* @param gachaId 招募表id
|
||||
* @param base 按普通概率获得的东西 内容参考gachaContent
|
||||
* @param floor 玩家保底数据
|
||||
*/
|
||||
export function getFloorResult(gachaId: number, base: number, floor: Floor[]) {
|
||||
let dicGachaContent = gameData.gachaContent.get(base); // 普通随机得出的结果是哪一类;
|
||||
if(!dicGachaContent) {
|
||||
console.error('dic_zyz_gachaContent error');
|
||||
return false; // DIC_NOT_FOUND 直接报错
|
||||
}
|
||||
|
||||
let touchedFloor = 0, touchedHeroQuality: number; // 触发的保底的id
|
||||
let dicFloorType = GACHA_TO_FLOOR.get(gachaId);
|
||||
for(let id of dicFloorType) {
|
||||
let { type, param } = dicGachaContent;
|
||||
let heroQuality = getHeroQuality(id);
|
||||
if(heroQuality == false) continue;
|
||||
|
||||
let isTarget = type == GACHA_CONTENT_TYPE.HERO && param[0] == heroQuality;
|
||||
if(!isTarget) { // 触发保底
|
||||
let percent = countFloorPercent(id, floor);
|
||||
let rand = Math.random();
|
||||
if(rand < percent) { // 可以替换为保底
|
||||
if(touchedFloor > 0 && touchedFloor < id) { // 如果已经触发过保底了
|
||||
// 更新被覆盖掉的那个保底数量
|
||||
updateUserFloor(floor, touchedFloor, false);
|
||||
}
|
||||
touchedFloor = id;
|
||||
touchedHeroQuality = heroQuality;
|
||||
} else {
|
||||
updateUserFloor(floor, id, false);
|
||||
}
|
||||
} else {
|
||||
updateUserFloor(floor, id, true);
|
||||
}
|
||||
}
|
||||
|
||||
if(touchedFloor > 0) {
|
||||
updateUserFloor(floor, touchedFloor, true);
|
||||
return gameData.gachaContentHero.get(touchedHeroQuality);
|
||||
} else {
|
||||
return base;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 更新玩家保底数据
|
||||
* @param floor 玩家保底数据
|
||||
* @param id 更新的保底类型
|
||||
* @param needReset 是否重置保底
|
||||
*/
|
||||
function updateUserFloor(floor: Floor[], id: number, needReset: boolean) {
|
||||
let curFloor = floor.find(cur => cur.id == id);
|
||||
if(!curFloor) {
|
||||
curFloor = { id, count: 0 };
|
||||
floor.push(curFloor);
|
||||
}
|
||||
if(needReset) {
|
||||
curFloor.count = 0;
|
||||
} else {
|
||||
curFloor.count ++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算保底概率
|
||||
* @param id 保底类型
|
||||
* @param floor 玩家保底数据
|
||||
*/
|
||||
function countFloorPercent(id: number, floor: Floor[]) {
|
||||
let curFloor = floor.find(cur => cur.id == id);
|
||||
let count = curFloor?curFloor.count: 0;
|
||||
// 保底概率,暂时使用线性公式,由策划使用后选择
|
||||
let floorCount = getDicGachaFloor(id);
|
||||
return count / floorCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取保底武将的品质
|
||||
* @param id 保底类型id in GACHA_FLOOR_TYPE
|
||||
*/
|
||||
function getHeroQuality(id: number) {
|
||||
if(id == GACHA_FLOOR_TYPE.PURPLE) {
|
||||
return HERO_QUALITY_TYPE.PURPLE;
|
||||
} else if (GACHA_FLOOR_TYPE.GOLD) {
|
||||
return HERO_QUALITY_TYPE.GOLD;
|
||||
} else if (GACHA_FLOOR_TYPE.ASSIGN) {
|
||||
return 0
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据contentId获得抽卡结果(包括心愿单)
|
||||
* @param contentId dic_zyz_gachaContent的id
|
||||
* @param lv 玩家等级
|
||||
* @param hope 玩家心愿单
|
||||
*/
|
||||
export function getResultFromContentId(contentId: number, lv: number, hope: Hope[]) {
|
||||
let dic = gameData.gachaContent.get(contentId);
|
||||
let { type, param, count } = dic;
|
||||
if(type == GACHA_CONTENT_TYPE.HERO) {
|
||||
let pool: number[] = getPoolByHope(hope, param[0]);
|
||||
|
||||
let hero = getRandEelm(pool);
|
||||
let result = new GachaResult(contentId);
|
||||
result.setHero(hero[0]);
|
||||
return result
|
||||
} else {
|
||||
let pool: number[] = [];
|
||||
if(type == GACHA_CONTENT_TYPE.HERO_PIECE) {
|
||||
pool = getAllItemByQuality(IT_TYPE.HERO_PIECE, param[0], lv);
|
||||
} else if (type == GACHA_CONTENT_TYPE.BLUEPRT) {
|
||||
pool = getAllItemByQuality(IT_TYPE.BLUEPRT, param[0], lv);
|
||||
} else if (type == GACHA_CONTENT_TYPE.JEWEL) {
|
||||
pool = getAllJewelByLv(param[0]);
|
||||
} else if (type == GACHA_CONTENT_TYPE.TERAPH_MATERIAL) {
|
||||
pool = param;
|
||||
} else if (type == GACHA_CONTENT_TYPE.SUIT_PAPER) {
|
||||
pool = getSuitPaper(lv);
|
||||
}
|
||||
let item = getRandEelm(pool);
|
||||
let result = new GachaResult(contentId);
|
||||
result.setItem(item[0], count);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 心愿
|
||||
* @param hope 玩家数据里的心愿单
|
||||
* @param qualtiy 武将品质
|
||||
*/
|
||||
function getPoolByHope(hope: Hope[], qualtiy: number) {
|
||||
if(qualtiy == HERO_QUALITY_TYPE.GOLD) {
|
||||
let hopeMap = new Map<number, Hope>();
|
||||
let hasGetHope: number[] = [];
|
||||
for(let h of hope) {
|
||||
hopeMap.set(h.id, h);
|
||||
if(h.hasGet) hasGetHope.push(h.id);
|
||||
}
|
||||
|
||||
let list = decodeArrayListStr(RECRUIT.RECRUIT_WISH_LIST).map(cur => {
|
||||
let curHope = hopeMap.get(parseInt(cur[0]));
|
||||
return { id: parseInt(cur[0]), hasGet: curHope?.hasGet||false, weight: parseInt(cur[1]) }
|
||||
});
|
||||
let { dic: { id, hasGet } } = getRandomWithWeight(list);
|
||||
if(id == 0 || hasGet) {
|
||||
return getAllHeroByQuality(qualtiy).filter(cur => !hasGetHope.includes(cur) );
|
||||
} else {
|
||||
if(hopeMap.has(id)) {
|
||||
let curHope = hopeMap.get(id);
|
||||
curHope.hasGet = true;
|
||||
return [curHope.hid];
|
||||
} else {
|
||||
return getAllHeroByQuality(qualtiy).filter(cur => !hasGetHope.includes(cur) );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return getAllHeroByQuality(qualtiy);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据品质获得武将池
|
||||
* @param quality 品质
|
||||
*/
|
||||
function getAllHeroByQuality(quality: number) {
|
||||
if(quality == 0) return [ GACHA_OCCUPY_HID ];
|
||||
|
||||
let allHero: number[] = [];
|
||||
for(let [id, dicHero] of gameData.hero) {
|
||||
if(dicHero.recruit && dicHero.quality == quality) {
|
||||
allHero.push(id);
|
||||
}
|
||||
}
|
||||
return allHero;
|
||||
}
|
||||
|
||||
function getAllItemByQuality(itid: number, quality: number, lv: number) {
|
||||
let allPiece: number[] = [];
|
||||
for(let [ id, dicGoods ] of gameData.goods) {
|
||||
if(dicGoods.itid == itid) {
|
||||
if((quality == 0 || dicGoods.quality == quality) || dicGoods.lvLimited <= lv) {
|
||||
allPiece.push(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
return allPiece;
|
||||
}
|
||||
|
||||
function getAllJewelByLv(lv: number) {
|
||||
let itids: number[] = [];
|
||||
for(let [ id, { type } ] of ITID) {
|
||||
if(type == CONSUME_TYPE.JEWEL) itids.push(id);
|
||||
}
|
||||
let items: number[] = [];
|
||||
for(let [ id, dicGoods ] of gameData.goods) {
|
||||
if(itids.includes(dicGoods.itid)) {
|
||||
if(lv == 0 || dicGoods.lvLimited == lv) {
|
||||
items.push(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
function getSuitPaper(lv: number) {
|
||||
let items: number[] = [];
|
||||
for(let [ id, dicGoods ] of gameData.goods) {
|
||||
if(dicGoods.itid == IT_TYPE.PAPER) {
|
||||
if(dicGoods.lvLimited <= lv) {
|
||||
items.push(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
export function transPiece(hid: number) {
|
||||
let dicHero = gameData.hero.get(hid);
|
||||
let { pieceId, quality } = dicHero;
|
||||
let dicPiece = decodeIdCntArrayStr(RECRUIT.RECRUIT_CHANGE_SHARD, 1); // 多少品质对应多少碎片
|
||||
return { pieceId, count: dicPiece.get(quality.toString()) }
|
||||
}
|
||||
@@ -8,11 +8,11 @@ import { calAllHeroCe, pushCalPlayerCe, pushCalAllHeroCe } from './playerCeServi
|
||||
import { ItemModel } from '../db/Item';
|
||||
import { STATUS } from '../consts/statusCode';
|
||||
import { pinus } from 'pinus';
|
||||
import { addEquips, addBags, addSkins, addFigure, unlockFigure as pubUnlockFigure, createHero as pubCreateHero } from '../pubUtils/itemUtils';
|
||||
import { addEquips, addBags, addSkins, addFigure, unlockFigure as pubUnlockFigure, createHero as pubCreateHero, createHeroes as pubCreateHeroes } 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 { HeroModel, HeroUpdate } from '../db/Hero';
|
||||
import { Figure } from '../domain/dbGeneral';
|
||||
import { Rank } from './rankService';
|
||||
import { pushTaskUpdate } from './taskService';
|
||||
@@ -304,7 +304,34 @@ export async function pushFigureUpdate(roleId: string, sid: string, figureInfo:
|
||||
}
|
||||
}
|
||||
|
||||
export async function createHero(roleId: string, sid: string, serverId: number, heroInfo) {
|
||||
/**
|
||||
* 创建多个武将
|
||||
* @param roleId
|
||||
* @param sid
|
||||
* @param serverId
|
||||
* @param heroInfo
|
||||
*/
|
||||
export async function createHeroes(roleId: string, sid: string, serverId: number, heroInfo: HeroUpdate[]) {
|
||||
let { heroes, role, figureInfo, calHeroResults, calAllHeroResults, taskPushMessage } = await pubCreateHeroes(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);
|
||||
|
||||
for(let calHeroResult of calHeroResults) {
|
||||
await pushCalPlayerCe(roleId, sid, calHeroResult);
|
||||
}
|
||||
for(let calAllHeroResult of calAllHeroResults) {
|
||||
await pushCalAllHeroCe(roleId, sid, calAllHeroResult);
|
||||
}
|
||||
|
||||
pushTaskUpdate(roleId, sid, null, taskPushMessage);
|
||||
|
||||
return heroes;
|
||||
}
|
||||
|
||||
export async function createHero(roleId: string, sid: string, serverId: number, heroInfo: HeroUpdate) {
|
||||
let { hero, role, figureInfo, calHeroResult, calAllHeroResult, taskPushMessage } = await pubCreateHero(roleId, heroInfo);
|
||||
|
||||
let r = new Rank(REDIS_KEY.HERO_NUM_RANK, { serverId });
|
||||
@@ -312,7 +339,7 @@ export async function createHero(roleId: string, sid: string, serverId: number,
|
||||
|
||||
await pushFigureUpdate(roleId, sid, figureInfo);
|
||||
|
||||
hero = await pushCalPlayerCe(roleId, sid, calHeroResult);
|
||||
await pushCalPlayerCe(roleId, sid, calHeroResult);
|
||||
await pushCalAllHeroCe(roleId, sid, calAllHeroResult);
|
||||
|
||||
pushTaskUpdate(roleId, sid, null, taskPushMessage);
|
||||
|
||||
@@ -10,6 +10,7 @@ import { BATTLE_REWARD_TYPE, BLUEPRT_CONST } from '../consts';
|
||||
import { addItems } from './rewardService';
|
||||
import { BattleBlueprtDropModel } from '../db/BattleBlueprtDrop'
|
||||
import { RoleModel } from '../db/Role';
|
||||
import { gameData } from '../pubUtils/data';
|
||||
|
||||
export class WarReward {
|
||||
private roleId: string;
|
||||
@@ -169,13 +170,12 @@ export class WarReward {
|
||||
|
||||
private async randomBlueprt() {
|
||||
const { lv } = await RoleModel.findByRoleId(this.roleId);
|
||||
const dicPossibility = getGamedata('dic_blueprt_possibility');
|
||||
const dicPossibility = gameData.blueprtPossibility;
|
||||
|
||||
const result = dicPossibility.find(cur => {return cur.min <= lv && cur.max >= lv});
|
||||
|
||||
if(result) {
|
||||
const dicOdds = decodeStr('possibility', result.possibility);
|
||||
const {dic: {id}} = getRandomWithWeight(dicOdds);
|
||||
const {dic: {id}} = getRandomWithWeight(result.possibility);
|
||||
|
||||
const blueprtList = getBluePrtByQuality(id);
|
||||
const gid = getRandomByLen(blueprtList);
|
||||
|
||||
Reference in New Issue
Block a user