试炼
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Application, BackendSession, pinus } from 'pinus';
|
||||
import { resResult, genCode } from '../../../pubUtils/util';
|
||||
import { resResult, genCode, getRandomByLen } from '../../../pubUtils/util';
|
||||
import { STATUS, GUILD_OPERATE, GUILD_AUTH, GUILD_JOB } from '../../../consts';
|
||||
import { GuildTrainModel } from '../../../db/GuildTrain';
|
||||
import { BattleRecordModel } from '../../../db/BattleRecord';
|
||||
@@ -10,6 +10,10 @@ import { lockData } from '../../../services/redLockService';
|
||||
import { GUILD_DATA_NAME } from '../../../consts/constModules/guildConst';
|
||||
import { UserGuildModel } from '../../../db/UserGuild';
|
||||
import { GuildModel } from '../../../db/Guild';
|
||||
import { getArmyTrainJuDian, getTrainSoloReward, getTrainBaseByLv } from '../../../pubUtils/data';
|
||||
import { CURRENCY_BY_TYPE, CURRENCY_TYPE } from '../../../consts/constModules/itemConst';
|
||||
import { handleCost, addItems } from '../../../services/rewardService';
|
||||
|
||||
export default function (app: Application) {
|
||||
return new GuildTrainHandler(app);
|
||||
}
|
||||
@@ -20,13 +24,13 @@ export class GuildTrainHandler {
|
||||
}
|
||||
|
||||
//获得试炼的详情
|
||||
async getTrainScriptByTrainId(msg: { code: string}, session: BackendSession) {
|
||||
const { code } = msg;
|
||||
async getTrainInstance(msg: {}, session: BackendSession) {
|
||||
const roleId = session.get('roleId');
|
||||
const serverId = session.get('serverId');
|
||||
let userGuild = await getUserGuild(roleId, code);
|
||||
let userGuild = await getUserGuild(roleId);
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
const { guildCode: code } = userGuild;
|
||||
let { trainId } = await GuildModel.findGuild(code, serverId, 'trainId');
|
||||
let trainIds = [trainId];
|
||||
if (trainId - 1 > 0) {
|
||||
@@ -44,65 +48,69 @@ export class GuildTrainHandler {
|
||||
return resResult(STATUS.SUCCESS, result);
|
||||
}
|
||||
|
||||
async trainScriptStart(msg: { code: string, trainId: number, hid: number }, session: BackendSession) {
|
||||
const { code, trainId, hid } = msg;
|
||||
async trainBattleStart(msg: { hid: number, trainId: number, difficulty: number }, session: BackendSession) {
|
||||
const { hid, difficulty, trainId } = msg;
|
||||
const roleId = session.get('roleId');
|
||||
const roleName = session.get('roleName');
|
||||
let userGuild = await getUserGuild(roleId, code);
|
||||
if (!userGuild)
|
||||
const serverId = session.get('serverId');
|
||||
let userGuild = await getUserGuild(roleId);
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
if (userGuild.trainCount > 2) //TODO检查次数
|
||||
const { guildCode: code } = userGuild;
|
||||
if (userGuild.trainCount <= 0)
|
||||
return resResult(STATUS.GUILD_TRAIN_BATTLE_COUNT_NOT_ENOUGH);
|
||||
let guildTrain = await GuildTrainModel.findTrainByTrainIdNotLock(code, trainId, 'trainId isComplete trainScripts');
|
||||
let { trainId: curTeainId } = await GuildModel.findGuild(code, serverId, 'trainId');
|
||||
if (curTeainId !== trainId)
|
||||
return resResult(STATUS.GUILD_TRAIN_LEVEL_IS_COMPLETE);
|
||||
let guildTrain = await GuildTrainModel.findTrainByTrainIdNotLock(code, trainId, 'trainId isComplete trainInstances');
|
||||
if (!guildTrain && guildTrain.isComplete)
|
||||
return resResult(STATUS.GUILD_TRAIN_SCRIPT_NOT_OPENED);
|
||||
let trainScript = findWhere(guildTrain.trainScripts, { hid });
|
||||
if (!trainScript)
|
||||
let { trainInstances } = getArmyTrainJuDian(trainId);
|
||||
let instance = findWhere(trainInstances, { hid });
|
||||
if (!instance)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
let trainInstance = findWhere(guildTrain.trainInstances, { hid });
|
||||
if (!trainInstance)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
//TODO 判断是否压制成功
|
||||
if (trainScript.progress >= 1000) {
|
||||
if (trainInstance.progress >= instance.progress) {
|
||||
return resResult(STATUS.GUILD_TRAIN_IS_COMPLETE);
|
||||
}
|
||||
const battleCode = genCode(8); // 关卡唯一值
|
||||
//TODO查看地图字典
|
||||
let warInfo;
|
||||
let warId;
|
||||
await BattleRecordModel.updateBattleRecordByCode(battleCode, {
|
||||
$set: {
|
||||
roleId, roleName, battleId: warId,
|
||||
roleId, roleName, battleId: instance.warId,
|
||||
status: 0,
|
||||
warName: warInfo.gk_name,
|
||||
warType: warInfo.warType,
|
||||
record: { heroes:[], trainId, hid},
|
||||
record: { heroes:[], trainId, hid, guildCode: code, difficulty},
|
||||
}
|
||||
}, true);
|
||||
return resResult(STATUS.SUCCESS, { battleCode });
|
||||
}
|
||||
|
||||
async trainScriptEnd(msg: { code: string, battleCode: string, isSuccess: boolean}, session: BackendSession) {
|
||||
const { code, battleCode, isSuccess} = msg;
|
||||
async trainBattleEnd(msg: { battleCode: string, isSuccess: boolean}, session: BackendSession) {
|
||||
const { battleCode, isSuccess } = msg;
|
||||
const roleId = session.get('roleId');
|
||||
const serverId = session.get('serverId');
|
||||
const battleRecord = await BattleRecordModel.getBattleRecordByCode(battleCode, true);
|
||||
if(!battleRecord || battleRecord.status != 0 || roleId != battleRecord.roleId) {
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
}
|
||||
let userGuild = await getUserGuild(roleId, code);
|
||||
const roleName = session.get('roleName');
|
||||
const sid = session.get('sid');
|
||||
let userGuild = await getUserGuild(roleId);
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
let time = battleRecord.createdAt.getTime()/1000;
|
||||
const { guildCode: code } = userGuild;
|
||||
const battleRecord = await BattleRecordModel.getBattleRecordByCode(battleCode, true);
|
||||
// if(!battleRecord || battleRecord.status != 0 || roleId != battleRecord.roleId || battleRecord.record.guildCode != code) {
|
||||
// return resResult(STATUS.WRONG_PARMS);
|
||||
// }
|
||||
let time = Math.floor(battleRecord.createdAt.getTime()/1000);
|
||||
// if (userGuild.trainCount - 1 < 0) {
|
||||
// return resResult(STATUS.WRONG_PARMS);
|
||||
// }
|
||||
if (time > getTodayZeroPoint()) {
|
||||
if (userGuild.trainTime > getTodayZeroPoint()) {
|
||||
userGuild = await UserGuildModel.updateInfo(roleId, {trainCount: userGuild.trainCount + 1});
|
||||
} else {
|
||||
userGuild = await UserGuildModel.updateInfo(roleId, {trainCount: 1, trainTime: nowSeconds()});
|
||||
}
|
||||
userGuild = await UserGuildModel.updateInfo(roleId, {trainCount: userGuild.trainCount - 1});
|
||||
}
|
||||
await BattleRecordModel.updateBattleRecordByCode(battleCode, {
|
||||
$set: { status: isSuccess?1:2 }
|
||||
}, true);
|
||||
let guildTrains = [];
|
||||
let trainIds = [];
|
||||
|
||||
let trainId = battleRecord.record.trainId;
|
||||
let hid = battleRecord.record.hid;
|
||||
let res:any = await lockData(serverId, GUILD_DATA_NAME.TRAIN, code + '_' + trainId);//加锁
|
||||
@@ -113,29 +121,39 @@ export class GuildTrainHandler {
|
||||
res.releaseCallback();//解锁
|
||||
return resResult(STATUS.GUILD_TRAIN_SCRIPT_NOT_OPENED);
|
||||
}
|
||||
let trainScript = findWhere(guildTrain.trainScripts,{hid});
|
||||
if (!trainScript)
|
||||
let trainInstance = findWhere(guildTrain.trainInstances, { hid });
|
||||
if (!trainInstance)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
let addScore;
|
||||
//结算奖励 TODO
|
||||
|
||||
|
||||
let { trainInstances } = getArmyTrainJuDian(trainId);
|
||||
let instance = findWhere(trainInstances, { hid });
|
||||
if (!instance)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
let trainSoloReward = getTrainSoloReward(battleRecord.record.difficulty);
|
||||
if (!trainSoloReward)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
let addScore = isSuccess?trainSoloReward.winScore:trainSoloReward.failScore;
|
||||
let goods = await addItems(roleId, roleName, sid, [{id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.HONOUR), count: isSuccess?trainSoloReward.failHonour:trainSoloReward.failHonour}]);
|
||||
let guildTrains = [];
|
||||
let trainIds = [];
|
||||
//是否压制
|
||||
let { isComplete, reports, ranks } = guildTrain;
|
||||
let index = findIndex(ranks, {roleId});
|
||||
if (index !== -1) {
|
||||
ranks[index].score += addScore;
|
||||
} else {
|
||||
ranks.push({score: addScore, roleId});
|
||||
}
|
||||
let needLockNext = false;
|
||||
let resGuildTrain;
|
||||
let report = {roleId, trainId, hid, score: addScore, time: nowSeconds(), isSuccessed: isSuccess, type: 1};//1表示普通战报, 2表示系统战报即:被成功压制
|
||||
if (trainScript.progress < 1000 ) {
|
||||
if (trainScript.progress + addScore >= 1000) {
|
||||
if (trainInstance.progress < instance.progress ) {
|
||||
if (trainInstance.progress + addScore >= instance.progress) {
|
||||
reports.push(...[{isSuccessed: true, type: 2, time:nowSeconds(), score: addScore, roleId, trainId, hid},report]);
|
||||
if (!isComplete) {
|
||||
isComplete = true;
|
||||
guildTrain.trainScripts.forEach(({hid: otherHid, progress})=>{
|
||||
if (hid != otherHid && progress == 1000) {
|
||||
guildTrain.trainInstances.forEach(({hid: otherHid, progress})=>{
|
||||
if (hid != otherHid && progress != instance.progress) {
|
||||
isComplete = false;
|
||||
}
|
||||
});
|
||||
@@ -143,7 +161,7 @@ export class GuildTrainHandler {
|
||||
needLockNext = true;
|
||||
}
|
||||
}
|
||||
let progress = 1000;
|
||||
let progress = instance.progress;
|
||||
resGuildTrain = await GuildTrainModel.updateGuildTrainProgress(code, trainId, hid, progress, ranks, reports, isComplete);
|
||||
if (needLockNext) { //
|
||||
let nextResGuildTrain = await lockTrain(code, trainId + 1);
|
||||
@@ -152,7 +170,7 @@ export class GuildTrainHandler {
|
||||
}
|
||||
res.releaseCallback();//解锁
|
||||
} else {
|
||||
let progress = trainScript.progress + addScore;
|
||||
let progress = trainInstance.progress + addScore;
|
||||
resGuildTrain = await GuildTrainModel.updateGuildTrainProgress(code, trainId, hid, progress, ranks, reports, isComplete);
|
||||
res.releaseCallback();//解锁
|
||||
}
|
||||
@@ -170,26 +188,35 @@ export class GuildTrainHandler {
|
||||
}
|
||||
guildTrains.push(resGuildTrain);
|
||||
let { trainCount, trainRewards } = userGuild;
|
||||
let result = getGuildTrainInfo(guildTrains, roleId, trainCount, trainRewards, trainIds);
|
||||
let result:any = getGuildTrainInfo(guildTrains, roleId, trainCount, trainRewards, trainIds);
|
||||
result.battleGoods = goods;
|
||||
return resResult(STATUS.SUCCESS, result);
|
||||
}
|
||||
|
||||
async getTrainScriptBox(msg: { code: string, trainId: number , hid: number, index: number}, session: BackendSession) {
|
||||
let { code, trainId, hid, index } = msg;
|
||||
async getTrainInstanceBox(msg: { trainId: number , hid: number, index: number}, session: BackendSession) {
|
||||
let { trainId, hid, index } = msg;
|
||||
const roleId = session.get('roleId');
|
||||
const serverId = session.get('serverId');
|
||||
let userGuild = await getUserGuild(roleId, code);
|
||||
if (!userGuild)
|
||||
const roleName = session.get('roleName');
|
||||
const sid = session.get('sid');
|
||||
let userGuild = await getUserGuild(roleId);
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
const { guildCode: code } = userGuild;
|
||||
let res:any = await lockData(serverId, GUILD_DATA_NAME.TRAIN_BOX, code + '_' + trainId);//加锁
|
||||
if (!!res.err)
|
||||
return resResult(STATUS.REDLOCK_ERR);
|
||||
let guildTrain = await GuildTrainModel.findTrainScriptBoxByIndex(code, roleId, trainId, hid, index, 1000, nowSeconds() - 24*60*60);
|
||||
let { heroRewards, trainInstances } = getArmyTrainJuDian(trainId);
|
||||
let { progress } = findWhere(trainInstances, {hid});
|
||||
let guildTrain = await GuildTrainModel.findTrainInstanceBoxByIndex(code, roleId, trainId, hid, index, progress, nowSeconds());
|
||||
if (!guildTrain) {
|
||||
res.releaseCallback();//解锁
|
||||
return resResult(STATUS.GUILD_TRAIN_SCRIPT_NOT_OPENED);
|
||||
}
|
||||
let good;
|
||||
|
||||
let good = getRandomByLen(heroRewards);
|
||||
let goods = await addItems(roleId, roleName, sid, [good]);
|
||||
|
||||
let resGuildTrain = await GuildTrainModel.receiveBoxByIndex(code, roleId, trainId, hid, index, good);
|
||||
res.releaseCallback();//解锁
|
||||
|
||||
@@ -199,21 +226,24 @@ export class GuildTrainHandler {
|
||||
}
|
||||
let result:any = getGuildTrainRewards(resGuildTrain);
|
||||
|
||||
result.goods = [good];
|
||||
result.goods = goods;
|
||||
return resResult(STATUS.SUCCESS, result);
|
||||
}
|
||||
|
||||
async getTrainLvUpRewards(msg: {code: string, trainId: number }, session: BackendSession) {
|
||||
let { code, trainId } = msg;
|
||||
async getTrainLvUpRewards(msg: {trainId: number }, session: BackendSession) {
|
||||
let { trainId } = msg;
|
||||
const roleId = session.get('roleId');
|
||||
//TODO奖励
|
||||
let good;
|
||||
const roleName = session.get('roleName');
|
||||
const sid = session.get('sid');
|
||||
|
||||
let { jinjieReward } = getTrainBaseByLv(trainId);
|
||||
let userGuild = await UserGuildModel.receiveTrainRewards(roleId, trainId);
|
||||
if (!userGuild) {
|
||||
return resResult(STATUS.GUILD_GET_TRAIN_REWARD_FAIL);
|
||||
}
|
||||
let goods = await addItems(roleId, roleName, sid, jinjieReward);
|
||||
let { trainRewards } = userGuild;
|
||||
return resResult(STATUS.SUCCESS, { trainRewards });
|
||||
return resResult(STATUS.SUCCESS, { trainRewards, goods });
|
||||
}
|
||||
//购买挑战次数
|
||||
async purchaseTrainCount(msg: {code: string, trainId: number }, session: BackendSession) {
|
||||
|
||||
@@ -79,6 +79,7 @@ export async function getBossInstanceWhenEnd(bossInstance: BossInstanceType, rol
|
||||
});
|
||||
result.myRank = myRank;
|
||||
result.ranks = pushRanks;
|
||||
result.isBattled = isBattled;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import { UserGuildModel } from '../db/UserGuild';
|
||||
import { getJobInfoById } from '../pubUtils/gamedata';
|
||||
import { getArmyTrainJuDian } from '../pubUtils/data';
|
||||
import { getTodayZeroPoint, nowSeconds } from '../pubUtils/timeUtil';
|
||||
import { GUILD_REPORT_NUM } from '../consts/constModules/guildConst';
|
||||
import { GuildTrainType, GuildTrainModel } from '../db/GuildTrain';
|
||||
import { GuildTrainType, GuildTrainModel, TrainInstance } from '../db/GuildTrain';
|
||||
import { GuildModel } from '../db/Guild';
|
||||
import { findWhere } from 'underscore';
|
||||
export async function getUserGuild(roleId: string, code: string) {
|
||||
export async function getUserGuild(roleId: string) {
|
||||
let userGuild = await UserGuildModel.getMyGuild(roleId,'trainCount trainTime trainRewards');
|
||||
if (!userGuild||userGuild.guildCode != code)
|
||||
if (!userGuild)
|
||||
return;
|
||||
let { trainCount, trainTime} = userGuild;
|
||||
if (trainTime < getTodayZeroPoint()) {
|
||||
trainCount = 0;
|
||||
trainCount = 2;
|
||||
}
|
||||
userGuild = await UserGuildModel.updateInfo(roleId, {trainCount, trainTime: nowSeconds()});
|
||||
return userGuild;
|
||||
@@ -37,16 +37,21 @@ export function getGuildTrain (guildTrains, trainCount:number, trainRewards: Arr
|
||||
return { list, trainCount, trainRewards};
|
||||
}
|
||||
|
||||
export function getGuildTrainRewards (guildTrain) {
|
||||
let trainBoxs = guildTrain.trainScripts.map(({hid, trainBoxs})=>{
|
||||
return {hid, recordBoxs: trainBoxs};
|
||||
export function getGuildTrainRewards (guildTrain) {
|
||||
let { trainInstances: instances } = getArmyTrainJuDian(guildTrain.trainId);
|
||||
let trainBoxs = guildTrain.trainInstances.map(({hid, trainBoxs, endTime})=>{
|
||||
let instance = findWhere(instances, { hid });
|
||||
let isComplete = false;
|
||||
if ( guildTrain.progress >= instance.progress)
|
||||
isComplete = true;
|
||||
return {hid, recordBoxs: trainBoxs, trainId: guildTrain.trainId, endTime, isComplete};
|
||||
})
|
||||
return { trainBoxs};
|
||||
}
|
||||
|
||||
export function getGuildTrainInfo (guildTrains: Array<GuildTrainType>, roleId: string, trainCount:number, trainRewards: Array<number>, trainIds:Array<number>) {
|
||||
let guildTrain;
|
||||
guildTrains.map(({trainId, isComplete, trainScripts, ranks, reports})=>{
|
||||
guildTrains.map(({trainId, isComplete, trainInstances, ranks, reports})=>{
|
||||
if (trainIds.indexOf(trainId) == -1) {
|
||||
return;
|
||||
}
|
||||
@@ -59,10 +64,15 @@ export function getGuildTrainInfo (guildTrains: Array<GuildTrainType>, roleId:
|
||||
myRank = {roleId: rankRoleId, score, rankLv: index+1};
|
||||
return {roleId: rankRoleId, score, rankLv: index+1};
|
||||
});
|
||||
let { trainInstances: instances } = getArmyTrainJuDian(trainId);
|
||||
let resTrainBoxs = [];
|
||||
let resTrainScripts = trainScripts.map(({hid, progress, time, trainBoxs})=>{
|
||||
resTrainBoxs.push({hid, recordBoxs: trainBoxs});
|
||||
return {hid, progress, time};
|
||||
let resTrainInstances = trainInstances.map(({hid, progress, endTime, trainBoxs})=>{
|
||||
let instance = findWhere(instances, { hid });
|
||||
let isComplete = false;
|
||||
if ( progress >= instance.progress)
|
||||
isComplete = true;
|
||||
resTrainBoxs.push({hid, recordBoxs: trainBoxs, trainId, endTime, isComplete});
|
||||
return {hid, progress, endTime, isComplete};
|
||||
})
|
||||
let lastGuildTrain = findWhere(guildTrains, { trainId: trainId - 1});
|
||||
if (!!lastGuildTrain) {
|
||||
@@ -74,17 +84,17 @@ export function getGuildTrainInfo (guildTrains: Array<GuildTrainType>, roleId:
|
||||
reports = [...trainReports, ...reports];
|
||||
}
|
||||
let flag = false;
|
||||
let lastTrainBoxs = lastGuildTrain.trainScripts.map(({hid, time, trainBoxs}) => {
|
||||
if (time + 24 * 60 * 60 < nowSeconds()) {
|
||||
let lastTrainBoxs = lastGuildTrain.trainInstances.map(({hid, endTime, trainBoxs}) => {
|
||||
if (endTime < nowSeconds()) {
|
||||
flag = true;
|
||||
}
|
||||
return {};
|
||||
return {hid, recordBoxs: trainBoxs, trainId: lastGuildTrain.trainId, endTime, isComplete: true};
|
||||
});
|
||||
if (flag) {
|
||||
resTrainBoxs.push(...lastTrainBoxs);
|
||||
}
|
||||
}
|
||||
guildTrain = {trainId, isComplete, trainScripts: resTrainScripts, trainBoxs: resTrainBoxs, reports, myRank, ranks: resRanks};
|
||||
guildTrain = {trainId, isComplete, trainInstances: resTrainInstances, trainBoxs: resTrainBoxs, reports, myRank, ranks: resRanks};
|
||||
});
|
||||
return { guildTrain, trainCount, trainRewards};
|
||||
}
|
||||
@@ -94,8 +104,19 @@ export async function lockTrain(code: string, trainId: number) {
|
||||
if (!!guildTrain) {
|
||||
return;
|
||||
}
|
||||
let trainScripts;
|
||||
guildTrain = await GuildTrainModel.openGuildTrain(code, trainId, trainScripts);
|
||||
await GuildModel.updateInfo(code, {trainId});
|
||||
let { trainInstances } = getArmyTrainJuDian(trainId);
|
||||
// 初始化
|
||||
|
||||
let instances:Array<TrainInstance> = trainInstances.map(trainInstance => {
|
||||
let t = new TrainInstance();
|
||||
t.hid = trainInstance.hid;
|
||||
t.progress = 0;
|
||||
t.endTime = 0;
|
||||
t.trainBoxs = [];
|
||||
return t;
|
||||
});
|
||||
guildTrain = await GuildTrainModel.openGuildTrain(code, trainId, instances);
|
||||
await GuildModel.updateInfo(code, {trainId}, {});
|
||||
|
||||
return guildTrain;
|
||||
}
|
||||
@@ -308,7 +308,10 @@ export const FILENAME = {
|
||||
DIC_GUILD_POSITION: 'dic_army_position',
|
||||
DIC_ACTIVE_DAY_REWARD: 'dic_army_activeDayReward',
|
||||
DIC_ACTIVE_WEEK_REWARD: 'dic_army_activeWeekReward',
|
||||
DIC_MAIL: 'dic_email_army'
|
||||
DIC_MAIL: 'dic_email_army',
|
||||
DIC_ARMY_TRAIN_JU_DIAN: 'dic_army_trainJuDian',
|
||||
DIC_ARMY_TRAIN_SOLO_REWARD: 'dic_army_trainSoloReward'
|
||||
|
||||
}
|
||||
|
||||
export const WAR_RELATE_TABLES = [
|
||||
|
||||
@@ -224,6 +224,7 @@ export const STATUS = {
|
||||
GUILD_GET_TRAIN_BOX_FAIL: {code: 30913, simStr: '宝箱领取失败'},
|
||||
GUILD_TRAIN_REWARD_IS_RECEIVED: {code: 30913, simStr: '试炼进阶奖励已领取'},
|
||||
GUILD_GET_TRAIN_REWARD_FAIL: {code: 30913, simStr: '宝箱领取失败'},
|
||||
GUILD_TRAIN_LEVEL_IS_COMPLETE: {code: 30913, simStr: '试炼已经进阶'},
|
||||
|
||||
// 社交相关状态 40000 - 49999
|
||||
// 运营模块相关状态 50000 - 59999
|
||||
|
||||
@@ -22,6 +22,10 @@ class Record {
|
||||
trainId?:number;
|
||||
@prop({ required: false })
|
||||
hid?:number;
|
||||
@prop({ required: false })
|
||||
guildCode?: string;
|
||||
@prop({ required: false })
|
||||
difficulty: number;
|
||||
}
|
||||
|
||||
export default class BattleRecord extends BaseModel {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType, Ref } from '@typegoose/typegoose';
|
||||
import { nowSeconds } from '../pubUtils/timeUtil';
|
||||
class Reward {
|
||||
@prop({ required: true })
|
||||
id: number;
|
||||
@@ -16,15 +17,15 @@ class TrainBox {
|
||||
index: number;
|
||||
}
|
||||
|
||||
class TrainScript {
|
||||
export class TrainInstance {
|
||||
@prop({ required: true })
|
||||
hid: number;
|
||||
@prop({ required: true })
|
||||
progress: number;
|
||||
@prop({ required: true })
|
||||
time: number;
|
||||
@prop({ required: true, default: [], type: TrainBox})
|
||||
trainBoxs: Array<TrainBox>;
|
||||
endTime: number;
|
||||
@prop({ required: true, default: [], type: TrainBox, _id: false })
|
||||
trainBoxs: TrainBox[];
|
||||
}
|
||||
|
||||
class Rank {
|
||||
@@ -58,12 +59,12 @@ export default class GuildTrain extends BaseModel {
|
||||
trainId: number;
|
||||
@prop({ required: true })
|
||||
isComplete: boolean;
|
||||
@prop({ required: true, default: [], type: TrainScript})
|
||||
trainScripts: Array<TrainScript>;
|
||||
@prop({ required: true, default: [], type: Rank })
|
||||
ranks: Array<Rank>;
|
||||
@prop({ required: true, default: [], type: Report })
|
||||
reports: Array<Report>;
|
||||
@prop({ required: true, default: [], type: TrainInstance, _id: false })
|
||||
trainInstances: TrainInstance[];
|
||||
@prop({ required: true, default: [], type: Rank, _id: false })
|
||||
ranks: Rank[];
|
||||
@prop({ required: true, default: [], type: Report, _id: false })
|
||||
reports: Report[];
|
||||
@prop({ required: true, default: false})
|
||||
locked: boolean;
|
||||
|
||||
@@ -83,30 +84,30 @@ export default class GuildTrain extends BaseModel {
|
||||
}
|
||||
|
||||
public static async updateGuildTrain(guildCode: string, trainId: number, update: GuildTrainTypeParam, lean = true) {
|
||||
const guildTrain: GuildTrainType = await GuildTrainModel.findOneAndUpdate({ guildCode, trainId}, { $set: update }).lean(lean);
|
||||
const guildTrain: GuildTrainType = await GuildTrainModel.findOneAndUpdate({ guildCode, trainId}, { $set: update }, {new: true}).lean(lean);
|
||||
return guildTrain;
|
||||
}
|
||||
|
||||
public static async updateGuildTrainProgress(guildCode: string, trainId: number, hid:number, progress: number, ranks:Array<Rank>, reports: Array<Report>, isComplete: boolean,lean = true) {
|
||||
const guildTrain: GuildTrainType = await GuildTrainModel.findOneAndUpdate({ guildCode, trainId, 'trainScripts.hid':hid},
|
||||
{ $set: {'trainScripts.$.progress': progress, ranks, reports, isComplete} }).lean(lean);
|
||||
const guildTrain: GuildTrainType = await GuildTrainModel.findOneAndUpdate({ guildCode, trainId, 'trainInstances.hid':hid},
|
||||
{ $set: {'trainInstances.$.progress': progress, ranks, reports, isComplete,'trainInstances.$.endTime': nowSeconds() + 24*60*60} },{new: true}).lean(lean);
|
||||
return guildTrain;
|
||||
}
|
||||
|
||||
public static async openGuildTrain(guildCode: string, trainId: number, trainScripts: Array<TrainScript>, lean = true) {
|
||||
const guildTrain: GuildTrainType = await GuildTrainModel.findOneAndUpdate({ guildCode, trainId },{ trainId, reports: [], locked: false, ranks: [], trainScripts, isComplete: false, guildCode}, {new: true, upsert: true}).lean(lean);
|
||||
public static async openGuildTrain(guildCode: string, trainId: number, trainInstances: Array<TrainInstance>, lean = true) {
|
||||
const guildTrain: GuildTrainType = await GuildTrainModel.findOneAndUpdate({ guildCode, trainId },{ trainId, reports: [], locked: false, ranks: [], trainInstances, isComplete: false, guildCode}, {new: true, upsert: true}).lean(lean);
|
||||
return guildTrain;
|
||||
}
|
||||
|
||||
public static async findTrainScriptBoxByIndex(guildCode: string, roleId: string, trainId: number, hid: number, index: number, progress: number, time, locked = false, lean = true) {
|
||||
const guildTrain: GuildTrainType = await GuildTrainModel.findOne({ guildCode, trainId, locked, 'trainScripts.hid': hid,
|
||||
'trainScripts.index':{$ne:index },'trainScripts.roleId':{$ne:roleId }, progress: {$gte: progress}, time:{$gte: time}}).lean(lean);
|
||||
public static async findTrainInstanceBoxByIndex(guildCode: string, roleId: string, trainId: number, hid: number, index: number, progress: number, time: number, locked = false, lean = true) {
|
||||
const guildTrain: GuildTrainType = await GuildTrainModel.findOne({ guildCode, trainId, locked, 'trainInstances.hid': hid,
|
||||
'trainInstances.trainBoxs.index':{$ne:index },'trainInstances.trainBoxs.roleId':{$ne:roleId }, 'trainInstances.progress': {$gte: progress}, 'trainInstances.endTime':{$gte: time}}).lean(lean);
|
||||
return guildTrain;
|
||||
}
|
||||
|
||||
public static async receiveBoxByIndex(guildCode: string, roleId: string, trainId: number, hid: number, index: number, good: Reward, locked = false, lean = true) {
|
||||
const guildTrain: GuildTrainType = await GuildTrainModel.findOneAndUpdate({ guildCode, trainId, locked, 'trainScripts.hid': hid, },
|
||||
{ $push:{ 'trainScripts.$.trainBoxs': {roleId, index, good} }} ).lean(lean);
|
||||
const guildTrain: GuildTrainType = await GuildTrainModel.findOneAndUpdate({ guildCode, trainId, locked, 'trainInstances.hid': hid, },
|
||||
{ $push:{ 'trainInstances.$.trainBoxs': {roleId, index, good} }}, {new: true}).lean(lean);
|
||||
return guildTrain;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,12 +128,13 @@ export default class UserGuild extends BaseModel {
|
||||
const result = await UserGuildModel.findOneAndUpdate({ roleId, status: USER_GUILD_STATUS.ON }, { $inc: { honourWeekly: inc } }, { new: true }).select(select).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static async receiveTrainRewards(roleId: string, trainId: number, lean = true) {
|
||||
const result = await UserGuildModel.findOneAndUpdate({ roleId, status: USER_GUILD_STATUS.ON, 'trainRewards':{$ne: trainId }},
|
||||
{$push:{trainRewards: trainId} }).lean(lean);
|
||||
{$push:{trainRewards: trainId} },{new: true}).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const UserGuildModel = getModelForClass(UserGuild);
|
||||
|
||||
@@ -49,6 +49,8 @@ import { dicGuildActiveDayReward } from './dictionary/DicGuildActiveDayReward';
|
||||
import { dicGuildActiveWeekReward } from './dictionary/DicGuildActiveWeekReward';
|
||||
import { dicGuildPosition } from "./dictionary/DicGuildPosition";
|
||||
import { dicMail } from "./dictionary/DicMail";
|
||||
import { dicArmyTrainJuDian } from './dictionary/dicArmyTrainJuDian';
|
||||
import { dicTrainSoloReward } from './dictionary/dicTrainSoloReward';
|
||||
|
||||
export const gameData = {
|
||||
blurprtCompose: dicBlueprtCompose,
|
||||
@@ -121,7 +123,8 @@ export const gameData = {
|
||||
guildActiveDayReward: dicGuildActiveDayReward,
|
||||
guildActiveWeekReward: dicGuildActiveWeekReward,
|
||||
guildPosition: dicGuildPosition,
|
||||
mail: dicMail
|
||||
armyTrainJuDian: dicArmyTrainJuDian,
|
||||
trainSoloReward: dicTrainSoloReward
|
||||
};
|
||||
|
||||
// 在此提供一些原先在gamedata中提供的方法,以便更方便获取gameData数据
|
||||
@@ -334,4 +337,16 @@ export function hasStructureConsume(structureId: number, level: number) {
|
||||
|
||||
export function getBossByLv(lv: number) {
|
||||
return gameData.bossBase.get(lv);
|
||||
}
|
||||
}
|
||||
|
||||
export function getArmyTrainJuDian(trainId: number) {
|
||||
return gameData.armyTrainJuDian.get(trainId);
|
||||
}
|
||||
export function getTrainSoloReward(id: number) {
|
||||
return gameData.trainSoloReward.get(id);
|
||||
}
|
||||
export function getTrainBaseByLv(lv: number) {
|
||||
return gameData.trainBase.get(lv);
|
||||
}
|
||||
|
||||
|
||||
|
||||
34
shared/pubUtils/dictionary/DicArmyTrainJuDian.ts
Normal file
34
shared/pubUtils/dictionary/DicArmyTrainJuDian.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { readJsonFile, parseGoodStr } from '../util'
|
||||
import { FILENAME } from '../../consts'
|
||||
type KeysEnum<T> = { [P in keyof Required<T>]: true };
|
||||
const _ = require('lodash');
|
||||
|
||||
export interface DicArmyTrainJuDian {
|
||||
|
||||
readonly id: number;
|
||||
// 目标品质
|
||||
readonly trainInstances: Array<{hid: number, warId: number, progress: number}>;
|
||||
readonly heroRewards: Array<{id: number, count: number}>;
|
||||
}
|
||||
|
||||
const DicArmyTrainJuDianKeys: KeysEnum<DicArmyTrainJuDian> = {
|
||||
id: true,
|
||||
trainInstances: true,
|
||||
heroRewards: true
|
||||
};
|
||||
|
||||
const str = readJsonFile(FILENAME.DIC_ARMY_TRAIN_JU_DIAN);
|
||||
let arr = JSON.parse(str);
|
||||
|
||||
export const dicArmyTrainJuDian = new Map<number, DicArmyTrainJuDian>();
|
||||
arr.forEach(o => {
|
||||
o.trainInstances = o.gkid.split('|').map(element => {
|
||||
let arr = element.split('&');
|
||||
return {hid: parseInt(arr[0]), warId: parseInt(arr[1]), progress: parseInt(arr[2])};
|
||||
});
|
||||
|
||||
o.heroRewards = parseGoodStr(o.shilianReward);
|
||||
|
||||
dicArmyTrainJuDian.set(o.id,_.pick(o, Object.keys(DicArmyTrainJuDianKeys)));
|
||||
});
|
||||
arr = undefined;
|
||||
50
shared/pubUtils/dictionary/DicTrainSoloReward.ts
Normal file
50
shared/pubUtils/dictionary/DicTrainSoloReward.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { readJsonFile } from '../util'
|
||||
import { FILENAME } from '../../consts'
|
||||
type KeysEnum<T> = { [P in keyof Required<T>]: true };
|
||||
const _ = require('lodash');
|
||||
|
||||
export interface DicTrainSoloReward {
|
||||
|
||||
readonly id: number;
|
||||
// 目标品质
|
||||
readonly ratio: number;
|
||||
readonly winScore: number;
|
||||
readonly failScore: number;
|
||||
readonly winHonour: number;
|
||||
readonly failHonour: number;
|
||||
|
||||
}
|
||||
|
||||
const DicTrainSoloRewardKeys: KeysEnum<DicTrainSoloReward> = {
|
||||
id: true,
|
||||
ratio: true,
|
||||
winScore: true,
|
||||
failScore: true,
|
||||
winHonour: true,
|
||||
failHonour: true,
|
||||
};
|
||||
|
||||
const str = readJsonFile(FILENAME.DIC_ARMY_TRAIN_SOLO_REWARD);
|
||||
let arr = JSON.parse(str);
|
||||
|
||||
export const dicTrainSoloReward = new Map<number, DicTrainSoloReward>();
|
||||
arr.forEach(o => {
|
||||
o.winReward.split('|').map(cur=>{
|
||||
let arr = cur.split('&');
|
||||
if (arr[0] == 1) {
|
||||
o.winScore = parseInt(arr[1]);
|
||||
} else if (arr[0] == 2) {
|
||||
o.winHonour = parseInt(arr[1]);
|
||||
}
|
||||
})
|
||||
o.failReward.split('|').map(cur=>{
|
||||
let arr = cur.split('&');
|
||||
if (arr[0] == 1) {
|
||||
o.failScore = parseInt(arr[1]);
|
||||
} else if (arr[0] == 2) {
|
||||
o.failHonour = parseInt(arr[1]);
|
||||
}
|
||||
})
|
||||
dicTrainSoloReward.set(o.id,_.pick(o, Object.keys(DicTrainSoloRewardKeys)));
|
||||
});
|
||||
arr = undefined;
|
||||
@@ -4,7 +4,7 @@
|
||||
"name": "试炼1-初出茅庐",
|
||||
"count": 4,
|
||||
"heroid": "1&3&5&4",
|
||||
"gkid": "1&8501|3&8502|5&8503|7&8504",
|
||||
"gkid": "1&8501&800|3&8502&800|5&8503&800|7&8504&800",
|
||||
"shilianReward": "40005&6000|20001&60|21008&30|42008&10",
|
||||
"soloRewardRatio": 1
|
||||
},
|
||||
@@ -13,7 +13,7 @@
|
||||
"name": "试炼2-过关斩将",
|
||||
"count": 4,
|
||||
"heroid": "2&3&5&7",
|
||||
"gkid": "2&8505|3&8506&|5&8507|7&8508",
|
||||
"gkid": "2&8505&800|3&8506&800|5&8507&800|7&8508&800",
|
||||
"shilianReward": "40005&4000|20001&60|21008&30|42008&11",
|
||||
"soloRewardRatio": 1.1
|
||||
},
|
||||
@@ -22,7 +22,7 @@
|
||||
"name": "试炼3-黄巾起义",
|
||||
"count": 4,
|
||||
"heroid": "7&8&9&10",
|
||||
"gkid": "7&8509|8&8510|9&8511|10&8512",
|
||||
"gkid": "7&8509&800|8&8510&800|9&8511&800|10&8512&800",
|
||||
"shilianReward": "40005&3000|20001&60|21008&30|42008&12",
|
||||
"soloRewardRatio": 1.2
|
||||
},
|
||||
@@ -31,7 +31,7 @@
|
||||
"name": "试炼4-火烧赤壁",
|
||||
"count": 4,
|
||||
"heroid": "11&12&13&14",
|
||||
"gkid": "11&8513|12&8514|13&8515|14&8516",
|
||||
"gkid": "11&8513&800|12&8514&800|13&8515&800|14&8516&800",
|
||||
"shilianReward": "40005&2000|20001&60|21008&30|42008&13",
|
||||
"soloRewardRatio": 1.3
|
||||
},
|
||||
@@ -40,7 +40,7 @@
|
||||
"name": "试炼5-官渡之战",
|
||||
"count": 4,
|
||||
"heroid": "7&8&9&11",
|
||||
"gkid": "7&8517|8&8518|9&8519|11&8520",
|
||||
"gkid": "7&8517&800|8&8518&800|9&8519&800|11&8520&800",
|
||||
"shilianReward": "40005&1000|20001&60|21008&30|42008&14",
|
||||
"soloRewardRatio": 1.4
|
||||
},
|
||||
@@ -49,7 +49,7 @@
|
||||
"name": "试炼6- 后起之秀",
|
||||
"count": 4,
|
||||
"heroid": "11&12&13&15",
|
||||
"gkid": "11&8521|12&8522|13&8523|15&8524",
|
||||
"gkid": "11&8521&800|12&8522&800|13&8523&800|15&8524&800",
|
||||
"shilianReward": "40005&500|20001&60|21008&30|42008&15",
|
||||
"soloRewardRatio": 1.5
|
||||
},
|
||||
@@ -58,7 +58,7 @@
|
||||
"name": "试炼7- 分庭抗礼",
|
||||
"count": 4,
|
||||
"heroid": "7&8&9&12",
|
||||
"gkid": "7&8525|8&8526|9&852712&8528",
|
||||
"gkid": "7&8525&800|8&8526&800|9&8527&800|12&8528&800",
|
||||
"shilianReward": "40005&6000|20001&60|21008&30|42008&16",
|
||||
"soloRewardRatio": 1.6
|
||||
},
|
||||
@@ -67,7 +67,7 @@
|
||||
"name": "试炼8- 群雄逐鹿",
|
||||
"count": 4,
|
||||
"heroid": "11&12&13&16",
|
||||
"gkid": "11&8529|12&8530|13&8531|16&8532",
|
||||
"gkid": "11&8529&800|12&8530&800|13&8531&800|16&8532&800",
|
||||
"shilianReward": "40005&4000|20001&60|21008&30|42008&17",
|
||||
"soloRewardRatio": 1.7
|
||||
},
|
||||
@@ -76,7 +76,7 @@
|
||||
"name": "试炼9-三足鼎立",
|
||||
"count": 4,
|
||||
"heroid": "7&8&9&13",
|
||||
"gkid": "7&8533|8&8534|9&8535|13&8536",
|
||||
"gkid": "7&8533&800|8&8534&800|9&8535&800|13&8536&800",
|
||||
"shilianReward": "40005&3000|20001&60|21008&30|42008&18",
|
||||
"soloRewardRatio": 1.8
|
||||
},
|
||||
@@ -85,7 +85,7 @@
|
||||
"name": "试炼10-封金挂印",
|
||||
"count": 4,
|
||||
"heroid": "11&12&13&17",
|
||||
"gkid": "11&8537|12&8538|13&8539|17&8540",
|
||||
"gkid": "11&8537&800|12&8538&800|13&8539&800|17&8540&800",
|
||||
"shilianReward": "40005&2000|20001&60|21008&30|42008&19",
|
||||
"soloRewardRatio": 2
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user