抽卡:修改抽卡奖池逻辑

This commit is contained in:
luying
2022-07-08 14:09:18 +08:00
parent e4d8708898
commit 35c7c57bda
20 changed files with 695 additions and 579 deletions
+348 -296
View File
@@ -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,8 +20,8 @@ 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)
userGacha = await refreshGacha(dicGacha, 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 {
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对应的武将品质
constructor(planId: number) {
this.planId = planId;
this.heroQuality = gameData.gachaPlanQuality.get(planId);
}
public changePlan(planId: number, heroQuality: number) {
this.planId = planId;
this.heroQuality = heroQuality;
}
public isTarget(floor: GachaFloor) {
return floor.heroQuality == this.heroQuality;
}
public setHero(hid: number, count: number) {
this.hid = hid;
this.count = count;
}
public setItem(id: number, count: number) {
this.id = id;
if(count) this.count = count;
}
}
export class GachaResults {
count: number = 0;
list: GachaResult[] = [];
addResult(contentId: number, id?: number) {
public addPlan(planId: number) {
this.count++;
this.list.push(new GachaResult(contentId, id));
this.list.push(new GachaResult(planId));
}
public shouldPurpleFloor(floorCount: number) {
return this.count % floorCount == 0 && !this.hasPurple();
}
public hasPurple() {
return this.list.findIndex(gachaResult => this.checkContentIsHero(gachaResult.contentId, HERO_QUALITY_TYPE.PURPLE)) != -1;
}
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 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;
}
}
/**
* 抽卡方法
*/
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();
constructor(gachaType: GACHA_ID, ) {
this.gachaType = gachaType;
}
// 一般抽卡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;
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;
}
}
}
// 心愿单
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);
}
this.player.setUserHope(gachaResult.hid); // 设置心愿单中了没有
}
private getRandomDetail(planId: number) {
let details = gameData.gachaPlan.get(planId)||[]
let { dic } = getRandEelmWithWeight(details);
return dic
}
// 创建信息
public getFinalResult(userHeroes: HeroType[]) {
return this.transferToFinalResult(this.result.list, userHeroes);
}
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,83 +263,235 @@ 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);
}
}
/**
* 根据品质获得武将池
@@ -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 } };
+2 -2
View File
@@ -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 });