装备:镶嵌或卸载地玉石
This commit is contained in:
@@ -11,7 +11,7 @@ import { calPlayerCeAndSave } from "../../../services/playerCeService";
|
||||
import { getGoodById, gameData, getEquipByJobClassAndEPlace, getNextEquipQuality, getEquipQualityIdByEquipIdAndPoint, getEquipStarIdByEquipId, getNextEquipStar } from "../../../pubUtils/data";
|
||||
import { BAG, EQUIP } from "../../../pubUtils/dicParam";
|
||||
import { ITID, QUALITY_TYPE, equipTypeToSortAttr, IT_TYPE, QUENCH_TYPE, REFINE_TYPE } from "../../../consts";
|
||||
import { checkMaterialEnough, checkEquipCanPut, quenchOnce, checkQuenchMaxByQualityAndGrade, getRandSeResult, refineOnce, checkRefineReachNextLv, calEquipCe, updateEplace, updateEplaces, checkJewelCanPutOnEquip } from "../../../services/equipService";
|
||||
import { checkMaterialEnough, checkEquipCanPut, quenchOnce, checkQuenchMaxByQualityAndGrade, getRandSeResult, refineOnce, checkRefineReachNextLv, calEquipCe, updateEplace, updateEplaces, checkJewelCanPutOnEquip, updateStone, checkStoneCanPutOnEquip } from "../../../services/equipService";
|
||||
|
||||
import { findIndex, isNumber, pick } from 'underscore';
|
||||
import { pushEquipRefineSucMsg, pushNormalEquipMsg, pushNormalItemMsg } from "../../../services/chatService";
|
||||
@@ -351,7 +351,47 @@ export class EquipHandler {
|
||||
|
||||
return resResult(STATUS.SUCCESS, { curHero, curJewel });
|
||||
}
|
||||
|
||||
// 装备或卸载地玉石
|
||||
public async putOnOrOffStone(msg: { hid: number, eplaceId: number, stonesId: number, gid: number }, session: BackendSession) {
|
||||
let { hid, eplaceId, stonesId, gid } = msg;
|
||||
let roleId: string = session.get('roleId');
|
||||
let roleName: string = session.get('roleName');
|
||||
let sid: string = session.get('sid');
|
||||
|
||||
let hero = await HeroModel.findByHidAndRole(hid, roleId);
|
||||
if (!hero) return resResult(STATUS.HERO_NOT_FIND);
|
||||
|
||||
let curEquip = hero.ePlace?.find(cur => cur.id == eplaceId);
|
||||
if(!curEquip) return resResult(STATUS.EQUIP_NOT_FIND);
|
||||
|
||||
let curStone = curEquip.stones?.find(cur => cur.id == stonesId)||{ id: stonesId, stone: 0 };
|
||||
if(curStone.stone == gid) {
|
||||
return resResult(gid == 0? STATUS.STONE_NOT_SUIT: STATUS.STONE_HAS_SUIT);
|
||||
}
|
||||
if(!checkStoneCanPutOnEquip(curEquip, stonesId, gid)) { // 是否可以镶嵌
|
||||
return resResult(STATUS.STONE_CANNOT_SUIT);
|
||||
}
|
||||
|
||||
let consumeResult = await handleCost(roleId, sid, [{ id: gid, count: 1 }], ITEM_CHANGE_REASON.EQUIP_FILL_HOLE);
|
||||
if (!consumeResult) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
|
||||
|
||||
if(curStone.stone > 0) { // 返回石头
|
||||
await addItems(roleId, roleName, sid, [{ id: curStone.stone, count: 1 }], ITEM_CHANGE_REASON.EQUIP_FILL_HOLE);
|
||||
}
|
||||
|
||||
let newStone = updateStone(curEquip.stones, stonesId, gid);
|
||||
let { newEplace, updatedEplace } = updateEplace(hero.ePlace, eplaceId, { stones: newStone });
|
||||
await calPlayerCeAndSave(HERO_SYSTEM_TYPE.EQUIP_STONE, sid, roleId, hero, { ePlace: newEplace }, [eplaceId]);
|
||||
let curHero = {
|
||||
hid,
|
||||
eplace: updatedEplace
|
||||
}
|
||||
|
||||
return resResult(STATUS.SUCCESS, { curHero });
|
||||
}
|
||||
|
||||
|
||||
// // 装备洗炼锁定
|
||||
// public async lockRandSe(msg: { eid: number, id: number, lock: boolean }, session: BackendSession) {
|
||||
// let roleId: string = session.get('roleId');
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { mergeSameGoods, getRandEelm, getRandValueByMinMax } from '../pubUtils/util';
|
||||
import { EquipModel, RandMain, RandSe } from "../db/Equip";
|
||||
import { EPlace, HeroModel, HeroType } from "../db/Hero";
|
||||
import { EPlace, HeroModel, HeroType, Stone } from "../db/Hero";
|
||||
import { getGoodById, gameData, getQuenchGradeByValue, getQuenchConsume, getQuenchByQualityAndGrade } from "../pubUtils/data";
|
||||
import { calPlayerCeAndSave } from "./playerCeService";
|
||||
import { CONSUME_TYPE, HERO_SYSTEM_TYPE, ITID, TASK_TYPE } from "../consts";
|
||||
@@ -200,6 +200,23 @@ export function calEquipCe(goodsAbility: Map<number, number>, randMain: RandMain
|
||||
return ce
|
||||
}
|
||||
|
||||
export function updateStone(origin: Stone[], id: number, target: number) {
|
||||
let newStones: Stone[] = [];
|
||||
let hasTarget = false;
|
||||
for(let stone of origin) {
|
||||
if(stone.id == id) {
|
||||
newStones.push({ id, stone: target });
|
||||
hasTarget = true;
|
||||
} else {
|
||||
newStones.push(stone);
|
||||
}
|
||||
}
|
||||
if(!hasTarget) {
|
||||
newStones.push({ id, stone: target });
|
||||
}
|
||||
return newStones;
|
||||
}
|
||||
|
||||
export function updateEplace(eplace: EPlace[], eplaceId: number, update: Partial<EPlace>) {
|
||||
let newEplace: EPlace[] = [];
|
||||
let updatedEplace: Partial<EPlace>[] = [];
|
||||
@@ -241,4 +258,15 @@ export function checkJewelCanPutOnEquip(equip: EPlace, jewel: JewelType) {
|
||||
let dicEquipQualityExtra = gameData.equipQualityExtra.get(equip.quality);
|
||||
if(!dicEquipQualityExtra || dicEquipQualityExtra.jewelCnt == 0) return false;
|
||||
return true
|
||||
}
|
||||
|
||||
export function checkStoneCanPutOnEquip(equip: EPlace, id: number, stone: number) {
|
||||
if(stone == 0) return true; // 卸载
|
||||
// 位置是否满足
|
||||
let dicStone = gameData.stone.get(stone);
|
||||
if(!dicStone || dicStone.eplaceId != equip.id) return false;
|
||||
// 品质是否满足
|
||||
let dicEquipQualityExtra = gameData.equipQualityExtra.get(equip.quality);
|
||||
if(!dicEquipQualityExtra || dicEquipQualityExtra.stoneCnt < id) return false;
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user