抽卡:修改抽卡奖池逻辑
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import { Application, BackendSession, HandlerService, } from "pinus";
|
||||
import { resResult, shouldRefresh, getRandSingleEelm } from "../../../pubUtils/util";
|
||||
import { STATUS, GACHA_ID, HERO_QUALITY_TYPE, TASK_TYPE, ITEM_CHANGE_REASON, } from "../../../consts";
|
||||
import { resResult, shouldRefresh, getRandSingleEelm, getGachaRemainFloor } from "../../../pubUtils/util";
|
||||
import { STATUS, GACHA_TYPE, HERO_QUALITY_TYPE, TASK_TYPE, ITEM_CHANGE_REASON, } from "../../../consts";
|
||||
import { gameData } from "../../../pubUtils/data";
|
||||
import { GachaResult, GachaData } from "../../../domain/activityField/gachaField";
|
||||
import { UserGachaModel } from "../../../db/UserGacha";
|
||||
import { refreshGacha, getGachaList, getVisitedHeroList, getAllHeroByQuality, GachaPull } from "../../../services/activity/gachaService";
|
||||
import { GachaData, GachaResultIndb } from "../../../domain/activityField/gachaField";
|
||||
import { SimpleResult, UserGachaModel } from "../../../db/UserGacha";
|
||||
import { refreshGacha, getGachaList, getVisitedHeroList, GachaPull, getGuideGachaId, GachaResults, getDicGachaByGachaCnt } from "../../../services/activity/gachaService";
|
||||
import { RoleModel } from "../../../db/Role";
|
||||
import { HeroModel } from "../../../db/Hero";
|
||||
import { handleCost, addItems } from "../../../services/role/rewardService";
|
||||
@@ -61,11 +61,13 @@ export class GachaHandler {
|
||||
let userGacha = await UserGachaModel.findByRole(roleId, gachaId, activityId);
|
||||
userGacha = await refreshGacha(dicGacha, userGacha);
|
||||
let { freeCount, point, pickHero, refFreeTime, count: historyCount } = userGacha;
|
||||
if ((gachaId == GACHA_ID.ASSIGN || gachaId == GACHA_ID.TIMELIMIT) && !pickHero) return resResult(STATUS.GACHA_NOT_ASSIGN);
|
||||
if ((gachaId == GACHA_TYPE.ASSIGN || gachaId == GACHA_TYPE.ACTIVITY) && !pickHero) return resResult(STATUS.GACHA_NOT_ASSIGN);
|
||||
|
||||
dicGacha = getDicGachaByGachaCnt(dicGacha, historyCount);
|
||||
if (!dicGacha) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
|
||||
let gachaPull = new GachaPull(dicGacha, userGacha);
|
||||
let userHeroes = await HeroModel.findByRole(roleId);
|
||||
let gachaPull = new GachaPull(gachaId);
|
||||
gachaPull.setByUserGacha(dicGacha, userGacha, false);
|
||||
let { resultList, heroInfo, items } = gachaPull.pull(count, userHeroes);
|
||||
let { hope, floor } = gachaPull.getUserGachaParam();
|
||||
|
||||
@@ -95,14 +97,15 @@ export class GachaHandler {
|
||||
});
|
||||
|
||||
await UserGachaRecModel.createRec(roleId, gachaId, activityId, count, resultList);
|
||||
await checkTaskInGacha(serverId, roleId, sid, count, resultHeroes, resultList, false);
|
||||
if(dicGacha.isTask) await checkTaskInGacha(serverId, roleId, sid, count, resultHeroes, resultList, false);
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
gachaId, activityId,
|
||||
freeCount, refFreeTime: userGacha.refFreeTime, count: userGacha.count, point: userGacha.point, floor, hope,
|
||||
guideResultCount: userGacha.guideResultCount,
|
||||
// heroes: resultHeroes,
|
||||
addHeros: heroes,
|
||||
result: resultList
|
||||
result: resultList,
|
||||
remainFloor: getGachaRemainFloor(gachaId, floor)
|
||||
});
|
||||
}
|
||||
|
||||
@@ -166,11 +169,11 @@ export class GachaHandler {
|
||||
let { point, turntable, costPoint } = userGacha;
|
||||
if (point < RECRUIT.RECRUIT_BONUS_RECRUIT) return resResult(STATUS.GACHA_TURNTABLE_POINT_NOT_ENOUGH);
|
||||
|
||||
let turntablePool: { quality: number, count: number }[] = [];
|
||||
for (let { quality, count } of gameData.gachaTurntable) {
|
||||
let turntablePool: { quality: number, count: number, planId: number }[] = [];
|
||||
for (let { quality, count, planId } of gameData.gachaTurntable) {
|
||||
let myTurntable = turntable.find(cur => cur.quality == quality);
|
||||
if (!myTurntable || !myTurntable.hasGet) {
|
||||
turntablePool.push({ quality, count });
|
||||
turntablePool.push({ quality, count, planId });
|
||||
}
|
||||
}
|
||||
if (turntablePool.length <= 0) { // 重置
|
||||
@@ -178,31 +181,20 @@ export class GachaHandler {
|
||||
}
|
||||
|
||||
let randTurntable = getRandSingleEelm(turntablePool);
|
||||
let { quality, count } = randTurntable;
|
||||
// 根据品质查武将
|
||||
let pool = getAllHeroByQuality(quality);
|
||||
let { quality, count, planId } = randTurntable;
|
||||
|
||||
let hero = getRandSingleEelm(pool);
|
||||
let contentId = gameData.gachaContentHero.get(hero);
|
||||
let userHeroes = await HeroModel.findByRole(roleId);
|
||||
let gachaResults = new GachaResults();
|
||||
gachaResults.addPlan(planId);
|
||||
gachaResults.processDetail(null, count);
|
||||
let { items, heroInfo, resultList } = gachaResults.transferToFinalResult(userHeroes);
|
||||
|
||||
// 获得或者转成碎片
|
||||
let heroInfo: { hid: number, count: number }[] = [];
|
||||
for (let i = 0; i < count; i++) {
|
||||
heroInfo.push({ hid: hero, count: 1 })
|
||||
}
|
||||
let { heroes, resultHeroes, goods } = await createHeroes(roleId, roleName, sid, serverId, heroInfo);
|
||||
let resultList: GachaResult[] = [];
|
||||
for (let h of resultHeroes) {
|
||||
let result = new GachaResult(contentId);
|
||||
result.setHero(h.hid, 1);
|
||||
resultList.push(result);
|
||||
}
|
||||
for (let g of goods) {
|
||||
let result = new GachaResult(contentId);
|
||||
result.setHero(hero, 1);
|
||||
result.transferToPiece(g.id, g.count);
|
||||
resultList.push(result);
|
||||
}
|
||||
// 给东西
|
||||
// console.log('****', heroInfo)
|
||||
let { heroes, resultHeroes } = await createHeroes(roleId, roleName, sid, serverId, heroInfo);
|
||||
await addItems(roleId, roleName, sid, items, ITEM_CHANGE_REASON.GACHA_ITEMS);
|
||||
// 更新数据
|
||||
await UserGachaRecModel.createRec(roleId, gachaId, 0, count, resultList);
|
||||
|
||||
// 记录
|
||||
let myTurntable = turntable.find(cur => cur.quality == quality);
|
||||
@@ -235,13 +227,13 @@ export class GachaHandler {
|
||||
const { gachaId, activityId = 0, pickHero } = msg;
|
||||
const roleId: string = session.get('roleId');
|
||||
const serverId: number = session.get('serverId');
|
||||
if (gachaId != GACHA_ID.ASSIGN && gachaId != GACHA_ID.TIMELIMIT)
|
||||
if (gachaId != GACHA_TYPE.ASSIGN && gachaId != GACHA_TYPE.ACTIVITY)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
let dicHero = gameData.hero.get(pickHero);
|
||||
if (!dicHero) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
|
||||
let heroes: number[] = [];
|
||||
if (gachaId == GACHA_ID.TIMELIMIT) {
|
||||
if (gachaId == GACHA_TYPE.ACTIVITY) {
|
||||
let activityData = await getActivityById(activityId);
|
||||
if (!activityData) return resResult(STATUS.ACTIVITY_MISSING);
|
||||
|
||||
@@ -299,7 +291,7 @@ export class GachaHandler {
|
||||
if (index == -1) return resResult(STATUS.GACHA_CAN_NOT_PICK);
|
||||
let { pieceId } = dicHero;
|
||||
|
||||
let { visitedHero, refVisitedTime } = await UserGachaModel.findByRole(roleId, GACHA_ID.NORMAL, 0);
|
||||
let { visitedHero, refVisitedTime } = await UserGachaModel.findByRole(roleId, GACHA_TYPE.NORMAL, 0);
|
||||
if (shouldRefresh(refVisitedTime, new Date())) {
|
||||
visitedHero = [];
|
||||
refVisitedTime = getZeroPointD();
|
||||
@@ -312,7 +304,7 @@ export class GachaHandler {
|
||||
}
|
||||
|
||||
visitedHero.push(hid);
|
||||
let userGacha = await UserGachaModel.updateInfo(roleId, GACHA_ID.NORMAL, 0, { visitedHero, refVisitedTime });
|
||||
let userGacha = await UserGachaModel.updateInfo(roleId, GACHA_TYPE.NORMAL, 0, { visitedHero, refVisitedTime });
|
||||
let goods = await addItems(roleId, roleName, sid, [{ id: pieceId, count: RECRUIT.RECRUIT_SHARD_LIMIT }], ITEM_CHANGE_REASON.VISIT_HERO);
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
@@ -333,7 +325,7 @@ export class GachaHandler {
|
||||
let { gachaHasGuide } = await RoleModel.findByRoleId(roleId, 'gachaHasGuide');
|
||||
let guideCount = 0, guideResultList = [], candidates = [];
|
||||
if(!gachaHasGuide) {
|
||||
const userGacha = await UserGachaModel.findByRole(roleId, GACHA_ID.NORMAL);
|
||||
const userGacha = await UserGachaModel.findByRole(roleId, GACHA_TYPE.NORMAL);
|
||||
({ guideCount = 0, guideResultList = [], candidates = [] } = userGacha);
|
||||
}
|
||||
|
||||
@@ -354,11 +346,11 @@ export class GachaHandler {
|
||||
const { } = msg;
|
||||
const roleId: string = session.get('roleId');
|
||||
const sid: string = session.get('sid');
|
||||
const gachaId = GACHA_ID.NORMAL;
|
||||
const count = 10;
|
||||
const gachaId = getGuideGachaId();
|
||||
const dicGacha = gameData.gacha.get(gachaId);
|
||||
|
||||
let userGacha = await UserGachaModel.findByRole(roleId, GACHA_ID.NORMAL);
|
||||
let userGacha = await UserGachaModel.findByRole(roleId, GACHA_TYPE.NORMAL);
|
||||
let { guideCount = 0 } = userGacha;
|
||||
if(guideCount >= RECRUIT.RECRUIT_FIRST_RECRUIT) return resResult(STATUS.GACHA_GUIDE_PULL_CNT_LACK);
|
||||
|
||||
@@ -370,8 +362,7 @@ export class GachaHandler {
|
||||
}
|
||||
|
||||
let userHeroes = await HeroModel.findByRole(roleId);
|
||||
let gachaPull = new GachaPull(gachaId);
|
||||
gachaPull.setByUserGacha(dicGacha, userGacha, true);
|
||||
let gachaPull = new GachaPull(dicGacha, userGacha);
|
||||
let { resultList } = gachaPull.pull(count, userHeroes);
|
||||
|
||||
userGacha = await UserGachaModel.updateInfo(roleId, gachaId, 0, { guideResultList: resultList, guideCount: guideCount + 1 })
|
||||
@@ -391,9 +382,9 @@ export class GachaHandler {
|
||||
async saveToCandidates(msg: { id: number }, session: BackendSession) {
|
||||
const { id } = msg;
|
||||
const roleId: string = session.get('roleId');
|
||||
const gachaId = GACHA_ID.NORMAL;
|
||||
const gachaId = getGuideGachaId();
|
||||
|
||||
let userGacha = await UserGachaModel.findByRole(roleId, GACHA_ID.NORMAL);
|
||||
let userGacha = await UserGachaModel.findByRole(roleId, gachaId);
|
||||
let { guideResultList, candidates = [], guideCount } = userGacha;
|
||||
|
||||
let index = candidates.findIndex(cur => cur.id == id);
|
||||
@@ -425,17 +416,18 @@ export class GachaHandler {
|
||||
const roleName: string = session.get('roleName');
|
||||
const serverId: number = session.get('serverId');
|
||||
const sid: string = session.get('sid');
|
||||
const gachaId = GACHA_ID.NORMAL;
|
||||
const count = 10;
|
||||
const gachaId = getGuideGachaId();
|
||||
const dicGacha = gameData.gacha.get(gachaId);
|
||||
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
if(role.gachaHasGuide) {
|
||||
return resResult(STATUS.GACHA_GUIDE_HAS_DONE);
|
||||
}
|
||||
let userGacha = await UserGachaModel.findByRole(roleId, GACHA_ID.NORMAL);
|
||||
let userGacha = await UserGachaModel.findByRole(roleId, gachaId);
|
||||
let { guideResultList = [], candidates = [], } = userGacha;
|
||||
|
||||
let simpleResult: { contentId: number, hid: number }[] = []
|
||||
let simpleResult: SimpleResult[] = []
|
||||
if(id == 0) {
|
||||
if(guideResultList.length <= 0) {
|
||||
return resResult(STATUS.GACHA_GUIDE_NOT_DO);
|
||||
@@ -448,8 +440,9 @@ export class GachaHandler {
|
||||
}
|
||||
|
||||
let userHeroes = await HeroModel.findByRole(roleId);
|
||||
let gachaPull = new GachaPull(gachaId);
|
||||
let { items, heroInfo, resultList } = gachaPull.pullBySimpleResult(simpleResult, userHeroes);
|
||||
let results = new GachaResults();
|
||||
results.addBySimpleResult(simpleResult);
|
||||
let { items, heroInfo, resultList } = results.transferToFinalResult(userHeroes);
|
||||
|
||||
userGacha = await UserGachaModel.updateInfo(roleId, gachaId, 0, { guideResultCount: count });
|
||||
|
||||
@@ -462,7 +455,7 @@ export class GachaHandler {
|
||||
await UserGachaRecModel.createRec(roleId, gachaId, 0, count, resultList);
|
||||
|
||||
// 任务
|
||||
await checkTaskInGacha(serverId, roleId, sid, count, resultHeroes, resultList, true);
|
||||
if(dicGacha.isTask) await checkTaskInGacha(serverId, roleId, sid, count, resultHeroes, resultList, true);
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
hasInit: !!role.gachaHasGuide,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Application, BackendSession, HandlerService, } from 'pinus';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
import { STATUS, GACHA_ID, ITEM_CHANGE_REASON } from '../../../consts';
|
||||
import { STATUS, GACHA_TYPE, ITEM_CHANGE_REASON } from '../../../consts';
|
||||
import { getPlayerNewHeroGachaData } from '../../../services/activity/newHeroGachaService';
|
||||
import { RoleModel } from '../../../db/Role';
|
||||
import { HeroModel } from '../../../db/Hero';
|
||||
@@ -62,50 +62,50 @@ export class NewHeroGachaHandler {
|
||||
* @param {BackendSession} session
|
||||
* @memberof NewHeroGachaHandler
|
||||
*/
|
||||
async pull(msg: { activityId: number, hid: number, count: number }, session: BackendSession) {
|
||||
const { activityId, hid, count } = msg;
|
||||
const roleId = session.get('roleId');
|
||||
const serverId = session.get('serverId');
|
||||
const sid = session.get('sid');
|
||||
const roleName = session.get('roleName');
|
||||
// async pull(msg: { activityId: number, hid: number, count: number }, session: BackendSession) {
|
||||
// const { activityId, hid, count } = msg;
|
||||
// const roleId = session.get('roleId');
|
||||
// const serverId = session.get('serverId');
|
||||
// const sid = session.get('sid');
|
||||
// const roleName = session.get('roleName');
|
||||
|
||||
if(count < 0) return resResult(STATUS.WRONG_PARMS);
|
||||
// if(count < 0) return resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
let playerData = await getPlayerNewHeroGachaData(activityId, serverId, roleId)
|
||||
if (!playerData) return resResult(STATUS.ACTIVITY_MISSING);
|
||||
// let playerData = await getPlayerNewHeroGachaData(activityId, serverId, roleId)
|
||||
// if (!playerData) return resResult(STATUS.ACTIVITY_MISSING);
|
||||
|
||||
let item = playerData.findItem(hid);
|
||||
if (!item) {
|
||||
return resResult(STATUS.ACTIVITY_DATA_ERROR);
|
||||
}
|
||||
// let item = playerData.findItem(hid);
|
||||
// if (!item) {
|
||||
// return resResult(STATUS.ACTIVITY_DATA_ERROR);
|
||||
// }
|
||||
|
||||
let userHeroes = await HeroModel.findByRole(roleId);
|
||||
// let userHeroes = await HeroModel.findByRole(roleId);
|
||||
|
||||
let gachaPull = new GachaPull(GACHA_ID.TIMELIMIT);
|
||||
gachaPull.setByActivity(item);
|
||||
let { items, heroInfo, resultList } = gachaPull.pull(count, userHeroes);
|
||||
let { hasGetFloor, floorCount } = gachaPull.getActivityParam();
|
||||
// let gachaPull = new GachaPull(GACHA_TYPE.TIMELIMIT);
|
||||
// gachaPull.setByActivity(item);
|
||||
// let { items, heroInfo, resultList } = gachaPull.pull(count, userHeroes);
|
||||
// let { hasGetFloor, floorCount } = gachaPull.getActivityParam();
|
||||
|
||||
// 消耗东西
|
||||
let cost = item.cost.map(cur => { return { id: cur.id, count: cur.count * count } });
|
||||
let costResult = await handleCost(roleId, sid, cost, ITEM_CHANGE_REASON.NEW_HERO_GACHA_PULL);
|
||||
if (!costResult) return resResult(STATUS.ACTIVITY_RES_NOT_ENOUGH);
|
||||
// // 消耗东西
|
||||
// let cost = item.cost.map(cur => { return { id: cur.id, count: cur.count * count } });
|
||||
// let costResult = await handleCost(roleId, sid, cost, ITEM_CHANGE_REASON.NEW_HERO_GACHA_PULL);
|
||||
// if (!costResult) return resResult(STATUS.ACTIVITY_RES_NOT_ENOUGH);
|
||||
|
||||
//记录数据
|
||||
await ActivityNewHeroGachaModel.addRecord(serverId, activityId, roleId, hid, floorCount, JSON.stringify(resultList), hasGetFloor);
|
||||
// //记录数据
|
||||
// await ActivityNewHeroGachaModel.addRecord(serverId, activityId, roleId, hid, floorCount, JSON.stringify(resultList), hasGetFloor);
|
||||
|
||||
// 给东西
|
||||
let { heroes, resultHeroes } = await createHeroes(roleId, roleName, sid, serverId, heroInfo);
|
||||
await addItems(roleId, roleName, sid, items, ITEM_CHANGE_REASON.GACHA_ITEMS);
|
||||
//固定奖励
|
||||
let rewardParamArr: Array<RewardParam> = stringToRewardParam(item.commonReward);
|
||||
let newRewardParamArr: Array<RewardParam> = rewardParamArr.map(obj => { return { id: obj.id, type: obj.type, count: obj.count * count } });
|
||||
let commonResult = await addReward(roleId, roleName, sid, serverId, newRewardParamArr, ITEM_CHANGE_REASON.NEW_HERO_GACHA_PULL)
|
||||
// // 给东西
|
||||
// let { heroes, resultHeroes } = await createHeroes(roleId, roleName, sid, serverId, heroInfo);
|
||||
// await addItems(roleId, roleName, sid, items, ITEM_CHANGE_REASON.GACHA_ITEMS);
|
||||
// //固定奖励
|
||||
// let rewardParamArr: Array<RewardParam> = stringToRewardParam(item.commonReward);
|
||||
// let newRewardParamArr: Array<RewardParam> = rewardParamArr.map(obj => { return { id: obj.id, type: obj.type, count: obj.count * count } });
|
||||
// let commonResult = await addReward(roleId, roleName, sid, serverId, newRewardParamArr, ITEM_CHANGE_REASON.NEW_HERO_GACHA_PULL)
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
hid, activityId, count, randomReward: { heroes: resultHeroes.map(cur => ({hid: cur.hid})), result: resultList }, commonReward: commonResult
|
||||
// return resResult(STATUS.SUCCESS, {
|
||||
// hid, activityId, count, randomReward: { heroes: resultHeroes.map(cur => ({hid: cur.hid})), result: resultList }, commonReward: commonResult
|
||||
|
||||
});
|
||||
}
|
||||
// });
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
import { GachaData, Floor, GachaResult, Hope, GachaListReturn } from "../../domain/activityField/gachaField";;
|
||||
import { GachaData, Floor as UserFloor, Hope as UserHope, GachaListReturn, GachaResultIndb } from "../../domain/activityField/gachaField";;
|
||||
import { DicGacha } from "../../pubUtils/dictionary/DicGacha";
|
||||
import { UserGachaType, UserGachaModel } from "../../db/UserGacha";
|
||||
import { UserGachaType, UserGachaModel, SimpleResult } from "../../db/UserGacha";
|
||||
import { shouldRefresh, getRandEelm, getRandEelmWithWeight, getRandSingleIndex, getRandSingleEelm } from "../../pubUtils/util";
|
||||
import { REFRESH_TIME, GACHA_TO_FLOOR, GACHA_FLOOR_TYPE, GACHA_CONTENT_TYPE, HERO_QUALITY_TYPE, GACHA_OCCUPY_HID, IT_TYPE, ITID, CONSUME_TYPE, SPECIAL_ATTR, TIME_OUTPUT_TYPE, GACHA_ID } from "../../consts";
|
||||
import { REFRESH_TIME, GACHA_FLOOR_TYPE, HERO_QUALITY_TYPE, IT_TYPE, ITID, CONSUME_TYPE, SPECIAL_ATTR, TIME_OUTPUT_TYPE, GACHA_TYPE, GACHA_PLAN_TYPE } from "../../consts";
|
||||
import { getTimeFunD, getZeroPointD } from "../../pubUtils/timeUtil";
|
||||
import { gameData, getDicGachaFloor, getGachaContentOfHeroQuality } from "../../pubUtils/data";
|
||||
import { RoleModel } from "../../db/Role";
|
||||
import { gameData } from "../../pubUtils/data";
|
||||
import { RewardInter } from "../../pubUtils/interface";
|
||||
import { CreateHeroParam } from "../../domain/roleField/hero";
|
||||
import { HeroType } from "../../db/Hero";
|
||||
import { NewHeroGachaItem } from "../../domain/activityField/newHeroGachaField";
|
||||
import { getActivityById } from "./activityService";
|
||||
import { transPiece } from "../role/util";
|
||||
import { getRoleCreateTime, getServerCreateTime } from "../redisService";
|
||||
@@ -22,7 +20,7 @@ export async function getGachaList(roleId: string) {
|
||||
let userGachaList = await UserGachaModel.findAllByRole(roleId);
|
||||
let list: GachaListReturn[] = [];
|
||||
for (let [id, dicGacha] of gameData.gacha) {
|
||||
if (id == GACHA_ID.TIMELIMIT) continue; // 不包括限时
|
||||
if(!dicGacha.showInMainPage) continue;
|
||||
|
||||
let userGacha = userGachaList.find(cur => cur.gachaId == id);
|
||||
if (userGacha)
|
||||
@@ -53,6 +51,11 @@ export async function getLimitGacha(serverId: number, roleId: string, activityId
|
||||
return gachaData
|
||||
}
|
||||
|
||||
export function getGuideGachaId() {
|
||||
let ids = gameData.gachaByType.get(GACHA_TYPE.GUIDE);
|
||||
return ids[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新免费次数
|
||||
* @param dicGacha
|
||||
@@ -81,7 +84,7 @@ export async function refreshGacha(dicGacha: DicGacha, userGacha: UserGachaType)
|
||||
|
||||
export async function getVisitedHeroList(roleId: string) {
|
||||
|
||||
let { visitedHero, refVisitedTime } = await UserGachaModel.findByRole(roleId, GACHA_ID.NORMAL, 0);
|
||||
let { visitedHero, refVisitedTime } = await UserGachaModel.findByRole(roleId, GACHA_TYPE.NORMAL, 0);
|
||||
if (shouldRefresh(refVisitedTime, new Date())) {
|
||||
visitedHero = [];
|
||||
}
|
||||
@@ -91,23 +94,20 @@ export async function getVisitedHeroList(roleId: string) {
|
||||
|
||||
class PlayerGachaRecord {
|
||||
public lv: number; // 玩家等级
|
||||
public hope: Hope[] = []; // 玩家记录的心愿单达成情况
|
||||
public floor: Floor[] = [];
|
||||
public hope: UserHope[] = []; // 玩家记录的心愿单达成情况
|
||||
public floor: UserFloor[] = [];
|
||||
public pickHero: number = 0;
|
||||
|
||||
constructor(userGacha: UserGachaType, item: NewHeroGachaItem) {
|
||||
constructor(userGacha: UserGachaType ) {
|
||||
if(userGacha) {
|
||||
this.floor = userGacha.floor;
|
||||
this.hope = userGacha.hope;
|
||||
this.pickHero = userGacha.pickHero;
|
||||
}
|
||||
if(item) {
|
||||
this.floor.push({ id: GACHA_FLOOR_TYPE.ASSIGN, count: item.count, hasGetFloor: item.hasGetFloor });
|
||||
}
|
||||
}
|
||||
|
||||
public getFloorCountByFloorType(floorType: GACHA_FLOOR_TYPE) {
|
||||
let userFloor = this.floor.find(cur => cur.id == floorType);
|
||||
public getFloorCountById(id: number) {
|
||||
let userFloor = this.floor.find(cur => cur.id == id);
|
||||
if(userFloor) {
|
||||
return { floorCount: userFloor.count, hasGetFloor: userFloor.hasGetFloor }
|
||||
} else {
|
||||
@@ -115,10 +115,10 @@ class PlayerGachaRecord {
|
||||
}
|
||||
}
|
||||
|
||||
public setFloorCount(floorType: GACHA_FLOOR_TYPE, count: number, hasGetFloor: boolean) {
|
||||
let index = this.floor.findIndex(cur => cur.id == floorType);
|
||||
public setFloorCount(id: number, count: number, hasGetFloor: boolean) {
|
||||
let index = this.floor.findIndex(cur => cur.id == id);
|
||||
if(index == -1) {
|
||||
this.floor.push({ id: floorType, count, hasGetFloor })
|
||||
this.floor.push({ id, count, hasGetFloor })
|
||||
} else {
|
||||
this.floor[index].count = count;
|
||||
this.floor[index].hasGetFloor = hasGetFloor;
|
||||
@@ -142,223 +142,113 @@ class PlayerGachaRecord {
|
||||
}
|
||||
}
|
||||
|
||||
class GachaResults {
|
||||
count: number = 0;
|
||||
list: GachaResult[] = [];
|
||||
export class GachaResult {
|
||||
planId: number = 0; // 计划id
|
||||
hid: number = 0; // 武将id
|
||||
isTransfer: boolean = false; // 是否转换为碎片
|
||||
id: number = 0; // 道具id
|
||||
count: number = 0; // 道具数量
|
||||
pickHero: number = 0; // 玩家选择的武将
|
||||
heroQuality: number = 0; // planId对应的武将品质
|
||||
|
||||
addResult(contentId: number, id?: number) {
|
||||
this.count++;
|
||||
this.list.push(new GachaResult(contentId, id));
|
||||
constructor(planId: number) {
|
||||
this.planId = planId;
|
||||
this.heroQuality = gameData.gachaPlanQuality.get(planId);
|
||||
}
|
||||
|
||||
public shouldPurpleFloor(floorCount: number) {
|
||||
return this.count % floorCount == 0 && !this.hasPurple();
|
||||
public changePlan(planId: number, heroQuality: number) {
|
||||
this.planId = planId;
|
||||
this.heroQuality = heroQuality;
|
||||
}
|
||||
|
||||
public hasPurple() {
|
||||
return this.list.findIndex(gachaResult => this.checkContentIsHero(gachaResult.contentId, HERO_QUALITY_TYPE.PURPLE)) != -1;
|
||||
public isTarget(floor: GachaFloor) {
|
||||
return floor.heroQuality == this.heroQuality;
|
||||
}
|
||||
|
||||
private checkContentIsHero(contentId: number, quality: HERO_QUALITY_TYPE) {
|
||||
let {type, param} = gameData.gachaContent.get(contentId);
|
||||
return type == GACHA_CONTENT_TYPE.HERO && param[0] >= quality;
|
||||
public setHero(hid: number, count: number) {
|
||||
this.hid = hid;
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
public getRandItemNotPurple() {
|
||||
let indexes = this.filterIndex(item => {
|
||||
return !this.checkContentIsHero(item.contentId, HERO_QUALITY_TYPE.PURPLE);
|
||||
});
|
||||
let index = getRandSingleEelm(indexes);
|
||||
return this.list[index];
|
||||
}
|
||||
|
||||
|
||||
private filterIndex(callback: (item: GachaResult) => boolean) {
|
||||
let result: number[] = [];
|
||||
for(let i = 0; i < this.list.length; i++) {
|
||||
if(callback(this.list[i])) {
|
||||
result.push(i);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
public setItem(id: number, count: number) {
|
||||
this.id = id;
|
||||
if(count) this.count = count;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 抽卡方法
|
||||
*/
|
||||
export class GachaPull {
|
||||
private gachaType: GACHA_ID; // 抽卡类型
|
||||
// 字典
|
||||
private dicFloor: Map<GACHA_FLOOR_TYPE, number> = new Map(); // 保底次数
|
||||
private percent: { id: number, weight: number, goodId?: number }[] = [];
|
||||
private bigReward: { id: number, weight: number, goodId?: number }; // 保底的一项,percent中的一项
|
||||
// 玩家数据
|
||||
private player: PlayerGachaRecord;
|
||||
// 结果
|
||||
private result = new GachaResults();
|
||||
export class GachaResults {
|
||||
count: number = 0;
|
||||
list: GachaResult[] = [];
|
||||
|
||||
constructor(gachaType: GACHA_ID, ) {
|
||||
this.gachaType = gachaType;
|
||||
public addPlan(planId: number) {
|
||||
this.count++;
|
||||
this.list.push(new GachaResult(planId));
|
||||
}
|
||||
|
||||
// 一般抽卡setter
|
||||
public setByUserGacha(dicGacha: DicGacha, userGacha: UserGachaType, isGuide: boolean) {
|
||||
// 字典方面
|
||||
this.percent = dicGacha.percent;
|
||||
if (dicGacha.floorReward > 0) {
|
||||
this.bigReward = this.percent[dicGacha.floorReward - 1];
|
||||
}
|
||||
if(!isGuide) this.setDicFloor();
|
||||
// 玩家数据
|
||||
this.player = new PlayerGachaRecord(userGacha, null);
|
||||
}
|
||||
|
||||
private setDicFloor() {
|
||||
let dicFloor = GACHA_TO_FLOOR.get(this.gachaType)||[];
|
||||
for(let id of dicFloor) {
|
||||
this.dicFloor.set(id, getDicGachaFloor(id));
|
||||
public addBySimpleResult(simpleResult: SimpleResult[]) {
|
||||
for(let { planId, hid } of simpleResult) {
|
||||
let gachaResult = new GachaResult(planId);
|
||||
gachaResult.setHero(hid, 1);
|
||||
this.list.push(gachaResult);
|
||||
}
|
||||
}
|
||||
|
||||
// 新武将活动setter
|
||||
public setByActivity(item: NewHeroGachaItem) {
|
||||
this.percent = item.percent;
|
||||
if (item.floorReward >= 0) {
|
||||
this.bigReward = item.percent[item.floorReward]
|
||||
}
|
||||
this.dicFloor.set(GACHA_FLOOR_TYPE.ASSIGN, item.floorCount);
|
||||
this.player = new PlayerGachaRecord(null, item);
|
||||
public getTargetCnt(floor: GachaFloor) {
|
||||
return this.getTarget(floor).length;
|
||||
}
|
||||
|
||||
|
||||
public pull(count: number, userHeroes: HeroType[]) {
|
||||
this.pullContent(count);
|
||||
this.processFloors();
|
||||
this.processDetail();
|
||||
this.processHope();
|
||||
let { heroInfo, items, resultList } = this.getFinalResult(userHeroes)
|
||||
return { resultList, heroInfo, items };
|
||||
public getRandomResultOfTarget(floor: GachaFloor, cnt: number) {
|
||||
return getRandEelm(this.getTarget(floor), cnt);
|
||||
}
|
||||
|
||||
// 根据基础的percent抽基地
|
||||
private pullContent(count: number) {
|
||||
for (let i = 0; i < count; i++) {
|
||||
// 按照一般概率抽出
|
||||
let { dic } = getRandEelmWithWeight(this.percent);
|
||||
if(dic) this.result.addResult(dic.id, dic.goodId);
|
||||
}
|
||||
}
|
||||
|
||||
// 保底
|
||||
private processFloors() {
|
||||
for(let [id, floorCount] of this.dicFloor) {
|
||||
switch(id) {
|
||||
case GACHA_FLOOR_TYPE.PURPLE:
|
||||
this.setPurpleFloor(floorCount);
|
||||
break;
|
||||
case GACHA_FLOOR_TYPE.GOLD:
|
||||
this.setGoldFloor(floorCount);
|
||||
break;
|
||||
case GACHA_FLOOR_TYPE.ASSIGN:
|
||||
this.setAssignFloor(floorCount);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 紫将保底,10连抽必出一个紫将
|
||||
private setPurpleFloor(floorCount: number) {
|
||||
if(this.result.shouldPurpleFloor(floorCount)) {
|
||||
let item = this.result.getRandItemNotPurple();
|
||||
item.setContentId(getGachaContentOfHeroQuality(HERO_QUALITY_TYPE.PURPLE));
|
||||
}
|
||||
}
|
||||
|
||||
// 元宝招募保底,金将保底,按次数给保底,抽到就重新计算次数,单抽也算
|
||||
public setGoldFloor(dicFloorCount: number) {
|
||||
let floorType = GACHA_FLOOR_TYPE.GOLD;
|
||||
let { floorCount: historyCount } = this.player.getFloorCountByFloorType(floorType);
|
||||
for(let gachaResult of this.result.list) {
|
||||
let isTarget = this.bigReward.id == gachaResult.contentId;
|
||||
if(++historyCount >= dicFloorCount || isTarget) {
|
||||
gachaResult.setContentId(this.bigReward.id, this.bigReward.goodId);
|
||||
historyCount = 0;
|
||||
}
|
||||
}
|
||||
this.player.setFloorCount(floorType, historyCount, false);
|
||||
}
|
||||
|
||||
// 求贤若渴,和活动抽卡金色保底,伪随机,n次内给且只给一个,单抽也算
|
||||
public setAssignFloor(dicFloorCount: number) {
|
||||
let floorType = GACHA_FLOOR_TYPE.ASSIGN;
|
||||
let { floorCount: historyCount, hasGetFloor } = this.player.getFloorCountByFloorType(floorType);
|
||||
for(let gachaResult of this.result.list) {
|
||||
let isTarget = this.bigReward.id == gachaResult.contentId;
|
||||
if(++historyCount >= dicFloorCount || isTarget) {
|
||||
if(hasGetFloor) { // 已经获得过一次保底了, 不给,换个给
|
||||
let notBigReward = this.percent.filter(cur => cur.id != this.bigReward.id);
|
||||
gachaResult.setContentId(notBigReward[0].id, notBigReward[0].goodId);
|
||||
} else {
|
||||
gachaResult.setContentId(this.bigReward.id, this.bigReward.goodId);
|
||||
hasGetFloor = true;
|
||||
}
|
||||
}
|
||||
if(historyCount >= dicFloorCount) {
|
||||
hasGetFloor = false;
|
||||
historyCount = 0;
|
||||
}
|
||||
}
|
||||
this.player.setFloorCount(floorType, historyCount, hasGetFloor);
|
||||
private getTarget(floor: GachaFloor) {
|
||||
return this.list.filter(cur => cur.heroQuality == floor.heroQuality);
|
||||
}
|
||||
|
||||
// 具体的卡池
|
||||
private processDetail() {
|
||||
for(let gachaResult of this.result.list) {
|
||||
let detail = new ContentDetail(gachaResult.contentId, gachaResult.pickHero||this.player.pickHero);
|
||||
let id = detail.getResult();
|
||||
gachaResult.setHidOrGid(id, detail.count);
|
||||
}
|
||||
}
|
||||
public processDetail(pickHero?: number, count?: number) {
|
||||
for(let gachaResult of this.list) {
|
||||
let detail = this.getRandomDetail(gachaResult.planId);
|
||||
if(!detail) continue;
|
||||
|
||||
// 心愿单
|
||||
private processHope() {
|
||||
if(this.gachaType != GACHA_ID.NORMAL) return;
|
||||
for(let gachaResult of this.result.list) {
|
||||
if(gachaResult.contentId != getGachaContentOfHeroQuality(HERO_QUALITY_TYPE.GOLD)) continue; // 只有橙将
|
||||
let { dic: { id: randHopePosition } } = getRandEelmWithWeight(gameData.gachaHope);
|
||||
if(randHopePosition > 0) { // 按玩家设置的心愿单塞
|
||||
let hopeHero = this.player.getHopeHero(randHopePosition)
|
||||
if(hopeHero > 0) gachaResult.setHidOrGid(hopeHero, 1);
|
||||
switch(detail.type) {
|
||||
case GACHA_PLAN_TYPE.HERO:
|
||||
gachaResult.setHero(detail.content, count||1);
|
||||
break;
|
||||
case GACHA_PLAN_TYPE.ASSIGN_HERO:
|
||||
gachaResult.setHero(pickHero, getPickHeroCnt(pickHero));
|
||||
break;
|
||||
case GACHA_PLAN_TYPE.ITEM:
|
||||
gachaResult.setItem(detail.content, detail.count);
|
||||
break;
|
||||
case GACHA_PLAN_TYPE.ASSIGN_ITEM:
|
||||
gachaResult.setItem(getPickHeroPiece(pickHero), detail.count);
|
||||
break;
|
||||
}
|
||||
this.player.setUserHope(gachaResult.hid); // 设置心愿单中了没有
|
||||
}
|
||||
}
|
||||
|
||||
// 创建信息
|
||||
public getFinalResult(userHeroes: HeroType[]) {
|
||||
return this.transferToFinalResult(this.result.list, userHeroes);
|
||||
private getRandomDetail(planId: number) {
|
||||
let details = gameData.gachaPlan.get(planId)||[]
|
||||
let { dic } = getRandEelmWithWeight(details);
|
||||
return dic
|
||||
}
|
||||
|
||||
public pullBySimpleResult(simpleResult: {contentId: number, hid: number }[], userHeroes: HeroType[]) {
|
||||
let results = simpleResult.map(obj => {
|
||||
let gachaResult = new GachaResult(obj.contentId);
|
||||
gachaResult.setHidOrGid(obj.hid, 1);
|
||||
return gachaResult;
|
||||
});
|
||||
|
||||
return this.transferToFinalResult(results, userHeroes);
|
||||
}
|
||||
|
||||
private transferToFinalResult(results: GachaResult[], userHeroes: HeroType[]) {
|
||||
public transferToFinalResult(userHeroes: HeroType[]) {
|
||||
let hids = userHeroes.map(cur => cur.hid);
|
||||
let items: RewardInter[] = [], heroInfo: CreateHeroParam[] = [];
|
||||
let newResult: GachaResult[] = [];
|
||||
for(let result of results) {
|
||||
let cnt = result.hid > 0? result.count: 1;
|
||||
newResult.push(...new Array(cnt).fill(result.copy()));
|
||||
let newResult: GachaResultIndb[] = [];
|
||||
for (let result of this.list) {
|
||||
if (result.hid > 0) {
|
||||
for(let i = 0; i < result.count; i++) {
|
||||
newResult.push(new GachaResultIndb(result));
|
||||
}
|
||||
} else {
|
||||
newResult.push(new GachaResultIndb(result));
|
||||
}
|
||||
}
|
||||
for (let result of newResult) {
|
||||
|
||||
for(let result of newResult) {
|
||||
if (result.hid > 0) {
|
||||
let hasHero = hids.indexOf(result.hid) != -1;
|
||||
if (hasHero) { // 已有转换为碎片
|
||||
@@ -373,84 +263,236 @@ export class GachaPull {
|
||||
items.push({ id: result.id, count: result.count });
|
||||
}
|
||||
}
|
||||
|
||||
return { items, heroInfo, resultList: newResult }
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
class GachaPlan {
|
||||
index: number;
|
||||
planId: number;
|
||||
weight: number;
|
||||
heroQuality: number;
|
||||
|
||||
constructor(planId: number, weight: number, index: number) {
|
||||
this.planId = planId;
|
||||
this.weight = weight;
|
||||
this.index = index;
|
||||
this.heroQuality = gameData.gachaPlanQuality.get(planId);
|
||||
}
|
||||
}
|
||||
|
||||
class GachaPercent {
|
||||
percents: GachaPlan[] = [];
|
||||
|
||||
constructor(percent: { planId: number, weight: number }[]) {
|
||||
for(let i = 1; i <= percent.length; i++) {
|
||||
let { planId, weight } = percent[i - 1];
|
||||
this.percents.push(new GachaPlan(planId, weight, i));
|
||||
}
|
||||
}
|
||||
|
||||
public getRandomPlan() {
|
||||
let { dic } = getRandEelmWithWeight(this.percents);
|
||||
return dic
|
||||
}
|
||||
|
||||
public getReplacePlan(heroQuality: number, isLower: boolean) {
|
||||
// 低一级顺序按 heroQuality: -1 => weight: 1 => index: -1 排序拿最前面那个
|
||||
// 高一级顺序按 heroQuality: 1 => weight: -1 => index: 1 排序最前面那个
|
||||
let arr = this.percents.filter(plan => {
|
||||
return isLower? plan.heroQuality < heroQuality: plan.heroQuality > heroQuality;
|
||||
}).sort((a, b) => {
|
||||
if(a.heroQuality != b.heroQuality) {
|
||||
return isLower? b.heroQuality - a.heroQuality: a.heroQuality - b.heroQuality;
|
||||
} else if(a.weight != b.weight) {
|
||||
return isLower? a.weight - b.weight: b.weight - a.weight;
|
||||
} else {
|
||||
return isLower? b.index - a.index: a.index - b.index;
|
||||
}
|
||||
});
|
||||
return arr[0];
|
||||
}
|
||||
|
||||
public getFloorTarget(heroQuality: number) {
|
||||
let arr = this.percents.filter(plan => plan.heroQuality == heroQuality).sort((a, b) => {
|
||||
if(a.weight != b.weight) {
|
||||
return a.weight - b.weight;
|
||||
} else {
|
||||
return b.index - a.index;
|
||||
}
|
||||
});
|
||||
return arr[0];
|
||||
}
|
||||
}
|
||||
|
||||
class GachaFloor {
|
||||
id: number;
|
||||
floorType: GACHA_FLOOR_TYPE;
|
||||
heroQuality: number;
|
||||
param: number;
|
||||
|
||||
constructor(id: number) {
|
||||
let dicGachaFloor = gameData.gachaFloor.get(id);
|
||||
if(dicGachaFloor) {
|
||||
this.id = dicGachaFloor.id;
|
||||
this.floorType = dicGachaFloor.floorType;
|
||||
this.heroQuality = dicGachaFloor.heroQuality;
|
||||
this.param = dicGachaFloor.param;
|
||||
}
|
||||
}
|
||||
|
||||
isReplaceLower() {
|
||||
return [
|
||||
GACHA_FLOOR_TYPE.MAIN_FLOOR,
|
||||
GACHA_FLOOR_TYPE.ONLY_ONE,
|
||||
GACHA_FLOOR_TYPE.TEN_MOST_LOWER,
|
||||
].indexOf(this.floorType) != -1
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 抽卡方法
|
||||
*/
|
||||
export class GachaPull {
|
||||
private gachaType: GACHA_TYPE; // 抽卡类型
|
||||
// 字典
|
||||
private floors: GachaFloor[] = []; // 保底次数
|
||||
private percent: GachaPercent;
|
||||
// 玩家数据
|
||||
private player: PlayerGachaRecord;
|
||||
// 结果
|
||||
private result = new GachaResults();
|
||||
|
||||
constructor(dicGacha: DicGacha, userGacha: UserGachaType) {
|
||||
this.gachaType = dicGacha.gachaType;
|
||||
this.percent = new GachaPercent(dicGacha.percent);
|
||||
this.player = new PlayerGachaRecord(userGacha);
|
||||
for(let id of dicGacha.floor) {
|
||||
let floor = new GachaFloor(id);
|
||||
if(floor && floor.id) this.floors.push(floor);
|
||||
}
|
||||
}
|
||||
|
||||
public pull(count: number, userHeroes: HeroType[]) {
|
||||
this.pullContent(count);
|
||||
this.processFloors();
|
||||
this.result.processDetail(this.player.pickHero);
|
||||
this.processHope();
|
||||
let { heroInfo, items, resultList } = this.getFinalResult(userHeroes)
|
||||
return { resultList, heroInfo, items };
|
||||
}
|
||||
|
||||
// 根据基础的percent抽基地
|
||||
private pullContent(count: number) {
|
||||
for (let i = 0; i < count; i++) {
|
||||
// 按照一般概率抽出
|
||||
let dic = this.percent.getRandomPlan();
|
||||
if(dic) this.result.addPlan(dic.planId);
|
||||
}
|
||||
}
|
||||
|
||||
// 保底
|
||||
private processFloors() {
|
||||
for(let floor of this.floors) {
|
||||
switch(floor.floorType) {
|
||||
case GACHA_FLOOR_TYPE.MAIN_FLOOR:
|
||||
this.setMainFloor(floor);
|
||||
break;
|
||||
case GACHA_FLOOR_TYPE.ONLY_ONE:
|
||||
this.setAssignFloor(floor);
|
||||
break;
|
||||
case GACHA_FLOOR_TYPE.TEN_MOST_HIGHER:
|
||||
case GACHA_FLOOR_TYPE.TEN_MOST_LOWER:
|
||||
this.setTenMostFloor(floor);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 元宝招募保底,金将保底,按次数给保底,抽到就重新计算次数,单抽也算
|
||||
private setMainFloor(floor: GachaFloor) {
|
||||
let { floorCount: historyCount } = this.player.getFloorCountById(floor.id);
|
||||
for(let gachaResult of this.result.list) {
|
||||
if(++historyCount >= floor.param || gachaResult.isTarget(floor)) {
|
||||
let replacePlan = this.percent.getFloorTarget(floor.heroQuality);
|
||||
if(replacePlan) gachaResult.changePlan(replacePlan.planId, replacePlan.heroQuality);
|
||||
historyCount = 0;
|
||||
}
|
||||
}
|
||||
this.player.setFloorCount(floor.id, historyCount, false);
|
||||
}
|
||||
|
||||
// 求贤若渴,和活动抽卡金色保底,伪随机,n次内给且只给一个,单抽也算
|
||||
public setAssignFloor(floor: GachaFloor) {
|
||||
let { floorCount: historyCount, hasGetFloor } = this.player.getFloorCountById(floor.id);
|
||||
for(let gachaResult of this.result.list) {
|
||||
if(++historyCount >= floor.param || gachaResult.isTarget(floor)) {
|
||||
if(hasGetFloor) { // 已经获得过一次保底了, 不给,换个给
|
||||
let replacePlan = this.percent.getReplacePlan(gachaResult.heroQuality, floor.isReplaceLower());
|
||||
if(replacePlan) gachaResult.changePlan(replacePlan.planId, replacePlan.heroQuality);
|
||||
} else { // 设置为保底
|
||||
let replacePlan = this.percent.getFloorTarget(floor.heroQuality);
|
||||
if(replacePlan) gachaResult.changePlan(replacePlan.planId, replacePlan.heroQuality);
|
||||
hasGetFloor = true;
|
||||
}
|
||||
}
|
||||
if(historyCount >= floor.param) {
|
||||
hasGetFloor = false;
|
||||
historyCount = 0;
|
||||
}
|
||||
}
|
||||
this.player.setFloorCount(floor.id, historyCount, hasGetFloor);
|
||||
}
|
||||
|
||||
|
||||
// 10连最多多少个武将
|
||||
private setTenMostFloor(floor: GachaFloor) {
|
||||
let targetCnt = this.result.getTargetCnt(floor);
|
||||
if(this.result.count == 10 && targetCnt >= floor.param) {
|
||||
let gachaResults = this.result.getRandomResultOfTarget(floor, targetCnt - floor.param);
|
||||
for(let gachaResult of gachaResults) {
|
||||
let replacePlan = this.percent.getReplacePlan(gachaResult.heroQuality, floor.isReplaceLower());
|
||||
if(replacePlan) gachaResult.changePlan(replacePlan.planId, replacePlan.heroQuality)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 心愿单
|
||||
private processHope() {
|
||||
if(this.gachaType != GACHA_TYPE.NORMAL) return;
|
||||
for(let gachaResult of this.result.list) {
|
||||
if(gachaResult.heroQuality != HERO_QUALITY_TYPE.GOLD) continue; // 只有橙将
|
||||
let { dic: { id: randHopePosition } } = getRandEelmWithWeight(gameData.gachaHope);
|
||||
if(randHopePosition > 0) { // 按玩家设置的心愿单塞
|
||||
let hopeHero = this.player.getHopeHero(randHopePosition)
|
||||
if(hopeHero > 0) gachaResult.setHero(hopeHero, 1);
|
||||
}
|
||||
this.player.setUserHope(gachaResult.hid); // 设置心愿单中了没有
|
||||
}
|
||||
}
|
||||
|
||||
// 创建信息
|
||||
public getFinalResult(userHeroes: HeroType[]) {
|
||||
return this.result.transferToFinalResult(userHeroes);
|
||||
}
|
||||
|
||||
// 获得需要储存的数据
|
||||
// 一般抽卡getter
|
||||
public getUserGachaParam() {
|
||||
return this.player.getUserGachaParam()
|
||||
}
|
||||
// 活动getter
|
||||
public getActivityParam() {
|
||||
let { hasGetFloor, floorCount } = this.player.getFloorCountByFloorType(GACHA_FLOOR_TYPE.ASSIGN);
|
||||
return { hasGetFloor, floorCount };
|
||||
|
||||
public clear() {
|
||||
this.floors = undefined;
|
||||
this.percent = undefined;
|
||||
this.player = undefined;
|
||||
this.result = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
class ContentDetail {
|
||||
contentId: number;
|
||||
type: number;
|
||||
count: number;
|
||||
param: number[];
|
||||
pickHero: number;
|
||||
|
||||
constructor(contentId: number, pickHero: number) {
|
||||
this.contentId = contentId;
|
||||
let dicGachaContet = gameData.gachaContent.get(contentId);
|
||||
this.type = dicGachaContet.type;
|
||||
this.count = dicGachaContet.count;
|
||||
this.param = dicGachaContet.param;
|
||||
this.pickHero = pickHero;
|
||||
}
|
||||
|
||||
public getResult() {
|
||||
let { type } = gameData.gachaContent.get(this.contentId);
|
||||
switch(type) {
|
||||
case GACHA_CONTENT_TYPE.HERO:
|
||||
return this.randomHeroByQuality(this.param[0]);
|
||||
case GACHA_CONTENT_TYPE.HERO_PIECE:
|
||||
return this.randomHeroPieceByQuality(this.param[0]);
|
||||
case GACHA_CONTENT_TYPE.STONE:
|
||||
return this.randomStoneByLv(this.param[0]);
|
||||
case GACHA_CONTENT_TYPE.ITEMS:
|
||||
return getRandSingleEelm(this.param);
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
private randomHeroByQuality(quality: number) {
|
||||
if(quality == 0) {
|
||||
this.setPickHeroCnt();
|
||||
return this.pickHero;
|
||||
}
|
||||
|
||||
let heroes = getAllHeroByQuality(quality);
|
||||
return getRandSingleEelm(heroes);
|
||||
}
|
||||
|
||||
private setPickHeroCnt() {
|
||||
if(this.pickHero && gameData.hero.has(this.pickHero)) {
|
||||
let dicHero = gameData.hero.get(this.pickHero);
|
||||
this.count = gameData.gachaPickHeroCnt.get(dicHero.quality)??1;
|
||||
}
|
||||
}
|
||||
|
||||
private randomHeroPieceByQuality(quality: number) {
|
||||
let pieces = getAllItemByQuality(IT_TYPE.HERO_PIECE, quality);
|
||||
return getRandSingleEelm(pieces);
|
||||
}
|
||||
|
||||
|
||||
private randomStoneByLv(lv: number) {
|
||||
let stones = getAllStoneByLv(lv);
|
||||
return getRandSingleEelm(stones);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据品质获得武将池
|
||||
* @param quality 品质
|
||||
@@ -473,22 +515,32 @@ export function getAllHeroByQuality(quality: number) {
|
||||
return allHero;
|
||||
}
|
||||
|
||||
export function getAllItemByQuality(itid: number, quality: number) {
|
||||
let allPiece: number[] = [];
|
||||
for (let [id, dicGoods] of gameData.goods) {
|
||||
if (dicGoods.itid == itid) {
|
||||
if (quality == 0 || dicGoods.quality == quality) {
|
||||
allPiece.push(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
return allPiece;
|
||||
function getPickHeroCnt(hid: number) {
|
||||
let dicHero = gameData.hero.get(hid);
|
||||
let cnt = gameData.gachaPickHeroCnt.get(dicHero?.quality)||0;
|
||||
return cnt
|
||||
}
|
||||
|
||||
export function getAllStoneByLv(lv: number) {
|
||||
let items: number[] = [];
|
||||
for(let [id, dicStone] of gameData.stone) {
|
||||
if(dicStone.lv == lv) items.push(id);
|
||||
}
|
||||
return items;
|
||||
function getPickHeroPiece(hid: number) {
|
||||
let dicHero = gameData.hero.get(hid);
|
||||
return dicHero?.pieceId??0
|
||||
}
|
||||
|
||||
export function getDicGachaByGachaCnt(dicGacha: DicGacha, historyCount: number) {
|
||||
if(isGachaCntIn(historyCount, dicGacha.gachaCnt.min, dicGacha.gachaCnt.max)) {
|
||||
return dicGacha;
|
||||
}
|
||||
let gachaIds = gameData.gachaByType.get(dicGacha.gachaType);
|
||||
for(let gachaId of gachaIds) {
|
||||
let dicGacha = gameData.gacha.get(gachaId);
|
||||
if(isGachaCntIn(historyCount, dicGacha.gachaCnt.min, dicGacha.gachaCnt.max)) {
|
||||
return dicGacha;
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
function isGachaCntIn(historyCount: number, min: number, max: number) {
|
||||
let nowCnt = historyCount + 1;
|
||||
return min <= nowCnt && (max >= nowCnt || max == -1);
|
||||
}
|
||||
@@ -12,7 +12,7 @@ import { HeroType } from '../../db/Hero';
|
||||
import { pinus } from 'pinus';
|
||||
import { getRandEelm, getRandSingleEelm } from '../../pubUtils/util';
|
||||
import { getAllOnlineRoles } from '../redisService';
|
||||
import { GachaResult } from '../../domain/activityField/gachaField';
|
||||
import { GachaResultIndb } from '../../domain/activityField/gachaField';
|
||||
import { gameData } from '../../pubUtils/data';
|
||||
|
||||
/**
|
||||
@@ -44,7 +44,7 @@ export async function getPopUpShopDataShow(activityId: number, serverId: number,
|
||||
return null
|
||||
}
|
||||
|
||||
export async function checkPopUpConditionInCreateHero(serverId: number, roleId: string, result: GachaResult[]) {
|
||||
export async function checkPopUpConditionInCreateHero(serverId: number, roleId: string, result: GachaResultIndb[]) {
|
||||
let conditions = result.map(gachaResult => {
|
||||
let dicHero = gameData.hero.get(gachaResult?.hid);
|
||||
return { conditionType: POP_UP_SHOP_CONDITION_TYPE.GET_HERO_BY_QUALITY, param: { quality: dicHero?.quality } };
|
||||
|
||||
@@ -19,7 +19,7 @@ import { JewelType } from '../../db/Jewel';
|
||||
import { checkPopUpCondition, checkPopUpConditionInCreateHero, checkPopUpConditionInEntry } from '../activity/popUpShopService';
|
||||
import { sendMessageToUserWithSuc } from '../pushService';
|
||||
import { getGoldId } from '../role/rewardService';
|
||||
import { GachaResult } from '../../domain/activityField/gachaField';
|
||||
import { GachaResultIndb } from '../../domain/activityField/gachaField';
|
||||
|
||||
export async function checkTaskWithRoles(serverId: number, roleId: string, sid: string, taskType: TASK_TYPE, roles: RoleType[]) {
|
||||
for (let role of roles) {
|
||||
@@ -219,7 +219,7 @@ export async function checkTaskInPvpEnd(serverId: number, roleId: string, sid: s
|
||||
}
|
||||
}
|
||||
|
||||
export async function checkTaskInGacha(serverId: number, roleId: string, sid: string, count: number, heroes: HeroType[], result: GachaResult[], isGuide: boolean) {
|
||||
export async function checkTaskInGacha(serverId: number, roleId: string, sid: string, count: number, heroes: HeroType[], result: GachaResultIndb[], isGuide: boolean) {
|
||||
let task = new CheckTask(serverId, roleId);
|
||||
task.setParam(TASK_TYPE.GACHA, { count });
|
||||
task.setParam(TASK_TYPE.GACHA_QUALITY_COUNT, { heroes });
|
||||
|
||||
@@ -3,7 +3,7 @@ import 'mocha';
|
||||
import { PinusWSClient } from 'pinus-robot-plugin';
|
||||
import { expect } from 'chai';
|
||||
import { checkSuccessResponse, checkDisplayItems, checkHero, addItem } from './CheckPatten';
|
||||
import { GACHA_ID } from '../../shared/consts';
|
||||
import { GACHA_TYPE } from '../../shared/consts';
|
||||
|
||||
|
||||
describe('抽卡测试', function () {
|
||||
@@ -40,12 +40,12 @@ describe('抽卡测试', function () {
|
||||
expect(gacha.refFreeTime).to.be.a('number');
|
||||
expect(gacha.count).to.be.a('number');
|
||||
checkFloor(gacha.floor);
|
||||
if(gacha.gachaId == GACHA_ID.NORMAL) {
|
||||
if(gacha.gachaId == GACHA_TYPE.NORMAL) {
|
||||
checkHope(gacha.hope);
|
||||
expect(gacha.point).to.be.a('number');
|
||||
checkTurntable(gacha.turntable);
|
||||
}
|
||||
if(gacha.gachaId == GACHA_ID.ASSIGN) {
|
||||
if(gacha.gachaId == GACHA_TYPE.ASSIGN) {
|
||||
expect(gacha.pickHero).to.be.a('number');
|
||||
}
|
||||
});
|
||||
@@ -54,27 +54,27 @@ describe('抽卡测试', function () {
|
||||
});
|
||||
|
||||
it('检查元宝招募', function (done) {
|
||||
let gachaId = GACHA_ID.ASSIGN;
|
||||
let gachaId = GACHA_TYPE.ASSIGN;
|
||||
let hid1 = 1, hid2 = 2;
|
||||
checkSetHope(pinusClient, gachaId, hid1, hid2, function(res) {
|
||||
addItem(pinusClient, 22001, 10, function(res) {
|
||||
checkPull(pinusClient, done, GACHA_ID.NORMAL, 0, 10);
|
||||
checkPull(pinusClient, done, GACHA_TYPE.NORMAL, 0, 10);
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
it('检查友情点招募', function (done) {
|
||||
addItem(pinusClient, 40003, 1000, function(res) {
|
||||
checkPull(pinusClient, done, GACHA_ID.FRDPOINT, 0, 10);
|
||||
checkPull(pinusClient, done, GACHA_TYPE.FRDPOINT, 0, 10);
|
||||
});
|
||||
});
|
||||
|
||||
it('检查求贤若渴招募', function (done) {
|
||||
let gachaId = GACHA_ID.ASSIGN;
|
||||
let gachaId = GACHA_TYPE.ASSIGN;
|
||||
let pickHero = 1;
|
||||
addItem(pinusClient, 22002, 10, function(res) {
|
||||
checkSetPickHero(pinusClient, gachaId, 0, pickHero, (res) => {
|
||||
checkPull(pinusClient, done, GACHA_ID.ASSIGN, 0, 5);
|
||||
checkPull(pinusClient, done, GACHA_TYPE.ASSIGN, 0, 5);
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
@@ -494,7 +494,8 @@ export const FILENAME = {
|
||||
DIC_TASK_BOX: 'dic_zyz_taskBox',
|
||||
DIC_ACHIEVEMENT_BOX: 'dic_zyz_achievementBox',
|
||||
DIC_GACHA: 'dic_zyz_gacha',
|
||||
DIC_GACHA_CONTENT: 'dic_zyz_recruitContent',
|
||||
DIC_GACHA_PLAN: 'dic_zyz_gachaPlan',
|
||||
DIC_GACHA_FLOOR: 'dic_zyz_gachaFloor',
|
||||
DIC_GIFT_PACKAGE: 'dic_zyz_giftPackage',
|
||||
DIC_RECRUIT: 'dic_zyz_recruit',
|
||||
DIC_RMB: 'dic_zyz_rmb',
|
||||
@@ -757,40 +758,28 @@ export enum TASK_SUM_TYPE {
|
||||
}
|
||||
|
||||
// 卡池类型
|
||||
export enum GACHA_ID {
|
||||
NORMAL = 1, // 元宝招募
|
||||
FRDPOINT = 2, // 友情点
|
||||
ASSIGN = 3, // 指定卡池
|
||||
TIMELIMIT = 4, // 限时
|
||||
export enum GACHA_TYPE {
|
||||
NORMAL = 1, // 元宝招募
|
||||
FRDPOINT = 2, // 友情点
|
||||
ASSIGN = 3, // 指定卡池
|
||||
GUIDE = 4, // 限时
|
||||
ACTIVITY = 5, // 新武将活动
|
||||
}
|
||||
|
||||
export enum GACHA_PLAN_TYPE {
|
||||
HERO = 1, // 武将
|
||||
ASSIGN_HERO = 2, // 指定武将
|
||||
ASSIGN_ITEM = 3, // 指定武将
|
||||
ITEM = 4, // 武将碎片
|
||||
}
|
||||
|
||||
// 抽卡保底类型
|
||||
export enum GACHA_FLOOR_TYPE {
|
||||
PURPLE = 1, // 紫色保底,10连必定会出一个紫的,单抽不算
|
||||
GOLD = 2, // 金色武将保底,按次数给保底,抽到就重新计算次数,单抽也算
|
||||
ASSIGN = 3, // 求贤若渴,和活动抽卡金色保底,伪随机,n次内给且只给一个,单抽也算
|
||||
MAIN_FLOOR = 1, // 主要保底, 每 param 次必得 1个目标物,获得之后次数重计(如当前的元宝招募)
|
||||
ONLY_ONE = 2, // 每 param 次有且仅有1次目标物(如当前的求贤若渴)
|
||||
TEN_MOST_HIGHER = 3, // 每次10连最多获得 param 个目标物(不计单抽)向上替换(如:蓝色不超过9个=紫色保底)
|
||||
TEN_MOST_LOWER = 4, // 每次10连最多获得 param 个目标物(不计单抽)向下替换 (如:橙色不超过3个)
|
||||
}
|
||||
|
||||
// 抽卡对应保底类型
|
||||
export const GACHA_TO_FLOOR = new Map([
|
||||
[GACHA_ID.NORMAL, [GACHA_FLOOR_TYPE.PURPLE, GACHA_FLOOR_TYPE.GOLD]],
|
||||
[GACHA_ID.FRDPOINT, []],
|
||||
[GACHA_ID.ASSIGN, [GACHA_FLOOR_TYPE.ASSIGN]],
|
||||
[GACHA_ID.TIMELIMIT, [GACHA_FLOOR_TYPE.ASSIGN]]
|
||||
])
|
||||
|
||||
// 抽卡里的卡池道具类型
|
||||
export enum GACHA_CONTENT_TYPE {
|
||||
HERO = 1, // 武将 param为武将品质
|
||||
HERO_PIECE = 2, // 武将碎片 武将品质
|
||||
// BLUEPRT = 3, // 藏宝图 藏宝图品质
|
||||
STONE = 4, // 宝石 宝石等级
|
||||
ITEMS = 5, // 物品id
|
||||
// SUIT_PAPER = 6, // 套装图纸
|
||||
}
|
||||
|
||||
export const GACHA_OCCUPY_HID = 9999; // 抽卡里占位的武将
|
||||
|
||||
// 跑马灯显示类型
|
||||
export enum MARQUEE_SHOW_TYPE {
|
||||
ONCE = 1, // 一次性
|
||||
|
||||
@@ -36,9 +36,9 @@ class Turntable {
|
||||
hasGet: boolean; // 是否得到
|
||||
}
|
||||
|
||||
class SimpleResult {
|
||||
export class SimpleResult {
|
||||
@prop({ required: true })
|
||||
contentId: number;
|
||||
planId: number;
|
||||
@prop({ required: true })
|
||||
hid: number;
|
||||
@prop({ required: true })
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType, modelOptions } from '@typegoose/typegoose';
|
||||
import { GachaResult } from '../domain/activityField/gachaField';
|
||||
import { GachaResultIndb } from '../domain/activityField/gachaField';
|
||||
import { genCode } from '../pubUtils/util';
|
||||
|
||||
/**
|
||||
@@ -26,10 +26,10 @@ export default class UserGachaRec extends BaseModel {
|
||||
@prop({ required: true, default: 0 })
|
||||
count: number; // 抽卡次数
|
||||
|
||||
@prop({ required: true, type: GachaResult, default: [], _id: false })
|
||||
result: GachaResult[]; // 结果
|
||||
@prop({ required: true, type: GachaResultIndb, default: [], _id: false })
|
||||
result: GachaResultIndb[]; // 结果
|
||||
|
||||
public static async createRec(roleId: string, gachaId: number, activityId: number, count: number, result: GachaResult[]) {
|
||||
public static async createRec(roleId: string, gachaId: number, activityId: number, count: number, result: GachaResultIndb[]) {
|
||||
let code = genCode(8);
|
||||
const rec = await UserGachaRecModel.findOneAndUpdate({ code }, { $set: { roleId, gachaId, activityId, count, result } }, { new: true, upsert: true });
|
||||
return rec;
|
||||
|
||||
@@ -4,9 +4,8 @@ import { prop } from '@typegoose/typegoose';
|
||||
import { UserGachaType } from '../../db/UserGacha';
|
||||
import { getTimeFun } from '../../pubUtils/timeUtil';
|
||||
import { DicGacha } from '../../pubUtils/dictionary/DicGacha';
|
||||
import { GACHA_CONTENT_TYPE, } from '../../consts';
|
||||
import { gameData } from '../../pubUtils/data';
|
||||
import { getFloorStatus } from '../../pubUtils/util';
|
||||
import { getGachaRemainFloor } from '../../pubUtils/util';
|
||||
|
||||
|
||||
// 抽卡数据
|
||||
@@ -85,11 +84,12 @@ export class Turntable {
|
||||
*/
|
||||
export class GachaListReturn {
|
||||
gachaId: number; // dicGacha里的id
|
||||
gachaType: number;
|
||||
freeCount: number = 0; // 免费次数
|
||||
refFreeTime: number = 0; // 免费次数下次刷新时间
|
||||
count: number = 0; // 整体已抽卡次数
|
||||
guideResultCount: number = 0; // 引导已抽卡次数
|
||||
floor: {id: number, count: number}[] = []; // 整体保底
|
||||
remainFloor: number = 0; // 还剩多少次可以保底
|
||||
hope: Hope[] = []; // 心愿单
|
||||
point: number = 0; // 积分
|
||||
turntable: Turntable[] = []; // 转盘记录
|
||||
@@ -97,6 +97,7 @@ export class GachaListReturn {
|
||||
|
||||
constructor(dicGacha: DicGacha, userGacha: UserGachaType) {
|
||||
this.gachaId = dicGacha.id;
|
||||
this.gachaType = dicGacha.gachaType;
|
||||
|
||||
if (userGacha) {
|
||||
this.freeCount = userGacha.freeCount;
|
||||
@@ -105,21 +106,19 @@ export class GachaListReturn {
|
||||
this.refFreeTime = <number>f.getAfterDayWithHour(dicGacha.free.day);
|
||||
}
|
||||
this.count = userGacha.count;
|
||||
this.floor = getFloorStatus(dicGacha.id, userGacha.floor);
|
||||
this.hope = userGacha.hope;
|
||||
this.point = userGacha.point;
|
||||
this.turntable = userGacha.turntable;
|
||||
this.pickHero = userGacha.pickHero;
|
||||
this.guideResultCount = userGacha.guideResultCount||0;
|
||||
} else {
|
||||
this.floor = getFloorStatus(dicGacha.id, []);
|
||||
this.remainFloor = getGachaRemainFloor(this.gachaId, userGacha.floor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class GachaResult {
|
||||
export class GachaResultIndb {
|
||||
@prop({ required: true })
|
||||
contentId: number; // 抽卡内容id
|
||||
planId: number = 0; // 计划id
|
||||
@prop({ required: true })
|
||||
hid: number = 0; // 武将id
|
||||
@prop({ required: true })
|
||||
@@ -128,52 +127,19 @@ export class GachaResult {
|
||||
id: number = 0; // 道具id
|
||||
@prop({ required: true })
|
||||
count: number = 0; // 道具数量
|
||||
pickHero: number = 0;
|
||||
|
||||
constructor(contentId: number, id?: number) {
|
||||
this.contentId = contentId;
|
||||
if(id) this.pickHero = id;
|
||||
constructor(gachaResult: Partial<GachaResultIndb>) {
|
||||
this.planId = gachaResult.planId;
|
||||
this.hid = gachaResult.hid;
|
||||
this.isTransfer = gachaResult.isTransfer;
|
||||
this.id = gachaResult.id;
|
||||
this.count = gachaResult.count;
|
||||
}
|
||||
|
||||
setContentId(contentId: number, id?: number) {
|
||||
this.contentId = contentId;
|
||||
if(id) this.pickHero = id;
|
||||
}
|
||||
|
||||
setHidOrGid(id: number, count: number) {
|
||||
let dicGachaContent = gameData.gachaContent.get(this.contentId);
|
||||
if(!dicGachaContent) return;
|
||||
|
||||
if(dicGachaContent.type == GACHA_CONTENT_TYPE.HERO) {
|
||||
this.setHero(id, count);
|
||||
} else {
|
||||
this.setItem(id, count||dicGachaContent.count);
|
||||
}
|
||||
}
|
||||
|
||||
setHero(hid: number, count: number) {
|
||||
this.hid = hid;
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
setItem(id: number, count: number) {
|
||||
this.id = id;
|
||||
if(count) this.count = count;
|
||||
}
|
||||
|
||||
transferToPiece(id: number, count: number) {
|
||||
this.isTransfer = true;
|
||||
this.id = id;
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
copy() {
|
||||
let result = new GachaResult(this.contentId);
|
||||
result.hid = this.hid;
|
||||
result.isTransfer = this.isTransfer;
|
||||
result.id = this.id;
|
||||
result.count = this.count;
|
||||
result.pickHero = this.pickHero;
|
||||
return result
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ import { dicTower, loadTower } from "./dictionary/DicTower";
|
||||
import { dicTowerTask, loadTowerTask } from "./dictionary/DicTowerTask";
|
||||
import { dicWar, dicWarPvp, dicDailyWarByType, loadWar, dicHeroIdByWar } from "./dictionary/DicWar";
|
||||
import { dicWarJson, loadWarJson } from "./dictionary/DicWarJson";
|
||||
import { AUCTION_TIME, GACHA_CONTENT_TYPE } from "../consts";
|
||||
import { AUCTION_TIME } from "../consts";
|
||||
import { dicFashions, dicFashionsByHeroId, loadFashions } from "./dictionary/DicFashions";
|
||||
import { friendShips, friendShipHidAandIds, loadFriendShip } from "./dictionary/DicFriendShip";
|
||||
import { maxFriendShipLv, dicFriendShipLevelMap, loadFriendShipLevel } from "./dictionary/DicFriendShipLevel";
|
||||
@@ -67,8 +67,9 @@ import { dicRankReward, loadRankReward } from "./dictionary/DicRankReward";
|
||||
import { dicTaskType, taskMap, dicMainTask, dicDailyTask, dicAchievement, loadTask, dicPvpDailyTask } from "./dictionary/DicTask";
|
||||
import { dicMainTaskStage, loadMainTaskStage } from "./dictionary/DicMainTaskStage";
|
||||
import { dicTaskBox, loadTaskBox } from './dictionary/DicTaskBox';
|
||||
import { dicGacha, loadGacha } from "./dictionary/DicGacha";
|
||||
import { dicGachaContent, dicGachaContentHero, loadGachaContent } from "./dictionary/DicGachaContent";
|
||||
import { dicGacha, dicGachaByGachaType, loadGacha } from "./dictionary/DicGacha";
|
||||
import { dicGachaPlan, dicGachaPlanQuality, loadGachaPlan } from "./dictionary/DicGachaPlan";
|
||||
import { dicGachaFloor, loadGachaFloor } from "./dictionary/DicGachaFloor";
|
||||
import { dicGiftPackage, loadGiftPackage } from "./dictionary/DicGiftPackage";
|
||||
import { dicRecruit, loadRecruit } from './dictionary/DicRecruit';
|
||||
import { loadRMB, dicRMB } from './dictionary/DicRMB';
|
||||
@@ -212,10 +213,12 @@ export const gameData = {
|
||||
mainTaskStage: dicMainTaskStage,
|
||||
taskBox: dicTaskBox,
|
||||
gacha: dicGacha,
|
||||
gachaContent: dicGachaContent,
|
||||
gachaContentHero: dicGachaContentHero,
|
||||
gachaByType: dicGachaByGachaType,
|
||||
gachaPlan: dicGachaPlan,
|
||||
gachaPlanQuality: dicGachaPlanQuality,
|
||||
gachaFloor: dicGachaFloor,
|
||||
gachaHope: new Array<{id: number, weight: number}>(),
|
||||
gachaTurntable: new Array<{quality: number, count: number}>(),
|
||||
gachaTurntable: new Array<{quality: number, count: number, planId: number}>(),
|
||||
gachaPickHeroCnt: new Map<number, number>(),
|
||||
heroTransPiece: new Map<number, number>(),
|
||||
giftPackage: dicGiftPackage,
|
||||
@@ -604,13 +607,6 @@ export function getFriendLvByExp(exp: number) {
|
||||
return resultLv;
|
||||
}
|
||||
|
||||
export function getGachaContentOfHeroQuality(quality: number) {
|
||||
for(let [id, { type, param }] of gameData.gachaContent) {
|
||||
if(type == GACHA_CONTENT_TYPE.HERO && param[0] == quality) return id;
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据主公当前经验获得当前等级
|
||||
* @param exp 累积经验
|
||||
@@ -763,7 +759,7 @@ function getGachaHopePercent() {
|
||||
function getGachaTurntablePercent() {
|
||||
let arr = decodeArrayListStr(RECRUIT.RECRUIT_BONUS_HERO_QUANTITY);
|
||||
gameData.gachaTurntable = arr.map(cur => {
|
||||
return { quality: parseInt(cur[0]), count: parseInt(cur[1]) }
|
||||
return { quality: parseInt(cur[0]), count: parseInt(cur[1]), planId: parseInt(cur[2]) }
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1106,7 +1102,8 @@ function loadDatas() {
|
||||
loadMainTaskStage();
|
||||
loadTaskBox();
|
||||
loadGacha();
|
||||
loadGachaContent();
|
||||
loadGachaPlan();
|
||||
loadGachaFloor();
|
||||
loadGiftPackage();
|
||||
loadRecruit();
|
||||
loadRMB();
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
import { readFileAndParse, parseNumberList, parseGoodStr, decodeArrayListStr } from '../util'
|
||||
import { FILENAME } from '../../consts'
|
||||
import { FILENAME, GACHA_TYPE } from '../../consts'
|
||||
import { RewardInter } from '../interface';
|
||||
|
||||
export interface DicGacha {
|
||||
// 抽卡id
|
||||
readonly id: number;
|
||||
// 抽卡类型
|
||||
readonly gachaType: GACHA_TYPE;
|
||||
// 保底类型, dic_zyz_gachaFloor的id
|
||||
readonly floor: number[];
|
||||
// 抽卡次数 1次,10次
|
||||
readonly count: number[];
|
||||
// 免费次数
|
||||
@@ -12,12 +16,17 @@ export interface DicGacha {
|
||||
// 消耗的招募券
|
||||
readonly cost: RewardInter[];
|
||||
// 概率
|
||||
readonly percent: { id: number, weight: number }[];
|
||||
// 哪一个是大奖
|
||||
readonly floorReward: number;
|
||||
readonly percent: { planId: number, weight: number }[];
|
||||
// 是否计入任务
|
||||
readonly isTask: number;
|
||||
// 玩家抽卡次数范围
|
||||
readonly gachaCnt: { min: number, max: number };
|
||||
// 是否显示在主界面
|
||||
readonly showInMainPage: number;
|
||||
}
|
||||
|
||||
export const dicGacha = new Map<number, DicGacha>(); // id => dic
|
||||
export const dicGachaByGachaType = new Map<number, number[]>(); // gachaType => id
|
||||
export function loadGacha() {
|
||||
dicGacha.clear();
|
||||
let arr = readFileAndParse(FILENAME.DIC_GACHA);
|
||||
@@ -25,9 +34,15 @@ export function loadGacha() {
|
||||
arr.forEach(o => {
|
||||
o.count = parseNumberList(o.count);
|
||||
o.free = parseFree(o.free);
|
||||
o.floor = parseNumberList(o.floor);
|
||||
o.cost = parseGoodStr(o.cost);
|
||||
o.percent = parsePercent(o.percent);
|
||||
o.gachaCnt = parseGachaCnt(o.gachaCnt);
|
||||
dicGacha.set(o.id, o);
|
||||
if(!dicGachaByGachaType.has(o.gachaType)) {
|
||||
dicGachaByGachaType.set(o.gachaType, []);
|
||||
}
|
||||
dicGachaByGachaType.get(o.gachaType).push(o.id);
|
||||
});
|
||||
arr = undefined;
|
||||
}
|
||||
@@ -45,14 +60,19 @@ function parseFree(str: string) {
|
||||
}
|
||||
|
||||
function parsePercent(str: string) {
|
||||
let result = new Array<{ id: number, weight: number }>();
|
||||
let result = new Array<{ planId: number, weight: number }>();
|
||||
if (!str) return result;
|
||||
let decodeArr = decodeArrayListStr(str);
|
||||
for (let [id, weight] of decodeArr) {
|
||||
if (isNaN(parseInt(id)) || isNaN(parseInt(weight))) {
|
||||
for (let [planId, weight] of decodeArr) {
|
||||
if (isNaN(parseInt(planId)) || isNaN(parseInt(weight))) {
|
||||
throw new Error('data table format wrong');
|
||||
}
|
||||
result.push({ id: parseInt(id), weight: parseInt(weight) });
|
||||
result.push({ planId: parseInt(planId), weight: parseInt(weight) });
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
function parseGachaCnt(str: string) {
|
||||
let arr = parseNumberList(str);
|
||||
return { min: arr[0]||0, max: arr[1]||-1 }
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
import { readFileAndParse, parseNumberList } from '../util'
|
||||
import { FILENAME, GACHA_CONTENT_TYPE } from '../../consts'
|
||||
|
||||
export interface DicGachaContent {
|
||||
// 内容id
|
||||
readonly id: number;
|
||||
// 道具类型 见sysConst 中的 GACHA_CONTENT_TYPE
|
||||
readonly type: number;
|
||||
// 对应参数 品质,等级,物品id 等
|
||||
readonly param: number[];
|
||||
// 道具数量
|
||||
readonly count: number;
|
||||
}
|
||||
|
||||
export const dicGachaContent = new Map<number, DicGachaContent>(); // id => dic
|
||||
export const dicGachaContentHero = new Map<number, number>(); // quality => dic
|
||||
export function loadGachaContent() {
|
||||
dicGachaContent.clear();
|
||||
dicGachaContentHero.clear();
|
||||
let arr = readFileAndParse(FILENAME.DIC_GACHA_CONTENT);
|
||||
|
||||
arr.forEach(o => {
|
||||
o.param = parseNumberList(o.param);
|
||||
if(o.type == GACHA_CONTENT_TYPE.HERO) {
|
||||
dicGachaContentHero.set(o.param[0], o.id);
|
||||
}
|
||||
dicGachaContent.set(o.id, o);
|
||||
});
|
||||
|
||||
arr = undefined;
|
||||
}
|
||||
25
shared/pubUtils/dictionary/DicGachaFloor.ts
Normal file
25
shared/pubUtils/dictionary/DicGachaFloor.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { readFileAndParse } from '../util';
|
||||
import { GACHA_FLOOR_TYPE, FILENAME } from '../../consts';
|
||||
|
||||
export interface DicGachaFloor {
|
||||
// 保底id
|
||||
readonly id: number;
|
||||
// 类型
|
||||
readonly floorType: GACHA_FLOOR_TYPE;
|
||||
// 目标武将品质
|
||||
readonly heroQuality: number;
|
||||
// 参数
|
||||
readonly param: number;
|
||||
}
|
||||
|
||||
export const dicGachaFloor = new Map<number, DicGachaFloor>(); // floorId => plans
|
||||
export function loadGachaFloor() {
|
||||
dicGachaFloor.clear();
|
||||
let arr = readFileAndParse(FILENAME.DIC_GACHA_FLOOR);
|
||||
|
||||
arr.forEach(o => {
|
||||
dicGachaFloor.set(o.id, o);
|
||||
});
|
||||
|
||||
arr = undefined;
|
||||
}
|
||||
40
shared/pubUtils/dictionary/DicGachaPlan.ts
Normal file
40
shared/pubUtils/dictionary/DicGachaPlan.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { readFileAndParse } from '../util';
|
||||
import { GACHA_PLAN_TYPE, FILENAME } from '../../consts';
|
||||
|
||||
export interface DicGachaPlan {
|
||||
// 内容id
|
||||
readonly id: number;
|
||||
// 指向gacha表的percent
|
||||
readonly planId: number;
|
||||
// 类型
|
||||
readonly type: GACHA_PLAN_TYPE;
|
||||
// 内容物具体id 武将id or 道具id
|
||||
readonly content: number;
|
||||
// 数量
|
||||
readonly count: number;
|
||||
// 权重
|
||||
readonly weight: number;
|
||||
// 武将品质,指定武将就当做是橙将。如果有混的,按照武将品质最高的来判断
|
||||
readonly heroQuality: number;
|
||||
}
|
||||
|
||||
export const dicGachaPlan = new Map<number, DicGachaPlan[]>(); // planId => plans
|
||||
export const dicGachaPlanQuality = new Map<number, number>(); // planId => heroQuality
|
||||
export function loadGachaPlan() {
|
||||
dicGachaPlan.clear();
|
||||
let arr = readFileAndParse(FILENAME.DIC_GACHA_PLAN);
|
||||
|
||||
arr.forEach(o => {
|
||||
if(!dicGachaPlan.has(o.planId)) {
|
||||
dicGachaPlan.set(o.planId, [o]);
|
||||
dicGachaPlanQuality.set(o.planId, o.heroQuality);
|
||||
} else {
|
||||
dicGachaPlan.get(o.planId)?.push(o);
|
||||
if(dicGachaPlanQuality.get(o.planId)??0 < o.heroQuality) {
|
||||
dicGachaPlanQuality.set(o.planId, o.heroQuality);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
arr = undefined;
|
||||
}
|
||||
@@ -5,13 +5,14 @@ import { isNumber } from 'underscore';
|
||||
const csprng = require('csprng');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
import { ABI_STAGE, GACHA_TO_FLOOR, REFRESH_TIME, ROBOT_SYS_TYPE, ITEM_CHANGE_REASON, WAR_TYPE, SHOP_REFRESH_TYPE } from '../consts';
|
||||
import { ABI_STAGE, REFRESH_TIME, ROBOT_SYS_TYPE, ITEM_CHANGE_REASON, WAR_TYPE, SHOP_REFRESH_TYPE, GACHA_TYPE, GACHA_FLOOR_TYPE } from '../consts';
|
||||
|
||||
import { findIndex } from 'underscore';
|
||||
import { getZeroPointD } from './timeUtil';
|
||||
import { Floor } from '../domain/activityField/gachaField';
|
||||
import { WhiteListModel } from '../db/RegionWhiteList';
|
||||
import { RewardInter } from './interface';
|
||||
import { gameData } from './data';
|
||||
const randomName = require("chinese-random-name");
|
||||
const moment = require('moment');
|
||||
const crypto = require('crypto');
|
||||
@@ -620,26 +621,6 @@ export function splitString(dataString: string, key: string) {
|
||||
return numberArray;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @description 获取抽卡保底状态
|
||||
* @param gachaId 招募类型
|
||||
* @param 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(gachaId);
|
||||
return dicFloorType.map(id => {
|
||||
return {
|
||||
id,
|
||||
count: floorMap.get(id) || 0
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export async function checkWhiteList(env: string, ip: string, uid: number, serverId: number) {
|
||||
if(ip) {
|
||||
let result = await WhiteListModel.checkIp(env, ip);
|
||||
@@ -819,3 +800,17 @@ export function addToMap<T>(map: Map<T, number>, id: T, value: number) {
|
||||
|
||||
// return { topLineup, topLineupCe };
|
||||
// }
|
||||
|
||||
export function getGachaRemainFloor(gachaId: number, userFloor: Floor[]) {
|
||||
let dicGacha = gameData.gacha.get(gachaId);
|
||||
if(dicGacha.gachaType != GACHA_TYPE.NORMAL) return 0;
|
||||
|
||||
for(let floorId of dicGacha.floor) {
|
||||
let dicGachaFloor = gameData.gachaFloor.get(floorId);
|
||||
if(dicGachaFloor && dicGachaFloor.floorType == GACHA_FLOOR_TYPE.MAIN_FLOOR) {
|
||||
let myFloor = userFloor.find(cur => cur.id == floorId);
|
||||
return dicGachaFloor.param - (myFloor?.count||0);
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
@@ -752,8 +752,8 @@
|
||||
"id": 108,
|
||||
"warid": 620,
|
||||
"c_type": 106,
|
||||
"data": "10&",
|
||||
"describe": "10回合内获得胜利"
|
||||
"data": "20&",
|
||||
"describe": "20回合内获得胜利"
|
||||
},
|
||||
{
|
||||
"id": 109,
|
||||
@@ -794,8 +794,8 @@
|
||||
"id": 114,
|
||||
"warid": 628,
|
||||
"c_type": 106,
|
||||
"data": "10&",
|
||||
"describe": "10回合内获得胜利"
|
||||
"data": "15&",
|
||||
"describe": "15回合内获得胜利"
|
||||
},
|
||||
{
|
||||
"id": 115,
|
||||
@@ -3426,7 +3426,7 @@
|
||||
"id": 490,
|
||||
"warid": 704,
|
||||
"c_type": 115,
|
||||
"data": "1&2&0",
|
||||
"data": "1&3&1",
|
||||
"describe": "阻止任意敌人登船"
|
||||
},
|
||||
{
|
||||
@@ -3573,7 +3573,7 @@
|
||||
"id": 511,
|
||||
"warid": 1704,
|
||||
"c_type": 115,
|
||||
"data": "1&2&0",
|
||||
"data": "1&3&1",
|
||||
"describe": "阻止任意敌人登船"
|
||||
},
|
||||
{
|
||||
|
||||
@@ -1,42 +1,42 @@
|
||||
[
|
||||
{
|
||||
"id": 1,
|
||||
"gachaType": 1,
|
||||
"floor": "1&3&4",
|
||||
"name": "元宝招募",
|
||||
"count": "1&10",
|
||||
"free": "1&1",
|
||||
"cost": "22001&1",
|
||||
"percent": "1&46|2&50|3&4",
|
||||
"floorReward": 3,
|
||||
"indirectId": 1
|
||||
"isTask": 1,
|
||||
"gachaCnt": "1&-1",
|
||||
"indirectId": 1,
|
||||
"showInMainPage": 1
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"gachaType": 2,
|
||||
"floor": "&",
|
||||
"name": "友情点招募",
|
||||
"count": "1&10",
|
||||
"free": "&",
|
||||
"cost": "40003&100",
|
||||
"percent": "1&49|2&50|3&1",
|
||||
"floorReward": 0,
|
||||
"indirectId": 0
|
||||
"indirectId": 0,
|
||||
"showInMainPage": 1
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"gachaType": 3,
|
||||
"floor": "2&",
|
||||
"name": "求贤若渴",
|
||||
"count": "1&5",
|
||||
"free": "1&1",
|
||||
"cost": "22002&1",
|
||||
"percent": "4&5|14&5|15&10|16&20|7&10|6&15|5&20|13&15",
|
||||
"percent": "4&5|5&45|6&50",
|
||||
"floorReward": 1,
|
||||
"indirectId": 2
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"name": "限时招募",
|
||||
"count": "1&5",
|
||||
"free": "&",
|
||||
"cost": "22003&1",
|
||||
"percent": "4&5|9&15|10&15|11&15|12&10|5&35|13&5",
|
||||
"floorReward": 1,
|
||||
"indirectId": 0
|
||||
"indirectId": 2,
|
||||
"showInMainPage": 1
|
||||
}
|
||||
]
|
||||
21
shared/resource/jsons/dic_zyz_gachaFloor.json
Normal file
21
shared/resource/jsons/dic_zyz_gachaFloor.json
Normal file
@@ -0,0 +1,21 @@
|
||||
[{
|
||||
"id":1,
|
||||
"floorType": 1,
|
||||
"heroQuality": 3,
|
||||
"param": 40
|
||||
},{
|
||||
"id": 2,
|
||||
"floorType": 2,
|
||||
"heroQuality": 3,
|
||||
"param": 20
|
||||
}, {
|
||||
"id": 3,
|
||||
"floorType": 3,
|
||||
"heroQuality": 1,
|
||||
"param": 9
|
||||
},{
|
||||
"id": 4,
|
||||
"floorType": 4,
|
||||
"heroQuality": 3,
|
||||
"param": 3
|
||||
}]
|
||||
49
shared/resource/jsons/dic_zyz_gachaPlan.json
Normal file
49
shared/resource/jsons/dic_zyz_gachaPlan.json
Normal file
@@ -0,0 +1,49 @@
|
||||
[{
|
||||
"id":1,
|
||||
"planId":1,
|
||||
"type": 1,
|
||||
"content":13,
|
||||
"count":1,
|
||||
"weight":1,
|
||||
"heroQuality":1
|
||||
},{
|
||||
"id":2,
|
||||
"planId":2,
|
||||
"type": 1,
|
||||
"content":8,
|
||||
"count":1,
|
||||
"weight":1,
|
||||
"heroQuality":2
|
||||
},{
|
||||
"id":3,
|
||||
"planId":3,
|
||||
"type": 1,
|
||||
"content":1,
|
||||
"count":1,
|
||||
"weight":1,
|
||||
"heroQuality":3
|
||||
},{
|
||||
"id":4,
|
||||
"planId":4,
|
||||
"type": 2,
|
||||
"content":0,
|
||||
"count":1,
|
||||
"weight":1,
|
||||
"heroQuality":3
|
||||
},{
|
||||
"id":5,
|
||||
"planId":5,
|
||||
"type": 3,
|
||||
"content":0,
|
||||
"count":1,
|
||||
"weight":1,
|
||||
"heroQuality":0
|
||||
},{
|
||||
"id":5,
|
||||
"planId":6,
|
||||
"type": 4,
|
||||
"content":31001,
|
||||
"count":10,
|
||||
"weight":1,
|
||||
"heroQuality":0
|
||||
}]
|
||||
Reference in New Issue
Block a user