合成藏宝图,消耗品单独开表
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
import { IT_TYPE } from '../../../consts/consts';
|
||||
import { getGoodById, getBossHpByBlueprtId, getComBtlSetByQuality } from '../../../pubUtils/gamedata';
|
||||
import { IT_TYPE, GOLD_COST_RATIO, CURRENCY_BY_TYPE, CURRENCY_TYPE } from '../../../consts/consts';
|
||||
import { getGoodById, getBossHpByBlueprtId, getComBtlSetByQuality, getBlueprtComposeByQuality, getBluePrtByQuality } from '../../../pubUtils/gamedata';
|
||||
import { COM_TEAM_STATUS, COM_TEAM_ENABLE_LV } from '../../../consts/consts';
|
||||
import { ComBattleTeamModel } from '../../../db/ComBattleTeam';
|
||||
import Role, { RoleModel } from '../../../db/Role';
|
||||
import { STATUS } from '../../../consts/statusCode';
|
||||
import { Application, BackendSession, BlackListFunction } from 'pinus';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
import { resResult, getRandomByLen, calculateNum } from '../../../pubUtils/util';
|
||||
import { RoleStatus } from '../../../db/ComBattleTeam';
|
||||
import { ItemModel } from '../../../db/Item';
|
||||
import { handleReward } from '../../../services/rewardService';
|
||||
|
||||
export default function(app: Application) {
|
||||
return new ComBattleHandler(app);
|
||||
@@ -52,9 +54,10 @@ export class ComBattleHandler {
|
||||
if (!goodData || goodData.itid !== IT_TYPE.BLUEPRT) return resResult(STATUS.COM_BATTLE_BLUEPRT_INVALID);
|
||||
|
||||
// 检查藏宝图是否足够
|
||||
let { consumeGoods, lv, headHid, topFiveCe, sHid } = await RoleModel.findByRoleId(roleId);
|
||||
let { lv, headHid, topFiveCe, sHid } = await RoleModel.findByRoleId(roleId);
|
||||
if (lv < COM_TEAM_ENABLE_LV) return resResult(STATUS.COM_BATTLE_LV_NOT_ENOUGH);
|
||||
let blueprt = consumeGoods.find(good => good.id === blueprtId && good.count >= 1);
|
||||
|
||||
let blueprt = await ItemModel.findbyRoleAndGidAndCount(roleId, blueprtId, 1);
|
||||
if (!blueprt) return resResult(STATUS.COM_BATTLE_BLUEPRT_NOT_FOUND);
|
||||
// 检查是否有已创建未结束的寻宝,预先占用一张藏宝图
|
||||
let teams = await ComBattleTeamModel.getTeamByCapAndStatus(roleId, COM_TEAM_STATUS.FIGHTING);
|
||||
@@ -410,4 +413,60 @@ export class ComBattleHandler {
|
||||
|
||||
// return resResult(STATUS.SUCCESS, { bossHp: this.bossHp});
|
||||
// }
|
||||
|
||||
|
||||
|
||||
async composeBlueprt(msg: {original: Array<{id: number, count: number}>}, session: BackendSession) {
|
||||
const roleId = session.get('roleId');
|
||||
const roleName = session.get('roleName');
|
||||
const { original } = msg;
|
||||
|
||||
// 原材料检查
|
||||
let originalQuality: number, originalSum: number;
|
||||
for(let {id, count} of original) {
|
||||
const goodInfo = getGoodById(id);
|
||||
if(!originalQuality) originalQuality = goodInfo.quality;
|
||||
if(originalQuality != goodInfo.quality) {
|
||||
return resResult(STATUS.COM_BLUEPRT_QUALITY_ERROR);
|
||||
}
|
||||
|
||||
if(goodInfo.itid == IT_TYPE.BLUEPRT) {
|
||||
originalSum += count;
|
||||
}
|
||||
}
|
||||
|
||||
const dicCompose = getBlueprtComposeByQuality(originalQuality);
|
||||
if(!dicCompose) {
|
||||
return resResult(STATUS.COM_BLUEPRT_QUALITY_CANNOT_COMPOSE);
|
||||
}
|
||||
if(originalSum != dicCompose.blueprtNum) {
|
||||
return resResult(STATUS.COM_BLUEPRT_COUNT_ERROR);
|
||||
}
|
||||
// 检查元宝
|
||||
const role = await RoleModel.findByRoleId(roleId);
|
||||
const costGold = calculateNum(GOLD_COST_RATIO.BLUEPRT_COMPOSE_COST, {num: originalQuality}, 1000);
|
||||
if(!role || role.gold < costGold) {
|
||||
return resResult(STATUS.TOWER_GOLD_NOT_ENOUGH);
|
||||
}
|
||||
// 添加寻宝币
|
||||
original.push({
|
||||
id: CURRENCY_BY_TYPE[CURRENCY_TYPE.TREASURE_POINT],
|
||||
count: dicCompose.coinNum
|
||||
});
|
||||
// 消耗藏宝图和寻宝币
|
||||
const rec = await ItemModel.decreaseItems(roleId, original);
|
||||
if(!rec) {
|
||||
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
|
||||
}
|
||||
// 消耗元宝
|
||||
await RoleModel.costGold(roleId, costGold);
|
||||
|
||||
const targetList = getBluePrtByQuality(dicCompose.targetQuality);
|
||||
const target = getRandomByLen(targetList);
|
||||
const reward = [{gid: target, count: 1}];
|
||||
const goods = await handleReward(roleId, roleName, reward);
|
||||
|
||||
|
||||
return resResult(STATUS.SUCCESS, { goods });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import { startEvent } from '../../../services/eventSercive';
|
||||
import { EVENT_START_LV } from '../../../consts/consts';
|
||||
import { getAp } from '../../../services/actionPointService';
|
||||
import Actor from '../../../pubUtils/actor';
|
||||
import { ItemModel } from '../../../db/Item';
|
||||
|
||||
export default function (app: Application) {
|
||||
return new EntryHandler(app);
|
||||
@@ -82,6 +83,7 @@ export class EntryHandler {
|
||||
// let users = await self.app.rpc.chat.chatRemote.add.route(session)(role.roleId, self.app.get('serverId'), rid, true);
|
||||
let heros = await HeroModel.findByRole(role.roleId);
|
||||
let equips = await EquipModel.findbyRole(role.roleId);
|
||||
let items = await ItemModel.findbyRole(role.roleId);
|
||||
|
||||
for(let hero of heros) {
|
||||
let actor = new Actor();
|
||||
@@ -91,6 +93,7 @@ export class EntryHandler {
|
||||
|
||||
role['heros'] = heros;
|
||||
role['equips'] = equips;
|
||||
role['consumeGoods'] = items;
|
||||
let apJson = await getAp(Date.now(), role.roleId);
|
||||
role['apJson'] = apJson;
|
||||
return resResult(STATUS.SUCCESS, { role });
|
||||
|
||||
@@ -38,7 +38,7 @@ export async function initRank(serverId: number) {
|
||||
|
||||
let ranks = await RoleModel.getRank('tower', serverId, ['roleId', 'roleName', 'towerLv', 'lv', 'vLv']);
|
||||
for(let {towerLv, roleId, roleName, lv, vLv, towerUpTime} of ranks) {
|
||||
console.log(roleId);
|
||||
// console.log(roleId);
|
||||
await redisZadd(getKeyName(REDIS_KEY.TOWER_RANK, serverId), encodeScoreWithTime(towerLv, towerUpTime?towerUpTime.getTime():0), roleId);
|
||||
await redisUserInfoAdd(roleId, {roleName, lv, vLv, guildName:"", head: "zhaoyun"});
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import { decodeStr } from '../pubUtils/util';
|
||||
import { getGoodById } from '../pubUtils/gamedata';
|
||||
import { RoleModel } from '../db/Role';
|
||||
import { setAp } from './actionPointService';
|
||||
import { ItemModel } from '../db/Item';
|
||||
|
||||
export async function handleFixedReward(roleId: string, roleName: string, rewardStr: string, multi: number) {
|
||||
let reward = decodeStr('fixReward', rewardStr);
|
||||
@@ -15,7 +16,7 @@ export async function handleFixedReward(roleId: string, roleName: string, reward
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function handleReward(roleId: string, roleName: string, rewards: Array<{type: number, gid: number, count: number, times: number}>) {
|
||||
export async function handleReward(roleId: string, roleName: string, rewards: Array<{type?: number, gid: number, count: number, times?: number}>) {
|
||||
|
||||
let returnGoods = new Array(), getGold = 0, getCoin = 0, getAp = 0;
|
||||
for(let goods of rewards) {
|
||||
@@ -24,11 +25,11 @@ export async function handleReward(roleId: string, roleName: string, rewards: Ar
|
||||
if(goodInfo.goodType == GOOD_TYPE.EQUIP) { // 装备
|
||||
result = await rewardWeapons(roleId, roleName, goodInfo, {id: goods.gid, cnt: goods.count });
|
||||
} else if(goodInfo.goodType == GOOD_TYPE.CONSUMES|| goodInfo.goodType == GOOD_TYPE.SCRIPT) { // 消耗品
|
||||
let {field, isCurrency} = ITID.get(goodInfo.itid);
|
||||
let {type, isCurrency} = ITID.get(goodInfo.itid);
|
||||
if(isCurrency) { // 货币
|
||||
result = await rewardCurrency(roleId, goodInfo, {id: goods.gid, cnt: goods.count });
|
||||
} else {
|
||||
result = await rewardItems(roleId, goodInfo, field, {id: goods.gid, cnt: goods.count });
|
||||
result = await rewardItems(roleId, roleName, goodInfo, type, {id: goods.gid, cnt: goods.count });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,20 +77,22 @@ async function rewardWeapons (roleId: string, roleName: string, dicGood: any, w
|
||||
}
|
||||
|
||||
// 消耗品
|
||||
async function rewardItems (roleId: string, dicGood: any, field: string, data: {id:number,cnt:number }) {
|
||||
async function rewardItems (roleId: string, roleName: string, dicGood: any, type: number, data: {id:number,cnt:number }) {
|
||||
|
||||
let goods = new Array();
|
||||
let {id, cnt} = data;
|
||||
|
||||
let result = await RoleModel.addItems(roleId, field, id, cnt);
|
||||
let result = await ItemModel.increaseItem(roleId, id, cnt, {roleId, roleName, itemName: dicGood.name, id, type, hid: dicGood.hid||0});
|
||||
|
||||
goods.push({
|
||||
id: id,
|
||||
name: dicGood.name,
|
||||
count: cnt,
|
||||
type: dicGood.goodType,
|
||||
isCurrency: false
|
||||
});
|
||||
if(result) {
|
||||
goods.push({
|
||||
id: id,
|
||||
name: dicGood.name,
|
||||
count: cnt,
|
||||
type: dicGood.goodType,
|
||||
isCurrency: false
|
||||
});
|
||||
}
|
||||
return goods;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
*/
|
||||
|
||||
import { BattleDropModel } from '../db/BattleDrop';
|
||||
import { getWarById, getBluePrtByQuality } from '../pubUtils/gamedata';
|
||||
import { getWarById, getBluePrtByQuality, getGamedata } from '../pubUtils/gamedata';
|
||||
import { decodeStr, getRefTime, getRandomWithWeight, getRandomByLen } from '../pubUtils/util';
|
||||
import { BATTLE_REWARD_TYPE, BLUEPRT_CONST, BLUEPRT_CHANCE } from '../consts/consts';
|
||||
import { BATTLE_REWARD_TYPE, BLUEPRT_CONST } from '../consts/consts';
|
||||
import { handleReward } from './rewardService';
|
||||
import { BattleBlueprtDropModel } from '../db/BattleBlueprtDrop'
|
||||
import { RoleModel } from '../db/Role';
|
||||
@@ -127,7 +127,6 @@ export class WarReward {
|
||||
}
|
||||
|
||||
private async handlerBlueprtReward(num: number) {
|
||||
|
||||
const refTime = getRefTime(new Date(), BLUEPRT_CONST.REFRESH_TIME);
|
||||
const battleBlueprtDrop = await BattleBlueprtDropModel.findByTime(this.roleId, refTime);
|
||||
if(battleBlueprtDrop) {
|
||||
@@ -164,10 +163,12 @@ export class WarReward {
|
||||
|
||||
private async randomBlueprt() {
|
||||
const { lv } = await RoleModel.findByRoleId(this.roleId);
|
||||
const result = BLUEPRT_CHANCE.find(cur => {return cur.min <= lv && cur.max >= lv});
|
||||
const dicPossibility = getGamedata('dic_blueprt_possibility');
|
||||
|
||||
const result = dicPossibility.find(cur => {return cur.min <= lv && cur.max >= lv});
|
||||
|
||||
if(result) {
|
||||
const dicOdds = decodeStr('possibility', result.chance);
|
||||
const dicOdds = decodeStr('possibility', result.possibility);
|
||||
const {dic: {id}} = getRandomWithWeight(dicOdds);
|
||||
|
||||
const blueprtList = getBluePrtByQuality(id);
|
||||
|
||||
Reference in New Issue
Block a user