创建初始装备
This commit is contained in:
@@ -25,6 +25,7 @@ import { dicFriendShipLevel, dicFriendShipLevelMap } from "./dictionary/DicFrien
|
||||
import { dicHeroQualityUp } from "./dictionary/DicHeroQualityUp";
|
||||
import { dicHeroStar } from "./dictionary/DicHeroStar";
|
||||
import { dicHeroWake } from "./dictionary/DicHeroWake";
|
||||
import { dicRandomEffectPool } from './dictionary/DicRandomEffectPool';
|
||||
|
||||
export const gameData = {
|
||||
blurprtCompose: dicBlueprtCompose,
|
||||
@@ -60,7 +61,8 @@ export const gameData = {
|
||||
friendShips: friendShips,
|
||||
friendShipHidAandIds: friendShipHidAandIds,
|
||||
friendShipLevel: dicFriendShipLevel,
|
||||
friendShipLevelMap: dicFriendShipLevelMap
|
||||
friendShipLevelMap: dicFriendShipLevelMap,
|
||||
randomEffectPool: dicRandomEffectPool,
|
||||
};
|
||||
|
||||
// 在此提供一些原先在gamedata中提供的方法,以便更方便获取gameData数据
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// 物品表
|
||||
import {decodeArrayListStr, readJsonFile, parseReward} from '../util'
|
||||
import {decodeArrayListStr, readJsonFile, parseReward, parseNumberList, decodeArrayStr} from '../util'
|
||||
import { FILENAME, IT_TYPE, ABI_TYPE } from '../../consts'
|
||||
import { RewardInter } from '../interface';
|
||||
const _ = require('lodash');
|
||||
@@ -15,12 +15,17 @@ export interface DicGoods {
|
||||
readonly pieces: number;
|
||||
// 合成材料
|
||||
readonly composeMaterial: Array<RewardInter>;
|
||||
// 特殊材料
|
||||
readonly specialMaterial: Array<{id: number[], count: number}>;
|
||||
// 分解所得
|
||||
readonly decomposeItem: Array<RewardInter>;
|
||||
// 物品品质
|
||||
readonly quality: number;
|
||||
// 洞数
|
||||
readonly hole: number;
|
||||
// 随机属性范围
|
||||
readonly randomEffect: Array<number>;
|
||||
|
||||
// 类型id
|
||||
readonly itid: number;
|
||||
// 物品类型
|
||||
@@ -32,7 +37,7 @@ export interface DicGoods {
|
||||
// 强化属性
|
||||
readonly goodsAbilityUp:Map<number, number>;
|
||||
// 套装id
|
||||
readonly setid: number;
|
||||
readonly suitId: number;
|
||||
// 特殊属性
|
||||
readonly specialAttr: Map<number, number>;
|
||||
// 属性外加的值,经验,好感
|
||||
@@ -44,7 +49,26 @@ const str = readJsonFile(FILENAME.DIC_GOODS);
|
||||
let arr = JSON.parse(str);
|
||||
|
||||
type KeysEnum<T> = { [P in keyof Required<T>]: true };
|
||||
const DicGoodsKeys: KeysEnum<DicGoods> = {good_id: true, name: true, lvLimted: true, pieces: true, composeMaterial: true, decomposeItem: true, quality: true, hole: true, itid: true, goodType: true, hid: true, goodsAbility: true, goodsAbilityUp: true, setid: true, specialAttr: true, value: true }
|
||||
const DicGoodsKeys: KeysEnum<DicGoods> = {
|
||||
good_id: true,
|
||||
name: true,
|
||||
lvLimted: true,
|
||||
pieces: true,
|
||||
composeMaterial: true,
|
||||
specialMaterial: true,
|
||||
decomposeItem: true,
|
||||
quality: true,
|
||||
hole: true,
|
||||
randomEffect: true,
|
||||
itid: true,
|
||||
goodType: true,
|
||||
hid: true,
|
||||
goodsAbility: true,
|
||||
goodsAbilityUp: true,
|
||||
suitId: true,
|
||||
specialAttr: true,
|
||||
value: true
|
||||
}
|
||||
|
||||
export const dicGoods = new Map<number, DicGoods>();
|
||||
export const blueprt = new Map<number, Array<number>>();
|
||||
@@ -55,6 +79,8 @@ arr.forEach(o => {
|
||||
o.composeMaterial = parseReward(o.composeMaterial);
|
||||
o.decomposeItem = parseReward(o.decomposeItem);
|
||||
o.specialAttr = parseSpecialAttr(o.specialAttr);
|
||||
o.specialMaterial = parseSpecialMaterial(o.specialMaterial);
|
||||
o.randomEffect = parseNumberList(o.randomEffect);
|
||||
dicGoods.set(o.good_id, _.pick(o, Object.keys(DicGoodsKeys)));
|
||||
|
||||
if(o.itid == IT_TYPE.BLUEPRT) {
|
||||
@@ -104,4 +130,18 @@ function parseAbilityUp(json) {
|
||||
map.set(ABI_TYPE.ABI_LUK, json.luk_up||0);
|
||||
map.set(ABI_TYPE.ABI_SPEED, json.speed_up||0);
|
||||
return map
|
||||
}
|
||||
|
||||
function parseSpecialMaterial(str: string) {
|
||||
let specialAttr = new Array<{id: number[], count: number}>();
|
||||
if(str) {
|
||||
let decodeArr = decodeArrayStr(str);
|
||||
if(decodeArr.length >= 2) {
|
||||
let ids = parseNumberList(decodeArr[0]);
|
||||
let count = parseInt(decodeArr[0]);
|
||||
if(isNaN(count)) return specialAttr;
|
||||
specialAttr.push({id: ids, count});
|
||||
}
|
||||
}
|
||||
return specialAttr;
|
||||
}
|
||||
31
shared/pubUtils/dictionary/DicRandomEffectPool.ts
Normal file
31
shared/pubUtils/dictionary/DicRandomEffectPool.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
// 武将特技表
|
||||
import { readJsonFile, parseNumberList } from '../util'
|
||||
import { FILENAME } from '../../consts'
|
||||
|
||||
export interface DicRandomEffectPool {
|
||||
|
||||
// 特技id
|
||||
readonly id: number;
|
||||
// 类型
|
||||
readonly type: number;
|
||||
// 包含的值
|
||||
readonly gainValueArr: Array<number>;
|
||||
// 随机值位置
|
||||
readonly index: number;
|
||||
// 随机最小值
|
||||
readonly min: number;
|
||||
// 随机最大值
|
||||
readonly max: number;
|
||||
|
||||
}
|
||||
|
||||
|
||||
const str = readJsonFile(FILENAME.DIC_RANDOM_EFFECT_POOL);
|
||||
let arr = JSON.parse(str);
|
||||
|
||||
export const dicRandomEffectPool = new Map<number, DicRandomEffectPool>();
|
||||
|
||||
arr.forEach(o => {
|
||||
o.gainValueArr = parseNumberList(o.gainvalue)
|
||||
dicRandomEffectPool.set(o.id, o);
|
||||
});
|
||||
@@ -26,5 +26,15 @@ export interface Attributes {
|
||||
ap?: number;
|
||||
}
|
||||
|
||||
export interface EquipInter {id: number, name: string, quality: number, type: number};
|
||||
export interface EquipInter {
|
||||
id: number;
|
||||
name: string;
|
||||
quality: number;
|
||||
suitId: number;
|
||||
hole: number;
|
||||
randomEffect: Array<number>;
|
||||
itid: number;
|
||||
};
|
||||
|
||||
|
||||
export interface BagInter {id: number, itemName: string, count: number, type: number, hid:number};
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import Actor from './actor';
|
||||
|
||||
import fs = require('fs');
|
||||
import path = require('path');
|
||||
import { DicRandomEffectPool } from './dictionary/DicRandomEffectPool';
|
||||
|
||||
const moment = require('moment');
|
||||
|
||||
@@ -188,6 +189,7 @@ export function decodeIdCntArrayStr(str: string, multi: number) {
|
||||
}
|
||||
|
||||
export function getRandomByLen(arr: Array<number>):number
|
||||
export function getRandomByLen(arr: Array<DicRandomEffectPool>):DicRandomEffectPool
|
||||
export function getRandomByLen(arr: Array<any>): any {
|
||||
let len = arr.length;
|
||||
return arr[Math.floor(Math.random() * len)]
|
||||
|
||||
Reference in New Issue
Block a user