diff --git a/src/controllers/ActivityController.ts b/src/controllers/ActivityController.ts index 7dd85e7..c06c8ba 100644 --- a/src/controllers/ActivityController.ts +++ b/src/controllers/ActivityController.ts @@ -24,7 +24,7 @@ export default class ActivityController extends BaseController { } else { day = (new Date(0)).format('yyyy-MM-dd', true) } - let record = (await ActRecord.findOrCreate({accountid, day})).doc + let record = (await ActRecord.findOrCreate({accountid, actid: id, day})).doc if (!cfg.repeat && record.count > 0) { throw new ZError(12, 'already goted') } @@ -41,8 +41,14 @@ export default class ActivityController extends BaseController { record.lasttime = Date.now() await record.save() const itemInfos: ItemInfo[] = ItemCtrl.getItemsByInfo(cfg.income) - await BagItem.addItems(accountid, itemInfos) + let results + if (id == 90001 || id == 90002) { + results = await BagItem.parseCardItems(req.user, itemInfos) + } else { + await BagItem.addItems(accountid, itemInfos) + results = itemInfos + } await record.save() - return itemInfos + return results } } diff --git a/src/controllers/CardController.ts b/src/controllers/CardController.ts index 258401e..83a3d8a 100644 --- a/src/controllers/CardController.ts +++ b/src/controllers/CardController.ts @@ -161,77 +161,9 @@ export default class CardController extends BaseController { throw new ZError(105, '解锁物品数量不足') } const items: ItemInfo[] = [] - for (let z = 0 ; z < count; z ++) { - items.push(ItemCtrl.getItemsByInfo(cfg.get)[0]) - } + items.push(...ItemCtrl.getItemsByInfo(cfg.get)) let account = req.user - const cfgMap = global.$cfg.get(BaseConst.ITEMCARD) - let results: any = [] - const cardMap = account.cardMap - let itemToSave: ItemInfo[] = [] - for (let item of items) { - if (item.type != ItemType.CARD) { - results.push({ - id: item.id, - used: 0, - count: item.count - }); - itemToSave.push(item) - continue - } - if (item.type == ItemType.CARD &&!cfgMap.has(item.id)) { - error(`抽卡 ${item.id} 的配置不存在`) - continue - } - const data = cfgMap.get(item.id) - if (data.unlocking >= 30000 ) { // 英雄 - for (let i = 0; i < item.count; i ++) { - let result = account.unlockHero(data.unlocking, data.unlockingtimes) - if (result == 1) { - await addHeroDefaultCardGroup(accountid, data.unlocking, cardMap) - } - if (result > 0) { - results.push({ - id: item.id, - used: 1, - count: 1, - heroid: data.unlocking - }) - } else { - let saveItem = new ItemInfo(item.id, 1, item.weight) - saveItem.type = item.type - itemToSave.push(saveItem) - results.push({ - id: item.id, - count: 1, - used: 0 - }) - } - } - } else { // 随从卡 - for (let i = 0; i < item.count; i ++) { - const result = account.unlockCard(data.unlocking, data.unlockingtimes) - if (result > 0) { - results.push({ - id: item.id, - used: 1, - count: 1, - cardid: data.unlocking - }) - } else { - let saveItem = new ItemInfo(item.id, 1, item.weight) - saveItem.type = item.type - itemToSave.push(saveItem) - results.push({ - id: item.id, - count: 1, - used: 0, - }) - } - } - } - } - await BagItem.addItems(accountid, itemToSave) + const results = await BagItem.parseCardItems(account, items) await account.save() record.count -= itemInfo[0].count await record.save() diff --git a/src/models/ActRecord.ts b/src/models/ActRecord.ts index 18fb311..342b2d5 100644 --- a/src/models/ActRecord.ts +++ b/src/models/ActRecord.ts @@ -19,7 +19,7 @@ interface ActRecordClass extends Base, TimeStamps { } @dbconn() -@index({ 'accountid': 1 , actid: 1, 'day': 1}, { unique: true }) +@index({ 'accountid': 1 , 'actid': 1, 'day': 1}, { unique: true }) @plugin(findOrCreate) @modelOptions({ schemaOptions: diff --git a/src/models/BagItem.ts b/src/models/BagItem.ts index c242643..2ea421d 100644 --- a/src/models/BagItem.ts +++ b/src/models/BagItem.ts @@ -18,6 +18,8 @@ import { BaseConst } from '../constants/BaseConst' import { DropItemCfg } from '../cfg/parsers/DropItemCfg' import { ItemCardCfg } from '../cfg/parsers/ItemCardCfg' import { ItemInfo } from '../logic/ItemDef' +import { error } from '../common/Debug' +import { addHeroDefaultCardGroup } from '../dao/CardGroupDao' export enum ItemType { UNKNOW = 0, // 未知 @@ -94,6 +96,84 @@ class BagItemClass extends FindOrCreate { type: this.itemtype } } + + /** + * 处理10连抽的物品列表 + * @param account + * @param {ItemInfo[]} items + * @return {Promise} + */ + public static async parseCardItems(account: any, items: ItemInfo[]) { + const cardMap = account.cardMap + const cfgMap = global.$cfg.get(BaseConst.ITEMCARD) + let itemToSave: ItemInfo[] = [] + const accountid = account._id + let results: any = [] + for (let item of items) { + if (item.type != ItemType.CARD) { + results.push({ + id: item.id, + used: 0, + count: item.count + }); + itemToSave.push(item) + continue + } + if (item.type == ItemType.CARD &&!cfgMap.has(item.id)) { + error(`抽卡 ${item.id} 的配置不存在`) + continue + } + const data = cfgMap.get(item.id) + if (data.unlocking >= 30000 ) { // 英雄 + for (let i = 0; i < item.count; i ++) { + let result = account.unlockHero(data.unlocking, data.unlockingtimes) + if (result == 1) { + await addHeroDefaultCardGroup(accountid, data.unlocking, cardMap) + } + if (result > 0) { + results.push({ + id: item.id, + used: 1, + count: 1, + heroid: data.unlocking + }) + } else { + let saveItem = new ItemInfo(item.id, 1, item.weight) + saveItem.type = item.type + itemToSave.push(saveItem) + results.push({ + id: item.id, + count: 1, + used: 0 + }) + } + } + } else { // 随从卡 + for (let i = 0; i < item.count; i ++) { + const result = account.unlockCard(data.unlocking, data.unlockingtimes) + if (result > 0) { + results.push({ + id: item.id, + used: 1, + count: 1, + cardid: data.unlocking + }) + } else { + let saveItem = new ItemInfo(item.id, 1, item.weight) + saveItem.type = item.type + itemToSave.push(saveItem) + results.push({ + id: item.id, + count: 1, + used: 0, + }) + } + } + } + } + await BagItem.addItems(accountid, itemToSave) + return results + } } export const BagItem = getModelForClass(BagItemClass,