Merge branch 'master' of gitlab.trgame.cn:zyztech/zyz_server
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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) { // 可以升星
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user