创建初始装备
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
|
||||
|
||||
import { HeroModel, EPlace } from '../db/Hero';
|
||||
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 { EquipModel, RandSe, Holes } from './../db/Equip';
|
||||
import { BagInter, EquipInter } from './interface';
|
||||
import { gameData } from './data';
|
||||
import { EQUIP_TYPE } from '../consts';
|
||||
import { RANDOM_SE_COUNT, FIX_ATTRIBUTES_RAN, ITID } from '../consts';
|
||||
import { getRandomByLen } from './util';
|
||||
|
||||
const _ = require('underscore');
|
||||
|
||||
@@ -32,7 +31,33 @@ export async function addBags(roleId: string, roleName: string, data: BagInter)
|
||||
}
|
||||
|
||||
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);
|
||||
let { id, name, quality, suitId, hole, randomEffect, itid } = weapon;
|
||||
let {type} = ITID.get(itid);
|
||||
console.log(itid, type)
|
||||
let randomNum = RANDOM_SE_COUNT.get(quality);
|
||||
let pool = randomEffect.map(cur => gameData.randomEffectPool.get(cur));
|
||||
let chosen = new Array<number>();
|
||||
let randSe = new Array<RandSe>();
|
||||
for(let i = 0; i < randomNum; i++) {
|
||||
pool = pool.filter(cur => !chosen.includes(cur.id));
|
||||
let random = getRandomByLen(pool);
|
||||
if(!random) break;
|
||||
chosen.push(random.id);
|
||||
let rand = 0;
|
||||
if(random.id > 0) rand = Math.floor(Math.random() * (random.max - random.min) + random.min);
|
||||
randSe.push({
|
||||
id: i + 1,
|
||||
seid: random.id,
|
||||
rand,
|
||||
locked: false
|
||||
});
|
||||
}
|
||||
let randRange = Math.floor(Math.random() * FIX_ATTRIBUTES_RAN);
|
||||
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});
|
||||
return equip
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user