✨ feat(gvg): 动态
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
|
||||
// 动态
|
||||
import { GVG_REC_ID, GVG_REC_TYPE, GVG_RESOURCE_TYPE } from "../../consts";
|
||||
import { GVGRecModel } from "../../db/GVGRec";
|
||||
import { nowSeconds } from "../../pubUtils/timeUtil";
|
||||
import { getGVGConfig } from "./gvgService";
|
||||
|
||||
// 加入军团
|
||||
export async function guildJoinLeagueRecord(leagueCode: string, guildName: string) {
|
||||
await leagueJoinOrQuitGuild(leagueCode, guildName, GVG_REC_ID.LEAGUE_JOIN_GUILD);
|
||||
}
|
||||
|
||||
// 退出军团
|
||||
export async function guildQuitLeagueRecord(leagueCode: string, guildName: string) {
|
||||
await leagueJoinOrQuitGuild(leagueCode, guildName, GVG_REC_ID.LEAGUE_QUIT_GUILD);
|
||||
}
|
||||
|
||||
async function leagueJoinOrQuitGuild(leagueCode: string, guildName: string, recId: GVG_REC_ID.LEAGUE_JOIN_GUILD|GVG_REC_ID.LEAGUE_QUIT_GUILD) {
|
||||
let { configId } = getGVGConfig();
|
||||
let params = [guildName];
|
||||
await GVGRecModel.addRec({ leagueCode, configId, type: GVG_REC_TYPE.PREPARE, recId, createTime: nowSeconds(), params })
|
||||
}
|
||||
|
||||
// 获得资源
|
||||
export async function addResourceRecord(roleId: string, roleName: string, leagueCode: string, resourceType: GVG_RESOURCE_TYPE, output: number) {
|
||||
let { configId } = getGVGConfig();
|
||||
let params = [roleName, getResourceNameByType(resourceType), `${output}`];
|
||||
await GVGRecModel.addRec({ roleId, leagueCode, configId, type: GVG_REC_TYPE.PREPARE, recId: GVG_REC_ID.ADD_RESOURCE, createTime: nowSeconds(), params })
|
||||
}
|
||||
|
||||
function getResourceNameByType(resourceType: GVG_RESOURCE_TYPE) {
|
||||
switch(resourceType) {
|
||||
case GVG_RESOURCE_TYPE.FOOD: return '粮食';
|
||||
case GVG_RESOURCE_TYPE.MINERAL: return '矿物';
|
||||
case GVG_RESOURCE_TYPE.WOOD: return '木堆';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user