This commit is contained in:
mamengke01
2020-12-25 14:15:03 +08:00
parent 0c5cb1daac
commit 04fa4e79cf
14 changed files with 304 additions and 27 deletions

View File

@@ -13,6 +13,7 @@ import { calPlayerCeAndSave } from "../../../services/playerCeService";
import { getHeroJob, getGoodById, gameData, getJewelById, getHeroEquipByClassId } from "../../../pubUtils/data";
import { EQUIP } from "../../../pubUtils/dicParam";
import { ITID, SPEICAL_ITEM, RANDOM_SE_COUNT } from "../../../consts/constModules/itemConst";
import { changeEquip } from "../../../services/equipService";
const _ = require('underscore');
@@ -426,8 +427,8 @@ export class EquipHandler {
if (!hero)
return resResult(STATUS.HERO_NOT_FIND);
if (type == 1) {
if (!!equip.hid)
return resResult(STATUS.EQUIP_IS_EQUIPED);
if (equip.hid == hid)
return resResult(STATUS.WRONG_PARMS);
if (goodInfo.lvLimited > hero.lv)
return resResult(STATUS.EQUIP_LEVEL_LIMIT);
let { jobid } = gameData.hero.get(hid);
@@ -439,12 +440,11 @@ export class EquipHandler {
if (index < 0)
return resResult(STATUS.WRONG_PARMS);
let objectId = <string>hero.ePlace[index].equip;
if (!!objectId) {
let {seqId, ePlaceId} = await EquipModel.updateEquipInfobyObjectId(objectId, { hid: 0, ePlaceId: 0 });
curEquips.push({ seqId, hid, ePlaceId });
}
await HeroModel.addEquip(roleId, hid, id, equip._id);
await calPlayerCeAndSave(sid, roleId, [hero], HERO_SYSTEM_TYPE.EQUIP, []);
let curEquip = await changeEquip(roleId, sid, objectId, equip.hid, id, eid);
if (!!curEquip)
curEquips.push(curEquip);
hero = await HeroModel.addEquip(roleId, hid, id, equip._id);
await calPlayerCeAndSave(sid, roleId, [hero]);
curEquips.push({ seqId: eid, hid, ePlaceId:id});
} else if (type == 2) {
if (!equip.hid)
@@ -453,9 +453,8 @@ export class EquipHandler {
if (index < 0)
return resResult(STATUS.WRONG_PARMS);
hero.ePlace[index].equip = null;
//await HeroModel.updateHeroInfo(roleId, hid, { ePlace: hero.ePlace });
let {seqId, ePlaceId} = await EquipModel.updateEquipInfo(eid, { hid: 0, ePlaceId: 0 });
await calPlayerCeAndSave(sid, roleId, [hero], HERO_SYSTEM_TYPE.EQUIP, []);
await calPlayerCeAndSave(sid, roleId, [hero]);
curEquips.push({ seqId, hid, ePlaceId });
}
return resResult(STATUS.SUCCESS, { curEquips: curEquips });

View File

@@ -6,8 +6,12 @@ import { EquipModel } from '../../../db/Equip';
import { calculateCE, resResult } from '../../../pubUtils/util';
import {Application, BackendSession, createTcpMailBox} from 'pinus';
import { COUNTER } from '../../../consts';
import { handleCost } from '../../../services/rewardService'
import { getTitle } from '../../../pubUtils/data'
import { handleCost } from '../../../services/rewardService';
import { getTitle, getTeraph } from '../../../pubUtils/data';
import { SSL_OP_SSLEAY_080_CLIENT_DH_BUG } from 'constants';
import { getTeraphAttr } from '../../../consts/constModules/abilityConst'
const _ = require('underscore');
export default function(app: Application) {
return new RoleHandler(app);
}
@@ -75,12 +79,10 @@ export class RoleHandler {
let roleId = session.get('roleId');
let role = await RoleModel.findByRoleId(roleId);
let sid: string = session.get('sid');
let title = ++role.title;
let titleInfo = getTitle(role.title);
if (!titleInfo)
return resResult(STATUS.DIC_DATA_NOT_FOUND)
let title = ++role.title;
if (!getTitle(title))
return resResult(STATUS.ROLE_REACH_MAX_TITLE_LEVEL)
if (titleInfo.lvLimited > role.lv)
return resResult(STATUS.COM_BATTLE_LV_NOT_ENOUGH)
let consumes = titleInfo.material;
@@ -91,4 +93,75 @@ export class RoleHandler {
return resResult(STATUS.SUCCESS, { roleId, title });
}
//神像强化
async roleTeraphStrengthen(msg: {id: number, type: number}, session: BackendSession){
let {id, type} = msg;
let roleId = session.get('roleId');
let role = await RoleModel.findByRoleId(roleId);
let sid: string = session.get('sid');
let index = _.findIndex(role.teraphs, {id});
if (index < 0)
return resResult(STATUS.WRONG_PARMS);
let teraph = role.teraphs[index];
let teraphInfo = getTeraph(id, teraph.grade);
if (!teraphInfo)
return resResult(STATUS.DIC_DATA_NOT_FOUND)
let falg = true;
for (let attrName in getTeraphAttr()) {
if (teraph[attrName] != teraphInfo[attrName]) {
falg = false;
break;
}
}
if (!!falg)
return resResult(STATUS.ROLE_TERAPH_NOT_STRENGTHEN);
//TODO强化属性
let consumes;
if (type == 1) {
consumes = teraphInfo.upMaterial;
} else if (type == 2) {
consumes = teraphInfo.upMaterial;
} else {
return resResult(STATUS.WRONG_PARMS);
}
let result = await handleCost(roleId, sid, consumes);
if (!result)
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
await RoleModel.updateRoleInfo(roleId, { teraphs: role.teraphs });
return resResult(STATUS.SUCCESS, { roleId, teraphs: role.teraphs });
}
//神像进阶
async roleTeraphQualityUp(msg: {id: number}, session: BackendSession){
let {id} = msg;
let roleId = session.get('roleId');
let role = await RoleModel.findByRoleId(roleId);
let sid: string = session.get('sid');
let index = _.findIndex(role.teraphs, {id});
if (index < 0)
return resResult(STATUS.WRONG_PARMS);
let teraph = role.teraphs[index];
let teraphInfo = getTeraph(id, teraph.grade);
if (!teraphInfo)
return resResult(STATUS.DIC_DATA_NOT_FOUND)
for (let attrName in getTeraphAttr()) {
if (teraph[attrName] != teraphInfo[attrName])
return resResult(STATUS.ROLE_TERAPH_NOT_QUILITY);
}
teraph.grade++;
teraph.atk = 0;
teraph.agi = 0;
teraph.def = 0;
teraph.hp = 0;
teraph.luk = 0;
teraph.mdef = 0;
if (getTeraph(index, teraph.grade))
return resResult(STATUS.DIC_DATA_NOT_FOUND)
let consumes = teraphInfo.upGradeMaterial;
let result = await handleCost(roleId, sid, consumes);
if (!result)
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
await RoleModel.updateRoleInfo(roleId, { teraphs: role.teraphs });
return resResult(STATUS.SUCCESS, { roleId, teraphs: role.teraphs });
}
}

View File

@@ -1,6 +1,10 @@
import { mergeSameGoods } from '../pubUtils/util';
import { getGoodById } from '../pubUtils/gamedata';
import { getJewelById } from '../pubUtils/data';
import { EquipModel } from "../db/Equip";
import { HeroModel, EPlace } from "../db/Hero";
import { ITID } from "../consts/constModules/itemConst";
import { getHeroJob, getGoodById, gameData, getJewelById, getHeroEquipByClassId } from "../pubUtils/data";
import { calPlayerCeAndSave } from "./playerCeService";
import { HERO_SYSTEM_TYPE } from "../consts";
const _ = require('underscore');
export function checkMaterialEnough(consumes:Array<{id: number, count: number}>, jewel: number, jewelCount: number) {
@@ -33,3 +37,47 @@ export function checkMaterialEnough(consumes:Array<{id: number, count: number}>,
return false;
return needConsumes;
}
export async function changeEquip(roleId: string, sid: string, objectId: string, hid: number, id: number, seqId: number) {
let hero;
if (!!hid)
hero = await HeroModel.findByHidAndRole(hid, roleId);
if (!!objectId) {
let equip = await EquipModel.getEquipByObjectId(objectId);
if (!!hero) {
let goodInfo = getGoodById(equip.id);
let obj = ITID.get(goodInfo.itid);
let ePlaceId = obj.type;
if (goodInfo.lvLimited > hero.lv)
return takeOffEquip(objectId);
let { jobid } = gameData.hero.get(hid);
let { job_class } = getHeroJob(jobid);
let { classId } = getHeroEquipByClassId(goodInfo.itid);
if (_.indexOf(classId, job_class) < 0)
return takeOffEquip(objectId);
hero = await HeroModel.addEquip(roleId, hero.hid, ePlaceId, objectId);
// await calPlayerCeAndSave(sid, roleId, [hero], HERO_SYSTEM_TYPE.EQUIP, []);
if (!!hero) {
await calPlayerCeAndSave(sid, roleId, [hero]);
let ePlaces = <EPlace>hero.ePlace;
let ePlace= _.findWhere(ePlaces,{ id: ePlaceId });
return {seqId: ePlace.equip.seqId, hid, ePlaceId};
}
} else {
return takeOffEquip(objectId);
}
}
if (!!hero) {
let index = _.findIndex(hero.ePlace, { id });
if (index < 0)
return;
hero.ePlace[index].equip = null;
await EquipModel.updateEquipInfo(seqId, { hid: 0, ePlaceId: 0 });
await calPlayerCeAndSave(sid, roleId, [hero]);
}
}
async function takeOffEquip(objectId: string) {
let {seqId, ePlaceId} = await EquipModel.updateEquipInfobyObjectId(objectId, { hid: 0, ePlaceId: 0 });
return { seqId, hid: 0, ePlaceId};
}