好友:赠送礼物
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { Application, BackendSession } from "pinus";
|
||||
import { resResult, getRandEelm, getResStr, shouldRefresh } from "../../../pubUtils/util";
|
||||
import { STATUS, ROLE, FRIEND_DROP_TYPE, FRIEND_RELATION_TYPE, POPULATE_TYPE, BLOCK_OPEATE } from "../../../consts";
|
||||
import { STATUS, ROLE, FRIEND_DROP_TYPE, FRIEND_RELATION_TYPE, POPULATE_TYPE, BLOCK_OPEATE, CONSUME_TYPE, ITID } from "../../../consts";
|
||||
import { RoleModel, RoleType } from "../../../db/Role";
|
||||
import { getBeforeDaySeconds } from "../../../pubUtils/timeUtil";
|
||||
import { FriendApplyModel } from "../../../db/FriendApply";
|
||||
@@ -11,8 +11,10 @@ import { isRoleOnline } from "../../../services/redisService";
|
||||
import { increaseFrdCnt, getRecommendType, sortByBeSentHeart } from "../../../services/friendService";
|
||||
import { FriendPointModel } from "../../../db/FriendPoint";
|
||||
import { gameData } from "../../../pubUtils/data";
|
||||
import { addItems } from "../../../services/rewardService";
|
||||
import { addItems, handleCost } from "../../../services/rewardService";
|
||||
import { getFriendPointObject } from "../../../pubUtils/itemUtils";
|
||||
import { RewardInter } from "../../../pubUtils/interface";
|
||||
import { FriendPresentLogModel } from '../../../db/FriendPresentLog';
|
||||
|
||||
|
||||
export default function (app: Application) {
|
||||
@@ -448,4 +450,45 @@ export class FriendHandler {
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// 赠送礼物
|
||||
public async sendPresent(msg: { roleId: string, items: RewardInter[] }, session: BackendSession) {
|
||||
let roleId: string = session.get('roleId');
|
||||
let sid: string = session.get('sid');
|
||||
|
||||
let { roleId: hisRoleId, items } = msg;
|
||||
let myRelation = await FriendRelationModel.findFriendByRole(roleId, POPULATE_TYPE.NOT);
|
||||
let friends = myRelation?myRelation.friends: [];
|
||||
let curFriend = friends.find(cur => cur.roleId == hisRoleId);
|
||||
if(!curFriend) return resResult(STATUS.FRIEND_NOT_FOUND);
|
||||
|
||||
let friendValueInc = 0;
|
||||
for(let {id, count} of items ) {
|
||||
let dicGood = gameData.goods.get(id);
|
||||
if(!dicGood) {
|
||||
return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
}
|
||||
|
||||
let dicItid = ITID.get(dicGood.itid);
|
||||
if (dicItid.type == CONSUME_TYPE.FRIEND_FAVOUR) {
|
||||
friendValueInc += dicGood.value * count;
|
||||
} else {
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
}
|
||||
}
|
||||
|
||||
let costResult = await handleCost(roleId, sid, items);
|
||||
if(!costResult) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
|
||||
|
||||
let result = await FriendShipModel.addFriendValue(roleId, hisRoleId, friendValueInc);
|
||||
if(!result) return resResult(STATUS.FRIEND_NOT_FOUND);
|
||||
|
||||
// TODO 日志可以转到log服
|
||||
await FriendPresentLogModel.createRecord(roleId, hisRoleId, items);
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
roleId: hisRoleId,
|
||||
...result
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user