寻宝:修改奖励
This commit is contained in:
@@ -71,7 +71,7 @@ export class ComBattleHandler {
|
||||
|
||||
// 创建队伍数据结构
|
||||
let comTeam = new MemComBtlTeam(teamCode, pub, blueprtId, roleId, ceLimit, sid);
|
||||
addRoleToTeam(comTeam, roleInfo, true, false);
|
||||
addRoleToTeam(comTeam, roleInfo, sid, true, false);
|
||||
addUserToTeamChannel(teamCode, true, roleId, sid);
|
||||
// 将正在匹配的符合要求的玩家加入队伍,并推送入队消息
|
||||
await addValidSearchingRoles(comTeam);
|
||||
@@ -135,7 +135,7 @@ export class ComBattleHandler {
|
||||
|
||||
let isFrd = await getFrd(roleId);
|
||||
// 将玩家加入队伍
|
||||
addRoleToTeam(comTeam, roleInfo, false, isFrd);
|
||||
addRoleToTeam(comTeam, roleInfo, sid, false, isFrd);
|
||||
addUserToTeamChannel(teamCode, true, roleId, sid);
|
||||
|
||||
// 创建并添加机器人
|
||||
@@ -195,7 +195,7 @@ export class ComBattleHandler {
|
||||
|
||||
// 加入队伍
|
||||
if (!validToJoin(teamStatus, roleId)) return resResult(STATUS.COM_BATTLE_TEAM_INVALID);
|
||||
let roleStatus = new RoleStatus(role, false, isFrd);
|
||||
let roleStatus = new RoleStatus(role, sid, false, isFrd);
|
||||
const team = await ComBattleTeamModel.addRole(teamCode, roleStatus);
|
||||
if (!team) {
|
||||
return resResult(STATUS.COM_BATTLE_JOIN_ERR);
|
||||
@@ -550,13 +550,6 @@ export class ComBattleHandler {
|
||||
roleSt = st;
|
||||
}
|
||||
});
|
||||
if (roleSt.gotReward) return resResult(STATUS.COM_BATTLE_REWARDED);
|
||||
let warInfo = getWarByBlueprtId(blueprtId);
|
||||
if (!warInfo) return resResult(STATUS.BATTLE_MISS_INFO);
|
||||
|
||||
await ComBattleTeamModel.updateRewardSt(teamCode, roleId, true);
|
||||
const goods = await addItems(roleId, roleName, sid, roleSt.rewards, ITEM_CHANGE_REASON.COM_BATTLE_END);
|
||||
|
||||
return resResult(STATUS.SUCCESS, { teamInfo: {status, teamCode, roleStatus, bossHpArr} });
|
||||
}
|
||||
|
||||
|
||||
@@ -10,17 +10,18 @@ import { RoleStatus, ComBattleTeamModel, ComBattleTeamType, ComBattleReward } fr
|
||||
import { getRandEelm, getRandValue, resResult, ratioReward, getRandValueByMinMax, getRandEelmWithWeight, getRobotInfo, getRandSingleEelm } from "../pubUtils/util";
|
||||
import { getRandRobot } from "./battleService";
|
||||
import { Channel, ChannelService, pinus } from 'pinus';
|
||||
import { TREASURE, EXTERIOR } from '../pubUtils/dicParam';
|
||||
import { TREASURE, EXTERIOR, FRIEND } from '../pubUtils/dicParam';
|
||||
import { getFriendLvAdd } from './friendService';
|
||||
import { getRoleIds } from '../pubUtils/friendUtil';
|
||||
import { getTeamSearchByLv, rmRoleFromQueue } from './redisService';
|
||||
import { getRewardByBlueprtId, gameData, getBossHpByBlueprtId, getDicBlueprtById } from '../pubUtils/data';
|
||||
import { getZeroPointD, nowSeconds } from '../pubUtils/timeUtil';
|
||||
import { getFriendPointObject, handleCost } from './role/rewardService';
|
||||
import { addItems, getFriendPointObject, handleCost } from './role/rewardService';
|
||||
import { addUserToTeamChannel, delTeamChannel, sendMessageToTeam, sendMessageToUsersWithSuc, sendMessageToUserWithSuc } from './pushService';
|
||||
import { checkTaskInComBattleEnd } from './task/taskService';
|
||||
import moment = require('moment');
|
||||
import { RewardInter } from '../pubUtils/interface';
|
||||
import { FriendPointModel } from '../db/FriendPoint';
|
||||
|
||||
/**
|
||||
* 在给定的品质列表中随机返回一定数量的藏宝图Id
|
||||
@@ -66,7 +67,7 @@ export function getRandComBtlRobots(topLineupCe: number, ceLimit: number, lv: nu
|
||||
roleName: robotRoleName,
|
||||
ce: robotCe,
|
||||
lv: robotLv
|
||||
}, false, false, robot, true);
|
||||
}, '', false, false, robot, true);
|
||||
robotStArr.push(robotStatus);
|
||||
robotIdArr.push(robotRoleId);
|
||||
});
|
||||
@@ -158,14 +159,22 @@ export function setComBtlTimer(teamCode: string, timer: NodeJS.Timer, timerMap:
|
||||
|
||||
export async function getRealReward(blueprtId: number, roleSts: RoleStatus[], roleSt: RoleStatus, hasTimeExtraReward: boolean): Promise<ComBattleReward[]> {
|
||||
let dicReward = getRewardByBlueprtId(blueprtId);
|
||||
if(!dicReward) return [];
|
||||
if(!dicReward || roleSt.isRobot) return [];
|
||||
|
||||
let fixRewards: RewardInter[], extraRewards: RewardInter[];
|
||||
let fixRewards: RewardInter[] = [], extraRewards: RewardInter[] = [];
|
||||
if (roleSt.isCap) {
|
||||
fixRewards.push(...dicReward.captainReward);
|
||||
} else {
|
||||
if (roleSt.isFrd) {
|
||||
fixRewards.push(getFriendPointObject(TREASURE.REWARD_FRIENDPOINT));
|
||||
// 情谊值有上限,送到上限为止
|
||||
let frdPointRec = await FriendPointModel.getFrdPointRecToday(roleSt.roleId, FRIEND_DROP_TYPE.COM_BATTLE);
|
||||
let { comBattleCnt = 0 } = frdPointRec || {};
|
||||
if(comBattleCnt < FRIEND.FRIEND_FRIENDPOINT_MAX) {
|
||||
let count = FRIEND.FRIEND_FRIENDPOINT_MAX - comBattleCnt > TREASURE.REWARD_FRIENDPOINT? TREASURE.REWARD_FRIENDPOINT: FRIEND.FRIEND_FRIENDPOINT_MAX - comBattleCnt;
|
||||
fixRewards.push(getFriendPointObject(count));
|
||||
await FriendPointModel.updateComBattleCntToday(roleSt.roleId, roleSt.roleName, count, FRIEND.FRIEND_FRIENDPOINT_MAX, FRIEND_DROP_TYPE.COM_BATTLE);
|
||||
}
|
||||
|
||||
} else {
|
||||
fixRewards.push(...dicReward.teammateReward)
|
||||
}
|
||||
@@ -252,6 +261,9 @@ export async function handleComBtlProgress(teamStatus: MemComBtlTeam, robotHurtT
|
||||
});
|
||||
for (let st of teamStatus.roleStatus) {
|
||||
st.rewards = await getRealReward(teamStatus.blueprtId, teamStatus.roleStatus, st, teamStatus.hasTimeExtraReward);
|
||||
await addItems(st.roleId, st.roleName, st.sid, st.rewards, ITEM_CHANGE_REASON.COM_BATTLE_END);
|
||||
await ComBattleTeamModel.updateRewardSt(teamCode, st.roleId, true);
|
||||
|
||||
};
|
||||
await checkTaskInComBattleEnd(teamStatus.roleStatus, teamStatus.capId);
|
||||
}
|
||||
@@ -451,14 +463,14 @@ async function teammateValid(roleInfo: Partial<RoleType>, roleId: string, roleId
|
||||
* @param {number} ceLimit
|
||||
* @returns
|
||||
*/
|
||||
export async function getValidTeammateRoleSt(roleId: string, roleIds: string[], ceLimit: number) {
|
||||
export async function getValidTeammateRoleSt(roleId: string, roleIds: string[], ceLimit: number, sid: string) {
|
||||
let roleInfo = await RoleModel.findByRoleId(roleId, null, true);
|
||||
|
||||
const valid = await teammateValid(roleInfo, roleId, roleIds, ceLimit);
|
||||
if (!valid) return null;
|
||||
|
||||
let isFrd = await getFrd(roleId);
|
||||
const result = new RoleStatus(roleInfo, false, isFrd);
|
||||
const result = new RoleStatus(roleInfo, sid, false, isFrd);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -509,8 +521,8 @@ export async function hasEnoughBlueprt(roleId: string, sid: string, blueprtId: n
|
||||
* @param {boolean} isCap
|
||||
* @param {boolean} isFrd
|
||||
*/
|
||||
export function addRoleToTeam(comTeam: MemComBtlTeam, roleInfo: RoleType, isCap: boolean, isFrd: boolean) {
|
||||
const roleSt = new RoleStatus(roleInfo, isCap, isFrd);
|
||||
export function addRoleToTeam(comTeam: MemComBtlTeam, roleInfo: RoleType, sid: string, isCap: boolean, isFrd: boolean) {
|
||||
const roleSt = new RoleStatus(roleInfo, sid, isCap, isFrd);
|
||||
addRoleStToTeam(comTeam, roleSt);
|
||||
}
|
||||
|
||||
@@ -539,7 +551,7 @@ export async function addValidSearchingRoles(comTeam: MemComBtlTeam) {
|
||||
if (teammates && teammates.length) {
|
||||
for (let teammate of teammates) {
|
||||
const { roleId: teammateRoleId, sid } = teammate;
|
||||
const st = await getValidTeammateRoleSt(teammateRoleId, comTeam.roleIds, comTeam.ceLimit);
|
||||
const st = await getValidTeammateRoleSt(teammateRoleId, comTeam.roleIds, comTeam.ceLimit, sid);
|
||||
if (!st) continue;
|
||||
await rmRoleFromQueue(teammateRoleId, sid); // 匹配成功后删除redis中该用户的匹配记录
|
||||
addRoleStToTeam(comTeam, st);
|
||||
|
||||
@@ -48,6 +48,8 @@ export class RoleStatus {
|
||||
@prop({ required: true })
|
||||
roleName: string;
|
||||
@prop({ required: true })
|
||||
sid: string;
|
||||
@prop({ required: true })
|
||||
guildCode: string;
|
||||
@prop({ required: true })
|
||||
isCap: boolean;
|
||||
@@ -96,7 +98,7 @@ export class RoleStatus {
|
||||
@prop({ required: true, default: 0 })
|
||||
frdRatio: number = 0;
|
||||
|
||||
constructor(role: RoleUpdate, isCap: boolean, isFrd: boolean, heroes: ComRoleStatusHero[] = [], isRobot = false) {
|
||||
constructor(role: RoleUpdate, sid: string, isCap: boolean, isFrd: boolean, heroes: ComRoleStatusHero[] = [], isRobot = false) {
|
||||
if(role) {
|
||||
this.roleId = role.roleId||'';
|
||||
this.roleName = role.roleName||'';
|
||||
@@ -107,6 +109,7 @@ export class RoleStatus {
|
||||
this.topLineupCe = role.topLineupCe||0;
|
||||
this.lv = role.lv||1;
|
||||
}
|
||||
this.sid = sid;
|
||||
this.isCap = isCap;
|
||||
this.totalDmg = 0;
|
||||
this.isFrd = isFrd;
|
||||
|
||||
@@ -45,6 +45,13 @@ export default class FriendPoint extends BaseModel {
|
||||
return rec;
|
||||
}
|
||||
|
||||
public static async updateComBattleCntToday(roleId: string, roleName: string, cntInc: number, maxPerDay: number, type: number, lean = true) {
|
||||
const curTime = getZeroPointD();
|
||||
// 当 oldCnt + cntInc > maxPerDay 时需计算实际可以获得的点数:cntInc - (newCnt - maxPerDay)
|
||||
const rec: FriendPointType = await FriendPointModel.findOneAndUpdate({roleId, roleName, createdAt: {$gte: curTime}, comBattleCnt: {$lt: maxPerDay}, type}, {$inc: {comBattleCnt: cntInc}}, {upsert: true, new: true}).lean(lean);
|
||||
return rec;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 某个类型当天情谊点获取情况
|
||||
* @static
|
||||
|
||||
@@ -88,7 +88,6 @@ export function loadWar() {
|
||||
o.fixReward = parseFixReward(o.fixReward);
|
||||
o.conditionReward = parseConditionReward(o.conditionReward);
|
||||
o.randomReward = parseRandomReward(o.RandomReward||o.randomReward);
|
||||
o.teammateReward = parseFixReward(o.teammateReward);
|
||||
o.fobiddenCharactor = parseForbiddenChara(o.fobiddenCharactor);
|
||||
o.mapseid = parseNumberList(o.mapseid);
|
||||
if(o.script_id && isString(o.script_id)) {
|
||||
@@ -113,8 +112,9 @@ export function loadWar() {
|
||||
o.winReward = parseTrainReward(o.winReward);
|
||||
o.failReward = parseTrainReward(o.failReward);
|
||||
} else if (o.warType == WAR_TYPE.COM_BATTLE) {
|
||||
console.log('####', o)
|
||||
let reward = {
|
||||
captainReward: parseGoodStr(o.fixReward),
|
||||
captainReward: o.fixReward,
|
||||
teammateReward: parseGoodStr(o.teammateReward),
|
||||
captainTimeReward: parseGoodStr(o.time_captain_normalReward),
|
||||
teammateTimeReward: parseGoodStr(o.time_normalReward),
|
||||
|
||||
Reference in New Issue
Block a user