mm_os
Version:
MM_OS服务端架构,用于快速构建应用程序,支持网站建设、小程序后台、AI应用、物联网(IOT/AIOT)、游戏服务端等多种场景。
77 lines (75 loc) • 1.77 kB
JavaScript
/**
* 游戏系统
*/
module.exports = {
/**
* 初始化
* @param {object} world 游戏世界类
* @param {object} eventer 事件总线
* @returns {Promise<void>}
*/
async _init(world, eventer) {
// this.log('debug', `初始化!`);
// 监听事件写在这
// eventer.on('事件名', this._方法名);
},
/**
* 启动
*/
async _start() {
// this.log('debug', `启动!`);
},
/**
* 停止
*/
async _stop() {
this.log('debug', `停止!`);
},
/**
* 销毁
* @param {...any} args 参数列表
*/
async _destroy(...args) {
this.log('debug', `销毁!`, { args });
},
/**
* 更新,用于游戏循环
*/
async update() {
// 循环更新的代码逻辑写在这
await this.main();
},
/**
* 主要逻辑
* @param {...any} args 参数列表
*/
async main(...args) {
// 主要代码写在这
this.log('debug', `主要逻辑被调用`, { args });
},
/**
* 怪物死亡(示例方法,可以删除)
* @param {object} monster 怪物
*/
onMonsterDeath(monster) {
// ✅ System 调用 Factory 创建实体
this.factory.effect.createExpOrb(
this.world,
monster.getComponent('position'),
monster.getComponent('monster').exp_reward
);
// 随机掉落物品
if (Math.random() < 0.3) {
this.factory.factory.item.createRandomDrop(
this.world,
monster.getComponent('monster').loot_table
);
}
// 处理死亡特效
this.factory.effect.createDeathEffect(
this.world,
monster.getComponent('position'),
monster.getComponent('monster').death_effect_type
);
}
};