活动:新武将抽卡活动
This commit is contained in:
@@ -198,19 +198,23 @@ export class ActivityMonopolyHandler {
|
||||
const sid = session.get('sid');
|
||||
const roleName = session.get('roleName');
|
||||
const funcs: number[] = session.get('funcs');
|
||||
|
||||
let playerMonopolyData: ActivityMonopolyModelType = await ActivityMonopolyModel.findData(serverId, activityId, roleId);
|
||||
let playerLandData: ActivityMonopolyLandModelType = await ActivityMonopolyLandModel.findDataByPosition(serverId, activityId, roleId, playerMonopolyData.curPosition);
|
||||
let playerData = await getPlayerRefreshShopDataByRoundIndex(activityId, serverId, roleId, playerLandData.stopCount);
|
||||
if (!playerData) {
|
||||
let playerData = await getPlayerMonopolyData(activityId, serverId, roleId)
|
||||
if (!playerData) return resResult(STATUS.ACTIVITY_MISSING);
|
||||
let landItem = playerData.findMonopolyItem(playerMonopolyData.curPosition)
|
||||
if (landItem.stopCount > landItem.shoppingCountMax) {
|
||||
return resResult(STATUS.SHOP_CLOSED);
|
||||
}
|
||||
let playerShopData = await getPlayerRefreshShopDataByRoundIndex(activityId, serverId, roleId, landItem.stopCount);
|
||||
if (!playerShopData) {
|
||||
return resResult(STATUS.ACTIVITY_MISSING);
|
||||
}
|
||||
|
||||
if (playerData.roundIndex != roundIndex) {
|
||||
if (playerShopData.roundIndex != roundIndex) {
|
||||
return resResult(STATUS.ACTIVITY_EXPIRE);
|
||||
}
|
||||
|
||||
let item = playerData.findItem(id, pageIndex);
|
||||
let item = playerShopData.findItem(id, pageIndex);
|
||||
if (!item) {
|
||||
return resResult(STATUS.ACTIVITY_ID_ERROR);
|
||||
}
|
||||
|
||||
133
game-server/app/servers/activity/handler/newHeroGachaHandler.ts
Normal file
133
game-server/app/servers/activity/handler/newHeroGachaHandler.ts
Normal file
@@ -0,0 +1,133 @@
|
||||
import { Application, BackendSession } from 'pinus';
|
||||
import { getRandEelmWithWeight, resResult } from '../../../pubUtils/util';
|
||||
import { STATUS } from '../../../consts';
|
||||
import { getPlayerNewHeroGachaData } from '../../../services/activity/newHeroGachaService';
|
||||
import { RoleModel } from '../../../db/Role';
|
||||
import { gameData } from '../../../pubUtils/data';
|
||||
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 { transPiece } from '../../../pubUtils/itemUtils';
|
||||
import { addItems, createHeroes, handleCost } from '../../../services/rewardService';
|
||||
import { ActivityNewHeroGachaModel } from '../../../db/ActivityNewHeroGacha';
|
||||
// import { NewHeroGachaItem } from '../../../domain/activityField/newHeroGachaField';
|
||||
|
||||
|
||||
export default function (app: Application) {
|
||||
return new NewHeroGachaHandler(app);
|
||||
}
|
||||
|
||||
export class NewHeroGachaHandler {
|
||||
constructor(private app: Application) {
|
||||
}
|
||||
|
||||
/************************新将擢迁, 新武将抽卡****************************/
|
||||
|
||||
/**
|
||||
* @description 获取新武将抽卡活动数据
|
||||
* @param {{ activityId: number}} msg
|
||||
* @param {BackendSession} session
|
||||
* @memberof NewHeroGachaHandler
|
||||
*/
|
||||
async getNewHeroGachaActivity(msg: { activityId: number }, session: BackendSession) {
|
||||
const { activityId } = msg;
|
||||
const roleId = session.get('roleId');
|
||||
const serverId = session.get('serverId');
|
||||
|
||||
let playerData = await getPlayerNewHeroGachaData(activityId, serverId, roleId)
|
||||
|
||||
if (!playerData) return resResult(STATUS.ACTIVITY_MISSING);
|
||||
|
||||
return resResult(STATUS.SUCCESS, playerData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 抽卡
|
||||
* @param {{ activityId: number, hid: number, count: number}} msg
|
||||
* @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');
|
||||
const funcs = session.get('funcs');
|
||||
|
||||
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 { lv } = await RoleModel.findByRoleId(roleId);
|
||||
|
||||
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 { dic: { id: base, goodId } } = getRandEelmWithWeight(item.percent);//{"dic":{"id":1,"weight":59,"goodId":1},"index":0}
|
||||
if (base == item.floorReward) {
|
||||
floorReward = true;
|
||||
}
|
||||
console.log('dddddddddddddddddd', JSON.stringify(base));
|
||||
// let contentId = getFloorResult(gachaId, base, floor);
|
||||
// if (contentId == false) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
let result = getResultFromContentIdNewHeroActivity(base, goodId, lv);
|
||||
console.log('ddddddddddd', JSON.stringify(result))
|
||||
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 cost = item.cost.map(cur => { return { id: cur.id, count: cur.count * count } });
|
||||
let costResult = await handleCost(roleId, sid, cost);
|
||||
if (!costResult) return resResult(STATUS.ACTIVITY_RES_NOT_ENOUGH);
|
||||
|
||||
//记录数据
|
||||
await ActivityNewHeroGachaModel.addRecord(serverId, activityId, roleId, hid, count, JSON.stringify(resultList));
|
||||
if (floorReward) {//抽中保底奖励,重置统计次数
|
||||
await ActivityNewHeroGachaModel.resetCount(serverId, activityId, roleId, hid, 0);
|
||||
}
|
||||
|
||||
// 给东西
|
||||
let { heroes } = await createHeroes(roleId, roleName, sid, serverId, funcs, heroInfo);
|
||||
await addItems(roleId, roleName, sid, items);
|
||||
|
||||
// // 任务
|
||||
// await checkTask(roleId, sid, funcs, TASK_TYPE.GASHA, count, true, {});
|
||||
// //活动统计
|
||||
// await checkActivityTask(serverId, sid, funcs, roleId, TASK_TYPE.GASHA, count)
|
||||
// for (let hero of heroes) {
|
||||
// activityData.push({ hid: hero.hid, quality: hero.quality });
|
||||
// }
|
||||
// await checkActivityTask(serverId, sid, funcs, roleId, TASK_TYPE.GACHA_QUALITY_COUNT, count, { heroes: activityData })
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
hid, activityId, count,
|
||||
heroes, result: resultList
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -42,6 +42,7 @@ export class orderHandler {
|
||||
//商品价格信息
|
||||
let productInfo = dicRMB.get(productID)
|
||||
if (!productInfo) {
|
||||
console.log(productID)
|
||||
return resResult(STATUS.NO_PRODUCT_ID);
|
||||
}
|
||||
|
||||
@@ -115,6 +116,7 @@ export class orderHandler {
|
||||
//商品价格信息
|
||||
let productInfo = dicRMB.get(orderInfo.productID)
|
||||
if (!productInfo) {
|
||||
console.log(orderInfo.productID)
|
||||
return resResult(STATUS.NO_PRODUCT_ID);
|
||||
}
|
||||
|
||||
@@ -231,6 +233,7 @@ export class orderHandler {
|
||||
//商品价格信息
|
||||
let productInfo = dicRMB.get(productID)
|
||||
if (!productInfo) {
|
||||
console.log(productID)
|
||||
return resResult(STATUS.NO_PRODUCT_ID);
|
||||
}
|
||||
|
||||
|
||||
@@ -310,3 +310,41 @@ function getSuitPaper(lv: number) {
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 根据contentId获得抽卡结果 新武将抽卡活动
|
||||
* @param contentId dic_zyz_gachaContent的id
|
||||
* @param lv 玩家等级
|
||||
* @param goodId 大于0指定id,0:随机
|
||||
*/
|
||||
export function getResultFromContentIdNewHeroActivity(contentId: number, goodId: number, lv: number,) {
|
||||
let dic = gameData.gachaContent.get(contentId);
|
||||
let { type, param, count } = dic;
|
||||
if (type == GACHA_CONTENT_TYPE.HERO) {
|
||||
let result = new GachaResult(contentId);
|
||||
result.setHero(goodId);
|
||||
return result
|
||||
} else {
|
||||
let pool: number[] = [];
|
||||
if (type == GACHA_CONTENT_TYPE.HERO_PIECE) {
|
||||
pool = getAllItemByQuality(IT_TYPE.HERO_PIECE, param[0], lv);
|
||||
} else if (type == GACHA_CONTENT_TYPE.BLUEPRT) {
|
||||
pool = getAllItemByQuality(IT_TYPE.BLUEPRT, param[0], lv);
|
||||
} else if (type == GACHA_CONTENT_TYPE.JEWEL) {
|
||||
pool = getAllJewelByLv(param[0]);
|
||||
} else if (type == GACHA_CONTENT_TYPE.TERAPH_MATERIAL) {
|
||||
pool = param;
|
||||
} else if (type == GACHA_CONTENT_TYPE.SUIT_PAPER) {
|
||||
pool = getSuitPaper(lv);
|
||||
}
|
||||
let item = getRandEelm(pool);
|
||||
let result = new GachaResult(contentId);
|
||||
result.setItem(item[0], count);
|
||||
if (goodId > 0) {
|
||||
result.setItem(goodId, count);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
50
game-server/app/services/activity/newHeroGachaService.ts
Normal file
50
game-server/app/services/activity/newHeroGachaService.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { ACTIVITY_TYPE } from '../../consts';
|
||||
import { ActivityModel, ActivityModelType } from '../../db/Activity';
|
||||
import { ActivityNewHeroGachaModel, ActivityNewHeroGachaModelType } from '../../db/ActivityNewHeroGacha';
|
||||
import { ServerlistModel } from '../../db/Serverlist';
|
||||
import { NewHeroGachaData } from '../../domain/activityField/newHeroGachaField';
|
||||
|
||||
|
||||
/**
|
||||
* 获取活动数据
|
||||
*
|
||||
* @param {number} serverId 区Id
|
||||
* @param {number} activityId 活动Id
|
||||
* @param {string} roleId 角色Id
|
||||
*
|
||||
*/
|
||||
export async function newHeroGachaActivity(serverId: number, roleId: string) {
|
||||
let { activityGroupId } = await ServerlistModel.findByServerId(serverId);
|
||||
let activityDataArray: ActivityModelType[] = await ActivityModel.findOpenActivityByType(activityGroupId, ACTIVITY_TYPE.NEW_HERO_GACHA, new Date());
|
||||
if (activityDataArray.length === 0) {
|
||||
return null;
|
||||
}
|
||||
let activityData: ActivityModelType = activityDataArray[0];
|
||||
let playerRecord: ActivityNewHeroGachaModelType[] = await ActivityNewHeroGachaModel.findData(serverId, activityData.activityId, roleId);
|
||||
let playerData = new NewHeroGachaData(activityData);
|
||||
playerData.setPlayerRecords(playerRecord);
|
||||
return playerData;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 玩家玩家活动数据
|
||||
*
|
||||
* @param {number} serverId 区Id
|
||||
* @param {number} activityId 活动Id
|
||||
* @param {string} roleId 角色Id
|
||||
*
|
||||
*/
|
||||
export async function getPlayerNewHeroGachaData(activityId: number, serverId: number, roleId: string) {
|
||||
let activityData: ActivityModelType = await ActivityModel.findActivity(activityId);
|
||||
let playerRecord: ActivityNewHeroGachaModelType[] = await ActivityNewHeroGachaModel.findData(serverId, activityId, roleId);
|
||||
|
||||
let playerData = new NewHeroGachaData(activityData);
|
||||
playerData.setPlayerRecords(playerRecord);
|
||||
|
||||
return playerData;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -121,14 +121,16 @@ export async function makeOrder(localOrderID: string, sid: string, orderInfo: Us
|
||||
if (orderInfo.paramStr) {//大富翁商店结算
|
||||
let paramObj = JSON.parse(orderInfo.paramStr);
|
||||
let activityId = paramObj.activityId;//大富翁活动id; orderInfo.activityId是大富翁中的商店活动id
|
||||
let playerMonopolyData: ActivityMonopolyModelType = await ActivityMonopolyModel.findData(orderInfo.serverId, activityId, roleId);
|
||||
let playerLandData: ActivityMonopolyLandModelType = await ActivityMonopolyLandModel.findDataByPosition(orderInfo.serverId, activityId, roleId, playerMonopolyData.curPosition);
|
||||
let roundIndex = playerLandData.stopCount;
|
||||
rewardResult = await makeRefreshShopReward(roleId, roleInfo.roleName, sid, orderInfo.serverId, roleInfo.funcs, orderInfo.activityId, orderInfo.productID, roundIndex)
|
||||
|
||||
} else {//正常商店结算
|
||||
rewardResult = await makeRefreshShopReward(roleId, roleInfo.roleName, sid, orderInfo.serverId, roleInfo.funcs, orderInfo.activityId, orderInfo.productID, 0)
|
||||
if (activityId) {
|
||||
let playerMonopolyData: ActivityMonopolyModelType = await ActivityMonopolyModel.findData(orderInfo.serverId, activityId, roleId);
|
||||
let playerLandData: ActivityMonopolyLandModelType = await ActivityMonopolyLandModel.findDataByPosition(orderInfo.serverId, activityId, roleId, playerMonopolyData.curPosition);
|
||||
let roundIndex = playerLandData.stopCount;
|
||||
rewardResult = await makeRefreshShopReward(roleId, roleInfo.roleName, sid, orderInfo.serverId, roleInfo.funcs, orderInfo.activityId, orderInfo.productID, roundIndex)
|
||||
break;
|
||||
}
|
||||
}
|
||||
//正常商店结算
|
||||
rewardResult = await makeRefreshShopReward(roleId, roleInfo.roleName, sid, orderInfo.serverId, roleInfo.funcs, orderInfo.activityId, orderInfo.productID, 0)
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
||||
@@ -51,6 +51,7 @@ export enum ACTIVITY_TYPE {
|
||||
COMMON_SIGN_IN = 36, //通用签到
|
||||
NEW_HERO_GIFTS = 37, //新将好礼(很多红包,用积分兑换一遍结束)
|
||||
NEW_HERO_GK = 38, //新将演绎 (配置N个武将,每个武将有X个关卡;活动期间,*天(时间自定义)开启每个武将对应的一个关卡,只有第一次通关会获得奖励)
|
||||
NEW_HERO_GACHA = 39, //新将擢迁(新武将抽取)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -370,6 +370,7 @@ export const STATUS = {
|
||||
MONOPOLY_BANK_COUNT_ERROR: { code: 50031, simStr: '数量错误' },
|
||||
MONOPOLY_BANK_SAVE_MAX: { code: 50032, simStr: '超过最大限制数量' },
|
||||
NOT_GIFTPACKAGE: { code: 50033, simStr: '非礼包类型' },
|
||||
SHOP_CLOSED: { code: 50034, simStr: '停业' },
|
||||
// GM后台相关状态 60000 - 69999
|
||||
GM_ERR_PASSWORD: { code: 60001, simStr: '账号或密码错误' },
|
||||
GM_MISS_API: { code: 60002, simStr: '未找到该接口' },
|
||||
|
||||
67
shared/db/ActivityNewHeroGacha.ts
Normal file
67
shared/db/ActivityNewHeroGacha.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
|
||||
export class Record {
|
||||
@prop({ required: true })
|
||||
count: number; // 次数
|
||||
@prop({ required: true })
|
||||
reward: string; // 奖励内容
|
||||
@prop({ required: true })
|
||||
time: Date; // 抽卡时间
|
||||
}
|
||||
|
||||
/**
|
||||
* 活动系统 - 每日关卡活动
|
||||
*/
|
||||
@index({ roleId: 1 })
|
||||
|
||||
export default class Activity_New_Hero_Gacha extends BaseModel {
|
||||
@prop({ required: true })
|
||||
serverId: number; // 服id
|
||||
@prop({ required: true })
|
||||
activityId: number; // 活动Id
|
||||
@prop({ required: true })
|
||||
roleId: string; // 用户Id
|
||||
@prop({ required: true })
|
||||
hid: number; // 武将id
|
||||
@prop({ required: true })
|
||||
count: number; // 抽卡次数,抽中大奖后重新统计
|
||||
@prop({ required: true })
|
||||
records: Record[]; // 抽卡历史记录
|
||||
|
||||
//重置统计次数
|
||||
public static async resetCount(serverId: number, activityId: number, roleId: string, hid: number, count: number) {
|
||||
let result: ActivityNewHeroGachaModelType = await ActivityNewHeroGachaModel.findOneAndUpdate({ serverId, roleId, activityId, hid },
|
||||
{ $set: { count } }, { upsert: true, new: true }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
//抽卡记录
|
||||
public static async addRecord(serverId: number, activityId: number, roleId: string, hid: number, count: number, reward: string) {
|
||||
let result: ActivityNewHeroGachaModelType = await ActivityNewHeroGachaModel.findOneAndUpdate({ serverId, roleId, activityId, hid },
|
||||
{ $inc: { count }, $push: { records: { count, reward, time: new Date() } } }, { upsert: true, new: true }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据活动id查询活动数据
|
||||
public static async findDataByHid(serverId: number, activityId: number, roleId: string, hid: number) {
|
||||
let result: ActivityNewHeroGachaModelType = await ActivityNewHeroGachaModel.findOne({ serverId, roleId, activityId, hid }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据活动id查询活动数据
|
||||
public static async findData(serverId: number, activityId: number, roleId: string) {
|
||||
let result: ActivityNewHeroGachaModelType[] = await ActivityNewHeroGachaModel.find({ serverId, roleId, activityId }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
//删除活动领取记录
|
||||
public static async deleteActivity(serverId: number, activityId: number, roleId: string) {
|
||||
await ActivityNewHeroGachaModel.deleteMany({ serverId, roleId, activityId });
|
||||
}
|
||||
}
|
||||
|
||||
export const ActivityNewHeroGachaModel = getModelForClass(Activity_New_Hero_Gacha);
|
||||
|
||||
export interface ActivityNewHeroGachaModelType extends Pick<DocumentType<Activity_New_Hero_Gacha>, keyof Activity_New_Hero_Gacha> { }
|
||||
export type ActivityNewHeroGachaModelTypeParam = Partial<ActivityNewHeroGachaModelType>; // 将所有字段变成可选项
|
||||
@@ -14,6 +14,7 @@ export class LandItem {
|
||||
saveMax: number //银行存钱最大数额
|
||||
takeOutMax: number //银行取钱最大次数
|
||||
shopActivityId: number //商店对应的商店id
|
||||
shoppingCountMax: number //逛商店次数
|
||||
|
||||
record: any[] = []; //历史操作
|
||||
stopCount: number //停留次数
|
||||
@@ -27,6 +28,7 @@ export class LandItem {
|
||||
this.saveMax = data.saveMax;
|
||||
this.takeOutMax = data.takeOutMax;
|
||||
this.shopActivityId = data.shopActivityId;
|
||||
this.shoppingCountMax = data.shoppingCountMax;
|
||||
this.record = [];
|
||||
this.stopCount = 0;
|
||||
}
|
||||
|
||||
72
shared/domain/activityField/newHeroGachaField.ts
Normal file
72
shared/domain/activityField/newHeroGachaField.ts
Normal file
@@ -0,0 +1,72 @@
|
||||
import { ActivityModelType } from '../../db/Activity';
|
||||
import { ActivityNewHeroGachaModelType } from '../../db/ActivityNewHeroGacha';
|
||||
import { RewardInter } from '../../pubUtils/interface';
|
||||
import { parseGoodStr, splitString } from '../../pubUtils/util';
|
||||
import { ActivityBase } from './activityField';
|
||||
|
||||
|
||||
// 每个英雄的奖池配置数据
|
||||
export class NewHeroGachaItem {
|
||||
floorCount: number = 0;//保底最大的次数,一定会出现一次
|
||||
count: number = 0;//多少次没有抽中
|
||||
hid: number = 0;//武将id
|
||||
name: string = '';//名字
|
||||
cost: RewardInter[];//每次抽卡消耗资源
|
||||
floorReward: number = 0;//保底奖励,percent下标+1
|
||||
percent: { id: number, weight: number, goodId: number }[];//奖品百分比 contentId & percent & id(英雄hid,物品id)
|
||||
|
||||
constructor(data: any) {
|
||||
this.hid = data.hid;
|
||||
this.name = data.name;
|
||||
this.floorCount = data.floorCount;
|
||||
this.cost = parseGoodStr(data.cost);
|
||||
this.percent = [];
|
||||
this.floorReward = data.floorReward;
|
||||
this.count = 0;
|
||||
let arr = data.percent.split('|').filter(obj => { return obj && obj != '' });
|
||||
for (let obj of arr) {
|
||||
let numArr = splitString(obj, '&');
|
||||
this.percent.push({
|
||||
id: numArr[0],
|
||||
weight: numArr[1],
|
||||
goodId: numArr.length > 2 ? numArr[2] : 0,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 每日关卡活动数据
|
||||
export class NewHeroGachaData extends ActivityBase {
|
||||
list: NewHeroGachaItem[] = [];
|
||||
|
||||
public findItem(hid: number) {
|
||||
let index = this.list.findIndex(obj => { return obj && obj.hid == hid })
|
||||
return (index != -1) ? this.list[index] : null;
|
||||
}
|
||||
|
||||
//解析玩家记录
|
||||
public setPlayerRecords(data: ActivityNewHeroGachaModelType[]) {
|
||||
for (let item of this.list) {
|
||||
let index = data.findIndex(obj => { return obj.hid == item.hid });
|
||||
if (index != -1) {
|
||||
item.count = data[index].count ? data[index].count : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public initData(data: string) {
|
||||
let dataObj = JSON.parse(data);
|
||||
let arr = dataObj;
|
||||
for (let obj of arr) {
|
||||
this.list.push(new NewHeroGachaItem(obj))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
constructor(activityData: ActivityModelType) {
|
||||
super(activityData)
|
||||
this.initData(activityData.data)
|
||||
}
|
||||
}
|
||||
@@ -58,11 +58,11 @@ export class RefreshShopData extends ActivityBase {
|
||||
nextRefreshTime: number;//下次刷新时间
|
||||
roundIndex: number = 1;//周期数从1开始
|
||||
|
||||
public findItemByProductID(productID: string) {
|
||||
public findItemByProductID(productID: string): RefreshShopItem {
|
||||
for (let pageData of this.list) {
|
||||
let index = pageData.items.findIndex(obj => { return obj && obj.productID === productID });
|
||||
if (index != -1) {
|
||||
this.list[index]
|
||||
return pageData.items[index]
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user