添加升星等的战力计算,计算方式修改为返回余量
This commit is contained in:
@@ -255,7 +255,7 @@ export class HeroHandler {
|
||||
let {fragmentNum, consume} = curDicHeroStar;
|
||||
let consumeArr = decodeStr('cost', consume);
|
||||
|
||||
console.log(JSON.stringify([{id: pieceId, count: fragmentNum}, ...consumeArr]))
|
||||
// console.log(JSON.stringify([{id: pieceId, count: fragmentNum}, ...consumeArr]))
|
||||
let costResult = await handleCost(roleId, sid, [{id: pieceId, count: fragmentNum}, ...consumeArr]);
|
||||
|
||||
if(!costResult) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
|
||||
|
||||
@@ -2,31 +2,35 @@
|
||||
* 体力系统
|
||||
*/
|
||||
|
||||
import { ActionPointModel } from '../db/ActionPoint';
|
||||
import { HERO_SYSTEM_TYPE } from '../consts/consts';
|
||||
import { HERO_SYSTEM_TYPE, WAR_JSON_ATTRIBUTE_TYPE } from '../consts/consts';
|
||||
import { pinus } from 'pinus';
|
||||
import { STATUS } from '../consts/statusCode';
|
||||
|
||||
import { resResult } from '../pubUtils/util';
|
||||
import { HeroModel } from '../db/Hero';
|
||||
import Hero from '../db/Hero';
|
||||
import { RoleModel } from '../db/Role';
|
||||
import { getJobInfoById, getJobByGradeAndClass, getHeroInfoById } from '../pubUtils/gamedata';
|
||||
import { HEROTARIN, CE_RATIO} from '../consts/abilityConst';
|
||||
import { getJobInfoById, getJobByGradeAndClass, getHeroInfoById, getHeroStar, getHeroWake } from '../pubUtils/gamedata';
|
||||
import { HEROTARIN, CE_RATIO, ABI_TYPE_TO_STAGE, ABI_STAGE} from '../consts/abilityConst';
|
||||
import { CeAttrData } from '../db/BaseModel';
|
||||
const HERO_CE_RATIO = 100;
|
||||
//战力计算TODO
|
||||
export function calPlayerCe(hero: any, type: number, args: Array<number>) {
|
||||
let incCe = 0;
|
||||
let incArr = {};
|
||||
let reIncAttr;
|
||||
let reIncAttr; // {"hp": {"base": number, "fixUp": number, "ratioUp": number}}
|
||||
if (type == HERO_SYSTEM_TYPE.STAR) {
|
||||
reIncAttr = calHeroStarIncAttr(hero, args);
|
||||
reIncAttr = calHeroStarIncAttr(hero, args); // 返回 计算后的值
|
||||
} else if (type == HERO_SYSTEM_TYPE.TRAIN) {
|
||||
reIncAttr = calHeroTrainIncAttr(hero);
|
||||
}
|
||||
for (let attrName in reIncAttr) {
|
||||
let originalAttrData: CeAttrData = hero.ceAttr[attrName];
|
||||
let oldCe = originalAttrData.fixUp * HERO_CE_RATIO + originalAttrData.base *(HERO_CE_RATIO + originalAttrData.ratioUp)
|
||||
|
||||
for (let attrKey in reIncAttr[attrName]) {
|
||||
hero.CeAttr[attrName][attrKey] += parseInt(reIncAttr[attrName][attrKey]);
|
||||
hero.CeAttr[attrName][attrKey] = parseInt(reIncAttr[attrName][attrKey]);
|
||||
}
|
||||
incArr[attrName] = reIncAttr[attrName].fixUp * HERO_CE_RATIO + reIncAttr[attrName].base *(HERO_CE_RATIO + reIncAttr[attrName].ratioUp); //计算属性
|
||||
incArr[attrName] = reIncAttr[attrName].fixUp * HERO_CE_RATIO + reIncAttr[attrName].base *(HERO_CE_RATIO + reIncAttr[attrName].ratioUp) - oldCe; //计算属性
|
||||
incCe += incArr[attrName] * CE_RATIO[attrName];
|
||||
}
|
||||
hero.ce += incCe;
|
||||
@@ -37,6 +41,7 @@ export function calPlayerCe(hero: any, type: number, args: Array<number>) {
|
||||
export async function calPlayerCeAndSave(sid: string, roleId: string, heros: Array<any>, type?: number, args?: Array<number>) {
|
||||
let incPlayerCe = 0;
|
||||
let pushHeros = [];
|
||||
|
||||
for (let hero of heros) {
|
||||
let incHeroCe = calPlayerCe(hero, type, args);
|
||||
incPlayerCe += incHeroCe;
|
||||
@@ -47,17 +52,58 @@ export async function calPlayerCeAndSave(sid: string, roleId: string, heros: Arr
|
||||
incHeroCe : incHeroCe,
|
||||
});
|
||||
}
|
||||
let role = await RoleModel.findOne({ roleId });
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
role.ce += incPlayerCe;
|
||||
await role.save();
|
||||
await RoleModel.updateRoleInfo(roleId, role);
|
||||
//下发战力
|
||||
let uids = [{ uid: roleId, sid }];
|
||||
pinus.app.get('channelService').pushMessageByUids('onPlayerCeUpdate', resResult(STATUS.SUCCESS, { ce: role.ce, heros: pushHeros, topFiveCe: 0 }), uids);
|
||||
return heros;
|
||||
}
|
||||
|
||||
export function calHeroStarIncAttr(hero: any, args: Array<number>) {
|
||||
return {};//属性增量可以是多个
|
||||
export function calHeroStarIncAttr (hero: Hero, _args: Array<number>) {
|
||||
let {star, starStage, quality, colorStar, colorStarStage, ceAttr} = hero;
|
||||
let res = {};
|
||||
const dicHero = getHeroInfoById(hero.hid);
|
||||
|
||||
const isWake = colorStar > 0; // 是否觉醒,只要激活了觉醒,彩星就会 > 1
|
||||
|
||||
let attrs = new Array<number>(); // 有升级的属性 1-hp 2-atk 3-def 4-mdef 5-agi 6-luk
|
||||
if(isWake) {
|
||||
if(colorStar == 1 && colorStarStage == ABI_STAGE.START) { // 当第一次觉醒时,一口气修改全部属性
|
||||
for(let stage = ABI_STAGE.START + 1; stage <= ABI_STAGE.END; stage++) {
|
||||
attrs.push(stage)
|
||||
};
|
||||
colorStar = colorStar -1; // 当第一次觉醒时,存的是1,读表的是上一行0
|
||||
} else { // 觉醒一次,相应的属性
|
||||
if(colorStarStage == ABI_STAGE.START) { // 当升一级的时候,存储会存0,但加的是6,读表读的是上一行
|
||||
colorStarStage = ABI_STAGE.END; colorStar = colorStar -1;
|
||||
}
|
||||
attrs.push(colorStarStage);
|
||||
}
|
||||
} else {
|
||||
if(starStage == ABI_STAGE.START) { // 当升一级的时候,存储会存0,但加的是6,读表读的是上一行
|
||||
starStage = ABI_STAGE.END; star = star -1;
|
||||
}
|
||||
attrs.push(starStage);
|
||||
}
|
||||
const dicStar = isWake? getHeroWake(quality, colorStar): getHeroStar(quality, star); // 星级表
|
||||
|
||||
for(let stage of attrs) {
|
||||
|
||||
let targetAttrId = getFieldByStage(stage, hero.job); // 转换为17维的属性id
|
||||
let heroAttr = dicHero.baseAbilityArr[targetAttrId]; // 武将表hp等
|
||||
let heroUpAttr = dicHero.baseAbilityUpArr[targetAttrId]; // 武将表hp_up等
|
||||
|
||||
let starUp = dicStar.ceAttr.get(stage);
|
||||
let newBase = heroAttr + hero.lv * (heroUpAttr + starUp);
|
||||
let field = WAR_JSON_ATTRIBUTE_TYPE[targetAttrId];
|
||||
let ceAttrData: CeAttrData = ceAttr[field]; // 存表中的属性下的base,fixup,ratioup
|
||||
let {ratioUp = 0, fixUp = 0} = ceAttrData;
|
||||
res[field] = { base: newBase, ratioUp, fixUp}; // base变动,增量为△base * ratio + 0
|
||||
}
|
||||
|
||||
return res;//属性增量可以是多个
|
||||
}
|
||||
|
||||
export function calHeroTrainIncAttr(hero: any) {
|
||||
@@ -74,3 +120,14 @@ export function calHeroTrainIncAttr(hero: any) {
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
// 根据存在升星表等的stage字段的id对应17维id
|
||||
function getFieldByStage(stage: number, jobid: number) {
|
||||
let targetAttrId = ABI_TYPE_TO_STAGE.get(stage);
|
||||
if(typeof targetAttrId === 'number') {
|
||||
return targetAttrId
|
||||
} else {
|
||||
const dicJob = getJobInfoById(jobid);
|
||||
return targetAttrId(dicJob.type);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user