添加最强五人战力

This commit is contained in:
luying
2020-12-29 16:49:08 +08:00
parent 74c6f19994
commit 315816ea59
11 changed files with 78 additions and 558 deletions

View File

@@ -1,6 +1,5 @@
import {Application, BackendSession} from 'pinus'; import {Application, BackendSession} from 'pinus';
import { HeroModel } from '../../../db/Hero';
import Actor from '../../../pubUtils/actor';
export default function(app: Application) { export default function(app: Application) {
return new ChatHandler(app); return new ChatHandler(app);

View File

@@ -3,17 +3,14 @@ import { EquipModel } from './../../../db/Equip';
import { RoleModel } from './../../../db/Role'; import { RoleModel } from './../../../db/Role';
import { UserModel } from '../../../db/User'; import { UserModel } from '../../../db/User';
import { GMUserModel } from '../../../db/GMUser'; import { GMUserModel } from '../../../db/GMUser';
import { Application, Session } from 'pinus'; import { Application } from 'pinus';
import {FrontendSession} from 'pinus'; import {FrontendSession} from 'pinus';
import { HeroModel } from './../../../db/Hero'; import { HeroModel } from './../../../db/Hero';
import { resResult, returnHeroCeRatio, reduceCe } from '../../../pubUtils/util'; import { resResult, returnHeroCeRatio, reduceCe } from '../../../pubUtils/util';
import { startEvent } from '../../../services/eventSercive'; import { FUNC_OPT_TYPE } from '../../../consts';
import { EVENT_START_LV, FUNC_OPT_TYPE, HERO_CE_RATIO } from '../../../consts';
import { getAp } from '../../../services/actionPointService'; import { getAp } from '../../../services/actionPointService';
import Actor from '../../../pubUtils/actor';
import { ItemModel } from '../../../db/Item'; import { ItemModel } from '../../../db/Item';
import { switchOnFunc } from '../../../services/funcSwitchService'; import { switchOnFunc } from '../../../services/funcSwitchService';
import { stat } from 'fs';
export default function (app: Application) { export default function (app: Application) {
return new EntryHandler(app); return new EntryHandler(app);

View File

@@ -5,9 +5,8 @@ import { PvpDefenseModel } from '../db/PvpDefense';
import { getWarJsons, getGamedata, getExpeditionById } from '../pubUtils/gamedata'; import { getWarJsons, getGamedata, getExpeditionById } from '../pubUtils/gamedata';
import { decodeStr, resResult, setLocalHours, shouldRefresh } from '../pubUtils/util'; import { decodeStr, resResult, setLocalHours, shouldRefresh } from '../pubUtils/util';
import { EXPEDITION_CONST, HERO_CE_RATIO } from '../consts'; import { EXPEDITION_CONST, HERO_CE_RATIO, getAttrCeRatio } from '../consts';
import { getAtrrNameById} from '../consts'; import { getAtrrNameById} from '../consts';
import Actor from '../pubUtils/actor';
import { ExpeditionWarRecordModel } from '../db/ExpeditionWarRecord'; import { ExpeditionWarRecordModel } from '../db/ExpeditionWarRecord';
export async function findOrCreateEnemies(roleId: string, myCe: number, expeditionCode: string, expeditionId: number, battleStatus: number) { export async function findOrCreateEnemies(roleId: string, myCe: number, expeditionCode: string, expeditionId: number, battleStatus: number) {
@@ -110,8 +109,10 @@ export async function matchRobots(scale: number, myCe: number, robotCe: number,
attribute[value] *= ratio; attribute[value] *= ratio;
attribute[value] = Math.round(attribute[value]); attribute[value] = Math.round(attribute[value]);
} }
let actor = new Actor(); let ce = 0;
let ce = actor.calculateCEByExpression(attribute); for(let attrName in attribute) {
ce += attribute[attrName] * getAttrCeRatio(attrName);
}
enemyObj.enemies.push({...enemy, attribute, lv}); enemyObj.enemies.push({...enemy, attribute, lv});
allCe += ce; allCe += ce;
} }

View File

@@ -13,16 +13,16 @@ const _ = require('underscore');
//修改并下发战力 //修改并下发战力
export async function calPlayerCeAndSave(sid: string, roleId: string, heros: Array<HeroType>, type?: number, args?: Array<number>) { export async function calPlayerCeAndSave(sid: string, roleId: string, heros: Array<HeroType>, type?: number, args?: Array<number>) {
let {role, pushHeros} = await pubCalPlayerCeAndSave(roleId, heros, type, args); let {role, pushHeros, topFiveCe} = await pubCalPlayerCeAndSave(roleId, heros, type, args);
//下发战力 //下发战力
let uids = [{ uid: roleId, sid }]; let uids = [{ uid: roleId, sid }];
pinus.app.get('channelService').pushMessageByUids('onPlayerCeUpdate', resResult(STATUS.SUCCESS, { ce: reduceCe(role.ce) , heros: pushHeros, topFiveCe: 0 }), uids); pinus.app.get('channelService').pushMessageByUids('onPlayerCeUpdate', resResult(STATUS.SUCCESS, { ce: reduceCe(role.ce) , heros: pushHeros, topFiveCe: reduceCe(topFiveCe) }), uids);
return heros; return heros;
} }
export async function calAllHeroCe(sid: string, roleId: string, type?:number, args?:Array<number>) { export async function calAllHeroCe(sid: string, roleId: string, type?:number, args?:Array<number>) {
let {ce, pushHeros}= await reCalAllHeroCe(roleId, type, args); let {ce, pushHeros, topFiveCe }= await reCalAllHeroCe(roleId, type, args);
let uids = [{ uid: roleId, sid }]; let uids = [{ uid: roleId, sid }];
pinus.app.get('channelService').pushMessageByUids('onPlayerCeUpdate', resResult(STATUS.SUCCESS, { ce: reduceCe(ce), heros: pushHeros, topFiveCe: 0 }), uids); pinus.app.get('channelService').pushMessageByUids('onPlayerCeUpdate', resResult(STATUS.SUCCESS, { ce: reduceCe(ce), heros: pushHeros, topFiveCe: reduceCe(topFiveCe) }), uids);
return; return;
} }

View File

@@ -39,10 +39,6 @@ export default class Utils extends Service {
return pubGamedata.getGoodById(gid); return pubGamedata.getGoodById(gid);
} }
public calculateCE(heroInfo: {hid: number, lv: number }) {
return pubUtils.calculateCE(heroInfo)
}
public getExpByLv(lv: number) { public getExpByLv(lv: number) {
return pubGamedata.getExpByLv(lv); return pubGamedata.getExpByLv(lv);
} }

View File

@@ -22,11 +22,11 @@ import { Service } from 'egg';
import Counter from '@db/Counter'; import Counter from '@db/Counter';
import { STATUS, HERO_SYSTEM_TYPE } from '@consts'; import { STATUS, HERO_SYSTEM_TYPE } from '@consts';
import { ITID, COUNTER } from '@consts'; import { ITID, COUNTER } from '@consts';
import Actor from '@pubUtils/actor';
import { ItemModel } from '@db/Item'; import { ItemModel } from '@db/Item';
import { gameData, getHeroExpByLv } from '@pubUtils/data'; import { gameData, getHeroExpByLv } from '@pubUtils/data';
import { calPlayerCeAndSave } from '@pubUtils/playerCe'; import { calPlayerCeAndSave } from '@pubUtils/playerCe';
import { SchoolModel } from '@db/School'; import { SchoolModel } from '@db/School';
import { CeAttrNumber } from '@db/generalField';
/** /**
* Test Service * Test Service
@@ -381,21 +381,26 @@ export default class GMUsers extends Service {
public async saveHeroToDefense(roleId: string, roleName: string, hid: number) { public async saveHeroToDefense(roleId: string, roleName: string, hid: number) {
const {ctx} = this; const {ctx} = this;
let hero = await HeroModel.findByHidAndRole(hid, roleId); let hero = await HeroModel.findByHidAndRole(hid, roleId);
if(!hero) { let role = await RoleModel.findByRoleId(roleId);
if(!hero || !role) {
return ctx.service.utils.resResult(STATUS.GM_HERO_NOT_FOUND); return ctx.service.utils.resResult(STATUS.GM_HERO_NOT_FOUND);
} }
let { lv } = hero; let { lv, ce, ceAttr } = hero;
let { globalCeAttr } = role;
let dicHero = ctx.service.utils.getHeroById(hid); let dicHero = ctx.service.utils.getHeroById(hid);
let actor = new Actor(); let attribute = new CeAttrNumber();
actor.initHero(hero); for(let attrName in attribute) {
let ce = actor.calculateCE(); let { base, ratioUp, fixUp, equipUp } = ceAttr[attrName];
let attribute = actor.getAttributeJson(); let { ratioUp: ratioUp2, fixUp: fixUp2 } = globalCeAttr[attrName];
attribute[attrName] += base * ( 1 + ratioUp + ratioUp2) + fixUp + fixUp2 + equipUp;
}
let heroInfo = { let heroInfo = {
actorId: dicHero.heroId, actorId: dicHero.heroId,
actorName: dicHero.name, actorName: dicHero.name,
attribute, lv, attribute: {...attribute, speed: 0, ap: 0}, lv,
ce ce
}; };

View File

@@ -71,9 +71,8 @@ export default class PvpDefense extends BaseModel {
} }
public static async updateCe(roleId: string, hid: number, ce: number, oldCe: number, lean = true) { public static async updateCe(roleId: string, hid: number, ce: number, lean = true) {
let distance = ce - oldCe; const rec: PvpDefenseType = await PvpDefenseModel.findOneAndUpdate({roleId, 'heroes.actorId': hid}, {$set: { ce }}).lean(lean);
const rec: PvpDefenseType = await PvpDefenseModel.findOneAndUpdate({roleId, 'heroes.actorId': hid}, {$inc: {ce: distance}}).lean(lean);
return rec return rec
} }

View File

@@ -4,7 +4,6 @@ import { CeAttrRole } from './generalField';
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose'; import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
import User from './User'; import User from './User';
import { shouldRefresh } from '../pubUtils/util'; import { shouldRefresh } from '../pubUtils/util';
import { HeroModel } from './Hero';
import { initRoleAtrr } from '../pubUtils/playerCe'; import { initRoleAtrr } from '../pubUtils/playerCe';
interface roleUpdate { interface roleUpdate {
ce?: number; ce?: number;
@@ -16,6 +15,8 @@ interface roleUpdate {
globalCeAttr?:CeAttrRole; globalCeAttr?:CeAttrRole;
title?:number; title?:number;
teraphs?: Teraph[]; teraphs?: Teraph[];
topFive?: TopHero[];
topFiveCe?: number;
} }
class TopHero { class TopHero {
@@ -382,41 +383,6 @@ export default class Role extends BaseModel {
return ranks; return ranks;
} }
public static async updateSumCe(roleId: string, hid: number, ce: number, oldCe: number, lean = true) {
let role = await RoleModel.findByRoleId(roleId);
let topFive = role?.topFive||new Array();
let distance = ce - oldCe;
topFive.sort((a, b) => {return b.ce - a.ce}); // 0-5最大-最小
let index = topFive.findIndex(cur => cur.hid == hid);
if(index == -1) { // 不在最强列表
if(topFive.length < 5) { // 不满5人
topFive.push({hid, ce});
} else if(topFive.length == 5){
if(ce > topFive[topFive.length - 1].ce) { // 跻身最强5人
topFive.pop();
topFive.push({hid, ce});
}
} else {
topFive.splice(5, topFive.length - 5);
}
} else { // 原来就是最强5人
if(ce < topFive[topFive.length - 1].ce) { // 滑出最强
let heroes = await HeroModel.getTopHero(roleId, 5);
topFive = heroes.map(cur => {return {hid: cur.hid, ce: cur.ce}});
} else {
topFive[index].ce = ce;
}
}
let topFiveCe = topFive.reduce((pre, cur) => {
return pre + cur.ce
}, 0);
role = await RoleModel.findOneAndUpdate({roleId}, { topFive, topFiveCe, $inc: {ce: distance} }).lean(lean);
return role;
}
// 保存秘境首通队伍 // 保存秘境首通队伍
public static async saveDungeonHero(roleId: string, battleId: number, heroes: Array<number>, isSuccess: boolean) { public static async saveDungeonHero(roleId: string, battleId: number, heroes: Array<number>, isSuccess: boolean) {
if(isSuccess) { if(isSuccess) {
@@ -438,7 +404,7 @@ export default class Role extends BaseModel {
public static async updateRoleInfo(roleId: string, roleUpdate:roleUpdate, lean = true) { public static async updateRoleInfo(roleId: string, roleUpdate:roleUpdate, lean = true) {
delete roleUpdate._id; delete roleUpdate._id;
let result: RoleType = await RoleModel.findOneAndUpdate({roleId}, {$set:roleUpdate}).lean(lean); let result: RoleType = await RoleModel.findOneAndUpdate({roleId}, {$set:roleUpdate}, {new: true}).lean(lean);
return result; return result;
} }
} }

View File

@@ -1,446 +0,0 @@
import { getHeroInfoById, getStarRatio, /*getHeroSkillById,*/ getSeidById, getOlySeidByType, getGoodById } from "./gamedata";
import { getAtrrNameById, ABI_TYPE, SEID_TYPE } from "../consts";
import { EXPRESSION } from '../consts';
export default class Actor {
private hid: number = 0;
private lv: number = 0;
private oldCe: number = 0;
private star: number = 0;
private colorStar: number = 0;
private equips: Array<any> = [];
private conections: Array<{id: number;name: string;valid: boolean;}> = [];
/**被动技能 */
private seidList:Array<any> = new Array<any>(3);
private effectList:Map<number,Array<any> > = new Map<number,Array<any> >();
initHero(hero: any) { // 从数据库拿到的hero
this.hid = hero.hid;
this.lv = hero.lv;
this.oldCe = hero.ce;
this.star = hero.star;
this.colorStar = hero.colorStar;
this.equips = hero.equips;
console.log(this.hid, this.lv, this.oldCe, this.star, this.colorStar, this.conections);
this.updateActorEffect();
}
updateActorEffect(){
//添加装备属性和效果
//添加技能
this.updateSkillInfo();
//添加被动效果1.0
for(let i = 0;i < this.seidList.length;i++){
if(this.seidList[i] && this.seidList[i].id > 0){
this.addSeidEffect(this.seidList[i].id,this.seidList[i].gainValueArr);
}
}
//添加被动效果 2.0
// for(let i = 0;i < this.seidList.length;i++){
// if(this.seidList[i]._id > 0){
// this.addSeidEffectNew(this.seidList[i]);
// }
// }
}
/**更新武将的被动技能 */
updateSkillInfo(){
// let dicHero = getHeroInfoById(this.hid);
// console.log('updateSkillInfo', dicHero.skill, getHeroSkillById(dicHero.skill))
//被动技能
// if(dicHero.skill){
// let {seidLvUpArr} = getHeroSkillById(dicHero.skill);
// for(let ii = 0;ii < seidLvUpArr.length;ii+=2){
// if(this.lv >= seidLvUpArr[ii + 1]){
// let dicSeid = getSeidById(seidLvUpArr[ii]);
// // console.log('updateSkillInfo*', seidLvUpArr[ii], dicSeid)
// if(dicSeid){
// this.seidList[Math.floor(ii/2)] = dicSeid;
// }
// }
// }
// }
}
addSeidEffect(seidId:number, seidValue?:Array<number>){
// console.log('addSeidEffect', seidId, seidValue)
let curSeid = getSeidById(seidId);
if(!curSeid) {console.log("seidId not found:"+seidId);return;}
if(!seidValue) seidValue = curSeid.gainValueArr;
if(!seidValue) seidValue = [];
if(curSeid.type === 999){
for(let i = 0;i < seidValue.length;i++){
this.addSeidEffect(seidValue[i]);
}
return;
}
let olySeid = getOlySeidByType(curSeid.type);
if(!olySeid) {console.log("olySeidType not found:"+curSeid.type);return;}
if(olySeid.isSeid){ // 是被动
let el = this.effectList.get(curSeid.type);
if(!el || !el.length){
if(!el){
this.effectList.set(curSeid.type, [Object.assign({}, curSeid)]);
} else {
el.push(Object.assign({}, curSeid));
}
}
else{
let buffArr = this.effectList.get(curSeid.type)||[];
if(olySeid.olyType == 101){
let identical:boolean = true;
buffArr.forEach((value)=>{
if(value.type != curSeid.type||value.gainValueArr.length != seidValue?.length){
identical = false;
return;
}
value.gainValueArr.forEach((val,key)=>{
if(!seidValue) seidValue = [];
if(val!= seidValue[key]){
identical = false;
return;
}
})
});
if(!identical){
let el = this.effectList.get(curSeid.type);
if(!el){
this.effectList.set(curSeid.type, [Object.assign({}, curSeid)]);
} else {
el.push(Object.assign({}, curSeid));
}
}
}
else
{
let tBuff,startIndex:number = 0;
if(olySeid.olyType >= 103){
startIndex = 1;
let addSeid:boolean = true;
for(let k = 0;k < buffArr.length;k++){
tBuff = buffArr[k];
if(tBuff && tBuff.gainValueArr && tBuff.gainValueArr[0] == seidValue[0]){
addSeid = false;
break;
}
}
if(addSeid){
tBuff = null;
let el = this.effectList.get(curSeid.type);
if(!el){
this.effectList.set(curSeid.type, [Object.assign({}, curSeid)]);
} else {
el.push(Object.assign({}, curSeid));
}
}
}
else {
tBuff = buffArr[0];
}
if(tBuff){
for(let j = startIndex;j < seidValue.length;j++){
switch(olySeid.olyType){
case 100:
tBuff.gainValueArr[j] += seidValue[j];
break;
case 102:
tBuff.gainValueArr[j] = seidValue[j];
break;
case 103:
if(tBuff.gainValueArr[j] < seidValue[j]){
tBuff.gainValueArr[j] = seidValue[j];
}
break;
case 104:
if(tBuff.gainValueArr[j] > seidValue[j]){
tBuff.gainValueArr[j] = seidValue[j];
}
break;
default:
break;
}
}
}
}
// switch(olySeid._olyType){
// case 1://对比
// break;
// case 2://
// default:
// console.log("not found _olyType:"+olySeid._olyType);
// break;
// }
}
}
}
getGrowUp(abilityType:number):number{
const dicHero = getHeroInfoById(this.hid);
const dicStarRatio = getStarRatio(this.star)||0;
return dicHero.baseAbilityUpArr[abilityType] * dicStarRatio;
}
getBaseAbility(abilityType:number):number{
const dicHero = getHeroInfoById(this.hid);
// console.log('getBaseAbility', dicHero.baseAbilityArr[abilityType]);
// console.log('getBaseAbility', this.lv);
// console.log('getBaseAbility', this.getGrowUp(abilityType));
return dicHero.baseAbilityArr[abilityType] + (this.lv - 1)*this.getGrowUp(abilityType);
}
isHadSeid(type:number):boolean{
let el = this.effectList.get(type);
if(this.effectList.has(type) && el && el.length){
return true;
}
return false;
}
/**
* 获取武将效果
* @type 特技type
* returns Array<Array<Buff> > 0:特技 1buff 2:光环
* */
getSeidEffect(type:number):Array<Array<any> >{
let retArr:Array<Array<any> > = new Array<Array<any> >();
let el = this.effectList.get(type);
if(this.effectList.has(type) && el && el.length){
retArr.push(el);
}
return retArr;
}
/**获取seid 数值效果 */
getSeidAddAbilityNumByAbility(type:number,ability:number){ // type: 101/102等ability1-17代表hp,atk等
let ret:number = 0;
if(this.isHadSeid(type)){ // effectList, buffList
let buff = this.getSeidEffect(type);
for(let i = 0;i < buff.length;i++){
for(let j = 0;j < buff[i].length;j++){
// console.log(ability, buff[i][j].gainValueArr[0], buff[i][j].gainValueArr[1])
if(ability == buff[i][j].gainValueArr[0]){
ret += buff[i][j].gainValueArr[1];
}
}
}
}
// console.log('getSeidAddAbilityNumByAbility', type, ret)
return ret;
}
getRealAbility(abilityType: number) {
let baseAbility:number = 0;
if(abilityType <= ABI_TYPE.ABI_SPEED){
// console.log('getRealAbility', this.getBaseAbility(abilityType));
// console.log('getRealAbility', this.getSeidAddAbilityNumByAbility(SEID_TYPE.TYPE102,abilityType));
// console.log('getRealAbility', this.getSeidAddAbilityNumByAbility(SEID_TYPE.TYPE101,abilityType));
baseAbility = this.getBaseAbility(abilityType)*(100+this.getSeidAddAbilityNumByAbility(SEID_TYPE.TYPE102,abilityType))/100 + this.getSeidAddAbilityNumByAbility(SEID_TYPE.TYPE101,abilityType);
}
else{
baseAbility = this.getSeidAddAbilityNumByAbility(SEID_TYPE.TYPE101,abilityType);
}
return baseAbility
}
getAttributeJson() {
let json = {hp: 0, atk: 0, matk: 0, def: 0, mdef: 0, agi: 0, speed: 0, luk: 0, hit: 0, cri: 0, flee: 0, antCri: 0, damageIncrease: 0, damageDecrease: 0, defIngnore: 0, bloodSuck: 0};
for(let i = ABI_TYPE.ABI_HP;i < ABI_TYPE.ABI_MAX;i++){
let field = getAtrrNameById(i);
json[field] = this.getRealAbility(i);
}
return json
}
calculateCE() {
// 武将
let json = this.getAttributeJson();
let ce = this.calculateCEByExpression(json);
// 装备
for(let equip of this.equips) {
let good = new HistoryGoods();
good.loadDataByJson(equip);
for(let i = ABI_TYPE.ABI_HP;i < ABI_TYPE.ABI_MAX;i++){
ce += good.getGoodsAddAbility(i);
}
}
return Math.floor(ce);
}
calculateCEByExpression(json: {hp:number, atk: number, matk: number, def: number, mdef: number, agi: number, luk: number, hit: number, cri: number, flee: number, antCri: number, damageIncrease: number, damageDecrease: number, defIngnore: number, bloodSuck: number}): number {
let {hp, atk, matk, def, mdef, agi, luk, hit, cri, flee, antCri, damageIncrease, damageDecrease, defIngnore, bloodSuck } = json;
console.log(JSON.stringify({hp, atk, matk, def, mdef, agi, luk, hit, cri, flee, antCri, damageIncrease, damageDecrease, defIngnore, bloodSuck}));
let ce = 0;
try {
ce = eval(EXPRESSION.CE);
} catch(e) {
console.error('expression wrong');
}
return ce
}
}
class HistoryGoods{
private _goodsId:number = 0;
private _serverGId:number = 0;
private _itid:number = 0;
private _quality:number = 0;
private _lv:number = 0;
/**物攻策攻数值浮动上下限变化率 */
private _randRange:number = 0;
/**装备的武将dataID */
private _equipActorDataId:number = 0;
/**装备属性 */
private _goodsAbility:Array<number> = new Array<number>();
/**装备属性 随机的百分比 */
private _goodsAbilityPre:Array<number> = new Array<number>();
resetAllData(){
this.setGoodsId(0);
this.setItid(0);
this.setEquipActorDataId(0);
for(let i = ABI_TYPE.ABI_HP;i < ABI_TYPE.ABI_MAX;i++){
this._goodsAbility[i] = 0;
this._goodsAbilityPre[i] = 0;
}
}
//加载
loadDataByJson(json){
// "_id": "5f841c27eb94a70b385beea4",
// "seqId": 8,
// "__v": 0,
// "createdAt": "2020-10-12T09:04:39.087Z",
// "eName": "青铜短剑",
// "eid": 1,
// "holes": [],
// "initHoleCnt": 0,
// "lv": 1,
// "randRange": 0,
// "randSe": [],
// "roleId": "1Emy2SnEaw",
// "roleName": "大蝈蝈",
// "type": 1,
// "updatedAt": "2020-10-12T09:04:39.087Z"
if(json.seqId){
this.setServerGId(json.seqId);
this.setGoodsId(json.eid);
this.setEquipActorDataId(json.hid);
//this.setQuality(json.quality);
this.setLevel(json.lv);
this.setRandRange(json.randRange);
let dicGoods = getGoodById(this.getGoodsId());
if(dicGoods){
this.setItid(dicGoods.itid);
}
}
}
//属性的获取方法///////////////
getGoodsId(){
return this._goodsId;
}
setGoodsId(goodsId:number){
this._goodsId = goodsId;
}
getServerGId(){
return this._serverGId;
}
setServerGId(serverGId:number){
this._serverGId = serverGId;
}
getItid(){
return this._itid;
}
setItid(itid:number){
this._itid = itid;
}
getQuality(){
return this._quality;
}
setQuality(quality:number){
this._quality = quality;
}
getLevel(){
return this._lv;
}
setLevel(lv:number){
this._lv = lv;
}
getRandRange(){
return this._randRange;
}
setRandRange(val:number){
this._randRange = val;
}
getEquipActorDataId(){
return this._equipActorDataId;
}
setEquipActorDataId(dataId:number){
this._equipActorDataId = dataId;
}
//属性的获取方法 end ////////////
constructor(){
for(let i = ABI_TYPE.ABI_HP;i < ABI_TYPE.ABI_MAX;i++){
this._goodsAbility[i] = 0;
this._goodsAbilityPre[i] = 0;
}
}
/**是否物品 */
isGoods(){
if(this.getGoodsId() > 0){
return true;
}
else{
return false;
}
}
/**是否装备 */
isEquipment(){
}
/**是否宝物 */
isTreasure(){
}
/**是否道具 */
isItem(){
}
getGoodsAddAbility(ability:number){
return Math.floor(this._goodsAbility[ability] * this._goodsAbilityPre[ability] / 100);
}
}

View File

@@ -16,6 +16,7 @@ import { DicRandomEffectPool } from './dictionary/DicRandomEffectPool';
import { getGoodById } from './gamedata'; import { getGoodById } from './gamedata';
import { SchoolModel } from '../db/School'; import { SchoolModel } from '../db/School';
import { getTeraphAttr } from '../consts/constModules/abilityConst' import { getTeraphAttr } from '../consts/constModules/abilityConst'
import { PvpDefenseModel } from '../db/PvpDefense';
const HERO_CE_RATIO = 100; const HERO_CE_RATIO = 100;
const _ = require('underscore'); const _ = require('underscore');
//战力计算TODO //战力计算TODO
@@ -84,9 +85,10 @@ export function calPlayerCe(globalCeAttr: CeAttrRole, hero: HeroType, type: numb
} }
} }
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); 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);
console.log(hero.hid, attrNumber, attrName, getAttrCeRatio(attrName))
heroCe += attrNumber * getAttrCeRatio(attrName); heroCe += attrNumber * getAttrCeRatio(attrName);
} }
let incCe = (heroCe - hero.ce) > 0?heroCe:0; let incCe = heroCe - hero.ce;
hero.ce = heroCe > 0?heroCe:1; hero.ce = heroCe > 0?heroCe:1;
if (hero.historyCe < hero.ce) hero.historyCe = hero.ce; if (hero.historyCe < hero.ce) hero.historyCe = hero.ce;
return incCe; return incCe;
@@ -102,9 +104,12 @@ export async function calPlayerCeAndSave(roleId: string, heros: Array<HeroType>,
await reCalRoleAttr(heros, role.globalCeAttr, type, args); await reCalRoleAttr(heros, role.globalCeAttr, type, args);
for (let hero of heros) { for (let hero of heros) {
let incHeroCe = calPlayerCe(role.globalCeAttr, hero, type, args); let incHeroCe = calPlayerCe(role.globalCeAttr, hero, type, args);
incPlayerCe += incHeroCe; incPlayerCe += incHeroCe;
hero.ce += incHeroCe; // hero.ce += incHeroCe;
await calculateTopFive(role, hero.hid, hero.ce); // 计算更新最强五人战力
await HeroModel.updateHeroInfo(roleId, hero.hid, hero); await HeroModel.updateHeroInfo(roleId, hero.hid, hero);
await PvpDefenseModel.updateCe(roleId, hero.hid, hero.ce); // 更新pvp防守阵最强五人战力
pushHeros.push({ pushHeros.push({
hid: hero.hid, hid: hero.hid,
ce: reduceCe(hero.ce), ce: reduceCe(hero.ce),
@@ -112,8 +117,44 @@ export async function calPlayerCeAndSave(roleId: string, heros: Array<HeroType>,
}); });
} }
role.ce += incPlayerCe; role.ce += incPlayerCe;
await RoleModel.updateRoleInfo(roleId, { globalCeAttr: role.globalCeAttr, ce: role.ce }); let { topFive, topFiveCe } = role;
return { pushHeros, role } await RoleModel.updateRoleInfo(roleId, { globalCeAttr: role.globalCeAttr, ce: role.ce, topFive, topFiveCe });
return { pushHeros, role, topFiveCe }
}
async function calculateTopFive(role: RoleType, hid: number, ce: number) {
let topFive = role?.topFive||new Array();
topFive.sort((a, b) => {return b.ce - a.ce}); // 0-5最大-最小
let index = topFive.findIndex(cur => cur.hid == hid);
if(index == -1) { // 不在最强列表
if(topFive.length < 5) { // 不满5人
topFive.push({hid, ce});
} else if(topFive.length == 5){
if(ce > topFive[topFive.length - 1].ce) { // 跻身最强5人
topFive.pop();
topFive.push({hid, ce});
}
} else {
topFive.splice(5, topFive.length - 5);
}
} else { // 原来就是最强5人
if(ce < topFive[topFive.length - 1].ce) { // 滑出最强
let heroes = await HeroModel.getTopHero(role.roleId, 5);
topFive = heroes.map(cur => {return {hid: cur.hid, ce: cur.ce}});
} else {
topFive[index].ce = ce;
}
}
let topFiveCe = topFive.reduce((pre, cur) => {
return pre + cur.ce
}, 0);
role.topFive = topFive;
role.topFiveCe = topFiveCe;
return role;
} }
// 初始战力 // 初始战力
@@ -229,6 +270,7 @@ export function calHeroStarIncAttr(hero: HeroType, type: number, hid: number, ar
if (!!dicStar && !!dicStar.ceAttr) { 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 newBase = (heroAttr + hero.lv * (heroUpAttr + starUp)) * HERO_CE_RATIO;
let field = getAtrrNameById(targetAttrId); let field = getAtrrNameById(targetAttrId);
let ceAttrData: CeAttrData = ceAttr[field] || new CeAttrData(); // 存表中的属性下的basefixupratioup let ceAttrData: CeAttrData = ceAttr[field] || new CeAttrData(); // 存表中的属性下的basefixupratioup
@@ -674,8 +716,8 @@ export async function reCalAllHeroCe(roleId: string, type: number, args: Array<n
pushHeros.push({ hid: hero.hid, ce: reduceCe(hero.ce), incHeroCe: reduceCe(incHeroCe) }); 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 }); role = await RoleModel.updateRoleInfo(roleId, { globalCeAttr: role.globalCeAttr, ce: role.ce });
return { pushHeros, ce: role.ce } return { pushHeros, ce: role.ce, topFiveCe: role.topFiveCe }
} }
function calHeroAddSkin(args: Array<number>, ceAttr: CeAttrRole) { function calHeroAddSkin(args: Array<number>, ceAttr: CeAttrRole) {

View File

@@ -1,10 +1,6 @@
import { STATUS } from './../consts/statusCode'; import { STATUS } from './../consts/statusCode';
import { getGamedata } from './gamedata';
import { HeroModel, HeroType } from '../db/Hero'; import { HeroModel, HeroType } from '../db/Hero';
import { RoleModel } from '../db/Role';
import { PvpDefenseModel } from '../db/PvpDefense';
import Actor from './actor';
import fs = require('fs'); import fs = require('fs');
import path = require('path'); import path = require('path');
@@ -170,26 +166,6 @@ export async function calculateSumCE(roleId: string, type: number, param: { num?
} }
return sum; return sum;
} }
// 计算当前武将战力
export function calculateCE(heroInfo: { hid: number, lv: number }) {
let { hid, lv } = heroInfo;
// 假设所有属性和等级的关系是简单的线性关系
let dicHero = getGamedata('dic_zyz_hero');
let curDicHero = dicHero.find(cur => cur.heroId == hid);
let { atk, matk, def, mdef, agi, luk, atk_up, matk_up, def_up, mdef_up, agi_up, luk_up } = curDicHero;
atk += lv * atk_up;
matk += lv * matk_up;
def += lv * def_up;
mdef += lv * mdef_up;
agi += lv * agi_up;
luk += lv * luk_up;
// 假设战力为所有属性的简单加法
let ce = atk + matk + def + mdef + agi + luk;
return ce;
}
export function getRandomByLen(arr: Array<number>): number export function getRandomByLen(arr: Array<number>): number
export function getRandomByLen(arr: Array<DicRandomEffectPool>): DicRandomEffectPool export function getRandomByLen(arr: Array<DicRandomEffectPool>): DicRandomEffectPool
@@ -405,21 +381,6 @@ export function setLocalHours(hour: number, curTime = new Date()) {
return localTime.getTime() - 8 * 60 * 60 * 1000; // 回到格林威治时间 return localTime.getTime() - 8 * 60 * 60 * 1000; // 回到格林威治时间
} }
export async function updateCe(roleId: string, hero: any) {
let { hid, ce: oldCe, historyCe } = hero;
let actor = new Actor();
actor.initHero(hero);
let ce = actor.calculateCE();
if (ce != oldCe) {
// 更新总战力&最强五人战力
await RoleModel.updateSumCe(roleId, hid, ce, oldCe);
// 更新pvp防守阵容战力
await PvpDefenseModel.updateCe(roleId, hid, ce, oldCe);
// 更新武将战力,历史最高战力
await HeroModel.updateCe(roleId, hid, ce, oldCe, historyCe);
}
}
export function ratioReward(rewardStr: string, ratio: number): string { export function ratioReward(rewardStr: string, ratio: number): string {
let rewards = decodeIdCntArrayStr(rewardStr, ratio); let rewards = decodeIdCntArrayStr(rewardStr, ratio);
let res = ''; let res = '';