diff --git a/game-server/app/servers/role/handler/heroHandler.ts b/game-server/app/servers/role/handler/heroHandler.ts index 45e85942a..c95fa2b8f 100644 --- a/game-server/app/servers/role/handler/heroHandler.ts +++ b/game-server/app/servers/role/handler/heroHandler.ts @@ -81,9 +81,9 @@ export class HeroHandler { let curHero = await HeroModel.createHero({ roleId, serverId, roleName, hid, hName, star, quality, job, skins:[{id: initialSkin, enable: true}] }); - await calPlayerCeAndSave(HERO_SYSTEM_TYPE.INIT, sid, roleId, curHero, {}); + let hero = await calPlayerCeAndSave(HERO_SYSTEM_TYPE.INIT, sid, roleId, curHero, {}); await calAllHeroCe(HERO_SYSTEM_TYPE.ADD_SKIN, sid, roleId, {}, [initialSkin]) - return resResult(STATUS.SUCCESS, {curHero: returnHeroCeRatio(curHero)}); + return resResult(STATUS.SUCCESS, {curHero: returnHeroCeRatio(hero)}); } // 武将升级 diff --git a/game-server/app/servers/role/handler/roleHandler.ts b/game-server/app/servers/role/handler/roleHandler.ts index ca77cb334..67b20d97d 100644 --- a/game-server/app/servers/role/handler/roleHandler.ts +++ b/game-server/app/servers/role/handler/roleHandler.ts @@ -158,7 +158,6 @@ export class RoleHandler { return resResult(STATUS.ROLE_TERAPH_NOT_QUILITY); teraph.attr.set(attrId, 0); - console.log('****', attrId, val) } teraph.grade ++; diff --git a/game-server/app/services/expeditionService.ts b/game-server/app/services/expeditionService.ts index 3d303890d..37d3db932 100644 --- a/game-server/app/services/expeditionService.ts +++ b/game-server/app/services/expeditionService.ts @@ -127,7 +127,7 @@ export async function matchRobots(scale: number, myCe: number, robotCe: number, const { attribute } = json; let newAttribute = getRobotAttribute(attribute, myCe, robotCe, scale); - let ce = newAttribute.calCe(); + let ce = newAttribute.calCelAndReduce(); enemyObj.enemies.push({...json, attribute: newAttribute, lv}); allCe += ce; } @@ -153,21 +153,6 @@ export async function getCEScaleAndRange(roleId: string, curDicExpedition: any) return {scale, range, lv: role.lv} } -// 远征表属性解码 -export function decodeWarJsonAttribute(attribute: string) { - let arr = decodeStr('attribute', attribute); - // 初始化 - let obj = {hp: 0, atk: 0, matk: 0, def: 0, mdef: 0, speed: 0, agi: 0, luk: 0, hit: 0, cri: 0, flee: 0, antCri: 0, damageIncrease: 0, damageDecrease: 0, defIngnore: 0, bloodSuck: 0} - - for(let {id, value} of arr) { - let field = getAtrrNameById(id); - if(field) { - obj[field] = value; - } - } - return obj -} - // 远征累计点数获取 export async function getPointRewardStatus(roleId: string, role?: Role) { if(!role) { diff --git a/game-server/app/services/playerCeService.ts b/game-server/app/services/playerCeService.ts index ce222a59a..5c52ed2ba 100644 --- a/game-server/app/services/playerCeService.ts +++ b/game-server/app/services/playerCeService.ts @@ -14,6 +14,7 @@ import { RoleUpdate } from '../db/Role'; //修改并下发战力 export async function calPlayerCeAndSave(type: number, sid: string, roleId: string, originHero: HeroType, update: HeroUpdate, args?: Array) { let {role, pushHeros, topLineupCe, hero} = await pubCalPlayerCeAndSave(type, roleId, originHero, update, null, args); + console.log(JSON.stringify(pushHeros)) //下发战力 let uids = [{ uid: roleId, sid }]; pinus.app.get('channelService').pushMessageByUids('onPlayerCeUpdate', resResult(STATUS.SUCCESS, { ce: reduceCe(role.ce) , heros: pushHeros, topLineupCe: reduceCe(topLineupCe) }), uids); @@ -23,7 +24,9 @@ export async function calPlayerCeAndSave(type: number, sid: string, roleId: stri export async function calAllHeroCe(type:number, sid: string, roleId: string, update: RoleUpdate, args?:Array) { let {role, ce, pushHeros, topLineupCe } = await reCalAllHeroCe(type, roleId, update, args); - let uids = [{ uid: roleId, sid }]; - pinus.app.get('channelService').pushMessageByUids('onPlayerCeUpdate', resResult(STATUS.SUCCESS, { ce: reduceCe(ce), heros: pushHeros, topLineupCe: reduceCe(topLineupCe) }), uids); + if(pushHeros.length > 0) { + let uids = [{ uid: roleId, sid }]; + pinus.app.get('channelService').pushMessageByUids('onPlayerCeUpdate', resResult(STATUS.SUCCESS, { ce: reduceCe(ce), heros: pushHeros, topLineupCe: reduceCe(topLineupCe) }), uids); + } return role; } \ No newline at end of file diff --git a/game-server/config/serverProtos.ts b/game-server/config/serverProtos.ts index f8c5370f7..9b65994f3 100644 --- a/game-server/config/serverProtos.ts +++ b/game-server/config/serverProtos.ts @@ -21,6 +21,7 @@ module.exports = { "message Hero": { 'required uInt32 hid': 1, 'required uInt32 ce': 2, + 'required uInt32 incHeroCe': 3, }, 'required uInt32 ce': 1, 'repeated Hero heros': 2, diff --git a/shared/domain/roleField/attribute.ts b/shared/domain/roleField/attribute.ts index 99f20c12f..3e3262cd4 100644 --- a/shared/domain/roleField/attribute.ts +++ b/shared/domain/roleField/attribute.ts @@ -4,7 +4,7 @@ import { HERO_CE_RATIO, getAtrrNameById, CE_CONST, HERO_SUB_ATTR_RATIO } from '. // hero表内属性基础格式 export class CeAttrData { @prop({ required: true }) - id?: number = 0; + id: number = 0; @prop({ required: true }) base: number = 0; @prop({ required: true }) @@ -13,16 +13,24 @@ export class CeAttrData { fixUp: number = 0; @prop({ required: true }) equipUp: number = 0; + + constructor(id: number) { + this.id = id; + } } // role表属性格式 export class CeAttrDataRole { @prop({ required: true }) - id?: number = 0; + id: number = 0; @prop({ required: true }) ratioUp: number = 0; @prop({ required: true }) fixUp: number = 0; + + constructor(id: number) { + this.id = id; + } } // 主属性 @@ -109,34 +117,51 @@ export class Attribute { private setSubAttrRatio() { return { - hit: this.hit / HERO_SUB_ATTR_RATIO, - cri: this.cri / HERO_SUB_ATTR_RATIO, - flee: this.flee / HERO_SUB_ATTR_RATIO, - antCri: this.antCri / HERO_SUB_ATTR_RATIO, - damageIncrease: this.damageIncrease / HERO_SUB_ATTR_RATIO, - damageDecrease: this.damageDecrease / HERO_SUB_ATTR_RATIO, - defIngnore: this.defIngnore / HERO_SUB_ATTR_RATIO, - damageCri: this.damageCri / HERO_SUB_ATTR_RATIO + hit: this.hit / HERO_SUB_ATTR_RATIO / HERO_CE_RATIO / HERO_CE_RATIO, + cri: this.cri / HERO_SUB_ATTR_RATIO / HERO_CE_RATIO / HERO_CE_RATIO, + flee: this.flee / HERO_SUB_ATTR_RATIO / HERO_CE_RATIO / HERO_CE_RATIO, + antCri: this.antCri / HERO_SUB_ATTR_RATIO / HERO_CE_RATIO / HERO_CE_RATIO, + damageIncrease: this.damageIncrease / HERO_SUB_ATTR_RATIO / HERO_CE_RATIO / HERO_CE_RATIO, + damageDecrease: this.damageDecrease / HERO_SUB_ATTR_RATIO / HERO_CE_RATIO / HERO_CE_RATIO, + defIngnore: this.defIngnore / HERO_SUB_ATTR_RATIO / HERO_CE_RATIO / HERO_CE_RATIO, + damageCri: this.damageCri / HERO_SUB_ATTR_RATIO / HERO_CE_RATIO / HERO_CE_RATIO } } - public calCe() { - let { cri, flee, damageIncrease, damageDecrease, damageCri } = this.setSubAttrRatio(); + private setMainAttrRatio() { + return { + hp: this.hp / HERO_CE_RATIO / HERO_CE_RATIO, + atk: this.atk / HERO_CE_RATIO / HERO_CE_RATIO, + def: this.def / HERO_CE_RATIO / HERO_CE_RATIO, + mdef: this.mdef / HERO_CE_RATIO / HERO_CE_RATIO + } + } - let hitRate = CE_CONST.HIT_RATE_BASE + CE_CONST.PUT_HIT/2 - flee; // 命中率 + // 战力计算 + public calCe() { + let { hp, atk, def, mdef } = this.setMainAttrRatio(); + let { cri, flee, damageIncrease, damageDecrease, damageCri } = this.setSubAttrRatio(); + let putHit = CE_CONST.PUT_HIT / HERO_SUB_ATTR_RATIO; + let putAntCri = CE_CONST.PUT_ANT_CRI / HERO_SUB_ATTR_RATIO; + + let hitRate = CE_CONST.HIT_RATE_BASE + putHit/2 - flee; // 命中率 if(hitRate > CE_CONST.HIT_RATE_MAX) hitRate = CE_CONST.HIT_RATE_MAX; if(hitRate < CE_CONST.HIT_RATE_MIN) hitRate = CE_CONST.HIT_RATE_MIN; let fleeRate = 1 - hitRate; // 格挡率 - let criRate = CE_CONST.CRI_RATE_BASE + cri - CE_CONST.PUT_ANT_CRI/2; + let criRate = CE_CONST.CRI_RATE_BASE + cri - putAntCri/2; if(criRate > CE_CONST.CRI_RATE_MAX) criRate = CE_CONST.CRI_RATE_MAX; if(criRate < CE_CONST.CRI_RATE_MIN) criRate = CE_CONST.CRI_RATE_MIN; let criValue = CE_CONST.CRI_VALUE_BASE + damageCri; - let validHp = this.hp + (this.def + this.mdef) * 0.5 / ((1 - fleeRate * CE_CONST.FLEE_VALUE) * (1 - damageDecrease)); // 有效生命 - let validAtk = this.atk * hitRate * ( 1 + criRate * criValue) * ( 1 + damageIncrease); // 有效输出 - let ce = Math.floor(validHp * validAtk); + let validHp = hp + (def + mdef) * 0.5 / ((1 - fleeRate * CE_CONST.FLEE_VALUE) * (1 - damageDecrease)); // 有效生命 + let validAtk = atk * hitRate * ( 1 + criRate * criValue) * ( 1 + damageIncrease); // 有效输出 + let ce = Math.floor(validHp * validAtk * HERO_CE_RATIO * HERO_CE_RATIO); return ce > 0? ce: 1; } + + public calCelAndReduce() { + return Math.floor(this.calCe() / HERO_CE_RATIO / HERO_CE_RATIO); + } } \ No newline at end of file diff --git a/shared/pubUtils/dictionary/DicHero.ts b/shared/pubUtils/dictionary/DicHero.ts index 8c448e04b..100703aea 100644 --- a/shared/pubUtils/dictionary/DicHero.ts +++ b/shared/pubUtils/dictionary/DicHero.ts @@ -46,12 +46,8 @@ function parseBaseAbilityArr(json) { let map = new Map(); map.set(ABI_TYPE.ABI_HP, json.hp||0); map.set(ABI_TYPE.ABI_ATK, json.atk||0); - map.set(ABI_TYPE.ABI_MATK, json.matk||0); map.set(ABI_TYPE.ABI_DEF, json.def||0); map.set(ABI_TYPE.ABI_MDEF, json.mdef||0); - map.set(ABI_TYPE.ABI_AGI, json.agi||0); - map.set(ABI_TYPE.ABI_LUK, json.luk||0); - map.set(ABI_TYPE.ABI_SPEED, json.speed||0); return map } @@ -59,11 +55,7 @@ function parseBaseAbilityUpArr(json) { let map = new Map(); map.set(ABI_TYPE.ABI_HP, json.hp_up||0); map.set(ABI_TYPE.ABI_ATK, json.atk_up||0); - map.set(ABI_TYPE.ABI_MATK, json.matk_up||0); map.set(ABI_TYPE.ABI_DEF, json.def_up||0); map.set(ABI_TYPE.ABI_MDEF, json.mdef_up||0); - map.set(ABI_TYPE.ABI_AGI, json.agi_up||0); - map.set(ABI_TYPE.ABI_LUK, json.luk_up||0); - map.set(ABI_TYPE.ABI_SPEED, json.speed_up||0); return map } \ No newline at end of file diff --git a/shared/pubUtils/playerCe.ts b/shared/pubUtils/playerCe.ts index 3ca980812..a388b3854 100644 --- a/shared/pubUtils/playerCe.ts +++ b/shared/pubUtils/playerCe.ts @@ -233,12 +233,16 @@ export async function calculatetopLineup(role: RoleType, hid?: number, ce?: numb * @param {number[]} removeSeidList 用于更新被动 */ export function calHeroInitIncAttr(hero: HeroType, addSeidList: Array, removeSeidList: Array) { - let originHero = new HeroModel(); - let heroAttrs = calHeroStarIncAttr(originHero, hero, HERO_SYSTEM_TYPE.INIT, addSeidList, removeSeidList); - let curSkin = hero.skins.find(cur => cur.enable); - heroAttrs = calHeroWearSkinIncAttr(hero, curSkin ? curSkin.id : 0, 0, addSeidList, removeSeidList, true); - heroAttrs = calHeroJobAttr(originHero, hero, addSeidList, removeSeidList); - return heroAttrs; + try{ + delete hero._id; + let heroAttrs = calHeroStarIncAttr(hero, hero, HERO_SYSTEM_TYPE.INIT, addSeidList, removeSeidList); + let curSkin = hero.skins.find(cur => cur.enable); + heroAttrs = calHeroWearSkinIncAttr(hero, curSkin ? curSkin.id : 0, 0, addSeidList, removeSeidList, true); + heroAttrs = calHeroJobAttr(hero, hero, addSeidList, removeSeidList); + return heroAttrs; + }catch(e) { + console.error(e); + } } /** @@ -271,13 +275,14 @@ function calHeroAddSkin(role: RoleType, skinIds: Array) { export function calHeroStarIncAttr(originHero: HeroType, update: HeroUpdate, type: number, addSeidList: Array, removeSeidList: Array) { let isInit = type == HERO_SYSTEM_TYPE.INIT; let { hid, star: originStar, starStage: originStarStage, quality: originQuality, colorStar: originColorStar, colorStarStage: originColorStarStage, attr: heroAttrs, skins, lv } = originHero; - let { star = originStar, starStage = originStarStage, quality = originQuality, colorStar = originStarStage, colorStarStage = originColorStarStage } = update; + let { star = originStar, starStage = originStarStage, quality = originQuality, colorStar = originColorStar, colorStarStage = originColorStarStage } = update; const dicHero = gameData.hero.get(hid); const isWake = colorStar > 0; // 是否觉醒,只要激活了觉醒,彩星就会 > 1 const isFirstWake = colorStar > 0 && originColorStar <= 0; // 是否是初次觉醒 - const isUpStar = originStarStage + 1 != starStage; // 如果升星了starStage会变成0 + const isUpStar = originStar != star || originColorStar != colorStar; // 是否有升星 + console.log('*isUpstar', isUpStar, originStar, star, originColorStar, colorStar) const dicStar = isWake ? getHeroWakeByQuality(dicHero.quality, originColorStar) : getHeroStarByQuality(quality, originStar); // 星级表 @@ -287,7 +292,7 @@ export function calHeroStarIncAttr(originHero: HeroType, update: HeroUpdate, typ } else if (type == HERO_SYSTEM_TYPE.LVUP) { stages = getAllAttrStage(); } else if (type == HERO_SYSTEM_TYPE.STAR) { - stages = [isUpStar ? ABI_STAGE.END : starStage]; + stages.push(isUpStar? ABI_STAGE.END: starStage); } else if (type == HERO_SYSTEM_TYPE.QUALITY) { stages = getAllAttrStage(); } else if (type = HERO_SYSTEM_TYPE.COLORSTAR) { @@ -335,7 +340,7 @@ type updateCeAttr = Partial; function updateHeroAttr(heroAttrs: CeAttrData[], id: number, update: { inc?: updateCeAttr, set?: updateCeAttr }) { let curAttr = heroAttrs.find(cur => cur.id == id); if(!curAttr) { - curAttr = new CeAttrData(); + curAttr = new CeAttrData(id); heroAttrs.push(curAttr); } if(update.inc) { @@ -358,7 +363,7 @@ type updateCeAttrRole = Partial; function updateRoleAttr(roleAttrs: CeAttrDataRole[], id: number, update: { inc?: updateCeAttrRole, set?: updateCeAttrRole }) { let curAttr = roleAttrs.find(cur => cur.id == id); if(!curAttr) { - curAttr = new CeAttrDataRole(); + curAttr = new CeAttrDataRole(id); roleAttrs.push(curAttr); } if(update.inc) { @@ -999,19 +1004,21 @@ function calHeroCeScrollIncAttr(originHero: HeroType, update: HeroUpdate) { */ function calTitle(role: RoleType, update: RoleUpdate) { let { title: oldTitle, attr: roleAttrs } = role; - let { title = oldTitle } = update; + let { title: newTitle = oldTitle } = update; - let dicTitle = gameData.title.get(title); - if(!dicTitle) return null; - - for (let i = ABI_TYPE.ABI_HP; i < ABI_TYPE.ABI_MAX; i++) { - if(dicTitle.mainAttrValue.has(i)) { - let fixUp = dicTitle.mainAttrValue.get(i) * HERO_CE_RATIO; - updateRoleAttr(roleAttrs, i, { inc: { fixUp }}); - } - if(dicTitle.assiAttrValue.has(i)) { - let fixUp = dicTitle.assiAttrValue.get(i) * HERO_CE_RATIO; - updateRoleAttr(roleAttrs, i, { inc: { fixUp }}); + for(let title = oldTitle; title <= newTitle; title++) { + let dicTitle = gameData.title.get(title); + if(!dicTitle) break; + + for (let i = ABI_TYPE.ABI_HP; i < ABI_TYPE.ABI_MAX; i++) { + if(dicTitle.mainAttrValue.has(i)) { + let fixUp = dicTitle.mainAttrValue.get(i) * HERO_CE_RATIO; + updateRoleAttr(roleAttrs, i, { inc: { fixUp }}); + } + if(dicTitle.assiAttrValue.has(i)) { + let fixUp = dicTitle.assiAttrValue.get(i) * HERO_CE_RATIO; + updateRoleAttr(roleAttrs, i, { inc: { fixUp }}); + } } } @@ -1080,5 +1087,6 @@ function calTeraphAssistAttr(role: RoleType, update: RoleUpdate, id: number) { * @param role */ export function initRoleAtrr(role: RoleType) { - calTitle(role, role); // 计算初始爵位带来的全局 + delete role._id; + calTitle({...role, title: 0}, role); // 计算初始爵位带来的全局 }