🦄 refactor(热更新): 分割状态代码和功能代码
This commit is contained in:
@@ -1,25 +1,19 @@
|
||||
// 军团活动蛮夷入侵城门血量等数据存储
|
||||
|
||||
import { GUILD_ACTIVITY_STATUS } from "../../consts";
|
||||
import { Member } from "../../domain/battleField/guildActivity";
|
||||
import { CityActivityData } from "../../domain/battleField/guildActivity";
|
||||
import { getCityActivityGateHp } from "./guildActivityService";
|
||||
|
||||
// 军团诸侯混战等数据
|
||||
export class CityActivityObject {
|
||||
public guildActivityStatus = GUILD_ACTIVITY_STATUS.WAITING; // 活动状态 0-未开始 1-已开始 2-已结束
|
||||
private gateHp: Map<string, number> = new Map(); // 城门血条,每个cityId有一条血条 serverId&cityId => gateHp
|
||||
private maxHp: Map<string, number> = new Map(); // 城门血条,每个cityId最大城门血量 serverId&cityId => gateHp
|
||||
private members: Map<string, Array<Member>> = new Map(); // 每个军团参与的成员 guildCode => [{roleId, job}]
|
||||
private cities: Map<string, string[]> = new Map(); // 各个城池参与的军团 serverId&cityId => [guildCode]
|
||||
private guilds: Map<string, number> = new Map(); // 军团所在的城池 guildCode => cityId
|
||||
private sentCity: string[] = [];
|
||||
private startTime: number = 0;
|
||||
data: CityActivityData = new CityActivityData();
|
||||
|
||||
private getKey(serverId: number, cityId: number) {
|
||||
|
||||
public getKey(serverId: number, cityId: number) {
|
||||
return `${serverId}_${cityId}`;
|
||||
}
|
||||
|
||||
private decodeKey(key: string) {
|
||||
public decodeKey(key: string) {
|
||||
let arr = key.split('_');
|
||||
return {
|
||||
serverId: parseInt(arr[0]),
|
||||
@@ -30,25 +24,29 @@ export class CityActivityObject {
|
||||
public getObj( serverId: number, cityId: number, guildCode: string) {
|
||||
let key = this.getKey(serverId, cityId);
|
||||
return {
|
||||
gateHp: this.gateHp.get(key),
|
||||
maxHp: this.maxHp.get(key),
|
||||
members: this.members.get(guildCode),
|
||||
city: this.cities.get(key),
|
||||
guild: this.guilds.get(guildCode)
|
||||
gateHp: this.data.gateHp.get(key),
|
||||
maxHp: this.data.maxHp.get(key),
|
||||
members: this.data.members.get(guildCode),
|
||||
city: this.data.cities.get(key),
|
||||
guild: this.data.guilds.get(guildCode)
|
||||
}
|
||||
}
|
||||
|
||||
public startActivity() {
|
||||
this.startTime = Date.now();
|
||||
this.guildActivityStatus = GUILD_ACTIVITY_STATUS.START;
|
||||
this.data.startTime = Date.now();
|
||||
this.data.guildActivityStatus = GUILD_ACTIVITY_STATUS.START;
|
||||
}
|
||||
|
||||
public endActivity() {
|
||||
this.guildActivityStatus = GUILD_ACTIVITY_STATUS.END;
|
||||
this.data.guildActivityStatus = GUILD_ACTIVITY_STATUS.END;
|
||||
}
|
||||
|
||||
public getStatus() {
|
||||
return this.data.guildActivityStatus;
|
||||
}
|
||||
|
||||
public getTimeGap() {
|
||||
return Math.floor((Date.now() - this.startTime)/1000);
|
||||
return Math.floor((Date.now() - this.data.startTime)/1000);
|
||||
}
|
||||
|
||||
public lockCity(serverId: number, cityId: number) {
|
||||
@@ -65,18 +63,18 @@ export class CityActivityObject {
|
||||
// this.guilds.delete(guildCode);
|
||||
// }
|
||||
// this.cities.delete(key);
|
||||
this.sentCity.push(key);
|
||||
this.data.sentCity.push(key);
|
||||
}
|
||||
|
||||
public hasSent(serverId: number, cityId: number) {
|
||||
let key = this.getKey(serverId, cityId);
|
||||
return this.sentCity.indexOf(key) != -1;
|
||||
return this.data.sentCity.indexOf(key) != -1;
|
||||
}
|
||||
|
||||
public getAllCities() {
|
||||
let allCities = new Array<{ serverId: number, cityId: number, guildCodes: string[]}>();
|
||||
let serverlists = new Array<number>();
|
||||
for(let [key, guildCodes] of this.cities) {
|
||||
for(let [key, guildCodes] of this.data.cities) {
|
||||
let { serverId, cityId } = this.decodeKey(key);
|
||||
if(!this.hasSent(serverId, cityId)) {
|
||||
allCities.push({ serverId, cityId, guildCodes });
|
||||
@@ -88,53 +86,53 @@ export class CityActivityObject {
|
||||
|
||||
public getGuildsInCity(serverId: number, cityId: number) {
|
||||
let key = this.getKey(serverId, cityId);
|
||||
return this.cities.get(key)||[];
|
||||
return this.data.cities.get(key)||[];
|
||||
}
|
||||
|
||||
public getMembersOfGuild(guildCode: string) {
|
||||
return this.members.get(guildCode)||[];
|
||||
return this.data.members.get(guildCode)||[];
|
||||
}
|
||||
|
||||
public async getGateHpAndInc(serverId: number, cityId: number, inc: number = 0) {
|
||||
let key = this.getKey(serverId, cityId);
|
||||
let gateHp = this.gateHp.get(key);
|
||||
if(!this.gateHp.has(key)) {
|
||||
let gateHp = this.data.gateHp.get(key);
|
||||
if(!this.data.gateHp.has(key)) {
|
||||
gateHp = await getCityActivityGateHp(serverId, cityId);
|
||||
this.gateHp.set(key, gateHp);
|
||||
this.maxHp.set(key, gateHp);
|
||||
this.data.gateHp.set(key, gateHp);
|
||||
this.data.maxHp.set(key, gateHp);
|
||||
}
|
||||
if(inc != 0) {
|
||||
gateHp += inc;
|
||||
this.gateHp.set(key, gateHp);
|
||||
this.data.gateHp.set(key, gateHp);
|
||||
}
|
||||
if(gateHp <= 0) gateHp = 0;
|
||||
return { gateHp, maxHp: this.maxHp.get(key)||0 }
|
||||
return { gateHp, maxHp: this.data.maxHp.get(key)||0 }
|
||||
}
|
||||
|
||||
public pushMembers(guildCode: string, roleId: string, job: number, code: string) {
|
||||
|
||||
if(this.members.has(guildCode)) {
|
||||
let members = this.members.get(guildCode);
|
||||
if(this.data.members.has(guildCode)) {
|
||||
let members = this.data.members.get(guildCode);
|
||||
if(members.findIndex(cur => cur.roleId == roleId) == -1) {
|
||||
members.push({ roleId, job, code });
|
||||
}
|
||||
} else {
|
||||
let arr = new Array<string>();
|
||||
arr.push(roleId);
|
||||
this.members.set(guildCode, [{ roleId, job, code }]);
|
||||
this.data.members.set(guildCode, [{ roleId, job, code }]);
|
||||
}
|
||||
}
|
||||
|
||||
public pushGuild(guildCode: string, serverId: number, cityId: number) {
|
||||
let key = this.getKey(serverId, cityId);
|
||||
if(!this.cities.has(key)) {
|
||||
this.cities.set(key, [guildCode]);
|
||||
if(!this.data.cities.has(key)) {
|
||||
this.data.cities.set(key, [guildCode]);
|
||||
} else {
|
||||
let arr = this.cities.get(key);
|
||||
let arr = this.data.cities.get(key);
|
||||
if(!arr.includes(guildCode)) {
|
||||
arr.push(guildCode);
|
||||
}
|
||||
}
|
||||
this.guilds.set(guildCode, cityId);
|
||||
this.data.guilds.set(guildCode, cityId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user