属性: 修改好感度添加方法

This commit is contained in:
luying
2021-02-24 11:36:28 +08:00
parent dd995e67eb
commit b14f751d92
9 changed files with 9754 additions and 111 deletions

View File

@@ -7,7 +7,7 @@ import {HeroModel} from '../../../db/Hero';
import {CURRENCY_BY_TYPE, CURRENCY_TYPE, CONSUME_TYPE, HERO_GROW_MAX, HERO_SYSTEM_TYPE, ITID, ABI_STAGE, HERO_CE_RATIO} from '../../../consts';
import { RoleModel } from '../../../db/Role';
import { ItemModel } from '../../../db/Item';
import { gameData, getHeroExpByLv, getHeroStarByQuality, getHeroWakeByQuality, getHeroLvByExp, getMaxGradeByjobClass, getJobByGradeAndClass, getFriendShipById } from '../../../pubUtils/data';
import { gameData, getHeroExpByLv, getHeroStarByQuality, getHeroWakeByQuality, getHeroLvByExp, getMaxGradeByjobClass, getJobByGradeAndClass, getFriendShipById, getFavourLvByExp } from '../../../pubUtils/data';
import { RewardInter } from '../../../pubUtils/interface';
import { getDropItems } from '../../../consts/constModules/itemConst'
export default function(app: Application) {
@@ -393,46 +393,70 @@ export class HeroHandler {
}
//赠送(包括一键赠送)
async heroGiveFavor(msg: {hid:number, items:Array<{id : number,count : number}>}, session: BackendSession) {
async heroGiveFavor(msg: {hid:number, type: number}, session: BackendSession) {
let roleId: string = session.get('roleId');
let sid: string = session.get('sid');
let { hid, items } = msg;
let { hid, type } = msg;
let addLv = 0;
if(type == 1) {
addLv = 1;
} else if (type == 5) {
addLv = 5;
} else {
return resResult(STATUS.WRONG_PARMS);
}
let hero = await HeroModel.findByHidAndRole(hid, roleId);
let lastLv = hero.favourLv;
if (!hero)
return resResult(STATUS.HERO_NOT_FIND);
let friendShipLevels = gameData.friendShipLevel;
if (friendShipLevels[friendShipLevels.length - 1].level <= hero.favourLv)
if (!hero) return resResult(STATUS.ROLE_HERO_NOT_EXISTS);
let { favourLv: oldLv, favour: oldExp } = hero;
let maxLv = gameData.maxFriendShipLv; // 好感度最大等级
if ( maxLv <= oldLv)
return resResult(STATUS.HERO_FAVOUR_LEVEL_REACH_MAXT);
//计算消耗物品转化的经验
let exp:number = 0;
for (let item of items) {
let itemInfo = gameData.goods.get(item.id);
if (!itemInfo)
return resResult(STATUS.DIC_DATA_NOT_FOUND)
let dicItid = ITID.get(itemInfo.itid);
if (dicItid.type == CONSUME_TYPE.FAVOUR) {
exp += itemInfo.value;
// 计算武将可以升的级数
if(oldLv + addLv > maxLv ) addLv = maxLv - oldLv;
let nextObj = gameData.friendShipLevelMap.get(oldLv + addLv - 1);
if(!nextObj) return resResult(STATUS.HERO_FAVOUR_LEVEL_REACH_MAXT);
let nextExp = nextObj.expSum;
let needExp = nextExp - oldExp;
let newExp = oldExp;
// 计算得材料可转换的经验
let originalConsumes = await ItemModel.findByRoleAndType(roleId, CONSUME_TYPE.FAVOUR);
let material = new Array<RewardInter>();
for(let {id, count} of originalConsumes) {
let dicGoods = gameData.goods.get(id);
if(!dicGoods) return resResult(STATUS.DIC_DATA_NOT_FOUND);
let _count = Math.ceil(needExp/dicGoods.value);
if(_count < count) {
material.push({id, count: _count});
newExp += dicGoods.value * _count;
break;
} else {
return resResult(STATUS.WRONG_PARMS);
material.push({id, count});
newExp += dicGoods.value * count;
}
}
hero.favour += exp;
for (let friendShipLevel of friendShipLevels) {
if (friendShipLevel.level < hero.favourLv)
continue;
if (friendShipLevel.exp > hero.favour)
break;
hero.favour -= friendShipLevel.exp;
hero.favourLv++;
if (newExp == oldExp) {
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
}
let result = await handleCost(roleId, sid, items);
let newLv = getFavourLvByExp(newExp);
hero.favour = newExp;
hero.favourLv = newLv;
let result = await handleCost(roleId, sid, material);
if(!result) {
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
}
//重算战力并下发
if (lastLv != hero.favourLv) {
await calPlayerCeAndSave(sid, roleId, [hero], HERO_SYSTEM_TYPE.FAVOUR, [lastLv]);
if (oldLv != hero.favourLv) {
await calPlayerCeAndSave(sid, roleId, [hero], HERO_SYSTEM_TYPE.FAVOUR, [oldLv]);
} else {
await HeroModel.updateHeroInfo(roleId, hero.hid, hero);
}

View File

@@ -4,7 +4,7 @@ import { HeroModel } from '../../../db/Hero';
import { resResult, decodeIdCntArrayStr, parseGoodStr, reduceCe } from '../../../pubUtils/util';
import {Application, BackendSession} from 'pinus';
import { handleCost } from '../../../services/rewardService';
import { getTitle, getTeraph, gameData, getScollByStar } from '../../../pubUtils/data';
import { getTitle, getTeraph, gameData, getScollByStar, getFriendLvByExp } from '../../../pubUtils/data';
import { SCHOOL, SCROLL } from '../../../pubUtils/dicParam';
import { getTeraphAttr, getAtrrNameById } from '../../../consts/constModules/abilityConst'
import { findIndex } from 'underscore';
@@ -119,6 +119,7 @@ export class RoleHandler {
}
if (!attrs.length)
return resResult(STATUS.ROLE_TERAPH_NOT_STRENGTHEN);
// 随机神像中的一条属性并检查道具是否足够
let {attr, consumes} = checkMaterialEnough(count, attrs, teraphInfo, teraph);
for (let key in attr) {
teraph[key] += attr[key];
@@ -311,19 +312,11 @@ export class RoleHandler {
update.scrollColorStar = 0;
// 获取一定好感度
let friendShipLevels = gameData.friendShipLevel;
if (friendShipLevels[friendShipLevels.length - 1].level > favourLv) {
let maxLv = gameData.maxFriendShipLv;
if (maxLv > favourLv) {
update.favour += SCROLL.SCROLL_ACTIVE_FAVOUR;
for (let friendShipLevel of friendShipLevels) {
if (friendShipLevel.level < update.favourLv)
continue;
if (friendShipLevel.exp > update.favour)
break;
update.favour -= friendShipLevel.exp;
update.favourLv++;
}
update.favourLv = getFriendLvByExp(update.favour);
}
} else {
if (star > scrollStar) { // 可以升星

View File

@@ -132,12 +132,8 @@ module.exports = {
"required uInt32 shipId": 1
},
"role.heroHandler.heroGiveFavor": {
"message Item": {
"required uInt32 id": 1,
"required uInt32 count": 2
},
"required uInt32 hid": 1,
"repeated Item items": 2
"required uInt32 type": 2,
},
"role.heroHandler.heroWearSkin": {
"required uInt32 id": 1

View File

@@ -129,9 +129,7 @@ const BASE_ATTR = {
'hp' : 1 ,
'atk' : 2,
'def' : 3,
'mdef' : 4,
'agi' : 5,
'luk' : 6
'mdef' : 4
}
export const ABI_TYPE_TO_STAGE = new Map<number, number | ((jobType: number) => number)>([
[ABI_STAGE.HP, ABI_TYPE.ABI_HP],

View File

@@ -21,7 +21,7 @@ import { dicXunbao } from "./dictionary/DicXunbao";
import { SPECIAL_ATTR } from "../consts/consts";
import { dicFashions } from "./dictionary/DicFashions";
import { friendShips, friendShipHidAandIds } from "./dictionary/DicFriendShip";
import { dicFriendShipLevel, dicFriendShipLevelMap } from "./dictionary/DicFriendShipLevel";
import { maxFriendShipLv, dicFriendShipLevelMap } from "./dictionary/DicFriendShipLevel";
import { dicHeroQualityUp } from "./dictionary/DicHeroQualityUp";
import { dicHeroStar } from "./dictionary/DicHeroStar";
import { dicHeroWake } from "./dictionary/DicHeroWake";
@@ -93,7 +93,7 @@ export const gameData = {
fashion: dicFashions,
friendShips: friendShips,
friendShipHidAandIds: friendShipHidAandIds,
friendShipLevel: dicFriendShipLevel,
maxFriendShipLv: maxFriendShipLv,
friendShipLevelMap: dicFriendShipLevelMap,
randomEffectPool: dicRandomEffectPool,
strengthenCost: dicStrengthenCost,
@@ -189,6 +189,20 @@ export function getHeroExpByLv(lv: number) {
return gameData.charexp.get(lv);
}
/**
* 根据武将当前好感获得好感等级
* @param exp 累积经验
*/
export function getFavourLvByExp(exp: number) {
let curLv = 0;
let entries = gameData.friendShipLevelMap.entries();
for (let [lv, { expSum: sum }] of entries) {
curLv = lv;
if(exp < sum) break;
}
return curLv;
}
export function getBossHpByWarId(warId: number) {
let bossHpSum = gameData.btlBossHpSum.get(warId) || 0;

View File

@@ -9,17 +9,19 @@ export interface DicFriendShipLevel {
readonly exp: number;
// 加成百分比
readonly add: number;
// 到这一级的总经验
readonly expSum: number;
}
const str = readJsonFile(FILENAME.DIC_FRIEND_SHIP_LEVEL);
let arr = JSON.parse(str);
export const dicFriendShipLevel = new Array<DicFriendShipLevel>();
export let maxFriendShipLv = 0;
export const dicFriendShipLevelMap = new Map<number, DicFriendShipLevel>();
let expSum = 0;
arr.forEach(o => {
dicFriendShipLevel.push(o);
expSum += o.exp;
o.expSum = expSum;
dicFriendShipLevelMap.set(o.level, o);
});
dicFriendShipLevel.sort(function(a, b) {
return a.level - b.level;
if(o.level > maxFriendShipLv) maxFriendShipLv = o.level;
});

View File

@@ -127,26 +127,26 @@ export async function calPlayerCeAndSave(roleId: string, heros: Array<HeroType>,
export async function calculateTopFive(role: RoleType, hid: number, ce: number, heroId: string) {
let topFive = role?.topFive || new Array();
topFive.sort((a, b) => { return b.ce - a.ce }); // 0-5,最大-最小
topFive.sort((a, b) => { return b.ce - a.ce }); // 0-6,最大-最小
let index = topFive.findIndex(cur => cur.hid == hid);
if(index != -1 && !heroId) {
let heroes = await HeroModel.getTopHero(role.roleId, 5);
let heroes = await HeroModel.getTopHero(role.roleId, 6);
topFive = heroes.map(cur => { return { hid: cur.hid, ce: cur.ce, hero: cur._id } });
} else {
if (index == -1) { // 不在最强列表
if (topFive.length < 5) { // 不满5
if (topFive.length < 6) { // 不满6
topFive.push({ hid, ce, hero: heroId });
} else if (topFive.length == 5) {
if (ce > topFive[topFive.length - 1].ce) { // 跻身最强5
} else if (topFive.length == 6) {
if (ce > topFive[topFive.length - 1].ce) { // 跻身最强6
topFive.pop();
topFive.push({ hid, ce, hero: heroId });
}
} else {
topFive.splice(5, topFive.length - 5);
topFive.splice(6, topFive.length - 6);
}
} else { // 原来就是最强5
} else { // 原来就是最强6
if (ce < topFive[topFive.length - 1].ce) { // 滑出最强
let heroes = await HeroModel.getTopHero(role.roleId, 5);
let heroes = await HeroModel.getTopHero(role.roleId, 6);
topFive = heroes.map(cur => { return { hid: cur.hid, ce: cur.ce, hero: cur._id } });
} else {
topFive[index].ce = ce;

File diff suppressed because it is too large Load Diff

View File

@@ -11,7 +11,7 @@
"suitLevel": "1&20",
"warId": 0,
"weight": 1,
"movePointArray": "26&27&28&29",
"movePointArray": "81&83&85&87",
"startDialogue": "1&4",
"winDialogue": "&",
"loseDialogue": "&"
@@ -28,7 +28,7 @@
"suitLevel": "1&20",
"warId": 0,
"weight": 1,
"movePointArray": "26&27&28&29",
"movePointArray": "81&83&85&87",
"startDialogue": "2&3",
"winDialogue": "&",
"loseDialogue": "&"
@@ -45,7 +45,7 @@
"suitLevel": "1&20",
"warId": 0,
"weight": 1,
"movePointArray": "26&27&28&29",
"movePointArray": "81&83&85&87",
"startDialogue": "1&4",
"winDialogue": "&",
"loseDialogue": "&"
@@ -62,7 +62,7 @@
"suitLevel": "1&20",
"warId": 0,
"weight": 1,
"movePointArray": "26&27&28&29",
"movePointArray": "81&83&85&87",
"startDialogue": "16&17",
"winDialogue": "18&",
"loseDialogue": "19&"
@@ -79,7 +79,7 @@
"suitLevel": "1&20",
"warId": 0,
"weight": 1,
"movePointArray": "26&27&28&29",
"movePointArray": "81&83&85&87",
"startDialogue": "16&17",
"winDialogue": "18&",
"loseDialogue": "19&"
@@ -96,7 +96,7 @@
"suitLevel": "1&20",
"warId": 0,
"weight": 1,
"movePointArray": "26&27&28&29",
"movePointArray": "81&83&85&87",
"startDialogue": "20&21&22&23&24",
"winDialogue": "25&",
"loseDialogue": "26&"
@@ -113,7 +113,7 @@
"suitLevel": "1&20",
"warId": 2001,
"weight": 1,
"movePointArray": "26&27&28&29",
"movePointArray": "81&83&85&87",
"startDialogue": "5&6",
"winDialogue": "3&",
"loseDialogue": "7&"
@@ -130,7 +130,7 @@
"suitLevel": "1&20",
"warId": 2002,
"weight": 1,
"movePointArray": "26&27&28&29",
"movePointArray": "81&83&85&87",
"startDialogue": "27&28&29&30&31",
"winDialogue": "32&33",
"loseDialogue": "34&"
@@ -147,7 +147,7 @@
"suitLevel": "1&20",
"warId": 2003,
"weight": 1,
"movePointArray": "26&27&28&29",
"movePointArray": "81&83&85&87",
"startDialogue": "8&9&10&11",
"winDialogue": "12&13",
"loseDialogue": "14&15"
@@ -164,7 +164,7 @@
"suitLevel": "21&40",
"warId": 0,
"weight": 1,
"movePointArray": "26&27&28&29",
"movePointArray": "81&83&85&87",
"startDialogue": "1&4",
"winDialogue": "&",
"loseDialogue": "&"
@@ -181,7 +181,7 @@
"suitLevel": "21&40",
"warId": 0,
"weight": 1,
"movePointArray": "26&27&28&29",
"movePointArray": "81&83&85&87",
"startDialogue": "2&3",
"winDialogue": "&",
"loseDialogue": "&"
@@ -198,7 +198,7 @@
"suitLevel": "21&40",
"warId": 0,
"weight": 1,
"movePointArray": "26&27&28&29",
"movePointArray": "81&83&85&87",
"startDialogue": "1&4",
"winDialogue": "&",
"loseDialogue": "&"
@@ -215,7 +215,7 @@
"suitLevel": "21&40",
"warId": 0,
"weight": 1,
"movePointArray": "26&27&28&29",
"movePointArray": "81&83&85&87",
"startDialogue": "16&17",
"winDialogue": "18&",
"loseDialogue": "19&"
@@ -232,7 +232,7 @@
"suitLevel": "21&40",
"warId": 0,
"weight": 1,
"movePointArray": "26&27&28&29",
"movePointArray": "81&83&85&87",
"startDialogue": "16&17",
"winDialogue": "18&",
"loseDialogue": "19&"
@@ -249,7 +249,7 @@
"suitLevel": "21&40",
"warId": 0,
"weight": 1,
"movePointArray": "26&27&28&29",
"movePointArray": "81&83&85&87",
"startDialogue": "20&21&22&23&24",
"winDialogue": "25&",
"loseDialogue": "26&"
@@ -266,7 +266,7 @@
"suitLevel": "21&40",
"warId": 2001,
"weight": 1,
"movePointArray": "26&27&28&29",
"movePointArray": "81&83&85&87",
"startDialogue": "5&6",
"winDialogue": "3&",
"loseDialogue": "7&"
@@ -283,7 +283,7 @@
"suitLevel": "21&40",
"warId": 2002,
"weight": 1,
"movePointArray": "26&27&28&29",
"movePointArray": "81&83&85&87",
"startDialogue": "27&28&29&30&31",
"winDialogue": "32&33",
"loseDialogue": "34&"
@@ -300,7 +300,7 @@
"suitLevel": "21&40",
"warId": 2003,
"weight": 1,
"movePointArray": "26&27&28&29",
"movePointArray": "81&83&85&87",
"startDialogue": "8&9&10&11",
"winDialogue": "12&13",
"loseDialogue": "14&15"
@@ -317,7 +317,7 @@
"suitLevel": "41&100",
"warId": 0,
"weight": 1,
"movePointArray": "26&27&28&29",
"movePointArray": "81&83&85&87",
"startDialogue": "1&4",
"winDialogue": "&",
"loseDialogue": "&"
@@ -334,7 +334,7 @@
"suitLevel": "41&100",
"warId": 0,
"weight": 1,
"movePointArray": "26&27&28&29",
"movePointArray": "81&83&85&87",
"startDialogue": "2&3",
"winDialogue": "&",
"loseDialogue": "&"
@@ -351,7 +351,7 @@
"suitLevel": "41&100",
"warId": 0,
"weight": 1,
"movePointArray": "26&27&28&29",
"movePointArray": "81&83&85&87",
"startDialogue": "1&4",
"winDialogue": "&",
"loseDialogue": "&"
@@ -368,7 +368,7 @@
"suitLevel": "41&100",
"warId": 0,
"weight": 1,
"movePointArray": "26&27&28&29",
"movePointArray": "81&83&85&87",
"startDialogue": "16&17",
"winDialogue": "18&",
"loseDialogue": "19&"
@@ -385,7 +385,7 @@
"suitLevel": "41&100",
"warId": 0,
"weight": 1,
"movePointArray": "26&27&28&29",
"movePointArray": "81&83&85&87",
"startDialogue": "16&17",
"winDialogue": "18&",
"loseDialogue": "19&"
@@ -402,7 +402,7 @@
"suitLevel": "41&100",
"warId": 0,
"weight": 1,
"movePointArray": "26&27&28&29",
"movePointArray": "81&83&85&87",
"startDialogue": "20&21&22&23&24",
"winDialogue": "25&",
"loseDialogue": "26&"
@@ -419,7 +419,7 @@
"suitLevel": "41&100",
"warId": 2001,
"weight": 1,
"movePointArray": "26&27&28&29",
"movePointArray": "81&83&85&87",
"startDialogue": "5&6",
"winDialogue": "3&",
"loseDialogue": "7&"
@@ -436,7 +436,7 @@
"suitLevel": "41&100",
"warId": 2002,
"weight": 1,
"movePointArray": "26&27&28&29",
"movePointArray": "81&83&85&87",
"startDialogue": "27&28&29&30&31",
"winDialogue": "32&33",
"loseDialogue": "34&"
@@ -453,7 +453,7 @@
"suitLevel": "41&100",
"warId": 2003,
"weight": 1,
"movePointArray": "26&27&28&29",
"movePointArray": "81&83&85&87",
"startDialogue": "8&9&10&11",
"winDialogue": "12&13",
"loseDialogue": "14&15"
@@ -470,7 +470,7 @@
"suitLevel": "61&100",
"warId": 0,
"weight": 1,
"movePointArray": "26&27&28&29",
"movePointArray": "81&83&85&87",
"startDialogue": "1&4",
"winDialogue": "&",
"loseDialogue": "&"
@@ -487,7 +487,7 @@
"suitLevel": "61&100",
"warId": 0,
"weight": 1,
"movePointArray": "26&27&28&29",
"movePointArray": "81&83&85&87",
"startDialogue": "2&3",
"winDialogue": "&",
"loseDialogue": "&"
@@ -504,7 +504,7 @@
"suitLevel": "61&100",
"warId": 0,
"weight": 1,
"movePointArray": "26&27&28&29",
"movePointArray": "81&83&85&87",
"startDialogue": "1&4",
"winDialogue": "&",
"loseDialogue": "&"
@@ -521,7 +521,7 @@
"suitLevel": "61&100",
"warId": 0,
"weight": 1,
"movePointArray": "26&27&28&29",
"movePointArray": "81&83&85&87",
"startDialogue": "16&17",
"winDialogue": "18&",
"loseDialogue": "19&"
@@ -538,7 +538,7 @@
"suitLevel": "61&100",
"warId": 0,
"weight": 1,
"movePointArray": "26&27&28&29",
"movePointArray": "81&83&85&87",
"startDialogue": "16&17",
"winDialogue": "18&",
"loseDialogue": "19&"
@@ -555,7 +555,7 @@
"suitLevel": "61&100",
"warId": 0,
"weight": 1,
"movePointArray": "26&27&28&29",
"movePointArray": "81&83&85&87",
"startDialogue": "20&21&22&23&24",
"winDialogue": "25&",
"loseDialogue": "26&"
@@ -572,7 +572,7 @@
"suitLevel": "61&100",
"warId": 2001,
"weight": 1,
"movePointArray": "26&27&28&29",
"movePointArray": "81&83&85&87",
"startDialogue": "5&6",
"winDialogue": "3&",
"loseDialogue": "7&"
@@ -589,7 +589,7 @@
"suitLevel": "61&100",
"warId": 2002,
"weight": 1,
"movePointArray": "26&27&28&29",
"movePointArray": "81&83&85&87",
"startDialogue": "27&28&29&30&31",
"winDialogue": "32&33",
"loseDialogue": "34&"
@@ -606,7 +606,7 @@
"suitLevel": "61&100",
"warId": 2003,
"weight": 1,
"movePointArray": "26&27&28&29",
"movePointArray": "81&83&85&87",
"startDialogue": "8&9&10&11",
"winDialogue": "12&13",
"loseDialogue": "14&15"