51 lines
1.9 KiB
TypeScript
51 lines
1.9 KiB
TypeScript
import { gameData } from "../pubUtils/data";
|
|
import { RoleType, RoleModel } from "../db/Role";
|
|
import { FriendRelationType } from "../db/FriendRelation";
|
|
import { getResStr } from "../pubUtils/util";
|
|
import { STATUS, FRIEND_RELATION_TYPE } from "../consts";
|
|
|
|
/**
|
|
* 增加双方好友数
|
|
* @param role1 我方
|
|
* @param role2 对方
|
|
* @returns 是否添加成功
|
|
*/
|
|
export async function increaseFrdCnt(role1: RoleType, role2: RoleType, originalFriendCnt: number) {
|
|
|
|
let { roleId, lv, friendCnt } = role1;
|
|
let dicFriend = gameData.roleFriend.get(lv);
|
|
|
|
if(friendCnt >= dicFriend.frdCnt) return getResStr(STATUS.FRIEND_MY_CNT_MAX);
|
|
|
|
let { roleId: _roleId, lv: _lv, friendCnt: _friendCnt } = role2;
|
|
let _dicFriend = gameData.roleFriend.get(_lv);
|
|
if(_friendCnt >= _dicFriend.frdCnt) return getResStr(STATUS.FRIEND_THEY_CNT_MAX);
|
|
|
|
let incMyFrdCnt = await RoleModel.increaseFriendCnt(roleId, 1, dicFriend.frdCnt);
|
|
if(!incMyFrdCnt) return getResStr(STATUS.FRIEND_MY_CNT_MAX);
|
|
let incHisFrdCnt = await RoleModel.increaseFriendCnt(_roleId, 1, _dicFriend.frdCnt);
|
|
if(!incHisFrdCnt) { // 回滚
|
|
await RoleModel.increaseFriendCnt(roleId, -1, dicFriend.frdCnt);
|
|
return getResStr(STATUS.FRIEND_THEY_CNT_MAX);
|
|
}
|
|
originalFriendCnt = incMyFrdCnt.friendCnt;
|
|
|
|
return '';
|
|
}
|
|
|
|
export function getRecommendType(myFriendRelation: FriendRelationType, myRoleId: string, roleId: string) {
|
|
if(myRoleId == roleId) {
|
|
return FRIEND_RELATION_TYPE.MYSELF;
|
|
}
|
|
let friendList = myFriendRelation? myFriendRelation.friends: [];
|
|
let blackList = myFriendRelation? myFriendRelation.blacklist: [];
|
|
let hasFriend = friendList.find(cur => cur.roleId == roleId);
|
|
if(hasFriend) {
|
|
return FRIEND_RELATION_TYPE.HAS_FRIEND;
|
|
}
|
|
let hasBlcklist = blackList.find(cur => cur.roleId == roleId);
|
|
if(hasBlcklist) {
|
|
return FRIEND_RELATION_TYPE.HAS_BLOCKED;
|
|
}
|
|
return FRIEND_RELATION_TYPE.NORMAL;
|
|
} |