diff --git a/game-server/app/servers/battle/handler/donateHandler.ts b/game-server/app/servers/battle/handler/donateHandler.ts index 144533290..6179cd6ec 100644 --- a/game-server/app/servers/battle/handler/donateHandler.ts +++ b/game-server/app/servers/battle/handler/donateHandler.ts @@ -20,7 +20,11 @@ export class DonationHandler { constructor(private app: Application) { } - + /** + * 捐献所的等级,捐献的次数,战报,捐献达到的基金,领取宝箱记录 + * @param msg + * @param session + */ async getDonation(msg: {}, session: BackendSession) { const roleId: string = session.get('roleId'); const serverId: number = parseInt(session.get('serverId')); @@ -32,7 +36,11 @@ export class DonationHandler { let { donateFund, reports, donationLv } = await getDonation(code, serverId); return resResult(STATUS.SUCCESS, { receiveBoxs, donateFund, reports, donateCnt:donateCnt||0, donationLv}); } - + /** + * 捐献 + * @param msg + * @param session + */ async donate(msg: {id: number}, session: BackendSession) { const { id } = msg; const roleId: string = session.get('roleId'); @@ -64,7 +72,11 @@ export class DonationHandler { return resResult(STATUS.SUCCESS, { donateFund, reports, donateCnt, goods }); } - + /** + * 领取宝箱 + * @param msg + * @param session + */ async receiveBox(msg: {id: number}, session: BackendSession) { const { id } = msg; const roleId: string = session.get('roleId'); diff --git a/game-server/app/servers/role/handler/equipHandler.ts b/game-server/app/servers/role/handler/equipHandler.ts index 97308080b..10e6e688d 100644 --- a/game-server/app/servers/role/handler/equipHandler.ts +++ b/game-server/app/servers/role/handler/equipHandler.ts @@ -528,8 +528,7 @@ export class EquipHandler { let good = ITID.get(goodInfo.itid); if (good.type != CONSUME_TYPE.JEWEL) return resResult(STATUS.WRONG_PARMS); - //检查宝石消耗是否合法TODO - let needConsumes = checkMaterialEnough(consumes, jewel, count); + let needConsumes = checkMaterialEnough(consumes, jewel, count);//检查是否可以合成,并返回最终需要消耗的材料 if (!needConsumes) return resResult(STATUS.WRONG_PARMS); let res = await handleCost(roleId, sid, needConsumes); @@ -576,26 +575,29 @@ export class EquipHandler { let good = ITID.get(goodInfo.itid); if (good.type != CONSUME_TYPE.JEWEL) return resResult(STATUS.WRONG_PARMS); - //检查宝石消耗是否合法TODO - if (!purchaseGoods) + if (!purchaseGoods) //需要购买才可进行合成的物品 purchaseGoods = []; if (!consumes) consumes = []; - let needConsumes = checkMaterialEnough(consumes.concat(purchaseGoods), jewel, count); + let needConsumes = checkMaterialEnough(consumes.concat(purchaseGoods), jewel, count);//检查是否可以合成,并返回最终需要消耗的材料 if (!needConsumes) return resResult(STATUS.WRONG_PARMS); let items:Array<{id: number, count: number, ratio?:number}> = []; for (let item of purchaseGoods) { - items.push({id: item.id, count: item.count, ratio: 1}) + items.push({id: item.id, count: item.count, ratio: 1})//加上购买的数量 } items = items.concat(needConsumes); - let hasError = await decreaseItems(roleId, sid, items); + let hasError = await decreaseItems(roleId, sid, items);//合并消耗是否足够 if (!!hasError) return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH); await addItems(roleId, roleName, sid, [{ id: jewel, count: count }]); return resResult(STATUS.SUCCESS); } - + /** + * 临时使用的购买物品,后应该在商店中购买 + * @param msg + * @param session + */ public async purchaseGoods(msg: { purchaseGoods: Array<{ id: number, count: number }>}, session: BackendSession) { let { purchaseGoods } = msg; let roleId: string = session.get('roleId'); @@ -607,7 +609,11 @@ export class EquipHandler { } return resResult(STATUS.SUCCESS); } - //合成下一级宝石并穿戴(装备镶嵌界面) + /** + * 合成下一级宝石并穿戴(装备镶嵌界面) + * @param msg + * @param session + */ public async composeNextLevelJewel(msg: { jewel: number, count: number, eid: number, id: number }, session: BackendSession) { let { count, jewel, eid, id } = msg; let roleId: string = session.get('roleId'); @@ -621,25 +627,27 @@ export class EquipHandler { if (good.type != CONSUME_TYPE.JEWEL) return resResult(STATUS.WRONG_PARMS); let equip; - if (!!eid) { + if (!!eid) {//合成并穿戴 equip = await EquipModel.getEquip(eid); let index = findIndex(equip.holes,{id}); + //装备上该位置有穿戴该宝石,且在合成的材料中 if (!!equip.holes[index] && equip.holes[index].jewel == goodInfo.composeMaterial[0].id) { oldJewel = equip.holes[index].jewel; - equip.holes[index].jewel = jewel; + equip.holes[index].jewel = jewel;//合成后的新宝石穿戴到装备上 needUpdate = true; - consumes.push({id: goodInfo.composeMaterial[0].id, count: 1, ratio: 1}); + consumes.push({id: goodInfo.composeMaterial[0].id, count: 1, ratio: 1});//ratio:1表示可以释放掉一颗宝石 } } consumes = consumes.concat(goodInfo.composeMaterial); if (goodInfo.specialMaterial.count) { consumes.push({id: goodInfo.specialMaterial.ids[0], count: goodInfo.specialMaterial.count}) } - let hasError = await decreaseItems(roleId, sid, consumes); + let hasError = await decreaseItems(roleId, sid, consumes);//检查是消耗是否足够 if (!!hasError) return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH); let result = {}; if (needUpdate) { + //穿戴宝石 await EquipModel.updateEquipInfo(eid, { holes: equip.holes }); if (!!equip.hid) { let hero = await HeroModel.findByHidAndRole(equip.hid, roleId); diff --git a/game-server/app/servers/role/handler/roleHandler.ts b/game-server/app/servers/role/handler/roleHandler.ts index bf1cbc21c..2d35a8b54 100644 --- a/game-server/app/servers/role/handler/roleHandler.ts +++ b/game-server/app/servers/role/handler/roleHandler.ts @@ -10,7 +10,7 @@ import { getTeraphAttr, getAtrrNameById } from '../../../consts/constModules/abi import { findIndex } from 'underscore'; import { SclResultInter, SclPosInter } from '../../../pubUtils/interface'; import { SchoolModel } from '../../../db/School'; -import { checkMaterialEnough } from '../../../services/roleService' +import { checkTeraphMaterialEnough } from '../../../services/roleService' import { calPlayerCeAndSave, calAllHeroCe } from '../../../services/playerCeService'; import { HERO_SYSTEM_TYPE } from '../../../consts'; @@ -94,7 +94,7 @@ export class RoleHandler { return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH); await RoleModel.updateRoleInfo(roleId, { title }); let {ce} = await calAllHeroCe( sid, roleId, HERO_SYSTEM_TYPE.TITLE, [title]); - return resResult(STATUS.SUCCESS, { roleId, title, oldCe: reduceCe(oldCe), incRoleCe: ce - reduceCe(oldCe)}); + return resResult(STATUS.SUCCESS, { roleId, title }); } //神像强化 @@ -120,7 +120,7 @@ export class RoleHandler { if (!attrs.length) return resResult(STATUS.ROLE_TERAPH_NOT_STRENGTHEN); // 随机神像中的一条属性并检查道具是否足够 - let {attr, consumes} = checkMaterialEnough(count, attrs, teraphInfo, teraph); + let {attr, consumes} = checkTeraphMaterialEnough(count, attrs, teraphInfo, teraph); for (let key in attr) { teraph[key] += attr[key]; role.globalCeAttr[key].fixUp += attr[key]; diff --git a/game-server/app/services/donateService.ts b/game-server/app/services/donateService.ts index e53126aaf..699434643 100644 --- a/game-server/app/services/donateService.ts +++ b/game-server/app/services/donateService.ts @@ -4,6 +4,11 @@ import { getTodayZeroPoint, nowSeconds } from '../pubUtils/timeUtil'; import { GuildModel } from '../db/Guild'; import { findWhere } from 'underscore'; import { GUILD_STRUCTURE } from '../consts/constModules/guildConst'; +/** + * 获得军团捐献,并检查是否刷新捐献数据 + * @param code + * @param serverId + */ export async function getDonation(code: string, serverId: number) { let donation = await DonationModel.getDonation(code); if (!donation) { @@ -17,7 +22,11 @@ export async function getDonation(code: string, serverId: number) { return donation; } - +/** + * 创建军团捐献信息 + * @param code + * @param serverId + */ export async function createDonation(code: string, serverId: number) { let { structure } = await GuildModel.findGuild(code, serverId, 'structure'); let { lv } = findWhere(structure, {id: GUILD_STRUCTURE.DONATE}); diff --git a/game-server/app/services/equipService.ts b/game-server/app/services/equipService.ts index 3f0eab37c..94abbff46 100644 --- a/game-server/app/services/equipService.ts +++ b/game-server/app/services/equipService.ts @@ -1,67 +1,93 @@ import { mergeSameGoods } from '../pubUtils/util'; import { EquipModel } from "../db/Equip"; import { HeroModel, EPlace, HeroType } from "../db/Hero"; -import { ITID } from "../consts/constModules/itemConst"; import { getHeroJob, getGoodById, gameData, getJewelById, getHeroEquipByClassId } from "../pubUtils/data"; import { calPlayerCeAndSave } from "./playerCeService"; import { HERO_SYSTEM_TYPE } from "../consts"; import { EquipType } from "../db/Equip"; import { calEquipSeids } from '../pubUtils/playerCe'; import { indexOf, findIndex } from 'underscore'; +/** + * 校验前端传入的消耗数量是否准确,并返回消耗的道具并加上特殊材料needConsumes + * @param consumes + * @param jewel + * @param jewelCount + */ export function checkMaterialEnough(consumes:Array<{id: number, count: number}>, jewel: number, jewelCount: number) { let comJewelMap = {}; consumes = mergeSameGoods(consumes); let needConsumes: Array<{id: number, count: number}> = []; - let gidJewelInfo = getGoodById(jewel); + let gidJewelInfo = getGoodById(jewel);//目标宝石信息 for (let { id, count } of consumes) { let jewelInfo = getJewelById(id); - if (!jewelInfo || !jewelInfo.count) + if (!jewelInfo || !jewelInfo.count) //筛选出特殊材料,特殊材料没有合成下一级需要的count数量 continue; - needConsumes.push({ id, count}); - comJewelMap[jewelInfo.good_id] = count + (comJewelMap[jewelInfo.good_id] || 0); - for (let i = jewelInfo.lvLimited; i < gidJewelInfo.lvLimited; i++) { - if (((comJewelMap[jewelInfo.good_id] || 0) % jewelInfo.count != 0)) { - break; + needConsumes.push({ id, count});//将该宝石加入消耗中 + comJewelMap[id] = count + (comJewelMap[id] || 0); + for (let i = jewelInfo.lvLimited; i < gidJewelInfo.lvLimited; i++) {//当前消耗的宝石升级到目标宝石的消耗 + if (((comJewelMap[id] || 0) % jewelInfo.count != 0)) {//jewelInfo的count,表示宝石id合成下一级需要的数量 + break;//数量有余,跳出循环,等待下次合成 } - let comcount = Math.floor(((comJewelMap[jewelInfo.good_id] || 0)) / jewelInfo.count); + let comcount = Math.floor(((comJewelMap[id] || 0)) / jewelInfo.count); if (comcount < 1) { - break; + break;//不能合成,跳出循环,等待下次合成 } - comJewelMap[jewelInfo.nextJewelId] = comcount + (comJewelMap[jewelInfo.nextJewelId] || 0); - delete comJewelMap[jewelInfo.good_id]; + comJewelMap[jewelInfo.nextJewelId] = comcount + (comJewelMap[jewelInfo.nextJewelId] || 0);//jewelInfo的nextJewelId,表示宝石id合成下一级的宝石good_id + delete comJewelMap[id]; if (!!jewelInfo.specialCount) - needConsumes.push({ count: jewelInfo.specialCount * comcount, id: jewelInfo.nextSpecialId}); + needConsumes.push({ count: jewelInfo.specialCount * comcount, id: jewelInfo.nextSpecialId});//消耗中曾加合成下一级需要的特殊消耗物品的数量 jewelInfo = getJewelById(jewelInfo.nextJewelId); } } - if (comJewelMap[jewel] != jewelCount || Object.keys(comJewelMap).length != 1) + if (comJewelMap[jewel] != jewelCount || Object.keys(comJewelMap).length != 1)//检查最终是否可以合成目标宝石jewel,以及对应的数量jewelCount return false; return needConsumes; } - +/** + * 将装备卸载下来,并坚持是否有替换装备的武将,若有则替换 + * @param roleId + * @param sid + * @param equip + * @param hid + * @param id + * @param seqId + */ export async function changeEquip(roleId: string, sid: string, equip: EquipType, hid: number, id: number, seqId: number) { let hero; if (!!hid) //需要卸下或者替换的武将 - hero = await HeroModel.findByHidAndRoleWithEquip(hid, roleId); + hero = await HeroModel.findByHidAndRoleWithEquip(hid, roleId);//需要替换的武将 if (!!equip) {//需要卸下的装备 - if (!!hero) {//判断是否替换装备 + if (!!hero) { let goodInfo = getGoodById(equip.id); - if (goodInfo.lvLimited > hero.lv) - return takeOffEquip(equip.seqId); + if (goodInfo.lvLimited > hero.lv) { + let res = await takeOffEquip(equip.seqId);//不能替换,卸载装备不算战力 + return res; + } let { jobid } = gameData.hero.get(hid); let { job_class } = getHeroJob(jobid); let { classId } = getHeroEquipByClassId(goodInfo.itid); - if (indexOf(classId, job_class) < 0) - return takeOffEquip(equip.seqId); - return dressEquip(roleId, sid, hero, equip); + if (indexOf(classId, job_class) < 0) { + let res = await takeOffEquip(equip.seqId);//不能替换,卸载装备不算战力 + return res; + } + let res = await dressEquip(roleId, sid, hero, equip);//替换给武将,并计算战力 + return res; } else { - return takeOffEquip(equip.seqId); + let res = await takeOffEquip(equip.seqId);//不能替换,卸载装备不算战力 + return res; } } else if (!!hero) {//从穿戴装备的武将上卸下装备 await takeOffEquipAndCalPlayerCe(roleId, sid, seqId, hero, id);//卸下装备并重算战力 } } - +/** + * 从穿戴装备的武将上卸下装备,并重算战力 + * @param roleId + * @param sid + * @param seqId + * @param hero + * @param id + */ export async function takeOffEquipAndCalPlayerCe(roleId: string, sid: string, seqId: number, hero:HeroType, id: number ) { let index = findIndex(hero.ePlace, { id }); if (index < 0) @@ -72,14 +98,23 @@ export async function takeOffEquipAndCalPlayerCe(roleId: string, sid: string, se await calPlayerCeAndSave(sid, roleId, [hero], HERO_SYSTEM_TYPE.EQUIP, args); return { seqId, hid: 0}; } - +/** + * 穿戴装备并重算战力 + * @param roleId + * @param sid + * @param hero + * @param equip + */ export async function dressEquip(roleId: string, sid: string, hero:HeroType, equip: EquipType) { hero = await HeroModel.addEquip(roleId, hero.hid, equip.ePlaceId, equip._id); let args = calEquipSeids(hero); await calPlayerCeAndSave(sid, roleId, [hero], HERO_SYSTEM_TYPE.EQUIP, args); return { seqId: equip.seqId, hid: hero.hid }; } - +/** + * 修改装备未穿戴状态,不计算战力 + * @param seqId + */ async function takeOffEquip(seqId: number) { await EquipModel.updateEquipInfo(seqId, { hid: 0 }); return { seqId, hid: 0}; diff --git a/game-server/app/services/roleService.ts b/game-server/app/services/roleService.ts index 43c99f0d0..8be3c531c 100644 --- a/game-server/app/services/roleService.ts +++ b/game-server/app/services/roleService.ts @@ -4,18 +4,25 @@ import { getRandNum, getRandomArr } from '../pubUtils/util'; import { TERAPH_RANDOM } from "../consts/consts"; import { indexOf } from 'underscore'; const TERAPH_STRENGTHEN = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; -export function checkMaterialEnough(count: number, attrs:Array, teraphInfo: any, teraph: any) { +/** + * 计算强化次数和消耗 + * @param count 强化次数 + * @param attrNames 可以强化的属性名字 + * @param teraphInfo 字典表对应的神像信息 + * @param teraph + */ +export function checkTeraphMaterialEnough(count: number, attrNames:Array, teraphInfo: any, teraph: any) { let res = {}; let consumes = []; let times = 0; if (count < 10) { for (let i = 0; i < count; i++) { - if (!attrs.length) { + if (!attrNames.length) { break; } let num = getRandNum(TERAPH_RANDOM.MIN, TERAPH_RANDOM.MAX); - let arr = getRandomArr(attrs, num) - let critical = getRandNum(0, 100); + let arr = getRandomArr(attrNames, num) + let critical = getRandNum(0, 100);//属性暴击率 let criEffect = 1; if (critical <= teraphInfo.criRate) criEffect = teraphInfo.criEffect; @@ -24,43 +31,48 @@ export function checkMaterialEnough(count: number, attrs:Array, teraphInfo: res[attrName] = teraphInfo[attrName] * criEffect; if (teraph[attrName] + res[attrName] > teraphInfo[attrNameMax]) { res[attrName] = teraphInfo[attrNameMax] - teraph[attrName]; - let attrIndex = indexOf(attrs, attrName); - attrs.splice(attrIndex, 1); + let attrIndex = indexOf(attrNames, attrName); + attrNames.splice(attrIndex, 1); } } times++; } } else if (count == 10){ - let criticalArr = getRandomArr(TERAPH_STRENGTHEN, 2); + let criticalArrTimes = getRandomArr(TERAPH_STRENGTHEN, 2);//10次中随机2次发生暴击 for (let item of TERAPH_STRENGTHEN) { - if (!attrs.length) { + if (!attrNames.length) { break; } let criEffect = 1; - let index = indexOf(criticalArr, {item}); + let index = indexOf(criticalArrTimes, {item}); if (index > 0) { - criEffect = teraphInfo.criEffect; + criEffect = teraphInfo.criEffect;//本次是暴击 item 在 criticalArrTimes 中 } let num = getRandNum(TERAPH_RANDOM.MIN, TERAPH_RANDOM.MAX); - let arr = getRandomArr(attrs, num); + let arr = getRandomArr(attrNames, num); for (let attrName of arr) { res[attrName] = (res[attrName]||0) + teraphInfo[attrName] * criEffect; let attrNameMax = attrName+'Max'; if (teraph[attrName] + res[attrName] > teraphInfo[attrNameMax]) { res[attrName] = teraphInfo[attrNameMax] - teraph[attrName]; - let attrIndex = indexOf(attrs, attrName); - attrs.splice(attrIndex, 1); + let attrIndex = indexOf(attrNames, attrName); + attrNames.splice(attrIndex, 1); } } times++; } } + //计算消耗 for (let {id, count} of teraphInfo.upMaterial) { consumes.push({ id, count: count*times}); } return {attr: res, consumes}; } - +/** + * + * @param channel + * @param user + */ export function addUserToChannel(channel: Channel, user: ChannelUser) { const users = channel.getMembers(); const { uid, sid } = user; diff --git a/game-server/app/services/timeTaskService.ts b/game-server/app/services/timeTaskService.ts index c2b930691..23cfb5262 100644 --- a/game-server/app/services/timeTaskService.ts +++ b/game-server/app/services/timeTaskService.ts @@ -152,6 +152,7 @@ export async function checkResult(pvpDefense: PvpDefenseType, seasonNum: number, score += heroScore.score; } let pLv = getLvByScore(pvpDefense.heroScores); + //pvp锁定的信息存入赛季结算表中 await PvpSeasonResultModel.updatePvpSeasonResult(pvpDefense.roleId, { oldSeasonData:{refOppCnt: pvpDefense.refOppCnt, rankLv, score: pvpDefense.score, pLv: oldPLv, heroScores: oldHeroScores, seasonNum: pvpDefense.seasonNum, challengeCnt, challengeRefTime, seasonEndTime: oldSeasonEndTime diff --git a/shared/db/UserGuild.ts b/shared/db/UserGuild.ts index 44ccbe0c3..f95de737c 100644 --- a/shared/db/UserGuild.ts +++ b/shared/db/UserGuild.ts @@ -66,7 +66,7 @@ export default class UserGuild extends BaseModel { @prop({ required: true, default: new Date(), select: false }) refTimeDaily: Date; - + //练兵场 @prop({ required: true, default: 0 }) trainCount: number;//每日挑战训练场的次数 @@ -78,18 +78,20 @@ export default class UserGuild extends BaseModel { @prop({ required: true, default: [] }) trainRewards: Array;//领取过的进阶等级 - - @prop({ required: true, default: [], type: WishGood, _id: false }) - wishGoods: Array; - + //捐献所 @prop({ required: true, default: [], type: Number }) - receiveBoxs: Array; - - @prop({ required: true, default: 0 }) - wishDntCnt: number;//今天许愿池捐献次数 + receiveBoxs: Array; //今天捐献所领取宝箱id记录, @prop({ required: true, default: 0 }) donateCnt: number;//今天捐献所次数 + //许愿池 + @prop({ required: true, default: [], type: WishGood, _id: false }) + wishGoods: Array; + + @prop({ required: true, default: 0 }) + wishDntCnt: number;//今天许愿池捐献次数 + + public static async getMyAuth(roleId: string, guildCode?: string, userGuild?: UserGuildType) { let myGuild: UserGuildType; diff --git a/shared/db/WishPoolReport.ts b/shared/db/WishPoolReport.ts index 5ecc793b1..15f665c71 100644 --- a/shared/db/WishPoolReport.ts +++ b/shared/db/WishPoolReport.ts @@ -6,16 +6,16 @@ import { nowSeconds, getTodayZeroPoint } from '../pubUtils/timeUtil'; export default class WishPoolReport extends BaseModel { @prop({ required: true }) - guildCode: string; // 角色 id + guildCode: string; // 军团code @prop({ required: true }) dntTime: number; //捐献时间 @prop({ required: true }) - wishRoleId: string; //被捐献人 + wishRoleId: string; //许愿者 @prop({ required: true }) - wishRoleName: string; //捐赠人 + wishRoleName: string; //许愿者name @prop({ required: true }) goodId: number; //捐献物品 @@ -27,7 +27,7 @@ export default class WishPoolReport extends BaseModel { dntRoleId: string; //捐赠人 @prop({ required: true }) - dntRoleName: string; //捐赠人 + dntRoleName: string; //捐赠人name public static async addReport(guildCode: string, wishRoleId: string, wishRoleName: string, dntRoleId: string, dntRoleName: string, goodId: number, count: number) { const doc = new WishPoolReportModel();