装备:镶嵌或卸载地玉石

This commit is contained in:
luying
2022-02-16 18:11:47 +08:00
parent e0bf64a35e
commit 925468ae64
5 changed files with 103 additions and 2 deletions

View File

@@ -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');

View File

@@ -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;
}

View File

@@ -26,6 +26,7 @@ export enum HERO_SYSTEM_TYPE {
EQUIP_QUALITY = 23, // 装备升品
EQUIP_STAR = 24, // 装备升星
EQUIP_JEWEL = 25, // 装备装上or卸下天晶石
EQUIP_STONE = 26, // 装备装上or卸下地玉石
};
// 武将上限

View File

@@ -318,6 +318,9 @@ export const STATUS = {
EQUIP_STARSTAGE_IS_MAX: { code: 30522, simStr: '该装备已到该星级下最高,请升星' },
JEWEL_HAS_SUIT: { code: 30523, simStr: '该装备已镶嵌该天晶石了' },
JEWEL_NOT_SUIT: { code: 30524, simStr: '该装备未镶嵌天晶石' },
STONE_HAS_SUIT: { code: 30525, simStr: '该装备该槽已镶嵌相同的地玉石了' },
STONE_NOT_SUIT: { code: 30526, simStr: '该装备该槽未镶嵌地玉石' },
STONE_CANNOT_SUIT: { code: 30527, simStr: '该装备不可装备该地玉石' },
//全局养成30600-30699
ROLE_REACH_MAX_TITLE_LEVEL: { code: 30600, simStr: '玩家已达到最高的爵位' },

View File

@@ -180,6 +180,9 @@ export async function calPlayerCe(hero: HeroType, update: HeroUpdate, type: numb
case HERO_SYSTEM_TYPE.EQUIP_JEWEL:
heroAttrs = await calEquipPutOnOrOffJewelIncAttr(hero, update, args, addSeidList, removeSeidList);
break;
case HERO_SYSTEM_TYPE.EQUIP_STONE:
heroAttrs = await calEquipPutOnOrOffStoneIncAttr(hero, update, args, addSeidList, removeSeidList);
break;
case HERO_SYSTEM_TYPE.EQUIP: //
heroAttrs = calEquipPutOnOffIncAttr(hero, args, addSeidList, removeSeidList);
break;
@@ -753,6 +756,32 @@ function isRandSeUnLock(jewelId: number, randSeId: number, stones: Stone[]) {
return stoneCnt >= dicJewelCondition.stoneCnt && stoneLv >= dicJewelCondition.stoneLv;
}
export async function calEquipPutOnOrOffStoneIncAttr(hero: HeroType, update: HeroUpdate, eplaceIds: number[], addSeidList: number[], removeSeidList: number[]) {
let { attr: heroAttrs, ePlace: oldEplace } = hero;
let { ePlace: newEplace } = update;
for(let eplaceId of eplaceIds) {
let oldEquip = oldEplace.find(cur => cur.id == eplaceId);
updateHeroAttrOfStone(heroAttrs, oldEquip, -1);
await setRandSeToSeidList(oldEquip, removeSeidList);
let newEquip = newEplace.find(cur => cur.id == eplaceId);
updateHeroAttrOfStone(heroAttrs, newEquip, 1);
await setRandSeToSeidList(newEquip, addSeidList); // 地玉石阶数变化可能导致属性词条解锁变化
}
return heroAttrs;
}
function updateHeroAttrOfStone(heroAttrs: CeAttrData[], equip: EPlace, ratio: number) {
for(let { stone } of equip.stones) {
let dicStone = gameData.stone.get(stone);
if(dicStone) {
for(let attr of dicStone.attribute) {
updateHeroAttr(heroAttrs, attr.id, { inc: { fixUp: ratio * attr.num * HERO_CE_RATIO } });
}
}
}
}
/**
* 穿脱, removeSeidList原来身上穿着的所有装备的seid包括套装的
* @param {HeroType} hero 武将