助战:神像强化暴击逻辑
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import { ITID, CONSUME_TYPE, ITEM_TABLE, REDIS_KEY, TASK_TYPE, CURRENCY, CURRENCY_TYPE, MAIL_TYPE, HANDLE_REWARD_TYPE, HERO_SYSTEM_TYPE } from './../consts';
|
||||
import { ITID, CONSUME_TYPE, ITEM_TABLE, REDIS_KEY, TASK_TYPE, CURRENCY, CURRENCY_TYPE, MAIL_TYPE, HANDLE_REWARD_TYPE, HERO_SYSTEM_TYPE, CURRENCY_BY_TYPE } from './../consts';
|
||||
import { EquipModel, EquipType } from './../db/Equip';
|
||||
import { resResult } from '../pubUtils/util';
|
||||
import { RoleModel, RoleType } from '../db/Role';
|
||||
import { setAp } from './actionPointService';
|
||||
import { pushCalPlayerCe, pushCalAllHeroCe, calPlayerCeAndSave } from './playerCeService';
|
||||
import { ItemModel } from '../db/Item';
|
||||
import { ItemModel, ItemType } from '../db/Item';
|
||||
import { STATUS } from '../consts/statusCode';
|
||||
import { pinus } from 'pinus';
|
||||
import { addEquips, addBags, addSkin, addFigure, unlockFigure as pubUnlockFigure, createHeroes as pubCreateHeroes, transPiece, getGoldObject, getCoinObject, getApObject } from '../pubUtils/itemUtils';
|
||||
@@ -22,6 +22,72 @@ import { BAG } from '../pubUtils/dicParam';
|
||||
import { sendMailByContent } from './mailService';
|
||||
import { calEquipSeids } from '../pubUtils/playerCe';
|
||||
|
||||
export class CheckMeterial {
|
||||
private roleId: string;
|
||||
private itemsIndb: Map<number, number> = new Map(); // 玩家已有的东西
|
||||
private consumes: ItemInter[] = []; // 消耗,正向数
|
||||
|
||||
private goldId = CURRENCY_BY_TYPE.get(CURRENCY_TYPE.GOLD);
|
||||
private coinId = CURRENCY_BY_TYPE.get(CURRENCY_TYPE.COIN);
|
||||
|
||||
constructor(roleId: string, role?: RoleType, items?: ItemType[]) {
|
||||
this.roleId = roleId;
|
||||
if(role) {
|
||||
this.itemsIndb.set(this.goldId, role.gold);
|
||||
this.itemsIndb.set(this.coinId, role.coin);
|
||||
}
|
||||
if(items && items.length) {
|
||||
for(let {id, count} of items) {
|
||||
this.itemsIndb.set(id, count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async decrease(goods: {id: number, count: number}[]) {
|
||||
let { items, gold, coin } = sortItems(goods, HANDLE_REWARD_TYPE.COST);
|
||||
let isEnough = true;
|
||||
for(let { id, count} of items) {
|
||||
if(!this.itemsIndb.has(id)) {
|
||||
let item = await ItemModel.findbyRoleAndGidAndCount(this.roleId, id, count);
|
||||
if(!item) {
|
||||
isEnough = false; break;
|
||||
}
|
||||
this.itemsIndb.set(id, item.count);
|
||||
}
|
||||
if(this.itemsIndb.get(id) < count) {
|
||||
isEnough = false; break;
|
||||
}
|
||||
this.itemsIndb.set(id, this.itemsIndb.get(id) - count);
|
||||
}
|
||||
|
||||
if(gold.length > 0) {
|
||||
if(!this.itemsIndb.has(this.goldId)) {
|
||||
let role = await RoleModel.findByRoleId(this.roleId, 'gold coin');
|
||||
this.itemsIndb.set(this.goldId, role.gold);
|
||||
this.itemsIndb.set(this.coinId, role.coin);
|
||||
}
|
||||
let goldCost = gold.reduce((pre, cur) => { return pre + cur.count }, 0);
|
||||
if(this.itemsIndb.get(this.goldId) < goldCost) isEnough = false;
|
||||
}
|
||||
if(isEnough && coin > 0) {
|
||||
if(!this.itemsIndb.has(this.coinId)) {
|
||||
let role = await RoleModel.findByRoleId(this.roleId, 'gold coin');
|
||||
this.itemsIndb.set(this.goldId, role.gold);
|
||||
this.itemsIndb.set(this.coinId, role.coin);
|
||||
}
|
||||
if(this.itemsIndb.get(this.coinId) < coin) isEnough = false;
|
||||
}
|
||||
|
||||
if(isEnough) this.consumes.push(...goods);
|
||||
return isEnough;
|
||||
}
|
||||
|
||||
public getConsume() {
|
||||
return this.consumes;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export async function handleCost(roleId: string, sid: string, goods: Array<ItemInter>) {
|
||||
|
||||
let uids = [{ uid: roleId, sid }];
|
||||
|
||||
Reference in New Issue
Block a user