好友:初步申请到查看链
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
|
||||
export enum ROLE {
|
||||
// 玩家列表显示基础数据
|
||||
SHOW_SIMPLE = 'roleId roleName ce headHid sHid lv title job quitTime',
|
||||
SHOW_SIMPLE = 'roleId roleName ce headHid sHid lv title job quitTime vLv guildName',
|
||||
HANDLE_APPLY = 'roleId friendCnt lv',
|
||||
|
||||
GET_LV = 'lv'
|
||||
GET_LV = 'lv',
|
||||
GET_ROLE_ID = 'lv'
|
||||
};
|
||||
|
||||
|
||||
@@ -324,6 +324,8 @@ export const FILENAME = {
|
||||
DIC_ARMY_DEVELOPMENTCONSUME: 'dic_army_developmentConsume',
|
||||
DIC_ARMY_BOSS_RANK_REWARD: 'dic_army_bossrankReward',
|
||||
DIC_ARMY_DONATE_BOX_REWARD: 'dic_army_donateBoxReward',
|
||||
DIC_ROLE_FRIEND: 'dic_zyz_friends',
|
||||
DIC_ROLE_FRIEND_LEVEL: 'dic_zyz_closelevel'
|
||||
}
|
||||
|
||||
export const WAR_RELATE_TABLES = [
|
||||
|
||||
70
shared/db/FriendApply.ts
Normal file
70
shared/db/FriendApply.ts
Normal file
@@ -0,0 +1,70 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType, mongoose, Ref } from '@typegoose/typegoose';
|
||||
import Role, { RoleType } from './Role';
|
||||
import { genCode } from '../pubUtils/util';
|
||||
import { ROLE } from '../consts';
|
||||
|
||||
/**
|
||||
* 好友系统关系表
|
||||
*/
|
||||
@index({ roleId: 1, createdAt: -1 })
|
||||
|
||||
export default class FriendApply extends BaseModel {
|
||||
|
||||
@prop({ required: true, default: '' })
|
||||
applyCode: string; // 唯一code
|
||||
@prop({ required: true, default: '' })
|
||||
roleId: string; // 操作玩家本人id
|
||||
|
||||
@prop({ required: true, default: '' })
|
||||
frdRoleId: string; // 好友id
|
||||
@prop({ required: true, ref: 'Role', type: mongoose.Schema.Types.ObjectId })
|
||||
friend: Ref<Role>;
|
||||
|
||||
// 创建申请
|
||||
public static async createApply(roleId: string, friend: RoleType) {
|
||||
const applyCode = genCode(10);
|
||||
const result: FriendApplyType = await FriendApplyModel.findOneAndUpdate({ roleId, frdRoleId: friend.roleId },
|
||||
{
|
||||
$set: { roleId, frdRoleId: friend.roleId, friend: friend._id },
|
||||
$setOnInsert: { applyCode }
|
||||
}, { upsert: true, new: true }).lean();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// 获取列表
|
||||
public static async getApplyList(roleId: string) {
|
||||
const list: FriendApplyType[] = await FriendApplyModel.find({ roleId }, { _id: 0 })
|
||||
// .select(select)
|
||||
.populate('friend', ROLE.SHOW_SIMPLE, 'Role')
|
||||
.lean({ getters: true });
|
||||
return list;
|
||||
}
|
||||
|
||||
// 根据applyCode获得申请
|
||||
public static async getApplyListByCode(applyCodeList: string[]) {
|
||||
const list: FriendApplyType[] = await FriendApplyModel.find({ applyCode: { $in: applyCodeList } }, { _id: 0 })
|
||||
// .select(select)
|
||||
.populate('friend', ROLE.SHOW_SIMPLE, 'Role')
|
||||
.lean({ getters: true });
|
||||
return list;
|
||||
}
|
||||
|
||||
// 删除申请
|
||||
public static async deleteApply(applyCodeList: string[]) {
|
||||
const result = await FriendApplyModel.deleteMany({ applyCode: { $in: applyCodeList } });
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static async deleteAccount(roleId: string) {
|
||||
let result = await FriendApplyModel.deleteMany({ $or: [{ roleId: roleId }, { frdRoleId: roleId }] });
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const FriendApplyModel = getModelForClass(FriendApply);
|
||||
|
||||
export interface FriendApplyType extends Pick<DocumentType<FriendApply>, keyof FriendApply> { };
|
||||
@@ -1,7 +1,8 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType, mongoose, Ref } from '@typegoose/typegoose';
|
||||
import Role from './Role';
|
||||
import FriendShip from './FriendShip';
|
||||
import Role, { RoleType } from './Role';
|
||||
import FriendShip, { FriendShipType } from './FriendShip';
|
||||
import { ROLE } from '../consts';
|
||||
|
||||
class Relation {
|
||||
@prop({ required: true, default: '' })
|
||||
@@ -26,9 +27,36 @@ export default class FriendRelation extends BaseModel {
|
||||
@prop({ required: true, default: [], type: Relation, _id: false })
|
||||
blacklist: Relation[]; // 黑名单列表
|
||||
|
||||
|
||||
// 创建
|
||||
public static async addFriend(roleId: string, friend: RoleType, friendShip: FriendShipType) {
|
||||
|
||||
const result: FriendRelationType = await FriendRelationModel.findOneAndUpdate(
|
||||
{ roleId }, {
|
||||
$setOnInsert: { blacklist: [] },
|
||||
$push: { friends: { roleId: friend.roleId, role: friend._id, friendShip: friendShip._id } }
|
||||
}, { upsert: true, new: true }).lean();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// 获取列表
|
||||
public static async findFriendByRole(roleId: string) {
|
||||
const result: FriendRelationType = await FriendRelationModel.findOne({ roleId })
|
||||
.populate('friends.role', ROLE.SHOW_SIMPLE, 'Role')
|
||||
.populate('friends.friendShip', null, 'FriendShip')
|
||||
.lean({ getters: true, virtuals: true });
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async deleteAccount(roleId: string) {
|
||||
let result = await FriendRelationModel.deleteMany({ roleId });
|
||||
await FriendRelationModel.updateMany({}, { $pull: { friends: { roleId }, blacklist: { roleId } }});
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export const FriendRelationModel = getModelForClass(FriendRelation);
|
||||
|
||||
export interface FriendRelationType extends Pick<DocumentType<FriendRelation>, keyof FriendRelation>{};
|
||||
export interface FriendRelationType extends Pick<DocumentType<FriendRelation>, keyof FriendRelation> { };
|
||||
@@ -1,5 +1,6 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
import { getFriendLvByExp } from '../pubUtils/data';
|
||||
|
||||
/**
|
||||
* 好友直接的亲密值
|
||||
@@ -28,15 +29,63 @@ export default class FriendShip extends BaseModel {
|
||||
refTime: Date;
|
||||
|
||||
@prop({ required: true, default: 0 })
|
||||
frdValue: number; // 两人之间的亲密值
|
||||
friendValue: number; // 两人之间的亲密值
|
||||
|
||||
public get frdLv() { // 亲密等级
|
||||
return this.frdValue;
|
||||
public get friendLv() { // 亲密等级
|
||||
return getFriendLvByExp(this.friendValue);
|
||||
}
|
||||
|
||||
private static getRoleIds(roleIds: string[]) {
|
||||
roleIds.sort();
|
||||
return {
|
||||
roleIdA: roleIds[0],
|
||||
roleIdB: roleIds[1],
|
||||
roleIds: roleIds.join('|')
|
||||
}
|
||||
}
|
||||
|
||||
public static getRoleSendAndReceive(myRoleId: string, roleIds: string[], friendShip: FriendShipType) {
|
||||
let { roleIdA, roleIdB } = this.getRoleIds(roleIds);
|
||||
if (roleIdA == myRoleId) {
|
||||
return {
|
||||
sendHeart: friendShip.sendHeartCntA,
|
||||
beSentHeart: friendShip.sendHeartCntB,
|
||||
recieveHeart: friendShip.receiveHeartCntA,
|
||||
beReceivedHeart: friendShip.receiveHeartCntB
|
||||
}
|
||||
} else if (roleIdB == myRoleId) {
|
||||
return {
|
||||
sendHeart: friendShip.sendHeartCntB,
|
||||
beSentHeart: friendShip.sendHeartCntA,
|
||||
receiveHeart: friendShip.receiveHeartCntB,
|
||||
beReceivedHeart: friendShip.receiveHeartCntA
|
||||
}
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// 创建
|
||||
public static async createFriendShip(roleIdList: string[]) {
|
||||
if (roleIdList.length != 2) return false;
|
||||
let { roleIdA, roleIdB, roleIds } = this.getRoleIds(roleIdList);
|
||||
console.log(roleIdA, roleIdB, roleIds)
|
||||
|
||||
const doc = new FriendShipModel();
|
||||
const update = Object.assign(doc.toJSON(), { roleIdA, roleIdB, roleIds });
|
||||
|
||||
const result: FriendShipType = await FriendShipModel.findOneAndUpdate({ roleIds }, update, { upsert: true, new: true }).lean();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async deleteAccount(roleId: string) {
|
||||
let result = await FriendShipModel.deleteMany({ $or: [{ roleIdA: roleId }, { roleIdB: roleId }] });
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
export const FriendShipModel = getModelForClass(FriendShip);
|
||||
|
||||
export interface FriendShipType extends Pick<DocumentType<FriendShip>, keyof FriendShip>{};
|
||||
export interface FriendShipType extends Pick<DocumentType<FriendShip>, keyof FriendShip> { };
|
||||
@@ -437,7 +437,7 @@ export default class Role extends BaseModel {
|
||||
|
||||
// 获取未加入公会且登录时间在三天内的人
|
||||
public static async getInviteList(time: number, serverId: number) {
|
||||
const result = await RoleModel.find({ quitTime: { $gt: time }, hasGuild: false, serverId })
|
||||
const result = await RoleModel.find({ loginTime: { $gt: time }, hasGuild: false, serverId })
|
||||
.select('roleId roleName ce headHid sHid lv title job quitTime')
|
||||
.sort({quitTime: -1, lv: -1, ce: -1})
|
||||
.limit(100).lean({getters: true});
|
||||
@@ -445,8 +445,8 @@ export default class Role extends BaseModel {
|
||||
}
|
||||
|
||||
// 获取好友推荐列表
|
||||
public static async getRecommedList(minLv: number, maxLv: number, time: number) {
|
||||
const result = await RoleModel.find({ quitTime: { $gt: time }, lv: { $gte: minLv, $lte: maxLv } }, { _id: 0 })
|
||||
public static async getRecommedList(roleId: string, minLv: number, maxLv: number, time: number) {
|
||||
const result = await RoleModel.find({ loginTime: { $gt: time }, lv: { $gte: minLv, $lte: maxLv }, roleId: { $ne: roleId } }, { _id: 0 })
|
||||
.select(ROLE.SHOW_SIMPLE)
|
||||
.sort({quitTime: -1, lv: -1, ce: -1})
|
||||
.limit(100).lean({ getters: true });
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
import { RoleType } from "../../db/Role";
|
||||
import { FriendShipType } from "../../db/FriendShip";
|
||||
|
||||
export class FriendParams {
|
||||
roleId: string;
|
||||
roleName: string;
|
||||
lv: number;
|
||||
headHid: number;
|
||||
sHid: number;
|
||||
ce: number;
|
||||
title: number;
|
||||
|
||||
constructor(role: RoleType) {
|
||||
this.roleId = role.roleId;
|
||||
this.roleName = role.roleName;
|
||||
this.lv = role.lv;
|
||||
this.headHid = role.headHid;
|
||||
this.sHid = role.sHid;
|
||||
this.ce = role.ce;
|
||||
this.title = role.title;
|
||||
}
|
||||
}
|
||||
|
||||
export class FriendApplyParams extends FriendParams {
|
||||
applyCode: string;
|
||||
constructor(applyCode: string, role: RoleType) {
|
||||
super(role);
|
||||
this.applyCode = applyCode;
|
||||
}
|
||||
}
|
||||
|
||||
export class FriendListParam extends FriendParams {
|
||||
guildName: string = "";
|
||||
isOnline: boolean = false;
|
||||
quitTime: number = 0;
|
||||
friendValue: number = 0;
|
||||
friendLv: number = 1;
|
||||
canReceive: boolean = false;
|
||||
canSend: boolean = false;
|
||||
|
||||
constructor(role: RoleType, friendship: FriendShipType) {
|
||||
super(role);
|
||||
if(role.guildName) this.guildName = role.guildName;
|
||||
this.quitTime = role.quitTime;
|
||||
|
||||
this.friendLv = friendship.friendLv;
|
||||
this.friendValue = friendship.friendValue;
|
||||
}
|
||||
|
||||
setOnline(isOnline: boolean) {
|
||||
this.isOnline = isOnline;
|
||||
}
|
||||
|
||||
setCanReceive(canReceive: boolean) {
|
||||
this.canReceive = canReceive;
|
||||
}
|
||||
|
||||
setCanSend(canSend: boolean) {
|
||||
this.canSend = canSend;
|
||||
}
|
||||
}
|
||||
@@ -56,6 +56,9 @@ import { RewardInter } from "./interface";
|
||||
import { dicArmyDevelopConsume } from '../pubUtils/dictionary/DicArmyDevelopConsume';
|
||||
import { dicArmyBossRank } from '../pubUtils/dictionary/DicArmyBossRank';
|
||||
import { dicArmyDonate } from '../pubUtils/dictionary/DicArmyDonateBoxReward';
|
||||
import { dicRoleFriend } from "./dictionary/DicRoleFriend";
|
||||
import { dicRoleFriendLv } from "./dictionary/DicRoleFriendLv";
|
||||
|
||||
export const gameData = {
|
||||
blurprtCompose: dicBlueprtCompose,
|
||||
blueprtPossibility: dicBlueprtPossibility,
|
||||
@@ -134,6 +137,8 @@ export const gameData = {
|
||||
armyDevelopConsume: dicArmyDevelopConsume,
|
||||
armyBossRank: dicArmyBossRank,
|
||||
armyDonateBox: dicArmyDonate,
|
||||
roleFriend: dicRoleFriend,
|
||||
roleFriendLv: dicRoleFriendLv,
|
||||
};
|
||||
|
||||
// 在此提供一些原先在gamedata中提供的方法,以便更方便获取gameData数据
|
||||
@@ -398,3 +403,12 @@ export function getArmyDonateBoxBaseById(id: number) {
|
||||
export function getArmyWishPoolBaseByLv(lv: number) {
|
||||
return gameData.armyWishPool.get(lv);
|
||||
}
|
||||
|
||||
export function getFriendLvByExp(exp: number) {
|
||||
let resultLv = 1;
|
||||
for(let [lv, {value}] of gameData.roleFriendLv) {
|
||||
resultLv = lv;
|
||||
if(exp < value) break;
|
||||
}
|
||||
return resultLv;
|
||||
}
|
||||
30
shared/pubUtils/dictionary/DicRoleFriend.ts
Normal file
30
shared/pubUtils/dictionary/DicRoleFriend.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
// 好友表
|
||||
import { readJsonFile } from '../util'
|
||||
import { FILENAME } from '../../consts'
|
||||
|
||||
export interface DicRoleFriend {
|
||||
|
||||
// id
|
||||
readonly id: number;
|
||||
// 主公等级
|
||||
readonly lv: number;
|
||||
// 好友数量
|
||||
readonly frdCnt: number;
|
||||
// 每日可收取好友情谊点上限
|
||||
readonly receiveMax: number;
|
||||
// 每日可赠送好友情谊点上限
|
||||
readonly sendMax: number;
|
||||
|
||||
}
|
||||
|
||||
|
||||
const str = readJsonFile(FILENAME.DIC_ROLE_FRIEND);
|
||||
let arr = JSON.parse(str);
|
||||
|
||||
export const dicRoleFriend = new Map<number, DicRoleFriend>();
|
||||
|
||||
arr.forEach(o => {
|
||||
dicRoleFriend.set(o.lv, o);
|
||||
});
|
||||
|
||||
arr = undefined;
|
||||
28
shared/pubUtils/dictionary/DicRoleFriendLv.ts
Normal file
28
shared/pubUtils/dictionary/DicRoleFriendLv.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
// 亲密度等级表
|
||||
import { readJsonFile } from '../util'
|
||||
import { FILENAME } from '../../consts'
|
||||
|
||||
export interface DicRoleFriendLv {
|
||||
|
||||
// id
|
||||
readonly id: number;
|
||||
// 亲密度等级
|
||||
readonly lv: number;
|
||||
// 亲密度值
|
||||
readonly value: number;
|
||||
// 寻宝加成
|
||||
readonly comBattleAdd: number;
|
||||
|
||||
}
|
||||
|
||||
|
||||
const str = readJsonFile(FILENAME.DIC_ROLE_FRIEND_LEVEL);
|
||||
let arr = JSON.parse(str);
|
||||
|
||||
export const dicRoleFriendLv = new Map<number, DicRoleFriendLv>();
|
||||
|
||||
arr.forEach(o => {
|
||||
dicRoleFriendLv.set(o.lv, o);
|
||||
});
|
||||
|
||||
arr = undefined;
|
||||
62
shared/resource/jsons/dic_zyz_closelevel.json
Normal file
62
shared/resource/jsons/dic_zyz_closelevel.json
Normal file
@@ -0,0 +1,62 @@
|
||||
[
|
||||
{
|
||||
"id": 1,
|
||||
"lv": 1,
|
||||
"value": 50,
|
||||
"comBattleAdd": 2
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"lv": 2,
|
||||
"value": 100,
|
||||
"comBattleAdd": 4
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"lv": 3,
|
||||
"value": 160,
|
||||
"comBattleAdd": 6
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"lv": 4,
|
||||
"value": 230,
|
||||
"comBattleAdd": 8
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"lv": 5,
|
||||
"value": 310,
|
||||
"comBattleAdd": 10
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"lv": 6,
|
||||
"value": 400,
|
||||
"comBattleAdd": 13
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
"lv": 7,
|
||||
"value": 500,
|
||||
"comBattleAdd": 16
|
||||
},
|
||||
{
|
||||
"id": 8,
|
||||
"lv": 8,
|
||||
"value": 610,
|
||||
"comBattleAdd": 19
|
||||
},
|
||||
{
|
||||
"id": 9,
|
||||
"lv": 9,
|
||||
"value": 730,
|
||||
"comBattleAdd": 22
|
||||
},
|
||||
{
|
||||
"id": 10,
|
||||
"lv": 10,
|
||||
"value": 860,
|
||||
"comBattleAdd": 25
|
||||
}
|
||||
]
|
||||
72
shared/resource/jsons/dic_zyz_friends.json
Normal file
72
shared/resource/jsons/dic_zyz_friends.json
Normal file
@@ -0,0 +1,72 @@
|
||||
[
|
||||
{
|
||||
"id": 1,
|
||||
"lv": 20,
|
||||
"frdCnt": 30,
|
||||
"receiveMax": 30,
|
||||
"sendMax": 30
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"lv": 30,
|
||||
"frdCnt": 40,
|
||||
"receiveMax": 35,
|
||||
"sendMax": 35
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"lv": 40,
|
||||
"frdCnt": 50,
|
||||
"receiveMax": 40,
|
||||
"sendMax": 40
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"lv": 50,
|
||||
"frdCnt": 60,
|
||||
"receiveMax": 45,
|
||||
"sendMax": 45
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"lv": 55,
|
||||
"frdCnt": 70,
|
||||
"receiveMax": 45,
|
||||
"sendMax": 45
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"lv": 60,
|
||||
"frdCnt": 80,
|
||||
"receiveMax": 50,
|
||||
"sendMax": 50
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
"lv": 65,
|
||||
"frdCnt": 90,
|
||||
"receiveMax": 50,
|
||||
"sendMax": 50
|
||||
},
|
||||
{
|
||||
"id": 8,
|
||||
"lv": 70,
|
||||
"frdCnt": 100,
|
||||
"receiveMax": 60,
|
||||
"sendMax": 60
|
||||
},
|
||||
{
|
||||
"id": 9,
|
||||
"lv": 75,
|
||||
"frdCnt": 120,
|
||||
"receiveMax": 60,
|
||||
"sendMax": 60
|
||||
},
|
||||
{
|
||||
"id": 10,
|
||||
"lv": 80,
|
||||
"frdCnt": 150,
|
||||
"receiveMax": 70,
|
||||
"sendMax": 70
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user