强化装备栏

This commit is contained in:
luying
2020-12-17 21:37:05 +08:00
parent b3ec0c85da
commit d2097a4264
9 changed files with 133 additions and 18 deletions

View File

@@ -1,11 +1,14 @@
import { Application, BackendSession } from "pinus";
import { resResult } from "../../../pubUtils/util";
import { STATUS } from "../../../consts";
import { STATUS, EQUIP_STRENGTHEN_TYPE, CURRENCY_BY_TYPE, CURRENCY_TYPE, HERO_SYSTEM_TYPE } from "../../../consts";
import { addItems, handleCost } from "../../../services/rewardService";
import { gameData } from "../../../pubUtils/data";
import { ItemInter } from "../../../pubUtils/interface";
import { EquipModel } from "../../../db/Equip";
import { GOOD_TYPE } from "../../../consts/consts";
import { HeroModel, EPlace } from "../../../db/Hero";
import Role from "../../../db/Role";
import { calPlayerCeAndSave } from "../../../services/playerCeService";
export default function(app: Application) {
return new EquipHandler(app);
@@ -49,17 +52,75 @@ export class EquipHandler {
count: targetGood.pieces
});
}
console.log(JSON.stringify(cost))
let result = await handleCost(roleId, sid, cost);
if(!result) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
let items = [{id: gid, count: 1}];
let items = [{type: GOOD_TYPE.EQUIP, id: gid, count: 1}];
let goods = await addItems(roleId, roleName, sid, items);
return resResult(STATUS.SUCCESS, { goods });
}
// TODO 装备栏强化
public async strengthen(msg: { }, session: BackendSession) {
public async strengthen(msg: { hid: number, ePlaceId: number, type: number }, session: BackendSession) {
let roleId: string = session.get('roleId');
// let roleName: string = session.get('roleName');
let sid: string = session.get('sid');
let {hid, ePlaceId, type} = msg;
let hero = await HeroModel.findByHidAndRole(hid, roleId);
if(!hero) return resResult(STATUS.HERO_NOT_FIND);
let { ePlace = new Array<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);
} else if (type == EQUIP_STRENGTHEN_TYPE.ALL_QUICK) { // 全六件(装备中)的强化
strengthenArr = ePlace.filter(cur => cur.equip);
}
if(strengthenArr.length <= 0) {
return resResult(STATUS.ROLE_EQUIP_PLACE_NOT_ENOUGH);
}
let minLv = strengthenArr[0].lv; // 从最低装备的等级开始
for(let {lv} of strengthenArr) {
if(lv < minLv) minLv = lv;
}
let {coin, lv: playerLv} = await Role.findByRoleId(roleId);
let maxLv = type == EQUIP_STRENGTHEN_TYPE.SINGLE?minLv + 1:playerLv;
let costCoin = 0; // 消耗铜币
let flag = false; // 铜币不足
for(let i = minLv; i < maxLv; i++) {
for(let s of strengthenArr) {
if(s.lv == i) {
let cost = gameData.strengthenCost.get(i + 1);
if(!cost) {flag = true; break;}
if(coin < costCoin + cost) { flag = true; break;}
costCoin += cost;
s.lv++;
}
}
if(flag) break;
}
if(costCoin <= 0) { // 连一级都不够升
return resResult(STATUS.ROLE_COIN_NOT_ENOUGH);
}
let result = await handleCost(roleId, sid, [{
id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.COIN),
count: costCoin
}]);
if(!result) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
hero.ePlace = ePlace;
await calPlayerCeAndSave(sid, roleId, [hero], HERO_SYSTEM_TYPE.EPLACE_STRENGTHEN);
const curHero = {
hid,
ePlace: strengthenArr
}
return resResult(STATUS.SUCCESS, {curHero});
}

View File

