PROPERTY_D = {}
setmetatable(PROPERTY_D, {__index = _G})
local _ENV = PROPERTY_D
local item_file = "data/txt/ItemInfo.txt"
local equip_file = "data/txt/EquipInfo.txt"
local item_table = {}
local equip_table = {}
local item_fields_list = {}
local equip_fields_list = {}
local property_callback = {}
local function load_item_table()
item_table = IMPORT_D.readcsv_to_mapping(item_file) or {}
local item_basic_ob
local name
for class_id, info in pairs(item_table) do
assert(class_id ~= 0,"item表中有class_id为0的道具")
info = dup(info)
if not info["ob_type"] then
info["ob_type"] = OB_TYPE_ITEM
end
item_basic_ob = clone_object(ITEM_TDCLS, info)
set_class_basic_object(class_id, item_basic_ob)
name = info["name"]
if name then
set_name_basic_object(name, item_basic_ob)
end
for _, f in ipairs(property_callback) do
f(info)
end
item_table[class_id] = set_table_read_only(info)
end
end
local function load_equip_table()
equip_table = IMPORT_D.readcsv_to_mapping(equip_file) or {}
local equip_basic_ob
local name
for class_id, info in pairs(equip_table) do
assert(class_id ~= 0,"equip表中有class_id为0的道具")
info = dup(info)
if not info["ob_type"] then
info["ob_type"] = OB_TYPE_EQUIP
end
equip_basic_ob = clone_object(EQUIP_TDCLS, info)
equip_basic_ob:set("amount", 1)
set_class_basic_object(class_id, equip_basic_ob)
name = info["name"]
if name then
set_name_basic_object(name, equip_basic_ob)
end
for _, f in ipairs(property_callback) do
f(info)
end
equip_table[class_id] = set_table_read_only(info)
end
end
function clone_object_from(class_id, property_info, from_db)
local basic_object = find_basic_object_by_class_id(class_id)
if not basic_object then
return
end
local ori_property_info = dup(property_info)
if not property_info["rid"] then
property_info["rid"] = NEW_RID()
end
property_info["class_id"] = class_id
if not property_info["amount"] then
property_info["amount"] = 1
end
local ob_type = property_info["ob_type"]
ob_type = ob_type or basic_object:query("ob_type")
local property_ob
if ob_type == OB_TYPE_ITEM then
property_ob = clone_object(ITEM_TDCLS, property_info)
elseif ob_type == OB_TYPE_EQUIP then
property_ob = clone_object(EQUIP_TDCLS, property_info)
ori_property_info["amount"] = nil
if not property_ob:query("lv") then
property_ob:set("lv", 0)
end
if not property_ob:query("exp") then
property_ob:set("exp", 0)
end
end
if from_db ~= true then
property_ob:set_temp("not_in_db", true)
end
property_ob:absorb_dbase(ori_property_info)
return property_ob
end
function get_property_info(class_id)
if equip_table[class_id] then
return equip_table[class_id]
elseif item_table[class_id] then
return item_table[class_id]
end
end
function get_item_dbase(class_id)
if not class_id then
return item_table
else
return item_table[class_id]
end
end
function get_equip_table(class_id)
if not class_id then
return equip_table
else
return equip_table[class_id]
end
end
function get_item_or_equip_info(class_id)
assert(class_id and class_id > 0," class_id must > 0")
if item_table[class_id] then
return item_table[class_id]
else
return equip_table[class_id]
end
end
function register_property_callback(f)
property_callback[#property_callback + 1] = f
end
local function init()
load_item_table()
load_equip_table()
end
function create()
register_post_init(init)
end
create()