合成藏宝图,消耗品单独开表

This commit is contained in:
luying
2020-11-25 20:31:42 +08:00
parent 3f3c716dc6
commit 169ba8cea7
17 changed files with 282 additions and 215 deletions

View File

@@ -32,12 +32,21 @@ export const IT_TYPE = {
BLUEPRT: 28
}
// 大类型,区分存到哪张表里
export const GOOD_TYPE = {
EQUIP: 1,
CONSUMES: 2,
SCRIPT: 3
};
// 存到消耗品表内显示的类型
export const CONSUME_TYPE = {
CONSUME: 1, // 消耗品
SOUL: 2, // 将魂
BLUEPRT: 3, // 藏宝图
POINT: 4 // 远征币等
};
const itid_array = [
{ id: 1, name: '剑', goodType: GOOD_TYPE.EQUIP },
{ id: 2, name: '枪', goodType: GOOD_TYPE.EQUIP },
@@ -60,20 +69,21 @@ const itid_array = [
{ id: 19, name: '战靴', goodType: GOOD_TYPE.EQUIP },
{ id: 20, name: '布鞋', goodType: GOOD_TYPE.EQUIP },
{ id: 21, name: '饰品', goodType: GOOD_TYPE.EQUIP },
{ id: 22, name: '消耗类物品(图纸类)', goodType: GOOD_TYPE.CONSUMES, field: "consumeGoods" },
{ id: 23, name: '消耗类物品(材料类)', goodType: GOOD_TYPE.CONSUMES, field: "consumeGoods" },
{ id: 24, name: '消耗类物品(宝箱类)', goodType: GOOD_TYPE.CONSUMES, field: "consumeGoods" },
{ id: 26, name: '武将碎片', goodType: GOOD_TYPE.CONSUMES, field: "souls" },
{ id: 27, name: '货币', goodType: GOOD_TYPE.CONSUMES, field: "currency", isCurrency: true },
{ id: 28, name: '藏宝图', goodType: GOOD_TYPE.CONSUMES, field: "consumeGoods" },
{ id: 22, name: '消耗类物品(图纸类)', goodType: GOOD_TYPE.CONSUMES, type: CONSUME_TYPE.CONSUME },
{ id: 23, name: '消耗类物品(材料类)', goodType: GOOD_TYPE.CONSUMES, type: CONSUME_TYPE.CONSUME },
{ id: 24, name: '消耗类物品(宝箱类)', goodType: GOOD_TYPE.CONSUMES, type: CONSUME_TYPE.CONSUME },
{ id: 26, name: '武将碎片', goodType: GOOD_TYPE.CONSUMES, type: CONSUME_TYPE.SOUL },
{ id: 27, name: '货币', goodType: GOOD_TYPE.CONSUMES, isCurrency: true },
{ id: 28, name: '藏宝图', goodType: GOOD_TYPE.CONSUMES, type: CONSUME_TYPE.BLUEPRT },
{ id: 29, name: '礼器', goodType: GOOD_TYPE.EQUIP },
{ id: 30, name: '宝甲', goodType: GOOD_TYPE.EQUIP },
{ id: 31, name: '名驹', goodType: GOOD_TYPE.EQUIP },
{ id: 32, name: '典籍', goodType: GOOD_TYPE.EQUIP },
{ id: 33, name: '神兵', goodType: GOOD_TYPE.EQUIP }
{ id: 33, name: '神兵', goodType: GOOD_TYPE.EQUIP },
{ id: 34, name: '代币', goodType: GOOD_TYPE.CONSUMES, type: CONSUME_TYPE.POINT }
];
export const ITID = new Map<number, {id: number, name: string, goodType: number, field?: string, isCurrency?: boolean}>();
export const ITID = new Map<number, {id: number, name: string, goodType: number, type?: number, isCurrency?: boolean}>();
for(let obj of itid_array) {
ITID.set(obj.id, obj);
}
@@ -81,17 +91,25 @@ for(let obj of itid_array) {
export const CURRENCY_TYPE = {
GOLD: "gold",
COIN: "coin",
ACTION_POINT: "ap"
ACTION_POINT: "ap",
TREASURE_POINT: "treasurePoint",
EXPEDITION_POINT: "expeditionPoint",
DUNGEON_POINT: "dungeonPoint"
}
const currencyArr = [
{ "gid": 31001, "name": "铜钱", "type": CURRENCY_TYPE.COIN },
{ "gid": 31002, "name": "元宝", "type": CURRENCY_TYPE.GOLD },
{ "gid": 31003, "name": "体力", "type": CURRENCY_TYPE.ACTION_POINT },
{ "gid": 40001, "name": "远征币", "type": CURRENCY_TYPE.EXPEDITION_POINT },
{ "gid": 40002, "name": "寻宝币", "type": CURRENCY_TYPE.TREASURE_POINT },
{ "gid": 40003, "name": "秘境币", "type": CURRENCY_TYPE.DUNGEON_POINT },
];
export const CURRENCY = new Map<number, {gid: number, name: string, type: string}>();
export const CURRENCY_BY_TYPE = new Map<string, number>();
for(let obj of currencyArr) {
CURRENCY.set(obj.gid, obj);
CURRENCY_BY_TYPE.set(obj.type, obj.gid);
}
export const WAR_TYPE = {
@@ -117,14 +135,6 @@ export const BLUEPRT_CONST = {
PER_AP: 15 // 每多少体力掉落1张藏宝图
};
// 藏宝图概率
export const BLUEPRT_CHANCE = [
{min: 20, max: 40, chance: "1&100"},
{min: 41, max: 60, chance: "1&70|2&30"},
{min: 61, max: 80, chance: "2&70|3&30"},
{min: 81, max: 100, chance: "2&60|3&40"}
];
// 事件,是否开启保存随机记录方式
export const EVENT_RANDOM_TYPE_ONE_OPEN = false;
// 奇遇事件每次刷新几个
@@ -243,7 +253,8 @@ export const GOLD_COST_RATIO = {
"TOWER_HANG_SPDUP": { "A": 0, "B": 50 }, // 天梯挂机加速花费
"TOWER_TASK_REF": { "A": 0, "B": 50 }, // 天梯派遣刷新花费
"DAILY_REF_NUM": { "A": 50, "B": 0 }, // 每日购买次数花费
"DUNGRON_BUY_NUM": { "A": 0, "B": 50 } // 秘境购买次数花费
"DUNGRON_BUY_NUM": { "A": 0, "B": 50 }, // 秘境购买次数花费
"BLUEPRT_COMPOSE_COST": { "A": 0, "B": 1000 } // 寻宝合成花费
}
export const EXPRESSION = {

View File

@@ -21,6 +21,7 @@ export const STATUS = {
BATTLE_ID_NOT_MATCH: { code: 20004, simStr: '战斗数据错误' },
BATTLE_STATUS_WRONG: { code: 20005, simStr: '关卡状态错误' },
BATTLE_HERO_NOT_FOUND: { code: 20006, simStr: '使用的武将不存在' },
BATTLE_CONSUMES_NOT_ENOUGH: { code: 20007, simStr: '道具不足' },
// 主线 20100 - 20199
BATTLE_INFO_VALIDATE_ERR: { code: 20101, simStr: '关卡信息不同' },
@@ -96,6 +97,11 @@ export const STATUS = {
COM_BATTLE_DISSMISS_ERR: { code: 20623, simStr: '解散队伍异常' },
COM_BATTLE_NO_RECENT_REC: { code: 20624, simStr: '没有最近的寻宝记录' },
// 共斗藏宝图合成
COM_BLUEPRT_QUALITY_CANNOT_COMPOSE: { code: 20630, simStr: '该品质藏宝图不可合成' },
COM_BLUEPRT_COUNT_ERROR: { code: 20631, simStr: '材料数量不足' },
COM_BLUEPRT_QUALITY_ERROR: { code: 20632, simStr: '品质错误' },
// 秘境 20700 - 20799
DUNGEON_REFRESH_TIMES_LACK: { code: 20701, simStr: '购买次数不足' },
DUNGEON_TIMES_LACK: { code: 20701, simStr: '挑战次数不足' },

View File

@@ -1,55 +0,0 @@
import BaseModel from './BaseModel';
import { index, getModelForClass, prop } from '@typegoose/typegoose';
@index({ roleId: 1, hid: 1 })
@index({ seqId: 1 })
export default class HeroSoul extends BaseModel {
@prop({ required: true })
roleId: string; // 角色 id
@prop({ required: true })
roleName: string; // 角色名称
@prop({ required: true })
soulid: number; // 道具 id
@prop({ required: true })
soulName: string; // 道具名称
@prop({ required: true })
hid: number; // 武将 id
@prop({ required: true })
hName: string; // 武将名称
@prop({ required: true })
seqId: number; // 将魂表自增 id
@prop({ required: true, default: 0 })
count: number; // 道具数量
public static async findbyRole(roleId: string, lean = true) {
const items = await HeroSoulModel.find({ roleId }).lean(lean);
return items;
}
public static async findbyItemid(itemid: number, roleId: string, lean = true) {
const equips = await HeroSoulModel.findOne({ itemid, roleId }).lean(lean);
return equips;
}
public static async changeItemCount(seqId: number, count: number, lean = true) {
const equips = await HeroSoulModel.findOneAndUpdate({ seqId }, {$inc:{count}}).lean(lean);
return equips;
}
public static async createItem(itemInfo: {roleId: string, roleName: string, soulid: number, seqId: number, soulName: string, count: number, hid: number, hName: string}, lean = true) {
const doc = new HeroSoulModel();
const update = Object.assign(doc.toJSON(), itemInfo);
const item = await HeroSoulModel.findOneAndUpdate({ seqId: itemInfo.seqId }, update, {upsert: true, new: true}).lean(lean);
return item;
}
public static async deleteAccount(roleId: string, lean = true) {
let result = await HeroSoulModel.deleteMany({roleId}).lean(lean);
return result||{};
}
}
export const HeroSoulModel = getModelForClass(HeroSoul);

View File

@@ -1,47 +1,59 @@
import BaseModel from './BaseModel';
import { index, getModelForClass, prop } from '@typegoose/typegoose';
@index({ roleId: 1, itemid: 1 })
@index({ roleId: 1, id: 1 })
@index({ seqId: 1 })
export default class Item extends BaseModel {
@prop({ required: true })
@prop({ required: true, default: '' })
roleId: string; // 角色 id
@prop({ required: true })
@prop({ required: true, default: '' })
roleName: string; // 角色名称
@prop({ required: true })
itemid: number; // 道具 id
@prop({ required: true })
type: number; // 装备类型
@prop({ required: true })
itemName: string; // 道具名称
@prop({ required: true })
seqId: number; // 道具表自增 id
@prop({ required: true, default: '' })
id: number; // 道具 id
@prop({ required: true, default: '' })
type: number; // 道具类型
@prop({ required: true, default: '' })
itemName: string; // 道具名称
@prop({ required: true, default: 0 })
count: number; // 道具数量
hid: number; // 将魂武将id其他0
@prop({ required: true })
count: number; // 道具数量
public static async findbyRole(roleId: string, lean = true) {
const items = await ItemModel.find({ roleId }).lean(lean);
const items = await ItemModel.find({ roleId }).select('id count type').lean(lean);
return items;
}
public static async findbyItemid(itemid: number, roleId: string, lean = true) {
const equips = await ItemModel.findOne({ itemid, roleId }).lean(lean);
return equips;
public static async findbyRoleAndGidAndCount(roleId: string, id: number, count: number, lean = true) {
const items = await ItemModel.findOne({ roleId, id, $gte: {count} }).select('id count type').lean(lean);
return items;
}
public static async changeItemCount(seqId: number, count: number, lean = true) {
const equips = await ItemModel.findOneAndUpdate({ seqId }, {$inc:{count}}, {upsert: true, new: true}).lean(lean);
return equips;
}
public static async createItem(itemInfo: {roleId: string, roleName: string, itemid: number, seqId: number, itemName: string, count: number, type: number}, lean = true) {
public static async increaseItem(roleId: string, id: number, count: number, itemInfo: {roleId: string, roleName: string, id: number, itemName: string, type: number, hid?: number }, lean = true) {
const doc = new ItemModel();
const update = Object.assign(doc.toJSON(), itemInfo);
const item = await ItemModel.findOneAndUpdate({ seqId: itemInfo.seqId }, update, {upsert: true, new: true}).lean(lean);
return item;
const setOnInsert = Object.assign(doc.toJSON(), itemInfo);
const equips = await ItemModel.findOneAndUpdate({roleId, id },{$setOnInsert: setOnInsert, $inc: { count }}, {new: true, upsert: true}).lean(lean);
return equips;
}
public static async decreaseItems(roleId: string, items: Array<{id: number, count: number}>, lean = true) {
let wrongItems = new Array<{id: number, count: number}>();
for(let {id, count} of items) {
const rec = await ItemModel.findOneAndUpdate({roleId, id, count: {$gte: count} },{ $inc: { count: -1 * count }}, {new: true}).lean(lean);
if(!rec) {
wrongItems.push({id, count}); break;
}
}
if(wrongItems.length > 0) { // 数量不足
for(let {id, count} of wrongItems) {
await ItemModel.findOneAndUpdate({roleId, id },{ $inc: { count }}, {new: true}).lean(lean);
}
return false
} else {
return true
}
}
public static async deleteAccount(roleId: string, lean = true) {

View File

@@ -89,11 +89,6 @@ export default class Role extends BaseModel {
@prop({ required: true, default: 0 })
frdCnt: number; // 情谊点
@prop({ required: true, default: [] })
consumeGoods: [{ // 消耗品
id: number; // id
count: number; // 数量
}];
@prop({ required: true, default: [] })
souls: [{ // 将魂
id: number; // 武将 id
@@ -233,32 +228,7 @@ export default class Role extends BaseModel {
let result = await RoleModel.deleteMany({roleId}).lean(lean);
return result||{};
}
public static async addItems(roleId: string, field: string, id: number, cnt: number, lean = true) {
try {
let role = await RoleModel.findOne({roleId}).lean(lean);
let item = role?role[field]:[];
let curItem = item.find(cur => cur.id == id);
if(!curItem) {
let addToSet = {};
addToSet[field] = {id, count: cnt};
let result = await RoleModel.findOneAndUpdate({roleId}, { $addToSet: addToSet }, { "new": true, "upsert": true}).lean(lean);
return result;
} else {
let condition = { roleId };
condition[`${field}.id`] = id;
let update = {};
update[`${field}.$.count`] = cnt;
let result = await RoleModel.findOneAndUpdate(condition, { $inc: update }, { "new": true, "upsert": true}).lean(lean);
return result;
}
}catch(e) {
console.error(e)
}
}
public static async addCoin(roleId: string, cnt: number, lean = true) {
let result = await RoleModel.findOneAndUpdate({roleId}, { $inc: {coin: cnt} }, { "new": true, "upsert": true}).lean(lean);
return result;

View File

@@ -1,54 +0,0 @@
import BaseModel from './BaseModel';
import { index, getModelForClass, prop } from '@typegoose/typegoose';
@index({ roleId: 1, itemid: 1 })
@index({ seqId: 1 })
export default class ScriptItem extends BaseModel {
@prop({ required: true })
roleId: string; // 角色 id
@prop({ required: true })
roleName: string; // 角色名称
@prop({ required: true })
itemid: number; // 道具 id
@prop({ required: true })
type: number; // 装备类型
@prop({ required: true })
itemName: string; // 道具名称
@prop({ required: true })
seqId: number; // 道具表自增 id
@prop({ required: true, default: 0 })
count: number; // 道具数量
public static async findbyRole(roleId: string, lean = true) {
const items = await ScriptItemModel.find({ roleId }).lean(lean);
return items;
}
public static async findbyItemid(itemid: number, roleId: string, lean = true) {
const equips = await ScriptItemModel.findOne({ itemid, roleId }).lean(lean);
return equips;
}
public static async changeItemCount(seqId: number, count: number, lean = true) {
const equips = await ScriptItemModel.findOneAndUpdate({ seqId }, {$inc:{count}}, {upsert: true, new: true}).lean(lean);
return equips;
}
public static async createItem(itemInfo: {roleId: string, roleName: string, itemid: number, seqId: number, itemName: string, count: number, type: number}, lean = true) {
const doc = new ScriptItemModel();
const update = Object.assign(doc.toJSON(), itemInfo);
const item = await ScriptItemModel.findOneAndUpdate({ seqId: itemInfo.seqId }, update, {upsert: true, new: true}).lean(lean);
return item;
}
public static async deleteAccount(roleId: string, lean = true) {
let result = await ScriptItemModel.deleteMany({roleId}).lean(lean);
return result||{};
}
}
export const ScriptItemModel = getModelForClass(ScriptItem);

View File

@@ -22,6 +22,7 @@ const btlBossHp = new Map<number, number>();
const blueprtBossHp = new Map<number, number>();
const goodInfo = new Map<number, any>();
const blueprt = new Map<number, Array<number>>();
const blueprtCompose = new Map<number, any>();
function parseWarData() {
let result = null;
@@ -208,6 +209,16 @@ function parseGood() {
});
}
function parseBlueprtCompose() {
const file = 'dic_blueprt_compose';
const data = gamedata['jsons'][file] || [];
data.forEach(elem => {
if (elem && elem.quality) {
blueprtCompose.set(elem.quality, elem);
}
});
}
function initData (folder: string) {
if(!gamedata.hasOwnProperty(folder)) {
gamedata[folder] = {};
@@ -246,6 +257,7 @@ function parseData() {
parseExpedition();
parseComBtlData();
parseGood();
parseBlueprtCompose();
}
initData('jsons'); // 加载一般json
@@ -372,4 +384,8 @@ export function getBossHpByBlueprtId(blueprtId: number) {
}
export function hasExpeditionById(id: number) {
return expeditionInfo.has(id);
}
export function getBlueprtComposeByQuality(quality: number) {
return blueprtCompose.get(quality);
}

View File

@@ -169,7 +169,8 @@ export function decodeIdCntArrayStr(str: string, multi: number) {
return ce;
}
export function getRandomByLen(arr: Array<any>) {
export function getRandomByLen(arr: Array<number>):number
export function getRandomByLen(arr: Array<any>): any {
let len = arr.length;
return arr[Math.floor(Math.random() * len)]
}

View File

@@ -0,0 +1,26 @@
[
{
"quality": 1,
"coinNum": 10,
"blueprtNum": 3,
"targetQuality": 2
},
{
"quality": 2,
"coinNum": 20,
"blueprtNum": 3,
"targetQuality": 3
},
{
"quality": 3,
"coinNum": 30,
"blueprtNum": 3,
"targetQuality": 4
},
{
"quality": 4,
"coinNum": 40,
"blueprtNum": 3,
"targetQuality": 5
}
]

View File

@@ -0,0 +1,22 @@
[
{
"min": 20,
"max": 39,
"possibility": "1&100"
},
{
"min": 40,
"max": 69,
"possibility": "1&70|2&30"
},
{
"min": 60,
"max": 79,
"possibility": "2&70|3&30"
},
{
"min": 80,
"max": 100,
"possibility": "2&60|3&40"
}
]

View File

@@ -23152,5 +23152,39 @@
"specialAttr": 0,
"__EMPTY": 0,
"__EMPTY_1": 0
},
{
"good_id": 40002,
"name": "寻宝币",
"lvLimted": 1,
"quality": 1,
"image_id": 0,
"itid": 34,
"goodType": 2,
"hid": 0,
"hp": 0,
"atk": 0,
"matk": 0,
"def": 0,
"mdef": 0,
"agi": 0,
"luk": 0,
"hp_up": 0,
"atk_up": 0,
"matk_up": 0,
"def_up": 0,
"mdef_up": 0,
"agi_up": 0,
"luk_up": 0,
"hp_up2": 0,
"atk_up2": 0,
"matk_up2": 0,
"def_up2": 0,
"mdef_up2": 0,
"agi_up2": 0,
"luk_up2": 0,
"specialAttr": 0,
"__EMPTY": 0,
"__EMPTY_1": 0
}
]