抽卡:新武将抽卡接入
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
import { Application, BackendSession } from 'pinus';
|
||||
import { getRandEelmWithWeight, resResult } from '../../../pubUtils/util';
|
||||
import { STATUS } from '../../../consts';
|
||||
import { STATUS, GACHA_ID } from '../../../consts';
|
||||
import { getPlayerNewHeroGachaData } from '../../../services/activity/newHeroGachaService';
|
||||
import { RoleModel } from '../../../db/Role';
|
||||
import { HeroModel } from '../../../db/Hero';
|
||||
import { RewardInter } from '../../../pubUtils/interface';
|
||||
import { CreateHeroParam } from '../../../domain/roleField/hero';
|
||||
import { GachaResult } from '../../../domain/activityField/gachaField';
|
||||
import { getResultFromContentIdNewHeroActivity } from '../../../services/activity/gachaService';
|
||||
import { getResultFromContentIdNewHeroActivity, GachaPull } from '../../../services/activity/gachaService';
|
||||
import { transPiece } from '../../../pubUtils/itemUtils';
|
||||
import { addItems, createHeroes, handleCost } from '../../../services/rewardService';
|
||||
import { ActivityNewHeroGachaModel } from '../../../db/ActivityNewHeroGacha';
|
||||
@@ -86,42 +86,10 @@ export class NewHeroGachaHandler {
|
||||
|
||||
let userHeroes = await HeroModel.findByRole(roleId);
|
||||
|
||||
let items: RewardInter[] = [], heroInfo: CreateHeroParam[] = [], resultList: GachaResult[] = [];
|
||||
|
||||
let floorReward = false;//是否中保底奖励
|
||||
let activityData = [];//活动需要统计抽中的英雄、碎片品质
|
||||
for (let i = 0; i < count; i++) {
|
||||
let base = 0;
|
||||
let goodId = 0;
|
||||
if (floorReward! && (item.count + i >= item.floorCount)) {//保底奖励
|
||||
let reward = item.percent[item.floorReward];//{"id":1,"weight":59,"goodId":1}
|
||||
base = reward.id;
|
||||
goodId = reward.goodId;
|
||||
} else {//按照一般概率抽出
|
||||
let randomObj = getRandEelmWithWeight(item.percent);//{"dic":{"id":1,"weight":59,"goodId":1},"index":0}
|
||||
base = randomObj.dic.id;
|
||||
goodId = randomObj.dic.goodId;
|
||||
}
|
||||
|
||||
if (base == item.floorReward) {//中了保底
|
||||
floorReward = true;
|
||||
}
|
||||
let result = getResultFromContentIdNewHeroActivity(base, goodId, lv);
|
||||
if (result.hid > 0) {
|
||||
let hasHero = userHeroes.find(cur => cur.hid == result.hid);
|
||||
if (hasHero) { // 已有转换为碎片
|
||||
activityData.push({ hid: hasHero.hid, quality: hasHero.quality });
|
||||
let { pieceId, count } = transPiece(result.hid);
|
||||
result.transferToPiece(pieceId, count);
|
||||
items.push({ id: pieceId, count });
|
||||
} else {
|
||||
heroInfo.push({ hid: result.hid, count: 1 })//默认1个英雄
|
||||
}
|
||||
} else {
|
||||
items.push({ id: result.id, count: result.count });
|
||||
}
|
||||
resultList.push(result);
|
||||
}
|
||||
let gachaPull = new GachaPull(GACHA_ID.TIMELIMIT, lv, userHeroes);
|
||||
gachaPull.setByActivity(item);
|
||||
let { items, heroInfo, resultList, activityData } = gachaPull.pull(count);
|
||||
let { hasGetFloor, floorCount } = gachaPull.getActivityParam();
|
||||
|
||||
// 消耗东西
|
||||
let cost = item.cost.map(cur => { return { id: cur.id, count: cur.count * count } });
|
||||
@@ -129,10 +97,7 @@ export class NewHeroGachaHandler {
|
||||
if (!costResult) return resResult(STATUS.ACTIVITY_RES_NOT_ENOUGH);
|
||||
|
||||
//记录数据
|
||||
await ActivityNewHeroGachaModel.addRecord(serverId, activityId, roleId, hid, count, JSON.stringify(resultList), floorReward);
|
||||
if (floorReward) {//抽中保底奖励,重置统计次数
|
||||
await ActivityNewHeroGachaModel.resetCount(serverId, activityId, roleId, 0);
|
||||
}
|
||||
await ActivityNewHeroGachaModel.addRecord(serverId, activityId, roleId, hid, floorCount, JSON.stringify(resultList), hasGetFloor);
|
||||
|
||||
// 给东西
|
||||
let { heroes } = await createHeroes(roleId, roleName, sid, serverId, funcs, heroInfo);
|
||||
|
||||
@@ -12,6 +12,7 @@ import { CreateHeroParam } from "../../domain/roleField/hero";
|
||||
import { UserGuildType } from "../../db/UserGuild";
|
||||
import { transPiece } from "../../pubUtils/itemUtils";
|
||||
import { HeroType } from "../../db/Hero";
|
||||
import { NewHeroGachaItem } from "../../domain/activityField/newHeroGachaField";
|
||||
|
||||
/**
|
||||
* 获取招募列表
|
||||
@@ -144,12 +145,14 @@ export class GachaPull {
|
||||
this.hope = userGacha.hope;
|
||||
}
|
||||
// 新武将活动setter
|
||||
public setByActivity() {
|
||||
// this.floorCount =
|
||||
// this.hasGetFloor =
|
||||
// this.percent =
|
||||
// this.dicFloorCount =
|
||||
// this.dicFloor =
|
||||
public setByActivity(item: NewHeroGachaItem) {
|
||||
this.floorCount = item.count;
|
||||
this.hasGetFloor = item.hasGetFloor;
|
||||
this.percent = item.percent;
|
||||
this.dicFloorCount = item.floorCount;
|
||||
if(item.floorReward >= 0) {
|
||||
this.dicFloor = item.percent[item.floorReward]
|
||||
}
|
||||
}
|
||||
|
||||
private getFloorResult(base: { id: number, weight: number, goodId?: number }) {
|
||||
@@ -335,8 +338,7 @@ export class GachaPull {
|
||||
}
|
||||
// 活动getter
|
||||
public getActivityParam() {
|
||||
// this.hasGetFloor
|
||||
// this.floorCount
|
||||
return { hasGetFloor: this.hasGetFloor, floorCount: this.floorCount };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,8 @@ export default class Activity_New_Hero_Gacha extends BaseModel {
|
||||
count: number; // 抽卡次数,抽中大奖后重新统计
|
||||
@prop({ required: true })
|
||||
records: Record[]; // 抽卡历史记录
|
||||
@prop({ required: true })
|
||||
hasGetFloor: boolean; // 是否抽到保底了
|
||||
|
||||
//重置统计次数
|
||||
public static async resetCount(serverId: number, activityId: number, roleId: string, count: number) {
|
||||
@@ -43,7 +45,7 @@ export default class Activity_New_Hero_Gacha extends BaseModel {
|
||||
//抽卡记录
|
||||
public static async addRecord(serverId: number, activityId: number, roleId: string, hid: number, count: number, reward: string, hasGetFloor: boolean) {
|
||||
let result: ActivityNewHeroGachaModelType = await ActivityNewHeroGachaModel.findOneAndUpdate({ serverId, roleId, activityId },
|
||||
{ $inc: { count }, $push: { records: { hid, count, reward, time: new Date(), hasGetFloor } } }, { upsert: true, new: true }).lean(true);
|
||||
{ $set: { count, hasGetFloor }, $push: { records: { hid, count, reward, time: new Date(), hasGetFloor } } }, { upsert: true, new: true }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ export class NewHeroGachaItem {
|
||||
selected: boolean = false;//选中武将
|
||||
floorCount: number = 0;//保底最大的次数,一定会出现一次
|
||||
count: number = 0;//多少次没有抽中
|
||||
hasGetFloor: boolean = false; // 是否有抽到保底,伪随机算法,抽到后未到保底次数强制不给
|
||||
hid: number = 0;//武将id
|
||||
name: string = '';//名字
|
||||
cost: RewardInter[];//每次抽卡消耗资源
|
||||
@@ -57,6 +58,7 @@ export class NewHeroGachaData extends ActivityBase {
|
||||
}
|
||||
for (let item of this.list) {
|
||||
item.count = data.count ? data.count : 0;
|
||||
item.hasGetFloor = data.hasGetFloor||false;
|
||||
item.selected = (data && data.selectedHid == item.hid);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user