活动:寻宝骑兵-每日物资
This commit is contained in:
@@ -10,14 +10,21 @@ import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoos
|
||||
@index({ roleId: 1 })
|
||||
|
||||
export default class Activity_Treasure_Hunt_Shop extends ActivityShop {
|
||||
@prop({ required: true })
|
||||
dayIndex: number; // 第几天
|
||||
@prop({ required: true })
|
||||
dayIndex: number; // 第几天
|
||||
|
||||
//根据活动id查询活动数据
|
||||
public static async findTreasureData(serverId: number, activityId: number, roleId: string, roundIndex: number, dayIndex: number) {
|
||||
let result: ActivityTreasureHuntShopModelType = await ActivityTreasureHuntShopModel.findOne({ roleId, activityId, roundIndex, dayIndex }).lean(true);
|
||||
return result;
|
||||
}
|
||||
//根据活动id查询活动数据
|
||||
public static async findTreasureData(serverId: number, activityId: number, roleId: string, roundIndex: number, dayIndex: number) {
|
||||
let result: ActivityTreasureHuntShopModelType = await ActivityTreasureHuntShopModel.findOne({ roleId, activityId, roundIndex, dayIndex }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
//购买领取奖励的记录
|
||||
public static async buyShopRecord(activityId: number, roleId: string, roundIndex: number, dayIndex: number, id: number) {
|
||||
let result: ActivityTreasureHuntShopModelType = await ActivityTreasureHuntShopModel.findOneAndUpdate({ roleId, activityId, roundIndex, dayIndex },
|
||||
{ $push: { records: { id, time: new Date() } } }, { upsert: true, new: true }).lean(true);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export const ActivityTreasureHuntShopModel = getModelForClass(Activity_Treasure_Hunt_Shop);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ActivityModelType } from '../../db/Activity';
|
||||
import { UserOrderModelType } from '../../db/UserOrder';
|
||||
import { ActivityTreasureHuntShopModelType } from '../../db/ActivityTreasureHuntShop';
|
||||
import { ActivityBase } from './activityField';
|
||||
|
||||
/************************************************************/
|
||||
@@ -41,6 +41,11 @@ export class TreasureHuntShopItem {
|
||||
}
|
||||
this.buyCount = 0;
|
||||
}
|
||||
|
||||
public getConsume() {
|
||||
let index = this.consume.findIndex(obj => { return obj && obj.count === this.buyCount + 1 });
|
||||
return (index != -1) ? this.consume[index].consume : '';
|
||||
}
|
||||
}
|
||||
|
||||
// 商店数据
|
||||
@@ -48,11 +53,25 @@ export class TreasureHuntShopData {
|
||||
name: string = '';//页签名字
|
||||
list: Array<TreasureHuntShopItem> = [];//商品
|
||||
|
||||
public getItem(cellIndex: number): TreasureHuntShopItem {
|
||||
let index = this.list.findIndex(obj => { return obj && obj.cellIndex === cellIndex })
|
||||
return (index != -1) ? this.list[index] : null;
|
||||
}
|
||||
|
||||
public setPlayerRecords(record: ActivityTreasureHuntShopModelType) {
|
||||
if (!record) {
|
||||
return;
|
||||
}
|
||||
for (let item of this.list) {
|
||||
let buyRecords = record.records.filter(obj => { obj.id === item.cellIndex });
|
||||
item.buyCount = buyRecords.length;
|
||||
}
|
||||
}
|
||||
|
||||
public initData(data: any) {
|
||||
this.name = data.name;
|
||||
let arr = data.data;
|
||||
for (let obj of arr) {
|
||||
console.log(JSON.stringify(obj))
|
||||
this.list.push(new TreasureHuntShopItem(obj))
|
||||
}
|
||||
}
|
||||
@@ -122,6 +141,8 @@ export class TreasureHuntData extends ActivityBase {
|
||||
roundIndex = 0;//周期数
|
||||
shop: TreasureHuntShopData = null;
|
||||
|
||||
|
||||
|
||||
public initData(data: any) {
|
||||
let dataObj = JSON.parse(data);
|
||||
this.name = dataObj.name;
|
||||
|
||||
Reference in New Issue
Block a user