62 lines
2.2 KiB
TypeScript
62 lines
2.2 KiB
TypeScript
|
|
|
|
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 } from '../consts';
|
|
import { getRandValueByMinMax, getRandEelm } from './util';
|
|
|
|
const _ = require('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, false);
|
|
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<RandSe> = 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<Holes>();
|
|
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
|
|
}
|