装备精炼,洗炼,缺少消耗
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Application, BackendSession } from "pinus";
|
||||
import { STATUS, EQUIP_STRENGTHEN_TYPE, CURRENCY_BY_TYPE, CURRENCY_TYPE, HERO_SYSTEM_TYPE, CONSUME_TYPE, GOOD_TYPE } from "../../../consts";
|
||||
import { STATUS, EQUIP_STRENGTHEN_TYPE, CURRENCY_BY_TYPE, CURRENCY_TYPE, HERO_SYSTEM_TYPE, CONSUME_TYPE, GOOD_TYPE, HERO_GROW_MAX } from "../../../consts";
|
||||
import { ItemInter } from "../../../pubUtils/interface";
|
||||
import { resResult, parseReward, getRandomByLen } from "../../../pubUtils/util";
|
||||
import { addItems, handleCost } from "../../../services/rewardService";
|
||||
@@ -73,7 +73,7 @@ export class EquipHandler {
|
||||
let hero = await HeroModel.findByHidAndRole(hid, roleId);
|
||||
if(!hero) return resResult(STATUS.HERO_NOT_FIND);
|
||||
|
||||
let { ePlace = new Array<EPlace>() } = hero; // 装备栏
|
||||
let { ePlace } = hero; // 装备栏
|
||||
let strengthenArr = new Array<EPlace>();
|
||||
if(type == EQUIP_STRENGTHEN_TYPE.SINGLE || type == EQUIP_STRENGTHEN_TYPE.SINGLE_QUICK) { // 单装备强化
|
||||
strengthenArr = ePlace.filter(cur => cur.id == ePlaceId && cur.equip);
|
||||
@@ -90,6 +90,9 @@ export class EquipHandler {
|
||||
|
||||
let {coin, lv: playerLv} = await Role.findByRoleId(roleId);
|
||||
let maxLv = type == EQUIP_STRENGTHEN_TYPE.SINGLE?minLv + 1:playerLv;
|
||||
if(minLv == maxLv) {
|
||||
return resResult(STATUS.ROLE_EQUIP_REACH_MAX);
|
||||
}
|
||||
let costCoin = 0; // 消耗铜币
|
||||
let flag = false; // 铜币不足
|
||||
for(let i = minLv; i < maxLv; i++) {
|
||||
@@ -128,11 +131,62 @@ export class EquipHandler {
|
||||
}
|
||||
|
||||
// TODO 装备栏精炼
|
||||
public async refine(msg: { }, session: BackendSession) {
|
||||
public async refine(msg: { hid: number, ePlaceId: number, material: {id: number, count: number}[] }, session: BackendSession) {
|
||||
let roleId: string = session.get('roleId');
|
||||
// let roleName: string = session.get('roleName');
|
||||
let sid: string = session.get('sid');
|
||||
|
||||
let {hid, ePlaceId, material} = msg;
|
||||
|
||||
let hero = await HeroModel.findByHidAndRole(hid, roleId);
|
||||
if(!hero) return resResult(STATUS.HERO_NOT_FIND);
|
||||
let { ePlace } = hero; // 装备栏
|
||||
|
||||
let curEplace = ePlace.find(cur => cur.id == ePlaceId);
|
||||
if(!curEplace) {
|
||||
return resResult(STATUS.ROLE_EQUIP_PLACE_NOT_ENOUGH);
|
||||
}
|
||||
let {lv, refineLv } = curEplace; // 强化等级,精炼等级,精炼次数
|
||||
|
||||
if(lv < HERO_GROW_MAX.EQUIP_STRENGTHEN) {
|
||||
return resResult(STATUS.ROLE_EQUIP_NOT_REACH_MAX);
|
||||
}
|
||||
if(refineLv >= HERO_GROW_MAX.EQUIP_REFINE) {
|
||||
return resResult(STATUS.ROLE_EQUIP_REACH_MAX);
|
||||
}
|
||||
|
||||
// TODO 是否成功精炼
|
||||
let dicRefine = gameData.refine.get(refineLv + 1);
|
||||
if(!dicRefine) {
|
||||
return resResult(STATUS.ROLE_INFO_NOT_FOUND)
|
||||
}
|
||||
let ran = Math.floor(Math.random() * 100)
|
||||
let isSuccess = ran <= dicRefine.successRate;
|
||||
// 消耗道具提升成功率 每个道具提升10%成功率
|
||||
|
||||
|
||||
// 精炼
|
||||
if(isSuccess) {
|
||||
curEplace.refineLv++;
|
||||
} else {
|
||||
curEplace.refineCount++;
|
||||
}
|
||||
|
||||
// TODO 消耗
|
||||
let cost = [];
|
||||
let result = await handleCost(roleId, sid, cost);
|
||||
if(!result) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
|
||||
|
||||
await calPlayerCeAndSave(sid, roleId, [hero], HERO_SYSTEM_TYPE.EPLACE_STRENGTHEN);
|
||||
|
||||
const curHero = {
|
||||
hid,
|
||||
ePlace: curEplace
|
||||
}
|
||||
return resResult(STATUS.SUCCESS, { isSuccess, curHero});
|
||||
}
|
||||
|
||||
// TODO 装备洗炼锁定
|
||||
// 装备洗炼锁定,消耗TODO
|
||||
public async lockRandSe(msg: { eid: number, id: number, lock: boolean }, session: BackendSession) {
|
||||
let roleId: string = session.get('roleId');
|
||||
// let roleName: string = session.get('roleName');
|
||||
@@ -147,6 +201,7 @@ export class EquipHandler {
|
||||
return resResult(STATUS.EQUIP_HAVE_NO_RANDSE);
|
||||
}
|
||||
|
||||
// TODO 锁
|
||||
// let lock = 0;
|
||||
// let result = await handleCost(roleId, sid, [{id: lock, count: 1}]);
|
||||
// if(!result) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
|
||||
@@ -159,7 +214,7 @@ export class EquipHandler {
|
||||
|
||||
}
|
||||
|
||||
// TODO 装备洗炼
|
||||
// TODO 装备洗炼,消耗TODO
|
||||
public async reStrengthen(msg: { eid: number }, session: BackendSession) {
|
||||
let roleId: string = session.get('roleId');
|
||||
// let roleName: string = session.get('roleName');
|
||||
@@ -179,37 +234,40 @@ export class EquipHandler {
|
||||
|
||||
let {randomEffect} = dicGoods;
|
||||
let pool = randomEffect.map(cur => gameData.randomEffectPool.get(cur));
|
||||
let chosen = randSe.map(cur => cur.seid);
|
||||
let newRandSe = new Array<RandSe>();
|
||||
let chosen = randSe.map(cur => cur.seid); // 上一轮和这一轮随机出来的
|
||||
let newTurnChosen = new Array<number>(); // 这一轮随机出来的
|
||||
let hasReset = false;
|
||||
for(let i = 0; i < randSe.length; i++) {
|
||||
if(!randSe[i].locked) {
|
||||
pool = pool.filter(cur => !chosen.includes(cur.id));
|
||||
let random = getRandomByLen(pool);
|
||||
if(!random) break;
|
||||
let newPool = pool.filter(cur => !chosen.includes(cur.id));
|
||||
if(newPool.length <= 0) newPool = pool.filter(cur => !newTurnChosen.includes(cur.id));
|
||||
let random = getRandomByLen(newPool);
|
||||
if(!random) {break};
|
||||
chosen.push(random.id);
|
||||
newTurnChosen.push(random.id);
|
||||
let rand = 0;
|
||||
if(random.id > 0) rand = Math.floor(Math.random() * (random.max - random.min) + random.min);
|
||||
newRandSe.push({
|
||||
id: i + 1,
|
||||
seid: random.id,
|
||||
rand,
|
||||
locked: false
|
||||
});
|
||||
} else {
|
||||
newRandSe.push({
|
||||
id: i + 1,
|
||||
seid: randSe[i].seid,
|
||||
rand: randSe[i].rand,
|
||||
locked: randSe[i].locked
|
||||
});
|
||||
console.log(Math.random(), random.Max, random.Min)
|
||||
if(random.id > 0) rand = Math.floor(Math.random() * (random.Max - random.Min) + random.Min);
|
||||
randSe[i].seid = random.id;
|
||||
randSe[i].rand = rand;
|
||||
hasReset = true;
|
||||
}
|
||||
}
|
||||
if(!hasReset) {
|
||||
return resResult(STATUS.ROLE_EQUIP_CANNOT_RESTRENGTHEN);
|
||||
}
|
||||
|
||||
// TODO 消耗
|
||||
let cost = [];
|
||||
let result = await handleCost(roleId, sid, cost);
|
||||
if(!result) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
|
||||
|
||||
let curEquip = await EquipModel.updateEquipInfo(eid, {randSe: newRandSe})
|
||||
let equipResult = await EquipModel.updateEquipInfo(eid, { randSe })
|
||||
let curEquip = {
|
||||
seqId: equipResult.seqId,
|
||||
id: equipResult.id,
|
||||
randSe: equipResult.randSe
|
||||
}
|
||||
return resResult(STATUS.SUCCESS,{curEquip});
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user