全局:属性修改

This commit is contained in:
luying
2021-03-04 15:33:24 +08:00
parent d4561c2e3d
commit 0966f025cf
35 changed files with 1186 additions and 1130 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
import { HeroModel } from './../db/Hero';
import { HangUpRecordModel } from './../db/HangUpRecord';
import { ChannelService, pinus } from 'pinus';
import { pinus } from 'pinus';
import { HANG_UP_CONSTS, TOWER_TASK_CONST, REDIS_KEY } from './../consts';
import { BattleRecordModel } from './../db/BattleRecord';
import { TowerRecordModel } from './../db/TowerRecord';
+10 -12
View File
@@ -1,4 +1,4 @@
import { mergeSameGoods } from '../pubUtils/util';
import { mergeSameGoods, deepCopy } from '../pubUtils/util';
import { EquipModel } from "../db/Equip";
import { HeroModel, EPlace, HeroType } from "../db/Hero";
import { getHeroJob, getGoodById, gameData, getJewelById, getHeroEquipByClassId } from "../pubUtils/data";
@@ -77,7 +77,7 @@ export async function changeEquip(roleId: string, sid: string, equip: EquipType,
return res;
}
} else if (!!hero) {//从穿戴装备的武将上卸下装备
await takeOffEquipAndCalPlayerCe(roleId, sid, seqId, hero, id);//卸下装备并重算战力
await takeOffEquipAndCalPlayerCe(roleId, sid, hero, equip, id);//卸下装备并重算战力
}
}
/**
@@ -88,15 +88,12 @@ export async function changeEquip(roleId: string, sid: string, equip: EquipType,
* @param hero
* @param id
*/
export async function takeOffEquipAndCalPlayerCe(roleId: string, sid: string, seqId: number, hero:HeroType, id: number ) {
let index = findIndex(hero.ePlace, { id });
if (index < 0)
return;
await EquipModel.updateEquipInfo(seqId, { hid: 0 });
hero.ePlace[index].equip = null;
export async function takeOffEquipAndCalPlayerCe(roleId: string, sid: string, hero:HeroType, equip: EquipType, id: number ) {
let args = calEquipSeids(hero);
await calPlayerCeAndSave(sid, roleId, [hero], HERO_SYSTEM_TYPE.EQUIP, args);
return { seqId, hid: 0};
hero = await HeroModel.removeEquip(roleId, hero.hid, id, equip._id);
await calPlayerCeAndSave(HERO_SYSTEM_TYPE.EQUIP, sid, roleId, hero, {}, args);
return { seqId: equip.seqId, hid: 0};
}
/**
* 穿戴装备并重算战力
@@ -106,9 +103,10 @@ export async function takeOffEquipAndCalPlayerCe(roleId: string, sid: string, se
* @param equip
*/
export async function dressEquip(roleId: string, sid: string, hero:HeroType, equip: EquipType) {
hero = await HeroModel.addEquip(roleId, hero.hid, equip.ePlaceId, equip._id);
let args = calEquipSeids(hero);
await calPlayerCeAndSave(sid, roleId, [hero], HERO_SYSTEM_TYPE.EQUIP, args);
hero = await HeroModel.addEquip(roleId, hero.hid, equip.ePlaceId, equip._id);
await calPlayerCeAndSave(HERO_SYSTEM_TYPE.EQUIP, sid, roleId, hero, {}, args);
return { seqId: equip.seqId, hid: hero.hid };
}
/**
+7 -10
View File
@@ -3,9 +3,9 @@ import { ExpeditionPointModel } from '../db/ExpeditionPoint';
import Role, { RoleModel, RoleType } from '../db/Role';
import { PvpDefenseModel } from '../db/PvpDefense';
import { getWarJsons, getGamedata, getExpeditionById } from '../pubUtils/gamedata';
import { decodeStr, resResult, shouldRefresh } from '../pubUtils/util';
import { EXPEDITION_CONST, HERO_CE_RATIO, getAttrCeRatio } from '../consts';
import { getWarJsons, getGamedata } from '../pubUtils/gamedata';
import { decodeStr, shouldRefresh } from '../pubUtils/util';
import { EXPEDITION_CONST, HERO_CE_RATIO } from '../consts';
import { getAtrrNameById} from '../consts';
import { ExpeditionWarRecordModel } from '../db/ExpeditionWarRecord';
import { HeroType } from '../db/Hero';
@@ -75,7 +75,7 @@ export async function matchPlayers(roleId: string, scale: number, range: number,
let result = resultRange[index];
let {roleId, heroes, defCe } = result;
let role = <RoleType>result.role;
let { globalCeAttr } = role;
let { attr: roleAttrs } = role;
enemyObj.enemyFrom = 1;
enemyObj.enemyId = roleId;
@@ -87,9 +87,9 @@ export async function matchPlayers(roleId: string, scale: number, range: number,
let hero = heroes[heroIndex];
if(hero) {
let h = <HeroType>hero.hero;
let { star, lv, ceAttr } = h;
let { star, lv, attr: heroAttrs } = h;
let dicHero = gameData.hero.get(hero.actorId);
let newAttribute = getPlayerAttribute(ceAttr, globalCeAttr);
let newAttribute = getPlayerAttribute(heroAttrs, roleAttrs);
let heroInfo = {
actorId: hero.actorId,
actorName: dicHero.name,
@@ -127,10 +127,7 @@ export async function matchRobots(scale: number, myCe: number, robotCe: number,
const { attribute } = json;
let newAttribute = getRobotAttribute(attribute, myCe, robotCe, scale);
let ce = 0;
for(let attrName in newAttribute) {
ce += newAttribute[attrName] * getAttrCeRatio(attrName)||0;
}
let ce = newAttribute.calCe();
enemyObj.enemies.push({...json, attribute: newAttribute, lv});
allCe += ce;
}
+8 -7
View File
@@ -7,22 +7,23 @@ import { STATUS } from '../consts/statusCode';
import { resResult, reduceCe } from '../pubUtils/util';
import { calPlayerCeAndSave as pubCalPlayerCeAndSave, reCalAllHeroCe } from '../pubUtils/playerCe';
import { HeroType } from '../db/Hero';
import Hero, { HeroType, HeroUpdate } from '../db/Hero';
import { defaultHeroes } from './pvpService';
import { RoleUpdate } from '../db/Role';
//修改并下发战力
export async function calPlayerCeAndSave(sid: string, roleId: string, heros: Array<HeroType>, type?: number, args?: Array<number>) {
let {role, pushHeros, topLineupCe} = await pubCalPlayerCeAndSave(roleId, heros, type, args);
export async function calPlayerCeAndSave(type: number, sid: string, roleId: string, originHero: HeroType, update: HeroUpdate, args?: Array<number>) {
let {role, pushHeros, topLineupCe, hero} = await pubCalPlayerCeAndSave(type, roleId, originHero, update, null, args);
//下发战力
let uids = [{ uid: roleId, sid }];
pinus.app.get('channelService').pushMessageByUids('onPlayerCeUpdate', resResult(STATUS.SUCCESS, { ce: reduceCe(role.ce) , heros: pushHeros, topLineupCe: reduceCe(topLineupCe) }), uids);
defaultHeroes(role);
return heros;
return hero;
}
export async function calAllHeroCe(sid: string, roleId: string, type?:number, args?:Array<number>) {
let {ce, pushHeros, topLineupCe }= await reCalAllHeroCe(roleId, type, args);
export async function calAllHeroCe(type:number, sid: string, roleId: string, update: RoleUpdate, args?:Array<number>) {
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);
return {ce: reduceCe(ce)};
return role;
}
+11 -22
View File
@@ -5,7 +5,7 @@ import { PVP_HERO_POS, ROBOT_NAME, REDIS_KEY, PVP_CONST, HERO_CE_RATIO } from '.
import { setPvpDefResult } from '../services/timeTaskService';
import { dicPvpOpponent, DicPvpOpponent } from "../pubUtils/dictionary/DicPvpOpponent";
import { getRandomIndexByLen, genCode, getRandomByLen, shouldRefresh, reduceCe, getChineseName } from '../pubUtils/util';
import { oppPlayersInter, pvpEndParamInter, Attributes } from '../pubUtils/interface';
import { oppPlayersInter, pvpEndParamInter } from '../pubUtils/interface';
import { RankParam } from '../domain/rank';
import { gameData, getPLvByScore } from "../pubUtils/data";
import { PVP } from '../pubUtils/dicParam';
@@ -14,7 +14,7 @@ import { setRank, getMyRank, getFieldByRank } from './redisService';
import { nowSeconds, checkTodayTime } from '../pubUtils/timeUtil';
import { HeroesRecord } from '../db/PvpRecord';
import { HeroModel, HeroType } from '../db/Hero';
import { CeAttrNumber, CeAttr, CeAttrRole, MainAttrNumber } from '../domain/roleField/attribute';
import { MainAttrNumber, Attribute, CeAttrData, CeAttrDataRole } from '../domain/roleField/attribute';
import { PvpEnemies, PvpHeroInfo, PvpOtherHeroes } from '../domain/dbGeneral';
import { DicWarJson } from '../pubUtils/dictionary/DicWarJson';
import { findWhere, findIndex } from 'underscore';
@@ -213,7 +213,7 @@ async function generPlayerOppHis(pvpdefense: PvpDefenseType, mapWarJson: DicWarJ
let heroInfo = new PvpHeroInfo();
heroInfo.setHeroInfo(dbHero);
heroInfo.setOutIndex(h.order);
let attribute = getPlayerAttribute(dbHero.ceAttr, role.globalCeAttr);
let attribute = getPlayerAttribute(dbHero.attr, role.attr);
heroInfo.setAttribute(attribute);
let enemy = new PvpEnemies(warJson, heroInfo, hs?hs.score: 0);
heroes.push(enemy);
@@ -491,14 +491,10 @@ export async function findPvpDefAllByRoleId(roleId: string) {
* @param enemyCe 出兵表对手战力
* @param ratio 系数
*/
export function getRobotAttribute(attribute: Attributes, ce: number, enemyCe: number, ratio: number) {
export function getRobotAttribute(attribute: {id: number, val: number}[], ce: number, enemyCe: number, ratio: number) {
let newAttribute = new CeAttrNumber();
for(let attrName in newAttribute) {
newAttribute[attrName] = Math.floor(attribute[attrName] * ce / enemyCe * ratio);
}
newAttribute['speed'] = 0;
newAttribute['ap'] = 0;
let newAttribute = new Attribute();
newAttribute.setByWarJson(attribute, ce / enemyCe * ratio)
return newAttribute;
}
@@ -508,16 +504,9 @@ export function getRobotAttribute(attribute: Attributes, ce: number, enemyCe: nu
* @param ceAttr hero表的ceAttr
* @param globalCeAttr role表中的globalCeAttr
*/
export function getPlayerAttribute(ceAttr: CeAttr, globalCeAttr: CeAttrRole) {
let newAttribute = new CeAttrNumber();
for(let attrName in newAttribute) {
let { base, ratioUp, fixUp, equipUp } = ceAttr[attrName];
let { ratioUp: ratioUp2, fixUp: fixUp2 } = globalCeAttr[attrName];
let result = base * ( HERO_CE_RATIO + ratioUp + ratioUp2) + (fixUp + fixUp2 + equipUp) * HERO_CE_RATIO;
newAttribute[attrName] += reduceCe(result);
}
newAttribute['speed'] = 0;
newAttribute['ap'] = 0;
export function getPlayerAttribute(heroAttrs: CeAttrData[], roleAttrs: CeAttrDataRole[]) {
let newAttribute = new Attribute();
newAttribute.setByDbData(roleAttrs, heroAttrs);
return newAttribute;
}
@@ -527,8 +516,8 @@ export function getPlayerAttribute(ceAttr: CeAttr, globalCeAttr: CeAttrRole) {
* @param ceAttr
* @param globalCeAttr
*/
export function getPlayerMainAttribute(ceAttr: CeAttr, globalCeAttr: CeAttrRole) {
let attribute = getPlayerAttribute(ceAttr, globalCeAttr);
export function getPlayerMainAttribute(heroAttrs: CeAttrData[], roleAttrs: CeAttrDataRole[]) {
let attribute = getPlayerAttribute(heroAttrs, roleAttrs);
let mainAttributes = new MainAttrNumber(attribute);
return mainAttributes;
+1 -1
View File
@@ -156,7 +156,7 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
}
}
if (!!skinInfos.length) {
calAllHeroCe(sid, roleId, HERO_SYSTEM_TYPE.ADD_SKIN, addSkinIds)
calAllHeroCe(HERO_SYSTEM_TYPE.ADD_SKIN, sid, roleId, {}, addSkinIds);
pinus.app.get('channelService').pushMessageByUids('onHeroSkinChange', resResult(STATUS.SUCCESS, {skinInfos}), uids);
}
return showItems;
+32 -26
View File
@@ -3,44 +3,47 @@ import { Channel } from 'pinus';
import { getRandNum, getRandomArr } from '../pubUtils/util';
import { TERAPH_RANDOM } from "../consts/consts";
import { indexOf } from 'underscore';
import { DicTeraph } from '../pubUtils/dictionary/DicTeraph';
import { Teraph } from '../db/Role';
const TERAPH_STRENGTHEN = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
/**
* 计算强化次数和消耗
* @param count 强化次数
* @param attrNames 可以强化的属性名字
* @param attrs 可以强化的属性名字
* @param teraphInfo 字典表对应的神像信息
* @param teraph
* @param teraph 数据库内单个神像信息
*/
export function checkTeraphMaterialEnough(count: number, attrNames:Array<any>, teraphInfo: any, teraph: any) {
let res = {};
export function checkTeraphMaterialEnough(count: number, attrs:number[], teraphInfo: DicTeraph, teraph: Teraph) {
let consumes = [];
let times = 0;
if (count < 10) {
for (let i = 0; i < count; i++) {
if (!attrNames.length) {
if (!attrs.length) {
break;
}
let num = getRandNum(TERAPH_RANDOM.MIN, TERAPH_RANDOM.MAX);
let arr = getRandomArr(attrNames, num)
let num = getRandNum(TERAPH_RANDOM.MIN, TERAPH_RANDOM.MAX); // 强化时随机增加 2-4 属性
let arr: number[] = getRandomArr(attrs, num); // 随机出的属性id
let critical = getRandNum(0, 100);//属性暴击率
let criEffect = 1;
let criEffect = 1; // 暴击效果
if (critical <= teraphInfo.criRate)
criEffect = teraphInfo.criEffect;
for (let attrName of arr) {
let attrNameMax = attrName+'Max';
res[attrName] = teraphInfo[attrName] * criEffect;
if (teraph[attrName] + res[attrName] > teraphInfo[attrNameMax]) {
res[attrName] = teraphInfo[attrNameMax] - teraph[attrName];
let attrIndex = indexOf(attrNames, attrName);
attrNames.splice(attrIndex, 1);
for (let attrId of arr) {
let val = teraph.attr.get(attrId); // 已有的强化值
val += teraphInfo.mainAttrUp.get(attrId) * criEffect;
let max = teraphInfo.mainAttrMax.get(attrId);
if(val > max) {
val = max;
let attrIndex = attrs.indexOf(attrId);
attrs.splice(attrIndex, 1);
}
teraph.attr.set(attrId, val);
}
times++;
}
} else if (count == 10){
let criticalArrTimes = getRandomArr(TERAPH_STRENGTHEN, 2);//10次中随机2次发生暴击
for (let item of TERAPH_STRENGTHEN) {
if (!attrNames.length) {
if (!attrs.length) {
break;
}
let criEffect = 1;
@@ -49,24 +52,27 @@ export function checkTeraphMaterialEnough(count: number, attrNames:Array<any>, t
criEffect = teraphInfo.criEffect;//本次是暴击 item 在 criticalArrTimes 中
}
let num = getRandNum(TERAPH_RANDOM.MIN, TERAPH_RANDOM.MAX);
let arr = getRandomArr(attrNames, num);
for (let attrName of arr) {
res[attrName] = (res[attrName]||0) + teraphInfo[attrName] * criEffect;
let attrNameMax = attrName+'Max';
if (teraph[attrName] + res[attrName] > teraphInfo[attrNameMax]) {
res[attrName] = teraphInfo[attrNameMax] - teraph[attrName];
let attrIndex = indexOf(attrNames, attrName);
attrNames.splice(attrIndex, 1);
let arr: number[] = getRandomArr(attrs, num);
for (let attrId of arr) {
let val = teraph.attr.get(attrId); // 已有的强化值
val += teraphInfo.mainAttrUp.get(attrId) * criEffect;
let max = teraphInfo.mainAttrMax.get(attrId);
if(val > max) {
val = max;
let attrIndex = attrs.indexOf(attrId);
attrs.splice(attrIndex, 1);
}
teraph.attr.set(attrId, val);
}
times++;
}
}
//计算消耗
for (let {id, count} of teraphInfo.upMaterial) {
consumes.push({ id, count: count*times});
consumes.push({ id, count: count * times});
}
return {attr: res, consumes};
return { consumes};
}
/**
*