许愿池

This commit is contained in:
mamengke01
2021-02-01 20:01:20 +08:00
parent b449995848
commit 830836b809
11 changed files with 149 additions and 36 deletions

View File

@@ -11,7 +11,8 @@ import { pinus } from 'pinus';
import { addEquips, addBags, addSkins } from '../pubUtils/itemUtils';
import { EquipInter, ItemInter, BagInter } from '../pubUtils/interface';
import { gameData } from '../pubUtils/data';
import { indexOf, findIndex } from 'underscore';
import { uniq, indexOf, findIndex } from 'underscore';
import { HeroModel } from '../db/Hero';
export async function handleFixedReward(roleId: string, roleName: string, sid: string, rewardStr: string, multi: number) {
let reward = parseGoodStr(rewardStr);
@@ -217,4 +218,48 @@ export async function decreaseItems(roleId: string, sid: string, bags: Array<{id
pinus.app.get('channelService').pushMessageByUids('onItemUpdate', resResult(STATUS.SUCCESS, {goods: result} ), uids);
}
return false;
}
export async function checkGoods(roleId: string, goodIds: Array<number>) {
let equipIds: Array<number> = [];
let itemIds: Array<number> = [];
let hids: Array<number> = [];
goodIds = uniq(goodIds);
for (let goodId of goodIds) {
let goodInfo = getGoodById(goodId);
if (!!goodInfo) {
let { table } = ITID.get(goodInfo.itid);
if(table == ITEM_TABLE.EQUIP) {
equipIds.push(goodId);
} else if (table == ITEM_TABLE.ITEM) {
itemIds.push(goodId);
}
} else {
hids.push(goodId);
}
}
if (!!hids.length) {
let heros = await HeroModel.findByHidRange(hids, roleId);
if (heros.length < hids.length)
return false;
}
//检查装备是否存在
if (!!equipIds.length) {
let resEquips = await EquipModel.getEquipsByIds(roleId, equipIds);
resEquips = uniq(resEquips, function(resEquip){
return resEquip.id;
});
if (resEquips.length < equipIds.length)
return false;
}
//检查并修改道具
if(itemIds.length > 0) {
let items = await ItemModel.findbyRoleAndIds(roleId, itemIds);
if (items.length < itemIds.length)
return false;
}
return true;
}