import { HeroModel } from '../db/Hero'; import { ItemModel } from '../db/Item'; import { EquipModel, RandSe, Holes } from './../db/Equip'; import { BagInter, EquipInter } from './interface'; import { gameData } from './data'; import { RANDOM_SE_COUNT, FIX_ATTRIBUTES_RAN, ITID, CURRENCY_BY_TYPE, CURRENCY_TYPE } from '../consts'; import { getRandValueByMinMax, getRandEelm } from './util'; import { findWhere } from 'underscore'; export async function addSkins(roleId: string, id: number) { let skinInfo = gameData.fashion.get(id); if (!skinInfo) return false; let hero = await HeroModel.findByHidAndRole(skinInfo.actorId, roleId); if (!hero) return false; if (!!findWhere(hero.skins, { id })) return false; hero.skins.push({ id, enable: false }); await HeroModel.updateHeroInfo(roleId, hero.hid, hero); return { skins: hero.skins, hid: hero.hid }; } export async function addBags(roleId: string, roleName: string, data: BagInter) { let { id, count, itemName, type, hid } = data; let item = await ItemModel.increaseItem(roleId, id, count, { roleId, roleName, itemName, id, type, hid }); return { id: item.id, count: item.count }; } export async function addEquips(roleId: string, roleName: string, weapon: EquipInter) { let { id, name, quality, suitId, hole, randomEffect, itid, hid } = weapon; let {type} = ITID.get(itid); let randomNum = RANDOM_SE_COUNT.get(quality); let randomResult: number[] = getRandEelm(randomEffect, randomNum); let randSe: Array = randomResult.map((id: number, i: number) => { let random = gameData.randomEffectPool.get(id) let rand = 0; if(random.id > 0) rand = getRandValueByMinMax(random.Min, random.Max, 0); return { id: i + 1, seid: random.id, rand, locked: false }; }); let randRange = getRandValueByMinMax(0 - FIX_ATTRIBUTES_RAN, FIX_ATTRIBUTES_RAN, 0); let holes = new Array(); for(let i = 0; i < hole; i++) { holes.push({id: i+1, isOpen: false, jewel: 0}) } const equip = await EquipModel.createEquip({roleId, roleName, id, name, quality, suitId, randRange, ePlaceId: type, randSe, holes, hid}); return equip } /** * @description 获取元宝物品 { id, count } * @param count 元宝数量 */ export function getGoldObject(count: number) { return { id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.GOLD), count}; }