144 lines
5.1 KiB
TypeScript
144 lines
5.1 KiB
TypeScript
import { GM_MAIL_TYPE, MAIL_TIME_TYPE, SERVER_TIMER } from "../../consts";
|
|
import { isArray } from 'underscore';
|
|
import GMMail from "../../db/GMMail";
|
|
import ServerStategy from "../../db/ServerStategy";
|
|
import { RegionType } from "../../db/Region";
|
|
|
|
export class UpdateMailParams {
|
|
hasGoods: boolean = false; // 是否有道具
|
|
goods: {id: number; count: number}[];
|
|
timeType: MAIL_TIME_TYPE; // 邮件时间类型
|
|
expire: number; // 有效时间,单位小时
|
|
startTime: number; // 发送时间,延时邮件使用
|
|
circleStart: number; // 循环邮件开始循环时间
|
|
circleEnd: number; // 循环邮件结束循环时间
|
|
circleDay: number; // 循环时间,每周几,0表示每天
|
|
circleHour: string; // 几点发送
|
|
title: string;
|
|
content: string;
|
|
sendName: string;
|
|
mailType: GM_MAIL_TYPE; // 收件人类型
|
|
receivers: {env: string; serverId: number; roleId: string; roleName: string; }[];
|
|
reason: string; // 原因
|
|
isSp: boolean = false; // 特殊邮件
|
|
isSingle: boolean;
|
|
|
|
constructor(obj: UpdateMailParams) {
|
|
this.goods = obj.goods;
|
|
this.hasGoods = obj.goods?.length > 0;
|
|
this.timeType = obj.timeType;
|
|
this.expire = obj.expire;
|
|
this.startTime = obj.startTime;
|
|
this.circleStart = obj.circleStart;
|
|
this.circleEnd = obj.circleEnd;
|
|
this.circleDay = obj.circleDay;
|
|
this.circleHour = obj.circleHour;
|
|
this.title = obj.title;
|
|
this.content = obj.content;
|
|
this.sendName = obj.sendName;
|
|
if(obj.isSingle == true) {
|
|
this.mailType = GM_MAIL_TYPE.SINGLE;
|
|
} else if (obj.isSingle == false) {
|
|
this.mailType = GM_MAIL_TYPE.SERVER;
|
|
}
|
|
this.receivers = obj.receivers;
|
|
this.reason = obj.reason;
|
|
}
|
|
|
|
checkParams() {
|
|
if(!this.title || !this.content || !this.sendName || !this.reason) return false;
|
|
if(this.timeType == MAIL_TIME_TYPE.IMMEDIATE) {
|
|
if(!this.expire) return false;
|
|
} else if (this.timeType == MAIL_TIME_TYPE.DELAY) {
|
|
if(!this.expire || !this.startTime) return false;
|
|
} else if (this.timeType == MAIL_TIME_TYPE.CIRCLE) {
|
|
if(!this.expire || !this.circleStart || !this.circleEnd || this.circleDay == undefined || !this.circleHour)
|
|
return false;
|
|
}
|
|
if(!this.receivers || !isArray(this.receivers)) return false;
|
|
if(!this.mailType) return false;
|
|
for(let { serverId, roleId, roleName } of this.receivers) {
|
|
if(!serverId) return false;
|
|
if(this.mailType == GM_MAIL_TYPE.SINGLE||this.mailType == GM_MAIL_TYPE.GROUP) {
|
|
if(!roleId || !roleName) return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
|
|
export class UpdateRegionParams {
|
|
id: number|'new' = 0; // 大区id
|
|
name: string = ''; // 大区名
|
|
prefix: string = ''; // 区名前缀
|
|
remark: string = '';
|
|
|
|
maxPlayerCnt: number = 0;
|
|
timers: SERVER_TIMER[] = [];
|
|
activityGroupId: number[] = [];
|
|
openMail?: GMMail;
|
|
circleMail?: GMMail;
|
|
stopRegisterTime: number = 0;
|
|
|
|
hasOpenMail: boolean = false;
|
|
hasCircleMail: boolean = false;
|
|
|
|
constructor(obj: UpdateRegionParams) {
|
|
for(let key in obj) {
|
|
this[key] = obj[key];
|
|
}
|
|
}
|
|
|
|
checkParams() {
|
|
if(!this.id || !this.name || !this.prefix || !this.maxPlayerCnt || !isArray(this.timers) || this.timers.length <= 0 || !isArray(this.activityGroupId) || this.activityGroupId.length <= 0 ) {
|
|
return false
|
|
}
|
|
return true;
|
|
}
|
|
|
|
getUpdateParam(oldRegion?: RegionType) {
|
|
if(!oldRegion) {
|
|
let stategy = new ServerStategy(this);
|
|
return {
|
|
name: this.name,
|
|
prefix: this.prefix,
|
|
remark: this.remark,
|
|
stategy
|
|
}
|
|
} else {
|
|
let stategy = new ServerStategy(this);
|
|
return {
|
|
name: this.name||oldRegion.name,
|
|
prefix: this.prefix||oldRegion.prefix,
|
|
remark: this.remark||oldRegion.remark,
|
|
stategy: { ...(oldRegion.stategy||{}), ...stategy }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
export class CreateServerParam {
|
|
env: string = '';
|
|
openTime: number = 0;
|
|
activityGroupId: number[] = [];
|
|
hasOpenMail: boolean = false;
|
|
openMail?: GMMail;
|
|
hasCircleMail: boolean = false;
|
|
circleMail?: GMMail;
|
|
stopRegisterTime: number = 0;
|
|
|
|
constructor(obj: CreateServerParam) {
|
|
for(let key in obj) {
|
|
this[key] = obj[key];
|
|
}
|
|
}
|
|
|
|
checkParams() {
|
|
if(!this.env || !this.openTime || !this.stopRegisterTime || !isArray(this.activityGroupId) || this.activityGroupId.length <= 0 ) {
|
|
return false
|
|
}
|
|
if(this.hasOpenMail && !this.openMail) return false;
|
|
if(this.hasCircleMail && !this.circleMail) return false;
|
|
return true;
|
|
}
|
|
} |