xy-server/game/core/Launch.ts
2025-04-23 09:34:08 +08:00

298 lines
9.8 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 启动模块
* 起始模块,初始化各个管理器,启动游戏主逻辑循环
*/
import GameUtil from "./GameUtil";
import PlayerMgr from "../object/PlayerMgr";
import Signal from "./Signal";
import NoticeMgr from "./NoticeMgr";
import AgentMgr from "../network/AgentMgr";
import LotteryMgr from "./LotteryMgr";
import DialMgr from "./DialMgr";
import ActivityMgr from "../activity/ActivityMgr";
import BangMgr from "../bang/BangMgr";
import ChargeSum from "./ChargeSum";
import RelationMgr from "../object/RelationMgr";
import PalaceFight from "../activity/PalaceFight";
import MapMgr from "./MapMgr";
import LevelMgr from "../object/LevelMgr";
import GoodsMgr from "../item/GoodsMgr";
import EquipMgr from "../object/EquipMgr";
import MagicWeaponMgr from "../object/MagicWeaponMgr";
import EffectMgr from "../skill/core/EffectMgr";
import Shop from "../object/Shop";
import World from "../object/World";
import DWorld from "../object/DWorld";
import NpcMgr from "./NpcMgr";
import MonsterMgr from "./MonsterMgr";
import MallMgr from "./MallMgr";
import ZhenbukuiMgr from "../activity/ZhenbukuiMgr";
import PaiHangMgr from "./PaiHangMgr";
import SignInMgr from "./SignInMgr";
import RespondentsMgr from "./RespondentsMgr";
import PetMgr from "./PetMgr";
import PartnerConfigMgr from "../object/PartnerConfigMgr";
import TaskConfigMgr from "../task/TaskConfigMgr";
import NpcConfigMgr from "./NpcConfigMgr";
import SkillUtil from '../skill/core/SkillUtil';
import SKLogger from '../gear/SKLogger';
import BoxMgr from './BoxMgr';
import DugMgr from '../role/DugMgr';
import { MsgCode } from "../role/EEnum";
import SchemeMgr from "../object/SchemeMgr";
import RobotMgr from "./RobotMgr";
import MailMgr from "../mail/MailMgr";
import JingJiChang from "../activity/JingJiChang";
import ChangeCard from "../object/ChangeCard";
import SKRedisUtil from "../gear/SKRedisUtil";
import FivePhases from "../object/FivePhases";
import SatAssembly from "../activity/SatAssembly";
import FactionWar from "../activity/FactionWar";
import SpecialEffect from "../object/SpecialEffect";
import PetSupport from "../object/PetSupport";
import Ofuda from "../object/Ofuda";
import DebrisMall from "./DebrisMall";
import Interface from "./Interface";
import OnlineRewards from "../activity/OnlineRewards";
import Currency from "../activity/Currency";
import Marry from "../object/Marry";
import TianTi from "../activity/TianTi";
import JIngChanSongFuMgr from "../JingChanSongFu/JIngChanSongFuMgr";
export default class Launch {
static shared = new Launch();
// 完成列表
completeList: any = {
["BangMgr"]: false,
["PaiHangMgr"]: false,
["ChargeSum"]: false,
["MailMgr"]: false,
["SignInMgr"]: false,
["RespondentsMgr"]: false,
};
// 服务存档列表
saveList: any = [
Shop,
];
saved: number = 0;
dt: number;
constructor() {
// 每秒4帧
GameUtil.frameTime = 1000 / 4;
// 主逻辑循环
this.dt = 0;
}
mainloop() {
if (isNaN(this.dt)) {
// 每秒4帧
GameUtil.frameTime = 1000 / 4;
// 主逻辑循环
this.dt = 0;
}
this.dt += GameUtil.frameTime;
// 内部通信循环
Signal.shared.update(this.dt);
AgentMgr.shared.update(this.dt);
NoticeMgr.shared.update(GameUtil.frameTime);
PlayerMgr.shared.update(this.dt);
LotteryMgr.shared.update(this.dt);
ActivityMgr.shared.update(this.dt);
PalaceFight.shared.update(GameUtil.frameTime);
RelationMgr.shared.update(this.dt);
GameUtil.gameTime += GameUtil.frameTime;
// 1分钟校正
if (this.dt % (1 * 60 * 1000) == 0) {
GameUtil.gameTime = Date.now();
}
};
start() {
GameUtil.gameTime = Date.now();
setInterval(this.mainloop, GameUtil.frameTime);
// 通知模块
NoticeMgr.shared.launch();
SKLogger.info('通知模块初始化完毕!');
// 地图模块
MapMgr.shared.launch();
SKLogger.info('地图模块加载完毕!');
// 任务配置
TaskConfigMgr.shared.launch();
SKLogger.info('任务配置模块加载完毕!');
// 地煞天元模块
World.shared.launch();
DWorld.shared.init();
SKLogger.info('地煞天元模块加载完毕!');
// 证道大会模块
SatAssembly.shared.init();
SKLogger.info('证道模块加载完毕!');
// NPC配置
NpcConfigMgr.shared.launch();
SKLogger.info('Npc配置模块加载完毕');
// NPC
NpcMgr.shared.launch();
SKLogger.info('Npc模块加载完毕');
// 玩家模块
PlayerMgr.shared.launch();
SKLogger.info('角色属性模块加载完毕!');
GoodsMgr.shared.launch();
SKLogger.info('物品模块加载完毕!');
// 经验模块
LevelMgr.shared.launch();
SKLogger.info('经验模块加载完毕!');
// 技能模块
SkillUtil.launch();
SKLogger.info('技能模块加载完毕!');
// 技能效果模块
EffectMgr.shared.launch();
SKLogger.info('技能效果模块加载完毕!');
// 装备模块
EquipMgr.shared.launch();
// 法宝模块
MagicWeaponMgr.shared.launch();
// 帮派模块
BangMgr.shared.launch();
// 怪物模块
MonsterMgr.shared.launch();
SKLogger.info('怪物模块加载完毕!');
// 商城模块
MallMgr.shared.init();
SKLogger.info('商城模块加载完毕!');
// 碎片模块
DebrisMall.shared.init();
SKLogger.info('碎片商城模块加载完毕!');
//甄不亏模块
ZhenbukuiMgr.shared.init();
SKLogger.info('甄不亏模块加载完毕!');
// 摆摊模块
Shop.shared.init();
SKLogger.info('摆摊模块加载完毕!');
// 排行榜模块
PaiHangMgr.shared.init();
ChangeCard.shared.init();
SpecialEffect.shared.init();
FivePhases.shared.init();
PetSupport.shared.init();
Ofuda.shared.init();
//竞技场
JingJiChang.shared.init();
// 签到模块
SignInMgr.shared.init();
// 答题模块
RespondentsMgr.shared.init();
// 宠物模块
PetMgr.shared.launch();
SchemeMgr.launch();
// 充值总额模块
ChargeSum.shared.init();
// 伙伴模块
PartnerConfigMgr.shared.init();
SKLogger.info('伙伴管理模块加载完毕!');
// 活动模块
ActivityMgr.shared.init();
SKLogger.info('活动模块加载完毕!');
// 开箱模块
BoxMgr.shared.init();
SKLogger.info(`开箱模块加载完毕`);
// 挖宝模块
DugMgr.shared.init();
SKLogger.info(`挖宝模块加载完毕`);
// 彩票模块
LotteryMgr.shared.init();
SKLogger.info('彩票模块加载完毕!');
// 幸运转盘
DialMgr.shared.init();
SKLogger.info('幸运转盘模块加载完毕!');
//关系模块
RelationMgr.shared.init();
SKLogger.info(`关系模块加载完毕`);
// 创建机器人
RobotMgr.shared.init();
SKLogger.info(`机器人模块加载完毕`);
MailMgr.shared.launch();
// 帮战模块
FactionWar.shared.init();
SKLogger.info('帮战模块加载完毕!');
// 在线奖励模块
OnlineRewards.shared.init();
SKLogger.info('在线奖励模块加载完毕!');
// 打金模块
Currency.shared.init();
SKLogger.info('打金模块加载完毕!');
// 白名单模块
Interface.shared.init();
SKLogger.info('白名单模块加载完毕!');
// 结婚模块
Marry.shared.init();
TianTi.shared.init();
SKLogger.info("天梯模块启动完毕")
JIngChanSongFuMgr.shared.launch();
SKLogger.info(`金蟾送服模块启动完毕`);
//启动Redis管理模块
// SKRedisUtil.launch();
// SKLogger.info(`Redis模块启动完毕`);
};
checkAllComplete() {
for (let key in this.completeList) {
if (this.completeList[key] == false) {
return false;
}
}
return true;
}
complete(mod: any) {
this.completeList[mod] = true;
SKLogger.info(`模块[${mod}]加载完成!`);
if (this.checkAllComplete()) {
// 连接代理模块
AgentMgr.shared.start();
// 向Gate服注册
Signal.shared.registerServer();
SKLogger.info('游戏服务器启动完毕,等待命令');
}
}
// 全部存档
saveAll(callback: (code: number) => void) {
this.saved = 0;
let self = this;
PlayerMgr.shared.saveAll(() => {
for (let key in self.saveList) {
let mgr = self.saveList[key];
mgr.saveAll((msg: string) => {
SKLogger.info(`全部存档:${msg}`);
self.saved++;
if (self.saved == self.saveList.length) {
callback(MsgCode.SUCCESS);
}
});
}
});
};
// 关服
close(callback: (code: number) => void) {
PlayerMgr.shared.readyToCloseServer();
let self = this;
setTimeout(() => {
self.saveAll((code: number) => {
AgentMgr.shared.close();
ActivityMgr.shared.close();
callback(code);
});
}, 12 * 1000);
};
// 是否关闭
isClose(): boolean {
if (this.saved == this.saveList.length) {
return true;
}
return false;
}
}