变量属性
自定义个人变量
接口
分组 | 接口名 | 参数 | 返回值 | 说明 |
---|---|---|---|---|
int2int | edi.player:get_int_kv | 1. 玩家对象 2. 模块值 3. 自定义数字Key | 自定义Key对应值(数字) | 获取Key对应的值 |
int2int | edi.player:set_int_kv | 1. 玩家对象 2. 模块值 3. 自定义数字Key 4. 数字Value | - | 设置Key对应值 |
int2int | edi.player:get_mod_int_key | 1. 玩家对象 2. 模块值 | 自定义Key 列表 | 获取Keys |
str2str | edi.player:get_str_kv | 1. 玩家对象 2. 模块值 3. 自定义字符串Key | 自定义Key对应值(字符串) | 获取Key对应的值 |
str2str | edi.player:set_str_kv | 1. 玩家对象 2. 模块值 3. 自定义字符串Key 4. 字符串Value | - | 设置Key对应值 |
str2str | edi.player:get_mod_str_key | 1. 玩家对象 2. 模块值 | 自定义Key 列表 | 获取Keys |
str2int | edi.player:get_growth_kv | 1. 玩家对象 2. 模块值 3. 自定义字符串Key | 自定义Key对应值(数字) | 获取Key对应的值 |
str2int | edi.player:set_growth_kv | 1. 玩家对象 2. 模块值 3. 自定义字符串Key 4. 数字Value | - | 设置Key对应值 |
str2int | edi.player:get_mod_growth_key | 1. 玩家对象 2. 模块值 | 自定义Key 列表 | 获取Keys |
和数字类型类似,Key是字符串,Value是数字
获取Key对应的值(str2int),返回自定义Key对应值(数字)
edi.player:get_growth_kv(玩家对象, 模块值, 字符串Key)
- 设置Key对应值(str2int)
edi.player:set_growth_kv(玩家对象, 模块值, 字符串Key, 数字Value)
- 获取Key(str2int),返回自定义模块对应key列表
edi.player:get_mod_growth_key(玩家对象, 模块值)
||||||
清理
- 清空Key,上述三种个人自定义变量都可被这个函数清理
edi.player:clear_mod_key(玩家对象, 模块值)
注意
KV_MODE
是用来区分模块的,不同模块相同Key是不会被覆盖的,方便根据模块查找设置的变量自定义模块ID(core_def.lua的KVModeDef枚举,引擎提供枚举值100以内, 客户自定义模块枚举值需>100,若使用引擎提供mod枚举,key需要>3000)
自定义模块ID(core_def.lua的KVModeDef枚举,引擎提供枚举值100以内, 客户自定义模块枚举值需>100,若使用引擎提供mod枚举,key需要>3000)
自定义模块ID(core_def.lua的KVModeDef枚举,引擎提供枚举值100以内, 客户自定义模块枚举值需>100,若使用引擎提供mod枚举,key需要>3000)
示例
- 玩家登录时判断、设置玩家累计登录天数
local const_def = include('define.const_def')
-- 查询、记录登录天数函数
local function _get_set_login_day(player)
-- 使用的测试mode
local mode = 9999
-- 使用的测试key:上次登录是哪一天
local last_login_day_key = 1
-- 使用的测试key:累积登录了多少天
local login_days_key = 2
-- 获得当前已经开服的天数
local now_open_day = edi.general:get_open_svr_day()
local last_login_day = edi.player:get_int_kv(player, mode, last_login_day_key)
if now_open_day > last_login_day then
-- 不是同一天,累积登录天数就 +1
local login_days = edi.player:get_int_kv(player, mode, login_days_key)
edi.player:set_int_kv(player, mode, last_login_day_key, now_open_day)
edi.player:set_int_kv(player, mode, login_days_key, login_days + 1)
-- 每天上线给100金币
edi.player:add_money(player, 1, 100)
local content = "亲爱的玩家【" .. edi.player:get_name(player) .. "】欢迎,已游戏【" .. (login_days + 1) .. "】 天"
edi.general:send_player_notice(player, const_def.NOTICE_TYPE.ChatBox, content)
-- 其他类型的
edi.player:set_str_kv(player, mode, "test_str_key", "1")
edi.player:set_growth_kv(player, mode, "test_growth_key", 2)
-- 看是不是有其他 Key
local other_int_keys = edi.player:get_mod_int_key(player, mode)
for _, one in pairs(other_int_keys) do
edi.general:send_player_notice(player, const_def.NOTICE_TYPE.ChatBox, "查到int:" .. one .. ":" .. edi.player:get_int_kv(player, mode, one))
end
local other_str_keys = edi.player:get_mod_str_key(player, mode)
for _, one in pairs(other_str_keys) do
edi.general:send_player_notice(player, const_def.NOTICE_TYPE.ChatBox, "查到str:" .. one .. ":" .. edi.player:get_str_kv(player, mode, one))
end
local other_growth_keys = edi.player:get_mod_growth_key(player, mode)
for _, one in pairs(other_growth_keys) do
edi.general:send_player_notice(player, const_def.NOTICE_TYPE.ChatBox, "查到growth:" .. one .. ":" .. edi.player:get_growth_kv(player, mode, one))
end
end
end
-- 登录事件
local function _on_login_111(player)
_get_set_login_day(player)
end
--@Main--
edi.event:reg(edi.event.login, _on_login_111, "个人变量测试")
自定义全局变量
接口
和 自定义个人变量 类似,这是全局的自定义变量
- 初始化全局数据,指定某个模块值是否存储,如果存储(默认有变化时3分钟模块自动存盘)
edi.general:init_global_val(模块值, 是否存储)
- 清空全局数据
edi.general:clean_global_val(模块值)
- 立即存盘
请勿频繁调用 请勿频繁调用
edi.general:save_global_val(模块值)
- 获取、设置接口:
分组 | 接口名 | 参数 | 返回值 | 说明 |
---|---|---|---|---|
int2int | edi.general:get_global_int | 1. 模块值 2. 自定义数字Key | 自定义Key对应值(数字) | 获取Key对应的值 |
int2int | edi.general:set_global_int | 1. 模块值 2. 自定义数字Key 3. 数字Value | - | 设置Key对应值 |
int2int | edi.general:get_all_global_int | 1. 模块值 | key, value 列表 | 获取全部数字数据(数字) |
str2str | edi.player:get_str_kv | 1. 玩家对象 2. 模块值 3. 自定义字符串Key | 自定义Key对应值(字符串) | 获取Key对应的值 |
str2str | edi.player:set_str_kv | 1. 玩家对象 2. 模块值 3. 自定义字符串Key 4. 字符串Value | - | 设置Key对应值 |
str2str | edi.general:get_all_global_str | 1. 模块值 | key, value 列表 | 获取全部字符串数据(字符串) |
示例
- 记录当前在线人数
local const_def = include('define.const_def')
-- 使用的测试mode
local mode = "global-9999"
-- 记录当前在线人数的函数
local function _change_online_count(value)
local online_count_key = 2
local online_count = edi.general:get_global_int(mode, online_count_key)
online_count = online_count + value
-- 避免成负值了
if online_count < 0 then
online_count = 0
end
edi.general:set_global_int(mode, online_count_key, online_count)
if value > 0 then
edi.general:send_broadcast_notice(const_def.NOTICE_TYPE.ChatBox, "欢迎,当前游戏人数:" .. online_count)
end
local global_ints = edi.general:get_all_global_int(mode)
for key, val in pairs(global_ints) do
LOGI("测试:当前有全局变量:" .. key .. ":" .. val)
end
end
-- 登录事件
local function _on_login_000(player)
_change_online_count(1)
end
-- 登出事件
local function _on_logout_000(player)
_change_online_count(-1)
end
-- 初始化测试用的这个模块
edi.general:init_global_val(mode, true)
--@Main--
edi.event:reg(edi.event.login, _on_login_000, "全局变量测试")
edi.event:reg(edi.event.logout, _on_logout_000, "全局变量测试")
战斗属性
表格
- 战斗属性定义在
attribute.xlsx
表格详情见 todo: 表格链接 - 附录:attr_def
接口
对应 attribute.xlsx 表 id 的属性枚举定义在 engine/define/attr_def.lua
- 获得指定属性值,返回具体属性值(数值)
edi.player:get_attr(玩家对象, 属性id)
- 设置属性值
edi.player:set_attr(玩家对象, 属性id, 具体值)
1. 注意这里涉及关联属性的属性最终值不是设置的值,请看下面示例
1. 注意这里涉及关联属性的属性最终值不是设置的值,请看下面示例
>>> 示例 <<<
> 假设当前玩家属性值:
> 生命上限:MaxHP = 1000
> 生命万分比:HPAdd = 10000 (100%)
> 实际生命上限:edi.player:get_attr(AttrDef.EN_ATTR_116) == 2000
> 执行:edi.player:set_attr(AttrDef.EN_ATTR_116, 2000 + 100)
> 得到:edi.player:get_attr(AttrDef.EN_ATTR_116) == 2200
> 公式:(1000(MaxHP) + 100) * (100 + 10000(HPAdd) / 100) / 100
> 同理:edi.player:change_attr
2. 若属性值超过配置(attribute.xlsx max配置值,将被修正成 1)
2. 若属性值超过配置(attribute.xlsx max配置值,将被修正成 1)
- 修改属性值,若修改值为正值则为加法,负值则为减法
edi.player:change_attr(玩家对象, 属性id, 修改值)
示例
- 玩家进入
比奇
的安全区,血蓝不满就定时恢复血蓝
local attr_def = include('define.attr_def')
-- 血蓝不满就定时恢复血蓝的函数
local function _recover_hpmp(player, is_stop)
local index_key = "player_recover_hpmp_timer"
-- 是关闭的就删掉(停止)定时器
if is_stop then
edi.player:del_timer(player, index_key)
-- 停止之后直接返回,避免执行后面的逻辑
return
end
-- 是开启的就开启定时器
local _timer_callback = function(uuid, timer_key, callback_params)
local player = edi.player:get_by_uuid(uuid)
local scene = edi.player:get_scene(player)
local scene_pos = edi.player:get_scene_pos(player)
-- 判断玩家是否在安全区范围
local is_safe = edi.scene:is_safe_pos(scene, scene_pos.x, scene_pos.y)
if is_safe == true then
local curr_hp = edi.player:get_attr(player, attr_def.EN_ATTR_1)
local curr_mp = edi.player:get_attr(player, attr_def.EN_ATTR_2)
local max_hp = edi.player:get_attr(player, attr_def.EN_ATTR_116)
local max_mp = edi.player:get_attr(player, attr_def.EN_ATTR_117)
-- 判断玩家血是不是满的
if curr_hp < max_hp then
edi.player:change_attr(player, attr_def.EN_ATTR_1, 10)
end
-- 判断玩家蓝是不是满的
if curr_mp < max_mp then
edi.player:change_attr(player, attr_def.EN_ATTR_2, 10)
end
end
end
local tick = 5000
local count = -1
edi.player:add_timer(player, index_key, tick, count, _timer_callback, "我是安全区回复定时器")
end
-- 玩家进入场景事件,开始恢复血蓝
local function _on_player_enter_scene(player, scene)
local scene_name = edi.scene:get_name(scene)
if scene_name == '比奇' then
-- 为方便测试,这里先把血蓝设置低点
edi.player:set_attr(player, attr_def.EN_ATTR_1, 10)
edi.player:set_attr(player, attr_def.EN_ATTR_2, 10)
_recover_hpmp(player, false)
end
end
-- 玩家离开场景事件,停止恢复血蓝
local function _on_player_leave_scene(player, scene)
local scene_name = edi.scene:get_name(scene)
if scene_name == '比奇' then
_recover_hpmp(player, true)
end
end
--@Main--
edi.event:reg(edi.event.player_enter_scene, _on_player_enter_scene, "安全区恢复血蓝测试")
edi.event:reg(edi.event.player_leave_scene, _on_player_leave_scene, "安全区恢复血蓝测试")