diff --git a/game-server/app/servers/role/handler/heroHandler.ts b/game-server/app/servers/role/handler/heroHandler.ts index ce811b93c..b0a102dd9 100644 --- a/game-server/app/servers/role/handler/heroHandler.ts +++ b/game-server/app/servers/role/handler/heroHandler.ts @@ -9,6 +9,7 @@ import { RoleModel } from '../../../db/Role'; import { ItemModel } from '../../../db/Item'; import { gameData, getHeroExpByLv, getHeroStarByQuality, getHeroWakeByQuality, getHeroLvByExp, getMaxGradeByjobClass, getJobByGradeAndClass, getFriendShipById } from '../../../pubUtils/data'; import { RewardInter } from '../../../pubUtils/interface'; +import { getDropItems } from '../../../consts/constModules/itemConst' export default function(app: Application) { return new HeroHandler(app); @@ -44,7 +45,14 @@ export class HeroHandler { let {id, count} = msg; //let result = await handleCost(roleId, sid, [{id, count}] ); - let result = await addItems(roleId, roleName, sid, [{id, count}] ); + let items = [{id, count}]; + if (id == 999999) { + items = getDropItems(); + let role = await RoleModel.findByRoleId(roleId); + role.lv = 60; + await RoleModel.updateRoleInfo(roleId, role); + } + let result = await addItems(roleId, roleName, sid, items ); if(!result) { return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH); } diff --git a/game-server/app/servers/role/handler/roleHandler.ts b/game-server/app/servers/role/handler/roleHandler.ts index 8f9669d92..00c0fa8f6 100644 --- a/game-server/app/servers/role/handler/roleHandler.ts +++ b/game-server/app/servers/role/handler/roleHandler.ts @@ -92,6 +92,7 @@ export class RoleHandler { if (!result) return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH); await RoleModel.updateRoleInfo(roleId, { title }); + await calAllHeroCe( sid, roleId, 2, [title]); return resResult(STATUS.SUCCESS, { roleId, title }); } @@ -284,7 +285,6 @@ export class RoleHandler { }); } - // 激活/升级名将谱 async activeHeroScroll(msg: { hid: number }, session: BackendSession) { let roleId = session.get('roleId'); diff --git a/game-server/app/services/playerCeService.ts b/game-server/app/services/playerCeService.ts index cc69b1427..7c28c80b9 100644 --- a/game-server/app/services/playerCeService.ts +++ b/game-server/app/services/playerCeService.ts @@ -21,7 +21,7 @@ export async function calPlayerCeAndSave(sid: string, roleId: string, heros: Arr } export async function calAllHeroCe(sid: string, roleId: string, type?:number, args?:Array) { - let {ce, pushHeros}= await reCalAllHeroCe(roleId,type, args); + let {ce, pushHeros}= await reCalAllHeroCe(roleId, type, args); let uids = [{ uid: roleId, sid }]; pinus.app.get('channelService').pushMessageByUids('onPlayerCeUpdate', resResult(STATUS.SUCCESS, { ce: reduceCe(ce), heros: pushHeros, topFiveCe: 0 }), uids); return; diff --git a/game-server/app/services/roleService.ts b/game-server/app/services/roleService.ts index f7599ebcd..aa94c1a83 100644 --- a/game-server/app/services/roleService.ts +++ b/game-server/app/services/roleService.ts @@ -1,11 +1,5 @@ import { getRandNum, getRandomArr } from '../pubUtils/util'; -import { EquipModel } from "../db/Equip"; -import { HeroModel, EPlace } from "../db/Hero"; -import { ITID } from "../consts/constModules/itemConst"; -import { getHeroJob, getGoodById, gameData, getJewelById, getHeroEquipByClassId } from "../pubUtils/data"; -import { calPlayerCeAndSave } from "./playerCeService"; import { TERAPH_RANDOM } from "../consts/consts"; -import { getTeraphAttr } from '../consts/constModules/abilityConst'; const _ = require('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) { diff --git a/shared/consts/constModules/heroConst.ts b/shared/consts/constModules/heroConst.ts index 0140b0e26..35518b705 100644 --- a/shared/consts/constModules/heroConst.ts +++ b/shared/consts/constModules/heroConst.ts @@ -17,7 +17,8 @@ export const HERO_SYSTEM_TYPE = { JEWEL_OFF: 14, ADD_SKIN: 15, SCHOOL: 16, - SCROLL: 17 + SCROLL: 17, + TITLE:18, }; // 武将上限 diff --git a/shared/consts/constModules/itemConst.ts b/shared/consts/constModules/itemConst.ts index bbd9288d3..38cdbdd6e 100644 --- a/shared/consts/constModules/itemConst.ts +++ b/shared/consts/constModules/itemConst.ts @@ -189,4 +189,30 @@ export function getCurNameById(gid) { } else if (currency.type == CURRENCY_TYPE.EXPEDITION_POINT) { return 'expeditionPoint'; } -} \ No newline at end of file +} + +export function getDropItems() { + let items = [ + { id:25 ,count: 1 },{ id:225 ,count: 1 },{ id:625 ,count: 1 },{ id:2025 ,count: 1 },{ id:3025 ,count: 1 },{ id:4025 ,count: 1 },{ id:5025 ,count: 1 },{ id:6025 ,count: 1 }, + { id:1 ,count: 1 },{ id:2 ,count: 1 },{ id:101 ,count: 1 },{ id:102 ,count: 1 },{ id:201 ,count: 1 },{ id:202 ,count: 1 },{ id:301 ,count: 1 },{ id:302 ,count: 1 }, + { id:401 ,count: 1 },{ id:501 ,count: 1 },{ id:601 ,count: 1 },{ id:602 ,count: 1 },{ id:701 ,count: 1 },{ id:702 ,count: 1 },{ id:2001 ,count: 1 },{ id:2002 ,count: 1 }, + { id:2101 ,count: 1 },{ id:2102 ,count: 1 },{ id:2201 ,count: 1 },{ id:2202 ,count: 1 },{ id:3001 ,count: 1 },{ id:3002 ,count: 1 },{ id:3101 ,count: 1 },{ id:3102 ,count: 1 }, + { id:3201 ,count: 1 },{ id:3202 ,count: 1 },{ id:4001 ,count: 1 },{ id:4002 ,count: 1 },{ id:4101 ,count: 1 },{ id:4102 ,count: 1 },{ id:4201 ,count: 1 },{ id:4202 ,count: 1 }, + { id:5001 ,count: 1 },{ id:5002 ,count: 1 },{ id:5101 ,count: 1 },{ id:5102 ,count: 1 },{ id:5201 ,count: 1 },{ id:5202 ,count: 1 },{ id:6001 ,count: 1 },{ id:6002 ,count: 1 }, + { id:6101 ,count: 1 },{ id:6102 ,count: 1 },{ id:11001 ,count: 10000},{ id:11002 ,count: 10000 },{ id:11003,count: 10000 },{ id:11004 ,count: 100000 },{ id:11011 ,count: 100000 }, + { id:11012 ,count: 100000 },{ id:11013 ,count: 100000 },{ id:11014 ,count: 100000 },{ id:11015 ,count: 100000 },{ id:11016 ,count: 100000 },{ id:11017 ,count: 100000 }, + { id:17001 ,count: 100000 },{ id:17002 ,count: 100000 },{ id:17003 ,count: 100000 },{ id:17004 ,count: 100000 },{ id:17005 ,count: 100000 },{ id:17006 ,count: 100000 }, + { id:17007 ,count: 100000 },{ id:17008 ,count: 100000 },{ id:17009 ,count: 100000 },{ id:17010 ,count: 100000 },{ id:17011 ,count: 100000 },{ id:17012 ,count: 100000 }, + { id:17013 ,count: 100000 },{ id:17014 ,count: 100000 },{ id:17015 ,count: 100000 },{ id:17016 ,count: 100000 },{ id:17016 ,count: 100000 },{ id:17017 ,count: 100000 }, + { id:17018 ,count: 100000 },{ id:17019 ,count: 100000 },{ id:17020 ,count: 100000 },{ id:17021 ,count: 100000 },{ id:17022 ,count: 100000 },{ id:17023 ,count: 100000 }, + + { id:17024 ,count: 100000 },{ id:17025 ,count: 100000 },{ id:17026 ,count: 100000 },{ id:17027 ,count: 100000 },{ id:17028 ,count: 100000 },{ id:17029 ,count: 100000 }, + { id:17030 ,count: 100000 },{ id:17031 ,count: 100000 },{ id:17032 ,count: 100000 },{ id:17033 ,count: 100000 },{ id:17034 ,count: 100000 },{ id:17035 ,count: 100000 }, + { id:17036 ,count: 100000 },{ id:17037 ,count: 100000 },{ id:17038 ,count: 100000 },{ id:17039 ,count: 100000 },{ id:17040 ,count: 100000 },{ id:17041 ,count: 100000 }, + { id:17042 ,count: 100000 },{ id:17043 ,count: 100000 },{ id:17044 ,count: 100000 },{ id:17045 ,count: 100000 },{ id:17046 ,count: 100000 },{ id:17047 ,count: 100000 }, + { id:21001 ,count: 100000 },{ id:21002 ,count: 100000 },{ id:31001 ,count: 100000 },{ id:31002 ,count: 100000 },{ id:31003 ,count: 100000 },{ id:33001 ,count: 100000 }, + { id:33002 ,count: 100000 },{ id:33003 ,count: 100000 },{ id:40001 ,count: 100000 },{ id:40002 ,count: 100000 },{ id:42001 ,count: 100000 },{ id:42002 ,count: 100000 }, + { id:50009 ,count: 100000 },{ id:50010 ,count: 100000 },{ id:60001 ,count: 100000 },{ id:60002 ,count: 100000 },{ id:60060 ,count: 100000 } + ] + return items; +} \ No newline at end of file diff --git a/shared/db/Role.ts b/shared/db/Role.ts index 895be28c7..9bf18b071 100644 --- a/shared/db/Role.ts +++ b/shared/db/Role.ts @@ -5,6 +5,7 @@ import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoos import User from './User'; import { shouldRefresh } from '../pubUtils/util'; import { HeroModel } from './Hero'; +import { initRoleAtrr } from '../pubUtils/playerCe'; interface roleUpdate { ce?: number; _id?:number; @@ -227,6 +228,7 @@ export default class Role extends BaseModel { if (!user) return null; const doc = new RoleModel(); const update = Object.assign(doc.toJSON(), roleInfo, { userInfo: user, serverType: user.serverType, serverId }); + initRoleAtrr(update); const role: RoleType = await RoleModel.findOneAndUpdate({ 'userInfo.uid': uid, serverId }, update, { upsert: true, new: true }).lean(lean); return role; } diff --git a/shared/pubUtils/dictionary/DicTitle.ts b/shared/pubUtils/dictionary/DicTitle.ts index 9fa6efa2f..79047d65e 100644 --- a/shared/pubUtils/dictionary/DicTitle.ts +++ b/shared/pubUtils/dictionary/DicTitle.ts @@ -17,7 +17,7 @@ export interface DicTitle { readonly mdef: number; readonly agi: number; readonly luk: number; - readonly assiAttrValue: Map; + readonly assiAttrValue: Array<{id: number, number: number}>; // 等级现在 readonly lvLimited: number; // 升级消耗 diff --git a/shared/pubUtils/playerCe.ts b/shared/pubUtils/playerCe.ts index 01721b377..74cec6f75 100644 --- a/shared/pubUtils/playerCe.ts +++ b/shared/pubUtils/playerCe.ts @@ -6,127 +6,114 @@ import { HERO_SYSTEM_TYPE, ABI_TYPE, JEWEL_ATTR } from '../consts'; import { deepCopy, getAllAttrStage, reduceCe } from './util'; import { HeroModel, HeroType } from '../db/Hero'; -import { RoleModel } from '../db/Role'; +import { RoleModel, RoleType } from '../db/Role'; import { CeAttrData, CeAttr, CeAttrRole, CeAttrNumber, CeAttrDataRole } from '../db/generalField'; -import { getAttrNameByJobStage, getAttrCeRatio, getAtrrNameById, ABI_STAGE, SEID_TYPE} from '../consts'; +import { getAttrNameByJobStage, getAttrCeRatio, getAtrrNameById, ABI_STAGE, SEID_TYPE } from '../consts'; import { gameData, getJobByGradeAndClass, getHeroWakeByQuality, getHeroStarByQuality, getFriendShipById, getSchoolRateByStar, getScollByStar, getFieldByStage } from './data'; -import { Attributes } from './interface'; import { DicSe } from './dictionary/DicSe'; import { EquipType } from '../db/Equip'; import { DicRandomEffectPool } from './dictionary/DicRandomEffectPool'; import { getGoodById } from './gamedata'; import { SchoolModel } from '../db/School'; - +import { getTeraphAttr } from '../consts/constModules/abilityConst' const HERO_CE_RATIO = 100; const _ = require('underscore'); //战力计算TODO export function calPlayerCe(globalCeAttr: CeAttrRole, hero: HeroType, type: number, args: Array = []) { - let incCe = 0; - let incArr: Attributes = {}; + let heroCe = 0; let reIncAttr: CeAttr = {}; // {"hp": {"base": number, "fixUp": number, "ratioUp": number}} let addSeidList = new Array(); let removeSeidList = new Array(); - if (type == HERO_SYSTEM_TYPE.INIT) { - reIncAttr = calHeroInitIncAttr(hero, addSeidList, removeSeidList); // args: 升的星盘 - } else if (type == HERO_SYSTEM_TYPE.STAR || type == HERO_SYSTEM_TYPE.LVUP || type == HERO_SYSTEM_TYPE.COLORSTAR || type == HERO_SYSTEM_TYPE.QUALITY) { - reIncAttr = calHeroStarIncAttr(hero, type, args.shift(), args, addSeidList, removeSeidList); // args: 升的星盘 - } else if (type == HERO_SYSTEM_TYPE.TRAIN) { - reIncAttr = calHeroTrainIncAttr(hero); - } else if (type == HERO_SYSTEM_TYPE.STAGEUP) { - reIncAttr = calHeroJobStageUpIncAttr(hero, args, addSeidList, removeSeidList ); - } else if (type == HERO_SYSTEM_TYPE.SKIN) { - reIncAttr = calHeroWearSkinIncAttr(hero, args, addSeidList, removeSeidList ); - } else if (type == HERO_SYSTEM_TYPE.FAVOUR) { - reIncAttr = calHeroFavourUpIncAttr(hero, args); - } else if (type == HERO_SYSTEM_TYPE.CONNECT) { - reIncAttr = calHeroConectIncAttr(hero, args); - } else if (type == HERO_SYSTEM_TYPE.EQUIP) { - reIncAttr = calEquipPutOnOffIncAttr(hero, args, addSeidList, removeSeidList); - } else if (type == HERO_SYSTEM_TYPE.EQUIP_BASE) { - reIncAttr = calHeroEquipIncAttr(hero); - } else if (type == HERO_SYSTEM_TYPE.RESTRENGTHEN) { - reIncAttr = calRestrengthenIncAttr(hero, args.shift(), args, addSeidList, removeSeidList); - } else if (type == HERO_SYSTEM_TYPE.JEWEL_ON) {//宝石穿戴 - reIncAttr = calHeroCeWhenJewelOn(hero, args); - } else if (type == HERO_SYSTEM_TYPE.JEWEL_OFF) {//宝石卸下 - reIncAttr = calHeroCeWhenJewelOff(hero, args); - } else if (type == HERO_SYSTEM_TYPE.SCROLL) { // 名将谱初次激活增加好感度 - reIncAttr = calHeroCeScrollIncAttr(hero, args[0], args[1]); - } else { - reIncAttr = hero.ceAttr; - } + switch (type) { + case HERO_SYSTEM_TYPE.INIT: + reIncAttr = calHeroInitIncAttr(hero, addSeidList, removeSeidList); // args: 升的星盘 + break; + case HERO_SYSTEM_TYPE.STAR: + case HERO_SYSTEM_TYPE.LVUP: + case HERO_SYSTEM_TYPE.COLORSTAR: + case HERO_SYSTEM_TYPE.QUALITY: + reIncAttr = calHeroStarIncAttr(hero, type, args.shift(), args, addSeidList, removeSeidList); // args: 升的星盘 + break; + case HERO_SYSTEM_TYPE.TRAIN: + reIncAttr = calHeroTrainIncAttr(hero); + break; + case HERO_SYSTEM_TYPE.STAGEUP: + reIncAttr = calHeroJobStageUpIncAttr(hero, args, addSeidList, removeSeidList); - addSeidEffect(reIncAttr, hero.ceAttr, addSeidList, removeSeidList); // 处理加值 - if(!hero.ceAttr) hero.ceAttr = new CeAttr(); - - for (let attrName in reIncAttr) { - if(!reIncAttr[attrName] || attrName == '_id') continue; - let originalAttrData: CeAttrData = hero.ceAttr[attrName]||new CeAttrData(); - let originalGlobalAttrData: CeAttrDataRole = globalCeAttr[attrName]||new CeAttrDataRole(); - let oldCe = (originalAttrData.fixUp + (originalAttrData.equipUp||0)) * HERO_CE_RATIO + originalAttrData.base *(HERO_CE_RATIO + originalAttrData.ratioUp + originalGlobalAttrData.ratioUp); - if(!hero.ceAttr[attrName]) hero.ceAttr[attrName] = new CeAttrData(); - for (let attrKey in reIncAttr[attrName]) { - if(attrKey == '_id') continue; - hero.ceAttr[attrName][attrKey] = parseInt(reIncAttr[attrName][attrKey]||0); - } - incArr[attrName] = (reIncAttr[attrName].fixUp + (reIncAttr[attrName].equipUp||0)) * HERO_CE_RATIO + reIncAttr[attrName].base *(HERO_CE_RATIO + reIncAttr[attrName].ratioUp + originalGlobalAttrData.ratioUp) - oldCe; //计算属性 - incCe += incArr[attrName] * getAttrCeRatio(attrName); + break; + case HERO_SYSTEM_TYPE.SKIN: + reIncAttr = calHeroWearSkinIncAttr(hero, args, addSeidList, removeSeidList); + break; + case HERO_SYSTEM_TYPE.FAVOUR: + reIncAttr = calHeroFavourUpIncAttr(hero, args); + break; + case HERO_SYSTEM_TYPE.CONNECT: + reIncAttr = calHeroConectIncAttr(hero, args); + break; + case HERO_SYSTEM_TYPE.EQUIP: + reIncAttr = calEquipPutOnOffIncAttr(hero, args, addSeidList, removeSeidList); + break; + case HERO_SYSTEM_TYPE.EQUIP_BASE: + reIncAttr = calHeroEquipIncAttr(hero); + break; + case HERO_SYSTEM_TYPE.RESTRENGTHEN: + reIncAttr = calRestrengthenIncAttr(hero, args.shift(), args, addSeidList, removeSeidList); + break; + case HERO_SYSTEM_TYPE.JEWEL_ON: + reIncAttr = calHeroCeWhenJewelOn(hero, args); + break; + case HERO_SYSTEM_TYPE.JEWEL_OFF: + reIncAttr = calHeroCeWhenJewelOff(hero, args); + break; + case HERO_SYSTEM_TYPE.SCROLL: + reIncAttr = calHeroCeScrollIncAttr(hero, args[0], args[1]); + break; + default: + reIncAttr = hero.ceAttr; } - hero.ce += incCe; - if(hero.historyCe < hero.ce) hero.historyCe = hero.ce; + addSeidEffect(reIncAttr, hero.ceAttr, addSeidList, removeSeidList); // 处理加值 + if (!hero.ceAttr) hero.ceAttr = new CeAttr(); + for (let attrName in reIncAttr) { + if (!reIncAttr[attrName] || attrName == '_id') continue; + let globalAttrData: CeAttrDataRole = globalCeAttr[attrName] || new CeAttrDataRole(); + if (!hero.ceAttr[attrName]) hero.ceAttr[attrName] = new CeAttrData(); + for (let attrKey in reIncAttr[attrName]) { + if (attrKey == '_id') continue; + hero.ceAttr[attrName][attrKey] = parseInt(reIncAttr[attrName][attrKey] || 0); + } + let attrNumber = (hero.ceAttr[attrName].fixUp + (hero.ceAttr[attrName].equipUp || 0) + globalAttrData.fixUp) * HERO_CE_RATIO + hero.ceAttr[attrName].base * (HERO_CE_RATIO + hero.ceAttr[attrName].ratioUp + globalAttrData.ratioUp); + heroCe += attrNumber * getAttrCeRatio(attrName); + } + let incCe = heroCe - hero.ce; + hero.ce = heroCe; + if (hero.historyCe < hero.ce) hero.historyCe = hero.ce; return incCe; } //修改并下发战力 export async function calPlayerCeAndSave(roleId: string, heros: Array, type?: number, args?: Array) { - if(!heros.length) heros = await HeroModel.findByRole(roleId); - + if (!heros.length) heros = await HeroModel.findByRole(roleId); let incPlayerCe = 0; - let pushHeros = new Array<{hid: number, ce: number, incHeroCe: number}>(); + let pushHeros = new Array<{ hid: number, ce: number, incHeroCe: number }>(); let role = await RoleModel.findByRoleId(roleId); - if(!role.globalCeAttr) role.globalCeAttr = new CeAttrRole(); - let originalAttr = role.globalCeAttr; - - let reIncAttr: CeAttrRole = {}; // role表属性增量 - - if (type == HERO_SYSTEM_TYPE.INIT) { - reIncAttr = calRoleInitIncAttr(heros, role.globalCeAttr); // 全局变量增 - } else if (type == HERO_SYSTEM_TYPE.ADD_SKIN) { - reIncAttr = calHeroAddSkin(args, role.globalCeAttr); - } else if (type == HERO_SYSTEM_TYPE.SCHOOL) { - reIncAttr = calSchoolAddAttr(heros, args[0], args[1], args[2], role.globalCeAttr); - } else if (type == HERO_SYSTEM_TYPE.SCROLL) { - reIncAttr = calScrollAddAttr(heros, args[0], role.globalCeAttr); - } else if (type == HERO_SYSTEM_TYPE.STAR || type == HERO_SYSTEM_TYPE.COLORSTAR || type == HERO_SYSTEM_TYPE.QUALITY) { // 升星时,在百家学宫中部署的武将加成会同时增加 - reIncAttr = await calSchoolStarIncAttr(heros, type, args, role.globalCeAttr); - } - + if (!role.globalCeAttr) role.globalCeAttr = new CeAttr(); + await reCalRoleAttr(heros, role.globalCeAttr, type, args); for (let hero of heros) { let incHeroCe = calPlayerCe(role.globalCeAttr, hero, type, args); - for (let attrName in reIncAttr) { - let oldcCe = originalAttr[attrName].fixUp * HERO_CE_RATIO + hero.ceAttr[attrName].base * (HERO_CE_RATIO + originalAttr[attrName].ratioUp); - let incArr = reIncAttr[attrName].fixUp * HERO_CE_RATIO + hero.ceAttr[attrName].base * (HERO_CE_RATIO + reIncAttr[attrName].ratioUp) - oldcCe; - incHeroCe += incArr * getAttrCeRatio(attrName); - } incPlayerCe += incHeroCe; hero.ce += incHeroCe; await HeroModel.updateHeroInfo(roleId, hero.hid, hero); pushHeros.push({ hid: hero.hid, ce: reduceCe(hero.ce), - incHeroCe : reduceCe(incHeroCe), + incHeroCe: reduceCe(incHeroCe), }); } - - for (let attrName in reIncAttr) { - role.globalCeAttr[attrName].fixUp = reIncAttr[attrName].fixUp; - role.globalCeAttr[attrName].ratioUp = reIncAttr[attrName].ratioUp; - } role.ce += incPlayerCe; - await RoleModel.updateRoleInfo(roleId, {globalCeAttr: role.globalCeAttr, ce: role.ce}); - return {pushHeros, role} + await RoleModel.updateRoleInfo(roleId, { globalCeAttr: role.globalCeAttr, ce: role.ce }); + return { pushHeros, role } } // 初始战力 @@ -135,7 +122,7 @@ export function calHeroInitIncAttr(hero: HeroType, addSeidList: Array, r let hero1 = combineHeroCeAttr(hero, res1); let curSkin = hero.skins.find(cur => cur.enable); - let res2 = calHeroWearSkinIncAttr(hero1, [curSkin?curSkin.id:0, 0], addSeidList, removeSeidList, true); + let res2 = calHeroWearSkinIncAttr(hero1, [curSkin ? curSkin.id : 0, 0], addSeidList, removeSeidList, true); let hero2 = combineHeroCeAttr(hero, res2); calHeroJobStageUpIncAttr(hero2, [0], addSeidList, removeSeidList); @@ -149,15 +136,15 @@ export function calHeroInitIncAttr(hero: HeroType, addSeidList: Array, r function combineAttrResult(target: CeAttr, origin: CeAttr) { - for(let attrName in origin) { - for(let attrKey in origin[attrName]) { - if(!target.hasOwnProperty(attrName)) { + for (let attrName in origin) { + for (let attrKey in origin[attrName]) { + if (!target.hasOwnProperty(attrName)) { target[attrName] = {}; } - if(!target[attrName].hasOwnProperty(attrKey)) { + if (!target[attrName].hasOwnProperty(attrKey)) { target[attrName][attrKey] = 0; } - if(origin[attrName][attrKey] > target[attrName][attrKey]) { + if (origin[attrName][attrKey] > target[attrName][attrKey]) { target[attrName][attrKey] = origin[attrName][attrKey]; } } @@ -166,8 +153,8 @@ function combineAttrResult(target: CeAttr, origin: CeAttr) { export function calRoleInitIncAttr(heros: HeroType[], globalCeAttr: CeAttrRole) { let args = new Array(); - for(let hero of heros) { - for(let skin of hero.skins) { + for (let hero of heros) { + for (let skin of hero.skins) { args.push(skin.id); } } @@ -178,12 +165,12 @@ export function calRoleInitIncAttr(heros: HeroType[], globalCeAttr: CeAttrRole) // 将hero的ceAttr暂时更新,不更新在originalHero本体上 function combineHeroCeAttr(originalHero: HeroType, result: CeAttr) { let hero = deepCopy(originalHero); - if(!hero.ceAttr) hero.ceAttr = new CeAttr(); + if (!hero.ceAttr) hero.ceAttr = new CeAttr(); for (let attrName in result) { - if(!result[attrName]) continue; - if(!hero.ceAttr[attrName]) hero.ceAttr[attrName] = new CeAttrData(); + if (!result[attrName]) continue; + if (!hero.ceAttr[attrName]) hero.ceAttr[attrName] = new CeAttrData(); for (let attrKey in result[attrName]) { - hero.ceAttr[attrName][attrKey] = parseInt(result[attrName][attrKey]||0); + hero.ceAttr[attrName][attrKey] = parseInt(result[attrName][attrKey] || 0); } } delete hero._id; @@ -199,13 +186,13 @@ function combineHeroCeAttr(originalHero: HeroType, result: CeAttr) { * @param addSeidList number[] 用于更新被动 * @param removeSeidList number[] 用于更新被动 */ -export function calHeroStarIncAttr (hero: HeroType, type: number, hid: number, args: number[], addSeidList: Array, removeSeidList: Array) { +export function calHeroStarIncAttr(hero: HeroType, type: number, hid: number, args: number[], addSeidList: Array, removeSeidList: Array) { let isInit = type == HERO_SYSTEM_TYPE.INIT; - let {star, starStage, quality, colorStar, colorStarStage, ceAttr, skins} = hero; + let { star, starStage, quality, colorStar, colorStarStage, ceAttr, skins } = hero; let originStar = star, originColorStar = colorStar; let res: CeAttr = {}; - if(hero.hid != hid) return res; + if (hero.hid != hid) return res; const dicHero = gameData.hero.get(hero.hid); @@ -215,52 +202,52 @@ export function calHeroStarIncAttr (hero: HeroType, type: number, hid: number, a } else { if(starStage == ABI_STAGE.START && !isInit) originStar = star - 1; } - const dicStar = isWake? getHeroWakeByQuality(quality, originColorStar): getHeroStarByQuality(quality, originStar); // 星级表 + const dicStar = isWake ? getHeroWakeByQuality(quality, originColorStar) : getHeroStarByQuality(quality, originStar); // 星级表 let stages = new Array(); // 需要升级的阶 - if(type == HERO_SYSTEM_TYPE.INIT) { + if (type == HERO_SYSTEM_TYPE.INIT) { stages = getAllAttrStage(); } else if (type == HERO_SYSTEM_TYPE.LVUP) { stages = getAllAttrStage(); } else if (type == HERO_SYSTEM_TYPE.STAR) { - stages = [args[0]? ABI_STAGE.END: starStage]; + stages = [args[0] ? ABI_STAGE.END : starStage]; } else if (type == HERO_SYSTEM_TYPE.QUALITY) { stages = getAllAttrStage(); } else if (type = HERO_SYSTEM_TYPE.COLORSTAR) { - if(args[1]) { // 首次觉醒 + if (args[1]) { // 首次觉醒 stages = getAllAttrStage(); } else { - stages.push(args[0]? ABI_STAGE.END: hero.colorStarStage) + stages.push(args[0] ? ABI_STAGE.END : hero.colorStarStage) } } - for(let stage of stages) { + for (let stage of stages) { let targetAttrId = getFieldByStage(stage, hero.job); // 转换为17维的属性id let heroAttr = dicHero.baseAbilityArr.get(targetAttrId); // 武将表hp等 let heroUpAttr = dicHero.baseAbilityUpArr.get(targetAttrId); // 武将表hp_up等 let starUp = 0; if (!!dicStar && !!dicStar.ceAttr) { - starUp = dicStar.ceAttr.get(stage); + starUp = dicStar.ceAttr.get(stage); } let newBase = (heroAttr + hero.lv * (heroUpAttr + starUp)) * HERO_CE_RATIO; let field = getAtrrNameById(targetAttrId); - let ceAttrData: CeAttrData = ceAttr[field]||new CeAttrData(); // 存表中的属性下的base,fixup,ratioup - let {ratioUp = 0, fixUp = 0} = ceAttrData; - res[field] = { base: newBase, ratioUp, fixUp}; // base变动,增量为△base * ratio + 0 + let ceAttrData: CeAttrData = ceAttr[field] || new CeAttrData(); // 存表中的属性下的base,fixup,ratioup + let { ratioUp = 0, fixUp = 0 } = ceAttrData; + res[field] = { base: newBase, ratioUp, fixUp }; // base变动,增量为△base * ratio + 0 } // 解锁技能 let curSkin = skins.find(cur => cur.enable); let curSeidList = getSeidListOfFashion(curSkin.id, star, colorStar); - let preSeidList = getSeidListOfFashion(curSkin.id, isInit?0:originStar, isInit?0:originColorStar); - for(let [type, seid] of curSeidList) { - if(!preSeidList.has(type)) { + let preSeidList = getSeidListOfFashion(curSkin.id, isInit ? 0 : originStar, isInit ? 0 : originColorStar); + for (let [type, seid] of curSeidList) { + if (!preSeidList.has(type)) { addSeidList.push(seid, 0); } } - for(let [type, seid] of preSeidList) { + for (let [type, seid] of preSeidList) { console.log(type, seid) - if(!curSeidList.has(type)) { + if (!curSeidList.has(type)) { removeSeidList.push(seid, 0); } } @@ -270,17 +257,17 @@ export function calHeroStarIncAttr (hero: HeroType, type: number, hid: number, a function getSeidListOfFashion(fashionid: number, originStar: number, originColorStar: number) { let seidList = new Map(); // type => seid - if(!gameData.fashion.has(fashionid)) return seidList; + if (!gameData.fashion.has(fashionid)) return seidList; let { skillId } = gameData.fashion.get(fashionid); let { starSeidArr, colorStarSeidArr } = gameData.heroSkill.get(skillId); - for(let {star, value, type} of starSeidArr) { - if(originStar >= star) { + for (let { star, value, type } of starSeidArr) { + if (originStar >= star) { seidList.set(type, value); } } - for(let {star, value, type} of colorStarSeidArr) { - if(originColorStar >= star) { + for (let { star, value, type } of colorStarSeidArr) { + if (originColorStar >= star) { seidList.set(type, value); } } @@ -291,7 +278,7 @@ function getSeidListOfFashion(fashionid: number, originStar: number, originColor export function calHeroTrainIncAttr(hero: HeroType) { let res: CeAttr = {}; let attrName: string = getAttrNameByJobStage(hero.jobStage); - res[attrName] = {fixUp: hero.ceAttr[attrName].fixUp, base: hero.ceAttr[attrName].base, ratioUp: hero.ceAttr[attrName].ratioUp}; + res[attrName] = { fixUp: hero.ceAttr[attrName].fixUp, base: hero.ceAttr[attrName].base, ratioUp: hero.ceAttr[attrName].ratioUp }; let currentJob = gameData.job.get(hero.job); if (currentJob.grade > 1) { let jobGradeAndClass = getJobByGradeAndClass(currentJob.job_class, currentJob.grade - 1); @@ -306,7 +293,7 @@ export function calHeroTrainIncAttr(hero: HeroType) { //进阶 export function calHeroJobStageUpIncAttr(hero: HeroType, args: Array, addSeidList: Array, removeSeidList: Array) { let res: CeAttr = {}; - let lastJob = gameData.job.get(args[0])||{seid:[]}; + let lastJob = gameData.job.get(args[0]) || { seid: [] }; let currentJob = gameData.job.get(hero.job); for (let seid of currentJob.seid) { let index = _.findIndex(lastJob.seid, seid); @@ -329,31 +316,31 @@ export function calHeroWearSkinIncAttr(hero: HeroType, args: Array, addS let addSkin = gameData.fashion.get(args[0]); let delSkin = gameData.fashion.get(args[1]); let attrName: string; - if(delSkin) { + if (delSkin) { for (let attr of delSkin.actorAttr) { attrName = getAtrrNameById(attr.id); - res[attrName] = {fixUp: hero.ceAttr[attrName].fixUp, base: hero.ceAttr[attrName].base, ratioUp: hero.ceAttr[attrName].ratioUp}; - res[attrName].fixUp -= attr.number * HERO_CE_RATIO; + res[attrName] = { fixUp: hero.ceAttr[attrName].fixUp, base: hero.ceAttr[attrName].base, ratioUp: hero.ceAttr[attrName].ratioUp }; + res[attrName].fixUp -= attr.number * HERO_CE_RATIO; } } for (let attr of addSkin.actorAttr) { attrName = getAtrrNameById(attr.id); - res[attrName] = {fixUp: hero.ceAttr[attrName].fixUp, base: hero.ceAttr[attrName].base, ratioUp: hero.ceAttr[attrName].ratioUp}; - res[attrName].fixUp += attr.number * HERO_CE_RATIO; + res[attrName] = { fixUp: hero.ceAttr[attrName].fixUp, base: hero.ceAttr[attrName].base, ratioUp: hero.ceAttr[attrName].ratioUp }; + res[attrName].fixUp += attr.number * HERO_CE_RATIO; } - if(!isInit) { // 初始的时候,这一段技能在calHeroStarIncAttr里计算了,不用重复算 + if (!isInit) { // 初始的时候,这一段技能在calHeroStarIncAttr里计算了,不用重复算 let { star, colorStar } = hero; - + let curSeidList = getSeidListOfFashion(args[0], star, colorStar); let preSeidList = getSeidListOfFashion(args[1], star, colorStar); - for(let [type, seid] of curSeidList) { - if(!preSeidList.has(type)) { + for (let [type, seid] of curSeidList) { + if (!preSeidList.has(type)) { removeSeidList.push(seid, 0); } } - for(let [type, seid] of preSeidList) { - if(!curSeidList.has(type)) { + for (let [type, seid] of preSeidList) { + if (!curSeidList.has(type)) { addSeidList.push(seid, 0); } } @@ -369,18 +356,18 @@ export function calHeroConectIncAttr(hero: HeroType, args: Array) { let shipId = args[0];//当前升级的羁绊序号 let level = args[1];//当前升级的羁绊等级 let attrName: string; - let currentShip = getFriendShipById(shipId, level); + let currentShip = getFriendShipById(shipId, level); for (let attr of currentShip.attributes) { attrName = getAtrrNameById(attr.id); - res[attrName] = {fixUp: hero.ceAttr[attrName].fixUp, base: hero.ceAttr[attrName].base, ratioUp: hero.ceAttr[attrName].ratioUp}; - res[attrName].fixUp += attr.number * (HERO_CE_RATIO + fiendShipLevel.add); + res[attrName] = { fixUp: hero.ceAttr[attrName].fixUp, base: hero.ceAttr[attrName].base, ratioUp: hero.ceAttr[attrName].ratioUp }; + res[attrName].fixUp += attr.number * (HERO_CE_RATIO + fiendShipLevel.add); } if (level > 1) { - let lastShip = getFriendShipById(shipId, level - 1); + let lastShip = getFriendShipById(shipId, level - 1); for (let attr of lastShip.attributes) { attrName = getAtrrNameById(attr.id); - res[attrName] = {fixUp: hero.ceAttr[attrName].fixUp, base: hero.ceAttr[attrName].base, ratioUp: hero.ceAttr[attrName].ratioUp}; - res[attrName].fixUp -= attr.number * (HERO_CE_RATIO + fiendShipLevel.add); + res[attrName] = { fixUp: hero.ceAttr[attrName].fixUp, base: hero.ceAttr[attrName].base, ratioUp: hero.ceAttr[attrName].ratioUp }; + res[attrName].fixUp -= attr.number * (HERO_CE_RATIO + fiendShipLevel.add); } } return res; @@ -397,11 +384,11 @@ export function calHeroFavourUpIncAttr(hero: HeroType, args: Array) { } let attrName: string; for (let connect of hero.connections) { - let heroShip = getFriendShipById(connect.shipId, connect.level); + let heroShip = getFriendShipById(connect.shipId, connect.level); for (let attr of heroShip.attributes) { attrName = getAtrrNameById(attr.id); - res[attrName] = {fixUp: hero.ceAttr[attrName].fixUp, base: hero.ceAttr[attrName].base, ratioUp: hero.ceAttr[attrName].ratioUp}; - res[attrName].fixUp += attr.number * (HERO_CE_RATIO + difAdd); + res[attrName] = { fixUp: hero.ceAttr[attrName].fixUp, base: hero.ceAttr[attrName].base, ratioUp: hero.ceAttr[attrName].ratioUp }; + res[attrName].fixUp += attr.number * (HERO_CE_RATIO + difAdd); } } return res; @@ -411,22 +398,22 @@ export function calHeroFavourUpIncAttr(hero: HeroType, args: Array) { export function calEquipPutOnOffIncAttr(hero: HeroType, args: Array, addSeidList: Array, removeSeidList: Array) { // 计算身上所有装备的战力值(特技相关以外) let res = calHeroEquipIncAttr(hero); - + // 计算被动技能 let { ePlace } = hero; let suits = new Map(); - for(let { equip } of ePlace) { - if(equip) { + for (let { equip } of ePlace) { + if (equip) { let e = equip; - for(let { seid, rand } of e.randSe) { + for (let { seid, rand } of e.randSe) { addSeidList.push(seid, rand); } - if(e.suitId > 0) { - if(suits.has(e.suitId)) { - suits.set(e.suitId, 1); - } else { + if (e.suitId > 0) { + if (suits.has(e.suitId)) { suits.set(e.suitId, suits.get(e.suitId) + 1); + } else { + suits.set(e.suitId, 1); } } } @@ -434,15 +421,15 @@ export function calEquipPutOnOffIncAttr(hero: HeroType, args: Array, add suits.forEach((suitId, count) => { let { effect } = gameData.suit.get(suitId); - for(let e of effect) { - if(count >= e.count) { + for (let e of effect) { + if (count >= e.count) { addSeidList.push(e.seid, 0); } } }); - for(let arg of args) { - removeSeidList.push(arg) + for (let arg of args) { + removeSeidList.push(arg) } return res @@ -454,25 +441,25 @@ export function calEquipSeids(hero: HeroType) { let { ePlace } = hero; let suits = new Map(); - for(let { equip } of ePlace) { - if(equip) { + for (let { equip } of ePlace) { + if (equip) { let e = equip; - for(let { seid, rand } of e.randSe) { + for (let { seid, rand } of e.randSe) { seids.push(seid, rand); } - if(e.suitId > 0) { - if(suits.has(e.suitId)) { - suits.set(e.suitId, 1); - } else { + if (e.suitId > 0) { + if (suits.has(e.suitId)) { suits.set(e.suitId, suits.get(e.suitId) + 1); + } else { + suits.set(e.suitId, 1); } } } } suits.forEach((suitId, count) => { let { effect } = gameData.suit.get(suitId); - for(let e of effect) { - if(count >= e.count) { + for (let e of effect) { + if (count >= e.count) { seids.push(e.seid, 0); } } @@ -487,21 +474,21 @@ export function calHeroEquipIncAttr(hero: HeroType) { let attrResult = new CeAttrNumber(); - for(let {equip, lv, refineLv} of ePlace) { - if(equip) { + for (let { equip, lv, refineLv } of ePlace) { + if (equip) { let e = equip; let dicGoods = gameData.goods.get(e.id); - let {goodsAbility, goodsAbilityUp} = dicGoods; + let { goodsAbility, goodsAbilityUp } = dicGoods; let dicRefine = gameData.refine.get(refineLv); let jewel = new Map(); - for(let {jewel: jewelId} of e.holes) { - if(jewelId > 0) { + for (let { jewel: jewelId } of e.holes) { + if (jewelId > 0) { let g = gameData.goods.get(jewelId); - if(g) { + if (g) { let jGoods = g.goodsAbility; jGoods.forEach((value, key) => { - if(jewel.has(key)) { + if (jewel.has(key)) { jewel.set(key, value); } else { jewel.set(key, jewel.get(key) + value); @@ -511,94 +498,94 @@ export function calHeroEquipIncAttr(hero: HeroType) { } } - for(let i = ABI_TYPE.ABI_HP; i < ABI_TYPE.ABI_MAX; i++) { - if(i == ABI_TYPE.ABI_SPEED || i == ABI_TYPE.ABI_AP) continue; + for (let i = ABI_TYPE.ABI_HP; i < ABI_TYPE.ABI_MAX; i++) { + if (i == ABI_TYPE.ABI_SPEED || i == ABI_TYPE.ABI_AP) continue; let attrName = getAtrrNameById(i); // console.log('***', i, attrName); - let value1 = goodsAbility.get(i)||0 * (HERO_CE_RATIO + e.randRange); + let value1 = goodsAbility.get(i) || 0 * (HERO_CE_RATIO + e.randRange); // console.log('基础值', value1); - let valueup = goodsAbilityUp.get(i)||0; + let valueup = goodsAbilityUp.get(i) || 0; // console.log('成长', lv, valueup); - let valueRefine = dicRefine?dicRefine.upPercent:0; + let valueRefine = dicRefine ? dicRefine.upPercent : 0; // console.log('refine', dicRefine?dicRefine.upPercent:0 ); - let valueJewel = jewel.get(i)||0; + let valueJewel = jewel.get(i) || 0; // console.log('jewel', valueJewel); - let attr = (value1 + lv * valueup) * ( HERO_CE_RATIO + valueRefine) + valueJewel * HERO_CE_RATIO; - + let attr = (value1 + lv * valueup) * (HERO_CE_RATIO + valueRefine) + valueJewel * HERO_CE_RATIO; + attrResult[attrName] += attr; } } } - for(let attrName in attrResult) { - let originalCe = hero.ceAttr[attrName].equipUp||0; + for (let attrName in attrResult) { + let originalCe = hero.ceAttr[attrName].equipUp || 0; console.log('装备战力:', attrName, attrResult[attrName] * HERO_CE_RATIO, originalCe); - res[attrName] = {fixUp: hero.ceAttr[attrName].fixUp, base: hero.ceAttr[attrName].base, ratioUp: hero.ceAttr[attrName].ratioUp, equipUp: originalCe}; - res[attrName].equipUp += attrResult[attrName] * HERO_CE_RATIO - originalCe; + res[attrName] = { fixUp: hero.ceAttr[attrName].fixUp, base: hero.ceAttr[attrName].base, ratioUp: hero.ceAttr[attrName].ratioUp, equipUp: originalCe }; + res[attrName].equipUp += attrResult[attrName] * HERO_CE_RATIO - originalCe; } return res; } // 洗炼 -export function calRestrengthenIncAttr (hero: HeroType, ePaceId: number, args: Array, addSeidList: Array, removeSeidList: Array) { +export function calRestrengthenIncAttr(hero: HeroType, ePaceId: number, args: Array, addSeidList: Array, removeSeidList: Array) { let res: CeAttr = {}; - let {ePlace} = hero; + let { ePlace } = hero; let curPlace = ePlace.find(cur => cur.id == ePaceId); - if(curPlace && curPlace.equip) { + if (curPlace && curPlace.equip) { let e = curPlace.equip; - for(let { seid, rand } of e.randSe) { + for (let { seid, rand } of e.randSe) { addSeidList.push(seid, rand); } } - for(let arg of args) { removeSeidList.push(arg) } + for (let arg of args) { removeSeidList.push(arg) } return res } // 添加技能增加的被动属性 -function addSeidEffect(reIncAttr: CeAttr, heroCeAttr: CeAttr,addSeidList: Array, removeSeidList: Array) { +function addSeidEffect(reIncAttr: CeAttr, heroCeAttr: CeAttr, addSeidList: Array, removeSeidList: Array) { console.log('addSeidList', addSeidList) console.log('removeSeidList', removeSeidList) let otiginalSeidList = [ - {list: addSeidList, multi: 1}, - {list: removeSeidList, multi: -1} + { list: addSeidList, multi: 1 }, + { list: removeSeidList, multi: -1 } ]; - for(let {list, multi} of otiginalSeidList) { + for (let { list, multi } of otiginalSeidList) { let effectList = new Array(); // any: dic_zyz_se表内容 - for(let ii = 0; ii < list.length; ii += 2 ) { + for (let ii = 0; ii < list.length; ii += 2) { let seid = list[ii]; - let rand = list[ii + 1]||0; - let dicSeid: DicSe|DicRandomEffectPool = gameData.se.get(seid); - if(!dicSeid) dicSeid = gameData.randomEffectPool.get(seid); - if(dicSeid && dicSeid.id > 0){ + let rand = list[ii + 1] || 0; + let dicSeid: DicSe | DicRandomEffectPool = gameData.se.get(seid); + if (!dicSeid) dicSeid = gameData.randomEffectPool.get(seid); + if (dicSeid && dicSeid.id > 0) { addSeid(effectList, dicSeid.id, rand, dicSeid.gainValueArr) } } - - for(let {type, gainValueArr: [ability, value]} of effectList) { + + for (let { type, gainValueArr: [ability, value] } of effectList) { let attrName = getAtrrNameById(ability); - if(!attrName) continue; - if(type == SEID_TYPE.TYPE101) { // 加值 - if(!reIncAttr[attrName]) { + if (!attrName) continue; + if (type == SEID_TYPE.TYPE101) { // 加值 + if (!reIncAttr[attrName]) { reIncAttr[attrName] = deepCopy(heroCeAttr[attrName]); } - if(!reIncAttr[attrName]) { + if (!reIncAttr[attrName]) { delete reIncAttr[attrName]; continue; } reIncAttr[attrName].fixUp += value * multi * HERO_CE_RATIO; delete reIncAttr[attrName]._id; } else if (type == SEID_TYPE.TYPE102) { // 加百分比 - if(!reIncAttr[attrName]) { + if (!reIncAttr[attrName]) { reIncAttr[attrName] = deepCopy(heroCeAttr[attrName]); } - if(!reIncAttr[attrName]) { + if (!reIncAttr[attrName]) { delete reIncAttr[attrName]; continue; } @@ -610,22 +597,22 @@ function addSeidEffect(reIncAttr: CeAttr, heroCeAttr: CeAttr,addSeidList: Array< } // 获取dic_zyz_se内容 -function addSeid(effectList: Array, seidId:number, rand: number, seidValue = new Array()){ +function addSeid(effectList: Array, seidId: number, rand: number, seidValue = new Array()) { // console.log('addSeidEffect', seidId, seidValue) - let curSeid: DicSe|DicRandomEffectPool = gameData.se.get(seidId); - if(!curSeid) curSeid = gameData.randomEffectPool.get(seidId); - if(!curSeid) {console.log("seidId not found:"+seidId);return;} - if(!seidValue) seidValue = curSeid.gainValueArr; + let curSeid: DicSe | DicRandomEffectPool = gameData.se.get(seidId); + if (!curSeid) curSeid = gameData.randomEffectPool.get(seidId); + if (!curSeid) { console.log("seidId not found:" + seidId); return; } + if (!seidValue) seidValue = curSeid.gainValueArr; - if(curSeid.type === SEID_TYPE.TYPE999){ - for(let i = 0;i < seidValue.length;i++){ + if (curSeid.type === SEID_TYPE.TYPE999) { + for (let i = 0; i < seidValue.length; i++) { addSeid(effectList, seidValue[i], rand); } return; } effectList.push(curSeid); - let seid: DicSe|DicRandomEffectPool = deepCopy(curSeid); - if(curSeid.index > 0) { + let seid: DicSe | DicRandomEffectPool = deepCopy(curSeid); + if (curSeid.index > 0) { seid.gainValueArr[curSeid.index - 1] = rand; } effectList.push(seid); @@ -637,25 +624,26 @@ function calHeroCeWhenJewelOn(hero: HeroType, args: Array) { let oldId = args[1]; let goodInfo = getGoodById(id); let oldGoodInfo; - if (!!oldId) + if (!!oldId) oldGoodInfo = getGoodById(oldId); for (let attrName in JEWEL_ATTR) { if (!!goodInfo[attrName]) { - res[attrName] = {fixUp: hero.ceAttr[attrName].fixUp, base: hero.ceAttr[attrName].base, ratioUp: hero.ceAttr[attrName].ratioUp}; + res[attrName] = { fixUp: hero.ceAttr[attrName].fixUp, base: hero.ceAttr[attrName].base, ratioUp: hero.ceAttr[attrName].ratioUp }; res[attrName].fixUp += goodInfo[attrName]; - if (oldGoodInfo) + if (oldGoodInfo) res[attrName].fixUp -= oldGoodInfo[attrName]; } } return res; } + function calHeroCeWhenJewelOff(hero: HeroType, args: Array) { let res: CeAttr = {}; for (let id of args) { let goodInfo = getGoodById(id); for (let attrName in JEWEL_ATTR) { if (!!goodInfo[attrName]) { - res[attrName] = {fixUp: hero.ceAttr[attrName].fixUp, base: hero.ceAttr[attrName].base, ratioUp: hero.ceAttr[attrName].ratioUp}; + res[attrName] = { fixUp: hero.ceAttr[attrName].fixUp, base: hero.ceAttr[attrName].base, ratioUp: hero.ceAttr[attrName].ratioUp }; res[attrName].fixUp -= goodInfo[attrName]; } } @@ -663,49 +651,41 @@ function calHeroCeWhenJewelOff(hero: HeroType, args: Array) { return res; } //全局属性加成 -export async function reCalAllHeroCe(roleId: string, type: number, args:Array) { - let reIncAttr: CeAttrRole = {}; +export async function reCalAllHeroCe(roleId: string, type: number, args: Array) { let role = await RoleModel.findByRoleId(roleId); - if(!role.globalCeAttr) role.globalCeAttr = new CeAttrRole(); - let pushHeros:Array<{hid:number, ce:number, incHeroCe:number}> = [] - if (type == 1) {//获得皮肤 - reIncAttr = calHeroAddSkin(args, role.globalCeAttr); - } - for (let attrName in reIncAttr) { - role.globalCeAttr[attrName].fixUp = reIncAttr[attrName].fixUp; - role.globalCeAttr[attrName].ratioUp = reIncAttr[attrName].ratioUp; - } - role.ce = 0; + if (!role.globalCeAttr) role.globalCeAttr = new CeAttr(); + let pushHeros: Array<{ hid: number, ce: number, incHeroCe: number }> = [] let heros = await HeroModel.findByRole(roleId); + await reCalRoleAttr(heros, role.globalCeAttr, type, args); + role.ce = 0; for (let hero of heros) { - let incHeroCe = 0; let heroCe = 0; for (let attrName in role.globalCeAttr) { if (attrName == '_id') continue; - let heroAttrData: CeAttrData = hero.ceAttr[attrName]||new CeAttrData(); - let globalAttrData: CeAttrDataRole = role.globalCeAttr[attrName]; - let attrNumber = (heroAttrData.fixUp + (heroAttrData.equipUp||0) + globalAttrData.fixUp) * HERO_CE_RATIO + heroAttrData.base *(HERO_CE_RATIO + heroAttrData.ratioUp + globalAttrData.ratioUp) ; + let heroAttrData: CeAttrData = hero.ceAttr[attrName] || new CeAttrData(); + let globalAttrData: CeAttrData = role.globalCeAttr[attrName]; + let attrNumber = (heroAttrData.fixUp + (heroAttrData.equipUp || 0) + globalAttrData.fixUp) * HERO_CE_RATIO + heroAttrData.base * (HERO_CE_RATIO + heroAttrData.ratioUp + globalAttrData.ratioUp); heroCe += attrNumber * getAttrCeRatio(attrName); } - incHeroCe = heroCe - hero.ce; + let incHeroCe = heroCe - hero.ce; hero.ce = heroCe; role.ce += hero.ce; pushHeros.push({ hid: hero.hid, ce: reduceCe(hero.ce), incHeroCe: reduceCe(incHeroCe) }); - await HeroModel.updateHeroInfo(roleId, hero.hid, {ce: hero.ce}); + await HeroModel.updateHeroInfo(roleId, hero.hid, { ce: hero.ce }); } - await RoleModel.updateRoleInfo(roleId, {globalCeAttr: role.globalCeAttr, ce: role.ce}); - return {pushHeros, ce: role.ce} + await RoleModel.updateRoleInfo(roleId, { globalCeAttr: role.globalCeAttr, ce: role.ce }); + return { pushHeros, ce: role.ce } } -function calHeroAddSkin(args:Array, ceAttr: CeAttrRole){ +function calHeroAddSkin(args: Array, ceAttr: CeAttrRole) { let res: CeAttrRole = {}; for (let arg of args) { let addSkin = gameData.fashion.get(arg); let attrName: string; for (let attr of addSkin.globalAttr) { attrName = getAtrrNameById(attr.id); - res[attrName] = {fixUp: ceAttr[attrName].fixUp, ratioUp: ceAttr[attrName].ratioUp}; + res[attrName] = { fixUp: ceAttr[attrName].fixUp, ratioUp: ceAttr[attrName].ratioUp }; res[attrName].fixUp += attr.number * HERO_CE_RATIO; } } @@ -720,22 +700,22 @@ function calHeroAddSkin(args:Array, ceAttr: CeAttrRole){ * @param preHid 撤下的武将 * @param ceAttr */ -function calSchoolAddAttr(heros: HeroType[], schoolId: number, hid: number, preHid: number, ceAttr: CeAttrRole){ +function calSchoolAddAttr(heros: HeroType[], schoolId: number, hid: number, preHid: number, ceAttr: CeAttrRole) { let res: CeAttrRole = {}; let school = gameData.school.get(schoolId); let preHero = heros.find(cur => cur.hid == preHid); let curHero = heros.find(cur => cur.hid == hid); - if(!school ) return res; + if (!school) return res; - let defaultPercent = {mainAttrAPerent: 0, assiAttrAddValue: 0}; - let preRate = preHero?getSchoolRateByStar(preHero.star, preHero.colorStar, preHero.quality):defaultPercent; - let curRate = curHero?getSchoolRateByStar(curHero.star, curHero.colorStar, curHero.quality):defaultPercent; + let defaultPercent = { mainAttrAPerent: 0, assiAttrAddValue: 0 }; + let preRate = preHero ? getSchoolRateByStar(preHero.star, preHero.colorStar, preHero.quality) : defaultPercent; + let curRate = curHero ? getSchoolRateByStar(curHero.star, curHero.colorStar, curHero.quality) : defaultPercent; let attrName: string; - for(let attrId of school.upAttribute) { + for (let attrId of school.upAttribute) { attrName = getAtrrNameById(attrId); - res[attrName] = {fixUp: ceAttr[attrName].fixUp, ratioUp: ceAttr[attrName].ratioUp}; - if(attrId < ABI_TYPE.ABI_SPEED) { // 主属性 + res[attrName] = { fixUp: ceAttr[attrName].fixUp, ratioUp: ceAttr[attrName].ratioUp }; + if (attrId < ABI_TYPE.ABI_SPEED) { // 主属性 res[attrName].ratioUp += curRate.mainAttrAPerent - preRate.mainAttrAPerent; } else { // 次级属性 res[attrName].fixUp += (curRate.assiAttrAddValue - preRate.assiAttrAddValue) * HERO_CE_RATIO; @@ -757,24 +737,24 @@ async function calSchoolStarIncAttr(heros: HeroType[], type: number, args: numbe let [hid, isStarUp] = args; // 是否升星,是否初次觉醒 let needCal = false; let roleId: string = ''; - for(let hero of heros) { - if(hero.hid != hid) { + for (let hero of heros) { + if (hero.hid != hid) { continue; } - if((type == HERO_SYSTEM_TYPE.STAR || type == HERO_SYSTEM_TYPE.COLORSTAR) && !isStarUp) { + if ((type == HERO_SYSTEM_TYPE.STAR || type == HERO_SYSTEM_TYPE.COLORSTAR) && !isStarUp) { continue; } roleId = hero.roleId; let curHeroInSchool = await SchoolModel.findByHid(roleId, hid); - if(!curHeroInSchool) continue; + if (!curHeroInSchool) continue; let preStar = hero.star, preColorStar = hero.colorStar, preQuality = hero.quality; - if( type == HERO_SYSTEM_TYPE.STAR && isStarUp) { - preStar --; - } else if ( type == HERO_SYSTEM_TYPE.QUALITY ) { - preQuality --; - } else if ( type == HERO_SYSTEM_TYPE.COLORSTAR ) { - preColorStar --; + if (type == HERO_SYSTEM_TYPE.STAR && isStarUp) { + preStar--; + } else if (type == HERO_SYSTEM_TYPE.QUALITY) { + preQuality--; + } else if (type == HERO_SYSTEM_TYPE.COLORSTAR) { + preColorStar--; } else { continue; } @@ -783,10 +763,10 @@ async function calSchoolStarIncAttr(heros: HeroType[], type: number, args: numbe let curRate = getSchoolRateByStar(hero.star, hero.colorStar, hero.quality); let attrName: string; - for(let attrId of school.upAttribute) { + for (let attrId of school.upAttribute) { attrName = getAtrrNameById(attrId); - res[attrName] = {fixUp: ceAttr[attrName].fixUp, ratioUp: ceAttr[attrName].ratioUp}; - if(attrId < ABI_TYPE.ABI_SPEED) { // 主属性 + res[attrName] = { fixUp: ceAttr[attrName].fixUp, ratioUp: ceAttr[attrName].ratioUp }; + if (attrId < ABI_TYPE.ABI_SPEED) { // 主属性 res[attrName].ratioUp += curRate.mainAttrAPerent - preRate.mainAttrAPerent; } else { // 次级属性 res[attrName].fixUp += (curRate.assiAttrAddValue - preRate.assiAttrAddValue) * HERO_CE_RATIO; @@ -796,10 +776,10 @@ async function calSchoolStarIncAttr(heros: HeroType[], type: number, args: numbe } - if(needCal) { + if (needCal) { const allHeros = await HeroModel.findByRole(roleId); - for(let hero of allHeros) { - if(hero.hid != hid) heros.push(hero); + for (let hero of allHeros) { + if (hero.hid != hid) heros.push(hero); } } return res; @@ -811,25 +791,25 @@ async function calSchoolStarIncAttr(heros: HeroType[], type: number, args: numbe * @param hid 激活的武将 * @param ceAttr */ -function calScrollAddAttr(heros: HeroType[], hid: number, ceAttr: CeAttrRole){ +function calScrollAddAttr(heros: HeroType[], hid: number, ceAttr: CeAttrRole) { let res: CeAttrRole = {}; let curHero = heros.find(cur => cur.hid == hid); let dicHero = gameData.hero.get(hid); - if(!curHero|| ! dicHero) return res; + if (!curHero || !dicHero) return res; let { quality } = dicHero; let { star, quality: curQuality, colorStar, job } = curHero; let heroScroll = getScollByStar(quality, star, curQuality, colorStar); - if(!heroScroll) return res; + if (!heroScroll) return res; - let preScroll = gameData.preHeroScroll.get(heroScroll.id); + let preScroll = gameData.preHeroScroll.get(heroScroll.id); heroScroll.ceAttr.forEach((add, id) => { let attId = getFieldByStage(id, job); let attrName = getAtrrNameById(attId); - let preAdd = preScroll?preScroll.ceAttr.get(id): 0; + let preAdd = preScroll ? preScroll.ceAttr.get(id) : 0; - res[attrName] = {fixUp: ceAttr[attrName].fixUp, ratioUp: ceAttr[attrName].ratioUp}; + res[attrName] = { fixUp: ceAttr[attrName].fixUp, ratioUp: ceAttr[attrName].ratioUp }; res[attrName].fixUp += (add - preAdd) * HERO_CE_RATIO; }); return res; @@ -843,8 +823,74 @@ function calScrollAddAttr(heros: HeroType[], hid: number, ceAttr: CeAttrRole){ */ function calHeroCeScrollIncAttr(hero: HeroType, hid: number, preFavourLv: number) { let res: CeAttr = {}; - if(hero.hid == hid && hero.favourLv != preFavourLv) { + if (hero.hid == hid && hero.favourLv != preFavourLv) { res = calHeroFavourUpIncAttr(hero, [preFavourLv]); } return res; } + +function calTitle(args: Array, ceAttr: CeAttrRole) { + let res: CeAttrRole = {}; + let titleId = args[0]; + let titleInfo = gameData.title.get(titleId); + for (let attrName in getTeraphAttr()) { + res[attrName] = { fixUp: ceAttr[attrName].fixUp, ratioUp: ceAttr[attrName].ratioUp }; + res[attrName].fixUp += titleInfo[attrName] * HERO_CE_RATIO; + } + for (let attr of titleInfo.assiAttrValue) { + let attrName = getAtrrNameById(attr.id); + res[attrName] = res[attrName] || { fixUp: ceAttr[attrName].fixUp, ratioUp: ceAttr[attrName].ratioUp }; + res[attrName].ratioUp += attr.number * HERO_CE_RATIO; + } + return res; +} + +export function initRoleAtrr(role: RoleType) { + if (!role.globalCeAttr) role.globalCeAttr = new CeAttr(); + let titleId = role.title; + let titleInfo = gameData.title.get(titleId); + if (!!titleInfo) { + for (let attrName in getTeraphAttr()) { + if (!attrName) continue; + role.globalCeAttr[attrName].fixUp += titleInfo[attrName] * HERO_CE_RATIO; + } + for (let attr of titleInfo.assiAttrValue) { + let attrName = getAtrrNameById(attr.id); + if (!attrName) continue; + role.globalCeAttr[attrName].ratioUp += attr.number * HERO_CE_RATIO; + } + } + return; +} + +async function reCalRoleAttr(heros:Array, ceAttr: CeAttrRole, type: number, args: Array) { + let reIncAttr: CeAttrRole = {}; // role表属性增量 + switch (type) { + case HERO_SYSTEM_TYPE.INIT: + reIncAttr = calRoleInitIncAttr(heros, ceAttr); // 全局变量增 + break; + case HERO_SYSTEM_TYPE.ADD_SKIN: + reIncAttr = calHeroAddSkin(args, ceAttr); + break; + case HERO_SYSTEM_TYPE.SCHOOL: + reIncAttr = calSchoolAddAttr(heros, args[0], args[1], args[2], ceAttr); + break; + case HERO_SYSTEM_TYPE.SCROLL: + reIncAttr = calScrollAddAttr(heros, args[0], ceAttr); + break; + case HERO_SYSTEM_TYPE.STAR: + case HERO_SYSTEM_TYPE.COLORSTAR: + case HERO_SYSTEM_TYPE.QUALITY: + reIncAttr = await calSchoolStarIncAttr(heros, type, args, ceAttr); + break; + case HERO_SYSTEM_TYPE.TITLE: + reIncAttr = calTitle(args, ceAttr); + } + for (let attrName in reIncAttr) { + if (attrName == '_id') continue; + let globalAttrData: CeAttrDataRole = reIncAttr[attrName] || new CeAttrDataRole(); + for (let key in globalAttrData) { + ceAttr[attrName][key] += parseInt(globalAttrData[key] || 0); + } + } +} \ No newline at end of file