Taiyi 合约
合约内置函数和模块的 LuaCATS 类型标注,可以用于 VSCode 等基于 lua lsp 的 IDE 中
| ---@meta taiyi_contract_builtin | |
| --#region MARK: Types | |
| ---@alias resource_symbol 'QI'|'YANG'|'GOLD'|'FOOD'|'WOOD'|'FABRIC'|'HERB' | |
| ---@class tiandao_property | |
| ---@field v_years integer | |
| ---@field v_months integer | |
| ---@field v_times integer | |
| ---@field v_1day_blocks integer | |
| ---@class contract_object | |
| ---@field id number contract id | |
| ---@field owner string owner account name | |
| ---@field name string contract name | |
| ---@field user_invoke_share_percent number default 100 | |
| ---@field current_version string transaction id of current version | |
| ---@field contract_authority string public key for contract authority | |
| ---@field is_release boolean whether contract is released | |
| ---@field check_contract_authority boolean whether to check contract authority | |
| ---@field contract_data table contract data table | |
| ---@field contract_ABI table contract ABI table | |
| ---@field lua_code_b_id number id of contract binary code | |
| ---@field creation_date string contract creation date | |
| ---@class contract_base_info | |
| ---@field owner string | |
| ---@field name string | |
| ---@field caller string | |
| ---@field creation_date string | |
| ---@field contract_authority string | |
| ---@field invoker_contract_name string | |
| ---@class contract_nfa_base_info | |
| ---@field nfa_id integer | |
| ---@field symbol string | |
| ---@field owner_account string | |
| ---@field creator_account string | |
| ---@field active_account string | |
| ---@field parent integer | |
| ---@field qi integer | |
| ---@field five_phase integer | |
| ---@field data table | |
| ---@class contract_actor_base_info | |
| ---@field nfa_id integer | |
| ---@field name string | |
| ---@field age integer | |
| ---@field health integer | |
| ---@field health_max integer | |
| ---@field born boolean | |
| ---@field born_vyears integer | |
| ---@field born_vmonths integer | |
| ---@field born_vtimes integer | |
| ---@field five_phase integer | |
| ---@field gender integer | |
| ---@field standpoint_type integer | |
| ---@field location string | |
| ---@field base string | |
| ---@class contract_zone_base_info | |
| ---@field nfa_id integer | |
| ---@field name string | |
| ---@field type string | |
| ---@class nfa_object | |
| ---@field id integer NFA ID | |
| ---@field symbol string NFA symbol name | |
| ---@field owner_account string Owner account name | |
| ---@field creator_account string Creator account name | |
| ---@field active_account string Active operator account name | |
| ---@field parent integer Parent NFA ID | |
| ---@field qi integer QI balance | |
| ---@field data table Contract data -- _Should be a generic type, check [LuaLS/lua-language-server#734](https://github.com/LuaLS/lua-language-server/issues/734)_ | |
| ---@field creation_date integer Creation timestamp | |
| ---@field contract_id integer Associated contract ID | |
| ---@field contract_authority string Contract authority public key | |
| ---@field is_released boolean Whether the NFA is released | |
| ---@field check_authority boolean Whether to check contract authority | |
| ---@field five_phase integer | |
| --#endregion | |
| -- #region MARK: Builtin function | |
| ---导入合约 | |
| ---@param contract_file string | |
| ---@return unknown | |
| ---@return unknown contract_data | |
| ---@diagnostic disable-next-line: missing-return | |
| function import_contract(contract_file) end | |
| ---格式化 table 为 vector | |
| ---@param table table | |
| ---@return string[] | |
| function format_vector_with_table(table) end | |
| ---格式化时间 | |
| ---@param format string | |
| ---@param timestamp integer | |
| ---@return string | |
| function date(format, timestamp) end | |
| --#endregion | |
| --#region MARK: Modules | |
| --#region contract_helper MARK: contract_helper | |
| ---@class contract_helper | |
| contract_helper = {} | |
| ---@param message string | |
| function contract_helper:log(message) end | |
| ---@param message string | |
| ---@param time_prefix boolean | |
| function contract_helper:narrate(message, time_prefix) end | |
| ---@param a number | |
| ---@param b number | |
| ---@return number | |
| function contract_helper:number_max(a, b) end | |
| ---@param a number | |
| ---@param b number | |
| ---@return number | |
| function contract_helper:number_min(a, b) end | |
| ---@param a integer | |
| ---@param b integer | |
| ---@return integer | |
| function contract_helper:integer_max(a, b) end | |
| ---@param a integer | |
| ---@param b integer | |
| ---@return integer | |
| function contract_helper:integer_min(a, b) end | |
| ---获取当前块高 | |
| ---@return integer | |
| function contract_helper:time() end | |
| ---获取当前块高 | |
| ---@return integer | |
| function contract_helper:block() end | |
| ---@param source string | |
| ---@return string | |
| function contract_helper:hash256(source) end | |
| ---@param source string | |
| ---@return string | |
| function contract_helper:hash512(source) end | |
| ---@param offset integer | |
| ---@return integer | |
| function contract_helper:generate_hash(offset) end | |
| ---@param memo string | |
| ---@return unknown | |
| function contract_helper:make_memo(memo) end | |
| ---@return integer | |
| function contract_helper:random() end | |
| ---@return boolean | |
| function contract_helper:is_owner() end | |
| ---@generic T : string | |
| ---@param data table<T,any> | |
| ---@param write_list table<T,boolean> | |
| function contract_helper:write_contract_data(data, write_list) end | |
| ---@generic T : string | |
| ---@param read_list table<T,boolean> | |
| ---@return table<T,any> | |
| function contract_helper:read_contract_data(read_list) end | |
| ---@param to_account string | |
| ---@param amount integer | |
| ---@param token_symbol string | |
| ---@param enable_logger boolean | |
| function contract_helper:transfer_from_caller(to_account, amount, token_symbol, enable_logger) end | |
| ---@param to_account string | |
| ---@param amount integer | |
| ---@param token_symbol string | |
| ---@param enable_logger boolean | |
| function contract_helper:transfer_from_owner(to_account, amount, token_symbol, enable_logger) end | |
| ---@param nfa_id integer | |
| ---@param action string | |
| ---@param params table | |
| ---@return table | |
| function contract_helper:eval_nfa_action(nfa_id, action, params) end | |
| ---@param nfa_id integer | |
| ---@return boolean | |
| function contract_helper:is_nfa_valid(nfa_id) end | |
| ---@param nfa_id integer | |
| ---@return nfa_object | |
| function contract_helper:get_nfa_info(nfa_id) end | |
| ---@param nfa_id integer | |
| ---@return table | |
| function contract_helper:get_nfa_resources(nfa_id) end | |
| ---@param nfa_id integer | |
| ---@return table | |
| function contract_helper:get_nfa_materials(nfa_id) end | |
| ---@param nfa_id integer | |
| ---@return table | |
| function contract_helper:list_nfa_inventory(nfa_id) end | |
| ---@param nfa_id integer | |
| ---@param contract_name string | |
| function contract_helper:change_nfa_contract(nfa_id, contract_name) end | |
| ---@return tiandao_property | |
| function contract_helper:get_tiandao_property() end | |
| ---@param nfa_id integer | |
| ---@return contract_actor_base_info | |
| function contract_helper:get_actor_info(nfa_id) end | |
| ---@param name string | |
| ---@return contract_actor_base_info | |
| function contract_helper:get_actor_info_by_name(name) end | |
| ---@param nfa_id integer | |
| ---@return table | |
| function contract_helper:get_actor_core_attributes(nfa_id) end | |
| ---@param name string | |
| ---@param gender integer | |
| ---@param sexuality integer | |
| ---@param init_attrs table | |
| ---@param zone_name string | |
| function contract_helper:born_actor(name, gender, sexuality, init_attrs, zone_name) end | |
| ---@param nfa_id integer | |
| ---@return boolean | |
| function contract_helper:is_actor_valid(nfa_id) end | |
| ---@param actor_name string | |
| ---@return boolean | |
| function contract_helper:is_actor_valid_by_name(actor_name) end | |
| ---@param actor_name string | |
| ---@param zone_name string | |
| ---@return string | |
| function contract_helper:move_actor(actor_name, zone_name) end | |
| ---@param nfa_id integer | |
| ---@return boolean | |
| function contract_helper:is_zone_valid(nfa_id) end | |
| ---@param zone_name string | |
| ---@return boolean | |
| function contract_helper:is_zone_valid_by_name(zone_name) end | |
| ---@param nfa_id integer | |
| ---@return contract_zone_base_info | |
| function contract_helper:get_zone_info(nfa_id) end | |
| ---@param zone_name string | |
| ---@return string | |
| function contract_helper:exploit_zone(actor_name, zone_name) end | |
| ---@param zone_name string | |
| ---@return contract_zone_base_info | |
| function contract_helper:get_zone_info_by_name(zone_name) end | |
| ---@param actor_name string | |
| ---@return string | |
| function contract_helper:break_new_zone(actor_name) end | |
| ---@param from_zone_nfa_id integer | |
| ---@param to_zone_nfa_id integer | |
| function contract_helper:connect_zones(from_zone_nfa_id, to_zone_nfa_id) end | |
| ---@param nfa_id integer | |
| ---@param beneficiary_nfa_ids table | |
| ---@param beneficiary_shares table | |
| ---@param prepare_time_seconds integer | |
| ---@return integer | |
| function contract_helper:create_cultivation(nfa_id, beneficiary_nfa_ids, beneficiary_shares, prepare_time_seconds) end | |
| ---@param cult_id integer | |
| ---@param nfa_id integer | |
| ---@param value integer | |
| ---@return string | |
| function contract_helper:participate_cultivation(cult_id, nfa_id, value) end | |
| ---@param cult_id integer | |
| ---@return string | |
| function contract_helper:start_cultivation(cult_id) end | |
| ---@param cult_id integer | |
| ---@return string | |
| function contract_helper:stop_and_close_cultivation(cult_id) end | |
| ---@param name string | |
| ---@param code string | |
| function contract_helper:create_named_contract(name, code) end | |
| ---@param nfa_id integer | |
| ---@return contract_actor_base_info[] | |
| function contract_helper:list_actors_on_zone(nfa_id) end | |
| --#endregion | |
| --#region nfa_helper MARK: nfa_helper | |
| ---@class nfa_helper | |
| nfa_helper = {} | |
| ---Enable heart beat tick for the current NFA | |
| function nfa_helper:enable_tick() end | |
| ---Disable heart beat tick for the current NFA | |
| function nfa_helper:disable_tick() end | |
| ---Get basic information about the current NFA | |
| ---@return nfa_object NFA basic information | |
| function nfa_helper:get_info() end | |
| ---Get resource balances of the current NFA | |
| ---@return table Resource balances including gold, food, wood, fabric and herb | |
| function nfa_helper:get_resources() end | |
| ---Get material balances of the current NFA | |
| ---@return table Material balances including gold, food, wood, fabric and herb | |
| function nfa_helper:get_materials() end | |
| ---@param from string | |
| ---@param amount integer | |
| ---@param resource_symbol resource_symbol | |
| ---@param enable_logger boolean | |
| function nfa_helper:deposit_from(from, amount, resource_symbol, enable_logger) end | |
| ---@param to string | |
| ---@param amount integer | |
| ---@param resource_symbol resource_symbol | |
| ---@param enable_logger boolean | |
| function nfa_helper:withdraw_to(to, amount, resource_symbol, enable_logger) end | |
| ---@param nfa_id integer | |
| ---@param amount integer | |
| ---@param resource_symbol resource_symbol | |
| ---@param enable_logger boolean | |
| function nfa_helper:inject_material_to(nfa_id, amount, resource_symbol, enable_logger) end | |
| ---@param nfa_id integer | |
| ---@param amount integer | |
| ---@param resource_symbol resource_symbol | |
| ---@param enable_logger boolean | |
| function nfa_helper:separate_material_out(nfa_id, amount, resource_symbol, enable_logger) end | |
| ---Convert QI to resource for the current NFA | |
| ---@param amount integer Amount to convert | |
| ---@param resource_symbol resource_symbol Target resource symbol name | |
| function nfa_helper:convert_qi_to_resource(amount, resource_symbol) end | |
| ---Convert resource to QI for the current NFA | |
| ---@param amount integer Amount to convert | |
| ---@param resource_symbol resource_symbol Source resource symbol name | |
| function nfa_helper:convert_resource_to_qi(amount, resource_symbol) end | |
| ---Add a child NFA to the current NFA | |
| ---@param nfa_id integer Child NFA ID to add | |
| function nfa_helper:add_child(nfa_id) end | |
| ---Add current NFA to a parent NFA | |
| ---@param parent_nfa_id integer Parent NFA ID to add to | |
| function nfa_helper:add_to_parent(parent_nfa_id) end | |
| ---Remove current NFA from its parent | |
| function nfa_helper:remove_from_parent() end | |
| ---Read contract data for the current NFA | |
| ---@param read_list table List of data fields to read | |
| ---@return table Contract data | |
| function nfa_helper:read_contract_data(read_list) end | |
| ---Write contract data for the current NFA | |
| ---@param data table Data to write | |
| ---@param write_list table List of data fields allowed to write | |
| function nfa_helper:write_contract_data(data, write_list) end | |
| ---Destroy the current NFA | |
| function nfa_helper:destroy() end | |
| ---Modify actor attributes for the current NFA | |
| ---@param values table Values to modify | |
| function nfa_helper:modify_actor_attributes(values) end | |
| --#endregion | |
| --#region contract_base_info MARK: contract_base_info | |
| ---@class contract_base_info | |
| contract_base_info = {} | |
| ---@param name string | |
| ---@return contract_object | |
| function contract_base_info:get_contract(name) end | |
| --#endregion | |
| --#endregion |