38 lines
1.4 KiB
TypeScript
38 lines
1.4 KiB
TypeScript
|
|
|
|
import { HeroModel } from '../db/Hero';
|
|
import { ItemModel } from '../db/Item';
|
|
import { EquipModel } from './../db/Equip';
|
|
import { CounterModel } from './../db/Counter';
|
|
import { COUNTER } from './../consts/consts';
|
|
import { BagInter, EquipInter } from './interface';
|
|
import { gameData } from './data';
|
|
|
|
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) {
|
|
const seqId = await CounterModel.getNewCounter(COUNTER.EID);
|
|
let equip = Object.assign({ seqId, roleId, roleName }, weapon);
|
|
return await EquipModel.createEquip(equip);
|
|
}
|