军团:添加邀请红点和演武台功能

This commit is contained in:
luying
2021-12-21 16:59:29 +08:00
parent a4f426e172
commit 5f2c07da00
10 changed files with 71 additions and 33 deletions

View File

@@ -22,6 +22,7 @@ import { getGoldObject } from '../../../pubUtils/itemUtils';
import { RoleModel } from '../../../db/Role';
import { sendMailToGuildByContent } from '../../../services/mailService';
import { genAuction } from '../../../services/auctionService';
import { getMedianCe } from '../../../services/guildActivityService';
export default function (app: Application) {
new HandlerService(app, {});
@@ -61,7 +62,12 @@ export class GuildHandler {
return resResult(STATUS.GUILD_STRUCTURE_NOT_FOUND);
}
let bossBase = getBossByLv(curStructure.lv);
let { bossHp, warId } = getRandSingleEelm(bossBase.wars);
let { bossHp: minBossHp, warId } = getRandSingleEelm(bossBase.wars);
let medianCe = await getMedianCe(serverId);
let bossHp = Math.ceil(medianCe * bossBase.ratio);
console.log('******* openBossInstance', medianCe, bossHp, minBossHp)
if(bossHp < minBossHp) bossHp = minBossHp;
let resGuild = await GuildModel.costFund(code, bossBase.opencost);
if (!resGuild) {
res.releaseCallback();
@@ -198,9 +204,11 @@ export class GuildHandler {
let { bossDamage = 0 } = battleRecord.record; // 伤害奖励
let dicBossBase = gameData.bossBaseByBossLv.get(bossInstance.bossLv);
let reward = dicBossBase.damageReward.map(({id, count}) => {
return { id, count: Math.floor(count * bossDamage * dicBossBase.ratio / 1000 ) }
});
let { basicReward, damageRewardTotal } = dicBossBase;
let damageReward = damageRewardTotal.map(cur => {
return { id: cur.id, count: Math.ceil(cur.count * bossDamage / bossInstance.bossTotalHp )}
})
let reward = [...basicReward, ...damageReward];
let battleGoods = await addItems(roleId, roleName, sid, reward, ITEM_CHANGE_REASON.BOSS_BATTLE_END);

View File

@@ -2,7 +2,7 @@ import { Application, BackendSession, ChannelService, HandlerService, } from 'pi
import { resResult, getRandEelm, shouldRefresh, sortArrRandom } from '../../../pubUtils/util';
import { STATUS, GUILD_OPERATE, GUILD_AUTH, GUILD_JOB, GUILD_APPLY_TYPE, GUILD_STRUCTURE, GUILD_REC_TYPE, GUILD_STRUCTURE_NAME, MAIL_TYPE, REDIS_KEY, GUILD_SELECT, USER_GUILD_SELECT, TASK_TYPE, DEBUG_MAGIC_WORD, CHANNEL_PREFIX, MSG_TYPE, MSG_SOURCE, ITEM_CHANGE_REASON, TA_EVENT, GUILD_DISMISS_WAY, GUILD_MASTER_CHANGE_WAY, GUILD_QUIT_WAY } from '../../../consts';
import { UserGuildModel, UserGuildType } from '../../../db/UserGuild';
import { checkAuth, joinGuild, getGuildWithRefActive, getUserGuildWithRefActive, addActive, settleGuildWeekly, getMyGuildInfo, refreshUserGuild, setUserGuildSession } from '../../../services/guildService';
import { checkAuth, joinGuild, getGuildWithRefActive, getUserGuildWithRefActive, addActive, settleGuildWeekly, getMyGuildInfo, refreshUserGuild, setUserGuildSession, getInvitationList } from '../../../services/guildService';
import { GuildModel, GuildType, GuildUpdateParam } from '../../../db/Guild';
import { RoleModel, RoleType } from '../../../db/Role';
import { ARMY } from '../../../pubUtils/dicParam';
@@ -424,14 +424,18 @@ export class GuildHandler {
const roleList = await RoleModel.findByRoleIds(roleIds);
let result = new Array<string>();
let uids = [];
for (let role of roleList) {
if (!role.hasGuild || role.serverId == serverId) {
await UserGuildApplyModel.createUserGuildApply(role, guild, GUILD_APPLY_TYPE.INVITE);
let apply = await UserGuildApplyModel.createUserGuildApply(role, guild, GUILD_APPLY_TYPE.INVITE);
result.push(role.roleId);
let hisInfo = await getRoleOnlineInfo(role.roleId);
if (hisInfo.isOnline) {
uids.push({ uid: role.roleId, sid: hisInfo.sid })
let uids = [{ uid: role.roleId, sid: hisInfo.sid }];
let guild = <GuildType>apply.guild;
let leader = <RoleType>guild.leader;
let invitation = { applyCode: apply.applyCode, ...guild, leader: leader.roleName };
this.channelService.pushMessageByUids('onGuildInvite', resResult(STATUS.SUCCESS, { invitation }), uids);
}
}
}
@@ -440,7 +444,6 @@ export class GuildHandler {
}
await GuildModel.recordInvitedMember(code, serverId, roleIds, shouldRefresh(guild.inviteTime, new Date()));
this.channelService.pushMessageByUids('onGuildInvite', resResult(STATUS.SUCCESS, { code }), uids);
return resResult(STATUS.SUCCESS, { roleIds: result });
@@ -451,14 +454,7 @@ export class GuildHandler {
const roleId = session.get('roleId');
const { lastApplyCode } = msg;
const result = await UserGuildApplyModel.findInviteByRole(roleId, lastApplyCode);
const list = result.map(cur => {
let guild = <GuildType>cur.guild;
let leader = <RoleType>guild.leader;
delete cur.guild;
return { applyCode: cur.applyCode, ...guild, leader: leader.roleName };
});
let list = await getInvitationList(roleId, lastApplyCode);
return resResult(STATUS.SUCCESS, { list });

View File

@@ -22,7 +22,7 @@ import { nowSeconds, getZeroPoint } from '../pubUtils/timeUtil';
import { getGachaList, getVisitedHeroList } from './activity/gachaService';
import { getSchoolList } from './roleService';
import { addRoleToGuildChannel } from './chatChannelService';
import { getMyGuildInfo, getGuildWithRefActive, getUserGuildWithRefActive, getWishPool } from './guildService';
import { getMyGuildInfo, getGuildWithRefActive, getUserGuildWithRefActive, getWishPool, getInvitationList } from './guildService';
import { getAuction } from './auctionService';
import { getGuildTrainInstance, getTrainBoxRewardsResult } from './guildTrainService';
import { BossInstanceModel } from '../db/BossInstance';
@@ -107,7 +107,8 @@ async function getModuleData(type: string, data: { role: RoleType, session: Fron
case 'school':
return await getSchoolList(roleId);
case 'guild':
return await guildResult;
let invitation = await getInvitationList(roleId, '');
return { ...guildResult, invitation };
case 'auction':
return hasGuild ? await getAuction(guildCode, session) : null;
case 'train':

View File

@@ -54,7 +54,7 @@ export function getRaceActivityObj() {
* 定时任务,获得前一天的活跃玩家中位数武将战力
*/
export async function setMedianCe() {
let servers = await ServerlistModel.getAllServerList();
let servers = await ServerlistModel.findByEnv(pinus.app.get('env'));
for (let server of servers) {
let medianRole = await RoleModel.getMedianRole(server.id);

View File

@@ -38,10 +38,10 @@ export async function getBossInstanceInfoByData(bossInstance: BossInstanceType,
let bossInfo = null;
if(bossInstance) {
let { warId, ranks, bossHp, bossLv, encourageCnt } = bossInstance;
let { warId, ranks, bossHp, bossTotalHp, bossLv, encourageCnt } = bossInstance;
let dicBossBase = gameData.bossBaseByBossLv.get(bossLv);
let rankInfo = getRanks(ranks, userGuild.roleId);
bossInfo = { warId, ...rankInfo, bossHp, bossLv, encourageCnt, encourageMax: dicBossBase.encourageSum };
bossInfo = { warId, ...rankInfo, bossHp, bossTotalHp, bossLv, encourageCnt, encourageMax: dicBossBase.encourageSum };
}
return { status, bossInfo, ...refObj }
}

View File

@@ -344,4 +344,15 @@ export function setUserGuildSession(session:FrontendOrBackendSession, myUserGuil
session.push('guildCode', () => {});
session.push('guildAuth', () => {});
}
}
export async function getInvitationList(roleId: string, lastApplyCode = '') {
const result = await UserGuildApplyModel.findInviteByRole(roleId, lastApplyCode);
const list = result.map(cur => {
let guild = <GuildType>cur.guild;
let leader = <RoleType>guild.leader;
delete cur.guild;
return { applyCode: cur.applyCode, ...guild, leader: leader.roleName };
});
return list;
}

View File

@@ -29,6 +29,9 @@ export default class BossInstance extends BaseModel {
@prop({ required: true })
bossHp: number;
@prop({ required: true })
bossTotalHp: number;
@prop({ required: true })
bossLv: number;
@@ -66,7 +69,7 @@ export default class BossInstance extends BaseModel {
public static async openBossInstance(guildCode: string, bossHp: number, warId: number, bossLv: number) {
let code = genCode(10);
let doc = new BossInstanceModel();
let update = Object.assign(doc.toJSON(), { guildCode, bossHp, bossLv, warId });
let update = Object.assign(doc.toJSON(), { guildCode, bossHp, bossTotalHp: bossHp, bossLv, warId });
const bossInstance: BossInstanceType = await BossInstanceModel.findOneAndUpdate({ code },{ $set: update }, {new: true, upsert: true}).lean();
return bossInstance;
}

View File

@@ -28,7 +28,22 @@ export default class UserGuildApply extends BaseModel {
// 创建申请或邀请
public static async createUserGuildApply(role: RoleType, guild: GuildType, type: number) {
const applyCode = genCode(10);
const result: UserGuildApplyType = await UserGuildApplyModel.findOneAndUpdate({ roleId: role.roleId, guildCode: guild.code, type }, { $set: { roleId: role.roleId, role: role._id, guildCode: guild.code, guild: guild._id }, $setOnInsert: { applyCode }}, { upsert: true, new: true }).lean();
const result: UserGuildApplyType = await UserGuildApplyModel.findOneAndUpdate(
{ roleId: role.roleId, guildCode: guild.code, type },
{ $set: { roleId: role.roleId, role: role._id, guildCode: guild.code, guild: guild._id }, $setOnInsert: { applyCode }
}, { upsert: true, new: true })
.select('applyCode guild')
.populate({
path: 'guild',
select: 'code icon name lv memberCnt leader ceLimit',
model: 'Guild',
populate: {
path: 'leader',
select: 'roleName',
model: 'Role'
}
})
.lean();
return result;
}

View File

@@ -61,9 +61,11 @@ export interface DicBossBase {
readonly opencost: number;
// 击杀奖励
readonly killReward: RewardInter[];
// 伤害加成奖励
readonly damageReward: RewardInter[];
// 伤害加成系数
// 伤害加成奖励 参与奖励
readonly basicReward: RewardInter[];
// 伤害加成奖励 伤害贡献奖励
readonly damageRewardTotal: RewardInter[];
// boss血量系数boss血量为中位数 * ratio
readonly ratio: number;
// 鼓舞次数
readonly encourageSum: number;
@@ -78,7 +80,8 @@ const DicBossKeys: KeysEnum<DicBossBase> = {
consume: true,
opencost: true,
killReward: true,
damageReward: true,
basicReward: true,
damageRewardTotal: true,
ratio: true,
encourageSum: true
};
@@ -214,7 +217,8 @@ export function loadStructure() {
return { warId: parseInt(warArr[0]), bossHp: parseInt(warArr[1])}
});
o.killReward = parseGoodStr(o.killReward);
o.damageReward = parseGoodStr(o.damageReward);
o.basicReward = parseGoodStr(o.basicReward);
o.damageRewardTotal = parseGoodStr(o.damageRewardTotal);
dicBossBase.set(o.level, _.pick(o, Object.keys(DicBossKeys)));
dicBossBaseByBossLv.set(o.bossLevel, _.pick(o, Object.keys(DicBossKeys)));
});

View File

@@ -252,7 +252,7 @@
{
"id": 26,
"name": "玉石",
"rewardBasicPool": "17052&10",
"rewardBasicPool": "17052&10&1",
"totalCount": 1,
"itid": 38,
"basePrice": "31002&120",
@@ -262,7 +262,7 @@
{
"id": 27,
"name": "玉髓",
"rewardBasicPool": "17053&1",
"rewardBasicPool": "17053&1&1",
"totalCount": 1,
"itid": 38,
"basePrice": "31002&40",
@@ -272,7 +272,7 @@
{
"id": 28,
"name": "蜀锦",
"rewardBasicPool": "40006&1",
"rewardBasicPool": "40006&1&1",
"totalCount": 1,
"itid": 38,
"basePrice": "31002&840",
@@ -282,7 +282,7 @@
{
"id": 29,
"name": "高级经验书",
"rewardBasicPool": "11003&1",
"rewardBasicPool": "11003&1&1",
"totalCount": 1,
"itid": 38,
"basePrice": "31002&300",