diff --git a/game-server/app/servers/battle/handler/donateHandler.ts b/game-server/app/servers/battle/handler/donateHandler.ts index fae5e8eab..eeef4c130 100644 --- a/game-server/app/servers/battle/handler/donateHandler.ts +++ b/game-server/app/servers/battle/handler/donateHandler.ts @@ -29,7 +29,7 @@ export class DonationHandler { return resResult(STATUS.WRONG_PARMS); const { guildCode: code, donateCnt, receiveBoxs } = userGuild; let { donateFund, reports } = await getDonation(code, serverId); - return resResult(STATUS.SUCCESS, { receiveBoxs, donateFund, reports, donateCnt }); + return resResult(STATUS.SUCCESS, { receiveBoxs, donateFund, reports, donateCnt:donateCnt||0 }); } async donate(msg: {id: number}, session: BackendSession) { diff --git a/game-server/app/servers/battle/handler/guildRefineHandler.ts b/game-server/app/servers/battle/handler/guildRefineHandler.ts index e6613fbf0..8699492b6 100644 --- a/game-server/app/servers/battle/handler/guildRefineHandler.ts +++ b/game-server/app/servers/battle/handler/guildRefineHandler.ts @@ -5,7 +5,7 @@ import { STATUS, GUILD_OPERATE } from '../../../consts'; import { GuildRefineModel } from '../../../db/GuildRefine'; import { getArmyDevelopConsumeById, getGoodById } from '../../../pubUtils/data'; import { nowSeconds } from '../../../pubUtils/timeUtil'; -import { handleCost, addItems } from '../../../services/rewardService'; +import { handleCost, addItems, checkGoods } from '../../../services/rewardService'; import { GuildModel } from '../../../db/Guild'; import { findIndex, findWhere } from 'underscore'; import { lockData } from '../../../services/redLockService'; @@ -41,12 +41,12 @@ export class GuildRefineHandler { const roleId: string = session.get('roleId'); const sid: string = session.get('sid'); const roleName: string = session.get('roleName'); + let pieceInfo = getGoodById(pid); let userGuild = await UserGuildModel.getMyGuild(roleId, 'guildCode'); if (!userGuild) return resResult(STATUS.WRONG_PARMS); let { guildCode: code } = userGuild; - let pieceInfo = getGoodById(pid); - //判断是否有该装备或物品 + let { scienceTrees } = await GuildRefineModel.getRefine(code); let findDevelopConsume; for (let scienceTree of scienceTrees) { @@ -60,7 +60,6 @@ export class GuildRefineHandler { } if (!findDevelopConsume) return resResult(STATUS.GUILD_NOT_REFINE_THE_EQUIP); - let result = await handleCost(roleId, sid, findDevelopConsume.honourConsume); if(!result) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH); diff --git a/game-server/app/servers/battle/handler/wishPoolHandler.ts b/game-server/app/servers/battle/handler/wishPoolHandler.ts index f34bd118a..048d10789 100644 --- a/game-server/app/servers/battle/handler/wishPoolHandler.ts +++ b/game-server/app/servers/battle/handler/wishPoolHandler.ts @@ -4,14 +4,14 @@ import { GuildModel } from '../../../db/Guild'; import { WishPoolReportModel } from '../../../db/WishPoolReport'; import { resResult, genCode } from '../../../pubUtils/util'; import { STATUS } from '../../../consts'; -import { nowSeconds } from '../../../pubUtils/timeUtil'; import { getArmyWishPoolBaseByLv, getGoodById } from '../../../pubUtils/data'; -import { handleCost, addItems } from '../../../services/rewardService'; -import { CHAT_SERVER } from '../../../consts'; +import { addItems, checkGoods } from '../../../services/rewardService'; +import { IT_TYPE } from '../../../consts/constModules/itemConst'; import { GUILD_STRUCTURE } from '../../../consts/constModules/guildConst'; import { getUserGuildWithRefActive } from '../../../services/guildService'; -import { ARMY } from '../../../pubUtils/dicParam'; import { findIndex, findWhere } from 'underscore'; +import { RoleModel } from '../../../db/Role'; +import { getRedis } from '../../../services/redisService'; export default function(app: Application) { return new WishPoolHandler(app); } @@ -23,18 +23,18 @@ export class WishPoolHandler { async getWishPool(msg: {}, session: BackendSession) { const roleId: string = session.get('roleId'); - let userGuild = await getUserGuildWithRefActive(roleId, 'donateCnt receiveBoxs guildCode'); + let userGuild = await getUserGuildWithRefActive(roleId, 'wishDntCnt wishGoods guildCode'); if (!userGuild) return resResult(STATUS.WRONG_PARMS); const { guildCode: code, wishDntCnt, wishGoods } = userGuild; - let userGuilds = await UserGuildModel.getWishPoolGoods(code, ' wishDntCnt wishGoods'); + let userGuilds = await UserGuildModel.getWishPoolGoods(code, ' wishDntCnt wishGoods roleId'); let list = []; - userGuilds.map(({ wishGoods })=>{ + userGuilds.map(({ wishGoods, roleId })=>{ wishGoods.map(({ type, goodId, count, receiveCnt, drawCnt, id })=>{ - list.push({ type, goodId, count, receiveCnt, drawCnt, id }) + list.push({ type, goodId, count, receiveCnt, drawCnt, id, roleId }) }); }); - return resResult(STATUS.SUCCESS, { list, wishDntCnt, wishGoods }); + return resResult(STATUS.SUCCESS, { list, wishDntCnt:wishDntCnt||0, wishGoods }); } // 许愿 @@ -46,10 +46,24 @@ export class WishPoolHandler { let goodInfo = getGoodById(goodId) if (!goodInfo) return resResult(STATUS.WRONG_PARMS); + if (!(goodInfo.goodType == IT_TYPE.HERO_PIECE && type == 2 ) && !(goodInfo.goodType == IT_TYPE.EQUIP_PIECE && type == 1 )) + return resResult(STATUS.WRONG_PARMS); let userGuild = await getUserGuildWithRefActive(roleId, ' wishDntCnt wishGoods guildCode wishGoods'); if (!userGuild) return resResult(STATUS.WRONG_PARMS); - const { guildCode: code, wishDntCnt, wishGoods } = userGuild; + let result = await checkGoods(roleId, [goodId]); + if (!result) { + if (goodInfo.goodType == IT_TYPE.HERO_PIECE ) { + result = await checkGoods(roleId, [goodInfo.hid]); + if (!result) + return resResult(STATUS.GUILD_WISH_POOL_NOT_OWN_HERO); + } else if (goodInfo.goodType == IT_TYPE.EQUIP_PIECE ) { + result = await checkGoods(roleId, [goodInfo.equipId]); + if (!result) + return resResult(STATUS.GUILD_WISH_POOL_NOT_OWN_EQUIP); + } + } + const { guildCode: code, wishGoods } = userGuild; let { structure } = await GuildModel.findGuild(code, serverId, 'structure'); let { lv } = findWhere(structure, {id: GUILD_STRUCTURE.DONATE}); let { wishGoodsEquips, wishGoodsHeros } = getArmyWishPoolBaseByLv(lv); @@ -58,33 +72,59 @@ export class WishPoolHandler { return resResult(STATUS.WRONG_PARMS); if (type == 1) { let wishGoodsEquip = findWhere(wishGoodsEquips, { quality: goodInfo.quality}); + if (!wishGoodsEquip) + return resResult(STATUS.WRONG_PARMS); count = wishGoodsEquip.count; } else { let wishGoodsHero = findWhere(wishGoodsHeros, { quality: goodInfo.quality}); + if (!wishGoodsHero) + return resResult(STATUS.WRONG_PARMS); count = wishGoodsHero.count; } + const id = genCode(6); - let { wishGoods : resWishGoods } = await UserGuildModel.pushAndUpdate(roleId, { wishGoods }, { wishGoods: { type, goodId, count, receiveCnt: 0, drawCnt: 0, id} }, 'wishGoods'); - return resResult(STATUS.SUCCESS, { wishDntCnt, wishGoods: resWishGoods }); + let { wishGoods : resWishGoods } = await UserGuildModel.pushAndUpdate(roleId, {}, { wishGoods: { type, goodId, count, receiveCnt: 0, drawCnt: 0, id} }, 'wishGoods'); + return resResult(STATUS.SUCCESS, { wishGoods: resWishGoods }); } // 捐赠 async donateGoods(msg: {wishRoleId: string, id: string}, session: BackendSession) { let { wishRoleId, id } = msg; const dntRoleId: string = session.get('roleId'); - const serverId: number = parseInt(session.get('serverId')); const dntRoleName: string = session.get('roleName'); - - let wishUserGuild = await getUserGuildWithRefActive(wishRoleId, ' wishDntCnt wishGoods guildCode wishGoods'); + if (wishRoleId == dntRoleId) + return resResult(STATUS.WRONG_PARMS); + let role = await RoleModel.findByRoleId(wishRoleId); + if (!role) + return resResult(STATUS.WRONG_PARMS);//没有玩家 + let wishUserGuild = await getUserGuildWithRefActive(wishRoleId, ' wishDntCnt wishGoods guildCode'); if (!wishUserGuild) return resResult(STATUS.WRONG_PARMS); const { guildCode: code, wishGoods } = wishUserGuild; - const { } = await GuildModel.findGuild(code, serverId); + let dntRoleGuild = await getUserGuildWithRefActive(dntRoleId, ' wishDntCnt wishGoods guildCode'); + if (!dntRoleGuild) + return resResult(STATUS.WRONG_PARMS); + if (dntRoleGuild.guildCode != code) + return resResult(STATUS.WRONG_PARMS); + if (dntRoleGuild.wishDntCnt >= 3) + return resResult(STATUS.WRONG_PARMS); let wishGood = findWhere(wishGoods, { id }); - if (wishGood) { - + if (!wishGood) + return resResult(STATUS.WRONG_PARMS);//没有该许愿 + if (wishGood.receiveCnt >= wishGood.count) + return resResult(STATUS.WRONG_PARMS);//已经收到 + let { wishDntCnt } = await UserGuildModel.donateGoods(dntRoleId, 1, 'wishDntCnt'); + let { wishGoods: resWishGoods } = await UserGuildModel.donateUpdate(wishRoleId, id, 'wishGoods'); + let key = 'login_roleId_' + wishRoleId; + let sid = await getRedis(key); + let goods = await addItems(wishRoleId, role.roleName , sid , [{ id : wishGood.goodId, count: 1 }]); + if (!!sid) { + this.app.channelService.pushMessageByUids('onWishGoodsRecive', resResult(STATUS.SUCCESS, { goods }), [{uid:wishRoleId, sid}]); } - // WishPoolReportModel.addReport(code, roleId: wishRoleId, roleName: , dntRoleId, dntRoleName, goodId, 1); + await WishPoolReportModel.addReport(code, wishRoleId, role.roleName , dntRoleId, dntRoleName, wishGood.goodId, 1); + return resResult(STATUS.SUCCESS, { wishDntCnt, updateWishGoods: resWishGoods.map(({type, goodId, count, receiveCnt, drawCnt, id})=>{ + return { type, goodId, count, receiveCnt, drawCnt, id, roleId: wishRoleId }; + })}); } async receiveGoods(msg: { id: string }, session: BackendSession) { @@ -92,7 +132,7 @@ export class WishPoolHandler { const roleId: string = session.get('roleId'); const roleName: string = session.get('roleName'); const sid: string = session.get('sid'); - let userGuild = await getUserGuildWithRefActive(roleId, 'donateCnt receiveBoxs guildCode'); + let userGuild = await getUserGuildWithRefActive(roleId, 'wishDntCnt wishGoods guildCode'); if (!userGuild) return resResult(STATUS.WRONG_PARMS); const { guildCode: code, wishGoods } = userGuild; @@ -114,7 +154,7 @@ export class WishPoolHandler { if (!userGuild) return resResult(STATUS.WRONG_PARMS); const { guildCode: code } = userGuild; - const reports = await WishPoolReportModel.getReportsByTime(code, 1); + const reports = await WishPoolReportModel.getReportsByTime(code, 1);//获得今天的捐赠日报 return resResult(STATUS.SUCCESS, { reports }); } diff --git a/game-server/app/services/rewardService.ts b/game-server/app/services/rewardService.ts index 861f00b11..078c687af 100644 --- a/game-server/app/services/rewardService.ts +++ b/game-server/app/services/rewardService.ts @@ -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) { + let equipIds: Array = []; + let itemIds: Array = []; + let hids: Array = []; + 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; } \ No newline at end of file diff --git a/shared/consts/constModules/itemConst.ts b/shared/consts/constModules/itemConst.ts index 2b2c51959..81597ba16 100644 --- a/shared/consts/constModules/itemConst.ts +++ b/shared/consts/constModules/itemConst.ts @@ -1,5 +1,8 @@ export const IT_TYPE = { BLUEPRT: 28, + EQUIP_PIECE: 3, + EQUIP: 2, + HERO_PIECE: 7, } diff --git a/shared/consts/statusCode.ts b/shared/consts/statusCode.ts index caaf639eb..e567e4df2 100644 --- a/shared/consts/statusCode.ts +++ b/shared/consts/statusCode.ts @@ -152,6 +152,8 @@ export const STATUS = { GUILD_DONATE_TIMES_NOT_ENOUGH: { code: 20922, simStr: '今日捐献的次数不够' }, GUILD_DONATE_BOXS_IS_GOT: { code: 20923, simStr: '该捐献宝箱已领取' }, GUILD_DONATE_BOXS_NOT_GOT: { code: 20924, simStr: '该捐献宝箱未达到领取条件' }, + GUILD_WISH_POOL_NOT_OWN_EQUIP: { code: 20926, simStr: '未拥有此装备或碎片,不能许愿' }, + GUILD_WISH_POOL_NOT_OWN_HERO: { code: 20927, simStr: '未拥有此武将或碎片,不能许愿' }, GUILD_SCRIPT_IS_OPENED_TODAY: { code: 20950, simStr: '今日演武场已开启' }, GUILD_SCRIPT_NOT_OPENED: { code: 20951, simStr: '演武场未开启' }, diff --git a/shared/db/Equip.ts b/shared/db/Equip.ts index 4792d0bb8..c475287a9 100644 --- a/shared/db/Equip.ts +++ b/shared/db/Equip.ts @@ -154,6 +154,12 @@ export default class Equip extends BaseModel { const user: EquipType[] = await EquipModel.find(searchObj).lean(lean); return user; } + + public static async getEquipsByIds(roleId: string, ids: Array) { + let result = await EquipModel.find({ roleId, id: { $in: ids } }); + return result; + } + } export const EquipModel = getModelForClass(Equip); diff --git a/shared/db/Item.ts b/shared/db/Item.ts index 3c9b3da9a..a122a103d 100644 --- a/shared/db/Item.ts +++ b/shared/db/Item.ts @@ -24,12 +24,12 @@ export default class Item extends BaseModel { public static async findbyRole(roleId: string, lean = true) { - const items: ItemType[] = await ItemModel.find({ roleId }).select('id count type').lean(lean); + const items: ItemType[] = await ItemModel.find({ roleId, count: {$gte: 0} }).select('id count type').lean(lean); return items; } public static async findbyRoleAndIds(roleId: string, ids: Array, lean = true) { - const items: ItemType[] = await ItemModel.find({ roleId, id: { $in: ids } }).select('id count type').lean(lean); + const items: ItemType[] = await ItemModel.find({ roleId, id: { $in: ids }, count: {$gte: 0} }).select('id count type').lean(lean); return items; } diff --git a/shared/db/UserGuild.ts b/shared/db/UserGuild.ts index 59846e5fe..0060598d4 100644 --- a/shared/db/UserGuild.ts +++ b/shared/db/UserGuild.ts @@ -83,10 +83,10 @@ export default class UserGuild extends BaseModel { @prop({ required: true, default: [], type: Number }) receiveBoxs: Array; - @prop({ required: true }) + @prop({ required: true, default: 0 }) wishDntCnt: number;//今天许愿池捐献次数 - @prop({ required: true }) + @prop({ required: true, default: 0 }) donateCnt: number;//今天捐献所次数 public static async getMyAuth(roleId: string, guildCode?: string, userGuild?: UserGuildType) { @@ -192,6 +192,16 @@ export default class UserGuild extends BaseModel { const result: UserGuildType = await UserGuildModel.findOneAndUpdate({ roleId, status: USER_GUILD_STATUS.ON }, { $set: update, $push: pushData }, { new: true }).select(select).lean(); return result; } + + public static async donateGoods(roleId: string, wishDntCnt: number, select?: string, lean = true) { + const result: UserGuildType = await UserGuildModel.findOneAndUpdate({ roleId, status: USER_GUILD_STATUS.ON }, { $inc: { wishDntCnt } }, { new: true }).select(select).lean(); + return result; + } + + public static async donateUpdate(roleId: string, id: string, select?: string, lean = true) { + const result: UserGuildType = await UserGuildModel.findOneAndUpdate({ roleId, status: USER_GUILD_STATUS.ON, 'wishGoods.id': id }, { $inc: { 'wishGoods.$.receiveCnt': 1, 'wishGoods.$.drawCnt': 1} }, { new: true }).select(select).lean(); + return result; + } } export const UserGuildModel = getModelForClass(UserGuild); diff --git a/shared/db/WishPoolReport.ts b/shared/db/WishPoolReport.ts index 36baac98f..a158ce1c0 100644 --- a/shared/db/WishPoolReport.ts +++ b/shared/db/WishPoolReport.ts @@ -12,10 +12,10 @@ export default class WishPoolReport extends BaseModel { dntTime: number; //捐献时间 @prop({ required: true }) - roleId: string; //被捐献人 + wishRoleId: string; //被捐献人 @prop({ required: true }) - roleName: string; //捐赠人 + wishRoleName: string; //捐赠人 @prop({ required: true }) goodId: number; //捐献物品 @@ -29,9 +29,9 @@ export default class WishPoolReport extends BaseModel { @prop({ required: true }) dntRoleName: string; //捐赠人 - public static async addReport(guildCode: string, roleId: string, roleName: string, dntRoleId: string, dntRoleName: string, goodId: number, count: number, lean = true) { + public static async addReport(guildCode: string, wishRoleId: string, wishRoleName: string, dntRoleId: string, dntRoleName: string, goodId: number, count: number, lean = true) { const doc = new WishPoolReportModel(); - const report = Object.assign(doc.toJSON(), { guildCode, roleId, roleName, dntRoleId, dntRoleName, goodId, dntTime: nowSeconds(), count }); + const report = Object.assign(doc.toJSON(), { guildCode, wishRoleId, wishRoleName, dntRoleId, dntRoleName, goodId, dntTime: nowSeconds(), count }); await WishPoolReportModel.create(report); return report; } diff --git a/shared/pubUtils/dictionary/DicGoods.ts b/shared/pubUtils/dictionary/DicGoods.ts index b28c34e89..06c13debd 100644 --- a/shared/pubUtils/dictionary/DicGoods.ts +++ b/shared/pubUtils/dictionary/DicGoods.ts @@ -56,6 +56,8 @@ export interface DicGoods { readonly nextJewelId?: number; readonly specialCount?: number; readonly nextSpecialId?: number; + // 对应的装备id + readonly equipId?: number; } const str = readJsonFile(FILENAME.DIC_GOODS); @@ -85,7 +87,8 @@ const DicGoodsKeys: KeysEnum = { count: true, nextJewelId: true, specialCount: true, - nextSpecialId: true + nextSpecialId: true, + equipId: true } export const dicJewel = new Map(); export const dicGoods = new Map(); @@ -98,6 +101,11 @@ arr.forEach(o => { o.specialAttr = parseSpecialAttr(o.specialAttr); o.specialMaterial = parseSpecialMaterial(o.specialMaterial); o.randomEffect = parseNumberList(o.randomEffect); + if (o.goodType == IT_TYPE.EQUIP_PIECE) { + let good = findWhere(arr, { pieceId: o.good_id }); + if (!!good) + o.equipId = good.good_id; + } dicGoods.set(o.good_id, _.pick(o, Object.keys(DicGoodsKeys))); if (o.itid == IT_TYPE.BLUEPRT) {