添加远征每日重置

This commit is contained in:
luying
2020-11-09 17:41:24 +08:00
parent 541e8a391d
commit 7fa9fe99ee
13 changed files with 187 additions and 87 deletions

View File

@@ -133,7 +133,6 @@ export const EVENT_ANSWER_STATUS = {
};
export const EVENT_START_BATTLE = 101;
export const EXPEDITION_INCREASE_POINT = 2; // 远征每成功一次累计的点数
export const HANG_UP_CONSTS = {
ENABLE_LV: 2, // 第几层开始可以挂机
@@ -154,6 +153,12 @@ export const DAILY_CONST = {
REFRESH_TIME: 5
}
export const EXPEDITION_CONST = {
REFRESH_TIME: 5, // 重置次数刷新时间
INCREASE_POINT: 2, // 远征每成功一次累计的点数
RESET_CNT: 1 // 可以免费重置的次数
}
export const WAR_JSON_ATTRIBUTE_TYPE = {
"1": "hp", // 生命
"2": "atk", // 物攻

View File

@@ -48,6 +48,7 @@ export const STATUS = {
EXPEDITION_POINT_NOT_ENOUGH: { code: 20408, simStr: '点数不足' },
EXPEDITION_POINT_RECORD_NOT_FOUND: { code: 20409, simStr: '点数宝箱已刷新' },
EXPEDITION_POINT_NEED_ALL_RECEIVED: { code: 20410, simStr: '宝箱需要领取完才可以刷新' },
EXPEDITION_RESET_NUM_NOT_ENOUGH: { code: 20411, simStr: '重置次数不足'},
// 天梯 20500 - 20599
TOWER_RESET_ERR: { code: 20501, simStr: '只能重置当前层' },
TOWER_INFO_NOT_FOUND: { code: 20502, simStr: '镇念塔层数异常' },

View File

@@ -1,9 +1,10 @@
import BaseModel from './BaseModel';
import { index, getModelForClass, prop } from '@typegoose/typegoose';
import { genCode } from '../pubUtils/util';
class Heroes {
@prop({ required: true })
hid: number; // 敌人id
seqId: number; // 唯一id
@prop({ required: true })
hp: number; // 血量
@prop({ required: true })
@@ -13,7 +14,7 @@ class Heroes {
/**
* 远征记录
*/
@index({ roleId: 1 })
@index({ roleId: 1, status: 1 })
@index({ expeditionCode: 1 })
export default class ExpeditionRecord extends BaseModel {
@@ -24,18 +25,27 @@ export default class ExpeditionRecord extends BaseModel {
@prop({ required: true, default: '' })
expeditionCode: string; // 远征的唯一标识
@prop({ required: true, default: 0 })
time: number; // 时间
myCe: number; // 我方在重置时的战力
@prop({ required: true, type: Heroes, default: [] })
heroes: Array<Heroes>; // 我方已出场武将
@prop({ required: true, default: 1 })
status: number; // 状态 1-显示 0-不显示
public static async getTodayRecord(roleId: string, time: number, lean = true) {
const result = await ExpeditionRecordModel.findOne({ roleId, time }).lean(lean);
public static async getCurRecord(roleId: string, lean = true) {
const result = await ExpeditionRecordModel.findOne({ roleId, status: 1 }).lean(lean);
return result;
}
public static async createTodayRecord(expeditionCode: string, params: { roleId: string, roleName: string, time: number, heroes: Array<Heroes> }, lean = true) {
const result = await ExpeditionRecordModel.findOneAndUpdate({ expeditionCode }, params, { new: true, upsert: true }).lean(lean);
public static async createRecord(params: { roleId: string, roleName: string, heroes: Array<{seqId: number, hp: number, ap: number}>, myCe: number }, lean = true) {
const code = genCode(8);
const result = await ExpeditionRecordModel.findOneAndUpdate({ expeditionCode: code }, {...params, status: 1}, { new: true, upsert: true }).lean(lean);
return result;
}
public static async hideRecord(roleId: string, lean = true) {
const result = await ExpeditionRecordModel.findOneAndUpdate({ roleId, status: 1 }, { status: 0 }, { new: true }).lean(lean);
return result;
}
@@ -44,22 +54,22 @@ export default class ExpeditionRecord extends BaseModel {
return result
}
public static async updateHeroStatus(expeditionCode: string, oldHeroes: Array<Heroes>, heroes: Array<{actorId: number, hp: number, ap: number}>, lean=true) {
public static async updateHeroStatus(expeditionCode: string, oldHeroes: Array<Heroes>, heroes: Array<{dataId: number, hp: number, ap: number}>, lean=true) {
let pushArr = new Array(), updateArr = new Array();
for(let hero of heroes) {
let {actorId, hp, ap} = hero;
let obj = oldHeroes.find(cur => cur.hid == actorId);
let {dataId, hp, ap} = hero;
let obj = oldHeroes.find(cur => cur.seqId == dataId);
if(!!obj) {
updateArr.push({hid: actorId, hp, ap});
updateArr.push({seqId: dataId, hp, ap});
} else {
pushArr.push({hid: actorId, hp, ap})
pushArr.push({seqId: dataId, hp, ap})
}
}
for(let {hid, hp, ap} of updateArr) {
for(let {seqId, hp, ap} of updateArr) {
await ExpeditionRecordModel.findOneAndUpdate(
{expeditionCode, 'heroes.hid': hid },
{$set: {'heroes.$.hid': hid, 'heroes.$.hp': hp, 'heroes.$.ap': ap}}
{expeditionCode, 'heroes.seqId': seqId },
{$set: {'heroes.$.seqId': seqId, 'heroes.$.hp': hp, 'heroes.$.ap': ap}}
)
}
const result = await ExpeditionRecordModel.findOneAndUpdate(

View File

@@ -57,6 +57,10 @@ export default class Hero extends BaseModel {
return heros || [];
}
public static async findBySeqIdAndRole(seqId: number, roleId: string, lean = true) {
const hero = await HeroModel.findOne({ seqId, roleId }).lean(lean);
return hero;
}
public static async findByHidAndRole(hid: number, roleId: string, lean = true) {
const hero = await HeroModel.findOne({ hid, roleId }).lean(lean);
return hero;

View File

@@ -114,11 +114,17 @@ export default class Role extends BaseModel {
@prop({ required: true, default: new Date()})
towerTaskRefTime: Date; // 刷新派遣任务的时间
@prop({ required: true })
// 奇遇事件相关
@prop({ required: true, default: 0 })
eventStatus: number; // 奇遇开启状态, 0-未开启 1-开启了第一场事件 2-完全开启
@prop({ required: true })
// 远征相关
@prop({ required: true, default: 0 })
expeditionPoint: number; // 远征点数
@prop({ required: true, default: 0 })
expeditionResetCnt: number; // 远征重置次数
@prop({ required: true, default: new Date() })
expeditionResetRefTime: Date; // 远征重置次数刷新时间
public static async findByUid(uid: number, serverId: number, lean = true) {
@@ -250,13 +256,25 @@ export default class Role extends BaseModel {
let role = null;
if (needRefresh) {
role = await RoleModel.findOneAndUpdate({roleId}, {towerTaskReCnt: 0, towerTaskRefTime: curTime}, {new: true}).lean(lean);
role = await RoleModel.findOneAndUpdate({roleId}, {towerTaskReCnt: 1, towerTaskRefTime: curTime}, {new: true}).lean(lean);
} else {
role = await RoleModel.findOneAndUpdate({roleId}, {$inc: {towerTaskReCnt: 1}}, {new: true}).lean(lean);
}
return role;
}
// 刷新远征重置次数
public static async increaseExpeditionResetCnt(roleId: string, needRefresh: boolean, curTime: Date, lean = true) {
let role = null;
if (needRefresh) {
role = await RoleModel.findOneAndUpdate({roleId}, {expeditionResetCnt: 1, expeditionResetRefTime: curTime}, {new: true}).lean(lean);
} else {
role = await RoleModel.findOneAndUpdate({roleId}, {$inc: {expeditionResetCnt: 1}}, {new: true}).lean(lean);
}
return role;
}
// 获取排行榜
public static async getRank(type: string, fields: Array<string>, page = 1, limit = 100, lean = true) {
let sortBy = {};

View File

@@ -1,13 +1,11 @@
import fs = require('fs');
import path = require('path');
import { decodeStr, decodeStrSingle } from './util';
let gamedata = {};
const wars = ['dic_zyz_gk_main', 'dic_zyz_gk_mainElite', 'dic_zyz_gk_daily', 'dic_zyz_gk_event', 'dic_zyz_gk_tower', 'dic_zyz_gk_expedition']; // 关卡相关的表
const allWarInfos = new Map<number, any>();
const towerInfos = new Map<number, any>();
const towerTaskInfos = new Map<number, any>();
const towerTasksByFloor = new Map<number, Array<number>>();
const heroInfos = new Map<number, any>();
const jobInfos = new Map<number, any>();
const levelInfos = new Map<number, {sum: number, cur: number}>();
@@ -41,9 +39,6 @@ function parseTowerTaskData() {
towerTaskData.forEach(elem => {
if (elem && elem.taskId) {
towerTaskInfos.set(elem.taskId, elem);
let tasks = towerTasksByFloor.get(elem.suitFloor) || [];
tasks.push(elem.taskId);
towerTasksByFloor.set(elem.suitFloor, tasks);
}
});
}
@@ -154,11 +149,6 @@ export function getTaskById(tid: number) {
return taskInfo;
}
export function getTaskIdByFloor(floor: number) {
const taskIds = towerTasksByFloor.get(floor);
return taskIds;
}
export function getHeroInfoById(hid: number) {
const heroInfo = heroInfos.get(hid);
return heroInfo;

View File

@@ -8,7 +8,7 @@
"termsForAdd": "1&2&2|2&2&1|3&1&1",
"actorNeeded": 2,
"completeTime": 60,
"suitFloor": 1,
"suitFloor": "1&",
"weight": 1
},
{
@@ -20,7 +20,7 @@
"termsForAdd": "2&1&1|3&2&1",
"actorNeeded": 2,
"completeTime": 60,
"suitFloor": 1,
"suitFloor": "1&",
"weight": 1
},
{
@@ -32,7 +32,7 @@
"termsForAdd": "2&3&1|3&3&1",
"actorNeeded": 2,
"completeTime": 60,
"suitFloor": 1,
"suitFloor": "1&",
"weight": 1
},
{
@@ -44,7 +44,7 @@
"termsForAdd": "2&4&1|3&4&1",
"actorNeeded": 2,
"completeTime": 60,
"suitFloor": 1,
"suitFloor": "1&",
"weight": 1
},
{
@@ -56,7 +56,7 @@
"termsForAdd": "1&1&1|2&4&1|3&5&1",
"actorNeeded": 2,
"completeTime": 60,
"suitFloor": 1,
"suitFloor": "1&",
"weight": 1
},
{
@@ -68,7 +68,7 @@
"termsForAdd": "3&6&1",
"actorNeeded": 2,
"completeTime": 60,
"suitFloor": 1,
"suitFloor": "1&",
"weight": 1
},
{
@@ -80,7 +80,7 @@
"termsForAdd": "3&7&1",
"actorNeeded": 2,
"completeTime": 60,
"suitFloor": 1,
"suitFloor": "1&",
"weight": 1
},
{
@@ -92,7 +92,7 @@
"termsForAdd": "3&8&2",
"actorNeeded": 3,
"completeTime": 60,
"suitFloor": 1,
"suitFloor": "10&",
"weight": 1
},
{
@@ -104,7 +104,7 @@
"termsForAdd": "1&1&1|2&1&1|3&1&1",
"actorNeeded": 3,
"completeTime": 60,
"suitFloor": 1,
"suitFloor": "10&",
"weight": 1
},
{
@@ -116,7 +116,7 @@
"termsForAdd": "1&2&1|2&2&1|3&2&1",
"actorNeeded": 3,
"completeTime": 120,
"suitFloor": 1,
"suitFloor": "10&",
"weight": 1
},
{
@@ -128,7 +128,7 @@
"termsForAdd": "1&1&1|2&3&1|3&3&1",
"actorNeeded": 3,
"completeTime": 120,
"suitFloor": 1,
"suitFloor": "10&",
"weight": 1
},
{
@@ -140,7 +140,7 @@
"termsForAdd": "1&2&1|2&4&1|3&4&1",
"actorNeeded": 3,
"completeTime": 120,
"suitFloor": 1,
"suitFloor": "10&",
"weight": 1
},
{
@@ -152,7 +152,7 @@
"termsForAdd": "1&1&1|2&1&1|3&5&1",
"actorNeeded": 3,
"completeTime": 120,
"suitFloor": 1,
"suitFloor": "10&",
"weight": 1
},
{
@@ -164,7 +164,7 @@
"termsForAdd": "1&2&1|2&2&1|3&6&1",
"actorNeeded": 3,
"completeTime": 120,
"suitFloor": 1,
"suitFloor": "10&",
"weight": 1
},
{
@@ -176,7 +176,7 @@
"termsForAdd": "1&1&1|2&3&1|3&7&1",
"actorNeeded": 3,
"completeTime": 120,
"suitFloor": 1,
"suitFloor": "10&",
"weight": 1
}
]