game_server.game_buffs
简介
buff系统
文件组织:
game_buffs: pkg.game_buffs的入口文件,提供了加载/获取buff特效功能模块、buff配置模板 等接口
FBuffBase: buff功能基础组件,提供增加/移除buff等功能
FBuffEffectBase: 处理buff特效功能的基础组件
FEntityBuffBase: 基于engine和FBuffBase实现的实体对象buff功能的组件
BuffClassMap: 一些buff数据结构 - 内置了FBuffBase要求的buff数据基础class以及基于时间的buff数据class
几点说明:
-
使用game_buffs.load_all_entry加载buff特效功能模块
-
使用game_buffs.set_buff_template新增buff的模板设置
-
BuffBase是buff数据结构的基础class,自定义的buff数据结构都应该继承BuffBase
-
buff的模板不是必须的,buff缺少模板配置时将使用默认实现
组件接口
FBuffBase.gs
buff的基础组件,基于class map实现
| 函数原型 | 函数作用 |
|---|---|
| map get_buffs() | 虚函数: 获取所有buff词典 |
| string alloc_buff_cookie() | 虚函数: 生成一个唯一的buff cookie(在此对象范围内必须唯一,并且跟历史值不重复) |
| void notify_buff_update(string buff_cookie, string op, BuffBase buff) | 虚函数: 通知buff更新消息 |
| void heartbeat_buffs(function filter_func = nil) | 执行一次buff心跳处理(处理buff心跳效果,清理过期buff) |
| BuffBase query_buff(string buff_cookie) | 通过cookie查询对应的buff |
| array query_cookies(string buff_id, function filter_func = nil) | 通过buff类型,查询该类的所有buff的cookie |
| array query_buffs_by_id(string buff_id, function filter_func = nil) | 通过buff类型,查询该类型的所有buff |
| bool contains_buff(string buff_id, function filter_func = nil) | 判断某个类型的buff是否存在 |
| string apply_buff(BuffBase buff) | 添加一个buff |
| void clear_buff(string buff_cookie) | 根据cookie清除一个buff |
| void clear_buffs_by_id(string buff_id, function filter_func = nil) | 清除一类buff |
| void clear_all_buffs(function filter_func = nil) | 清除所有buff |
FBuffEffectBase.gs
处理buff各阶段回调的基础组件
| 函数原型 | 函数作用 |
|---|---|
| bool pre_apply(object ob, BuffBase buff) | 虚函数: apply buff时的前处理 |
| void post_apply(object ob, string buff_cookie, BuffBase buff) | 虚函数: apply buff时的后处理 |
| void pre_clear(object ob, string buff_cookie, BuffBase buff) | 虚函数:clear buff时的前处理 |
| void post_clear(object ob, string buff_cookie, BuffBase buff) | 虚函数:clear buff时的后处理 |
| void heartbeat(object ob, string buff_cookie, BuffBase buff) | 虚函数: buff的心跳处理 |
FEntityBuffBase.gs
基于FEntity实现的实体buff组件(包含FBuffBase)
| 函数原型 | 函数作用 |
|---|---|
| map FBuffBase.get_buffs() | 虚函数: 获取所有buff词典 |
| string FBuffBase.alloc_buff_cookie() | 虚函数: 生成一个唯一的buff cookie |
| void FBuffBase.notify_buff_update(string buff_cookie, string op, BuffBase buff) | 虚函数: 通知buff更新消息 |
game_buffs.gs
| 函数原型 | 函数作用 |
|---|---|
| bool setup(map para = ) | 初始化buff系统 |
| void set_buff_template(string buff_id, map buff_template) | 设置buff的模板配置 |
| map get_buff_template(string buff_id) | 根据buff id获取模板配置 |
| object get_effect_ob(string buff_id) | 根据buff id获取buff的特效功能模块对象 |
类
BuffBase
buff数据基础类
成员变量
| 变量名 | 类型 | 初始值 | 须初始化 | 描述 |
|---|---|---|---|---|
| id | string | nil | 可选 | buff id |
成员方法
| 函数原型 | 函数作用 |
|---|---|
| bool is_capable_heartbeat() | 是不是可以心跳 |
| bool heartbeat_once(object owner) | 执行一次心跳 |
| bool is_eternal_life() | buff生命周期是不是永久 |
| bool is_out_of_life(object owner) | buff是否超出生命周期 |
| bool match(object owner, ...) |
TimeBaseBuff
继承自 BuffBase
基于时间的buff实现
成员变量
| 变量名 | 类型 | 初始值 | 须初始化 | 描述 |
|---|---|---|---|---|
| life_time | int | -1 | 可选 | 存在时间 |
| heartbeat_interval | int | -1 | 可选 | 心跳间隔 |
| heartbeat_time | int | -1 | 可选 | 心跳时间 |
| data | map | nil | 可选 | 其它数据 |
成员方法
| 函数原 型 | 函数作用 |
|---|---|
| bool is_capable_heartbeat() | 是不是可以心跳 |
| bool is_eternal_life() | buff生命周期是不是永久 |
| bool is_out_of_life(object owner) | buff是否超出生命周期 |
| bool heartbeat_once(object owner) | 执行一次心跳 |
| void set_duration(int duration_in_ms) | 设置生存时长 |
| void set_heartbeat_interval(int interval_in_ms) | 设置心跳间隔 |
BuffRuntimeManager
buff运行时信息的管理器
成员变量
| 变量名 | 类型 | 初始值 | 须初始化 | 描述 |
|---|---|---|---|---|
| mortal_list | array | nil | 可选 | 非永久周期的buff列表 |
| heartbeat_list | array | nil | 可选 | 有心跳能力的buff列表 |
成员方法
| 函数原型 | 函数作用 |
|---|---|
| void update(object owner, function filter_func = nil) | 清除过期buff并执行一次心跳 |
| void update_life(object owner, function filter_func = nil) | 清除所有超过生存时间的非永久生命周期buff |
| void update_heartbeat(object owner, function filter_func = nil) | 所有有心跳能力的buff执行心跳 |
| void add_buff(string buff_cookie, BuffBase buff) | 添加buff |
| void remove_buff(string buff_cookie) | 移除buff |
样例
// game_buffs模块初始化
//
map buff_templates = {};
// 加载buff模板
map hp_inc_template = {
"effect_mod" : "common_effect",
};
buff_templates["HP_INC"] = hp_inc_template;
map hp_dec_template = {
"effect_mod" : "common_effect",
"override" : false
};
buff_templates["HP_DEC"] = hp_dec_template;
game_buffs.setup({
"effect_mod_path" : __DIR__ "effect_mods/",
"buff_templates" : buff_templates
});