@@ -1,4 +1,4 @@
import { GOOD_TYPE, ITID, CURRENCY, CURRENCY_TYPE, CONSUME_TYPE, getCurNameById } from './../consts/consts';
import { GOOD_TYPE, ITID, CURRENCY, CURRENCY_TYPE, CONSUME_TYPE, getCurNameById } from './../consts';
import { EquipModel } from './../db/Equip';
import { decodeStr, resResult } from '../pubUtils/util';
import { getGoodById } from '../pubUtils/gamedata';
@@ -264,7 +264,9 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
function sortItems (goods: Array<ItemInter>, bags: Array<BagInter>, skins: Array<number>, currencysMap: any, equips: Array<EquipInter>, showItems: Array<ItemInter>) {
for (let good of goods) {
let goodInfo = gameData.goods.get(good.id);
console.log('*****', good.id, goodInfo.goodType)
if (goodInfo.goodType == GOOD_TYPE.EQUIP) { // 装备
console.log()
for (let i = 0; i < good.count; i++) {
equips.push({id: good.id, ...goodInfo});
}

View File

@@ -5,7 +5,8 @@ export const HERO_SYSTEM_TYPE = {
STAGEUP:6,
SKIN:7,
FAVOUR:8,
CONNECT:9
CONNECT:9,
EPLACE_STRENGTHEN: 10
};
// 武将上限

View File

@@ -5,8 +5,8 @@ export const IT_TYPE = {
// 大类型,区分存到哪张表里
export const GOOD_TYPE = {
EQUIP: 1,
CONSUMES: 2,
EQUIP: 2,
CONSUMES: 1,
SCRIPT: 3
};
@@ -131,4 +131,23 @@ export const RANDOM_SE_COUNT = new Map<number, number>([
[QUALITY_TYPE.GOLD, 4]
]);
export const FIX_ATTRIBUTES_RAN = 20; // 固定属性值+-20%随机
export const FIX_ATTRIBUTES_RAN = 20; // 固定属性值+-20%随机
export function getCurNameById(gid) {
let currency = CURRENCY.get(gid);
if (!currency) {
return;
}
if (currency.type == CURRENCY_TYPE.COIN) {
return 'coin';
} else if (currency.type == CURRENCY_TYPE.GOLD) {
return 'gold';
} else if (currency.type == CURRENCY_TYPE.ACTION_POINT) {
return 'ap';
} else if (currency.type == CURRENCY_TYPE.FRIEND_POINT) {
return 'frdCnt';
} else if (currency.type == CURRENCY_TYPE.EXPEDITION_POINT) {
return 'expeditionPoint';
}
}

View File

@@ -8,13 +8,13 @@ export const ENCRYPT_KEY = 'fiqaxijabbantusmprc234fj';
export const AUTH_SMS_CNT_PER_DAY = 8;
export const COUNTER = {
UID: {name:'uid',def:1},
GMUID: {name:'gmuid',def:1},
API: {name:'api',def:1},
GM_GROUP: {name:'gmgroup',def:1},
HID: {name:'hid',def:10000},
EID: {name:'eid',def:1},
ROLE: {name:'role',def:1}
UID: { name: 'uid', def: 1 },
GMUID: { name: 'gmuid', def: 1 },
API: { name: 'api', def: 1 },
GM_GROUP: { name: 'gmgroup', def: 1 },
HID: { name: 'hid', def: 10000 },
EID: { name: 'eid', def: 1 },
ROLE: { name: 'role', def: 1 }
};
export const DEFAULT_HEROES = [12, 14, 11, 9, 15];
@@ -83,7 +83,8 @@ export const FILENAME = {
DIC_TOWER: 'dic_zyz_tower',
DIC_XUNBAO: 'dic_zyz_xunbao',
DIC_QUESTION: 'Questions',
DIC_RANDOM_EFFECT_POOL: 'dic_random_effect_pool'
DIC_RANDOM_EFFECT_POOL: 'dic_random_effect_pool',
DIC_STRENGTHEN_COST: 'dic_zyz_enhancementCost'
}
export const WAR_RELATE_TABLES = [
@@ -98,3 +99,10 @@ export const WAR_RELATE_TABLES = [
FILENAME.DIC_GK_TOWER,
FILENAME.DIC_GK_TREASURE
]
// 装备栏强化类型
export const EQUIP_STRENGTHEN_TYPE = {
SINGLE: 1, // 单件单级强化
SINGLE_QUICK: 2, // 单件一键强化
ALL_QUICK: 3 // 武将全部装备栏一键强化
}

View File

@@ -144,6 +144,9 @@ export const STATUS = {
ROLE_SHORT_HERO_CONECTION:{code: 30308, simStr: '未拥有羁绊武将'},
HERO_FAVOUR_LEVEL_REACH_MAXT:{code: 30308, simStr: '武将好感等级以达到最大'},
// 装备养成 30400-30499
ROLE_EQUIP_PLACE_NOT_ENOUGH: {code: 30400, simStr: '装备栏未装备或无可强化'},
ROLE_COIN_NOT_ENOUGH: {code: 30401, simStr: '铜币不足'},
// 社交相关状态 40000 - 49999
// 运营模块相关状态 50000 - 59999

View File

@@ -26,6 +26,7 @@ import { dicHeroQualityUp } from "./dictionary/DicHeroQualityUp";
import { dicHeroStar } from "./dictionary/DicHeroStar";
import { dicHeroWake } from "./dictionary/DicHeroWake";
import { dicRandomEffectPool } from './dictionary/DicRandomEffectPool';
import { dicStrengthenCost } from './dictionary/DicStrengthenCost';
export const gameData = {
blurprtCompose: dicBlueprtCompose,
@@ -63,6 +64,7 @@ export const gameData = {
friendShipLevel: dicFriendShipLevel,
friendShipLevelMap: dicFriendShipLevelMap,
randomEffectPool: dicRandomEffectPool,
strengthenCost: dicStrengthenCost
};
// 在此提供一些原先在gamedata中提供的方法以便更方便获取gameData数据

View File

@@ -0,0 +1,19 @@
// 强化消耗表
import {readJsonFile} from '../util'
import { FILENAME } from '../../consts'
export interface DicStrengthenCost {
// 等级
readonly level: number;
// 消耗铜钱
readonly costCoin: number;
}
const str = readJsonFile(FILENAME.DIC_STRENGTHEN_COST);
let arr = JSON.parse(str);
export const dicStrengthenCost = new Map<number, number>();
arr.forEach(o => {
dicStrengthenCost.set(o.level, o.costCoin);
});

View File

@@ -52,7 +52,7 @@ export async function addEquips(roleId: string, roleName: string, weapon: EquipI
locked: false
});
}
let randRange = Math.floor(Math.random() * FIX_ATTRIBUTES_RAN);
let randRange = Math.floor(Math.random() * FIX_ATTRIBUTES_RAN * 2) - FIX_ATTRIBUTES_RAN;
let holes = new Array<Holes>();
for(let i = 0; i < hole; i++) {
holes.push({id: i+1, isOpen: false, jewel: 0})