Type: concept
Confidence: 0.85
Created: 2026-04-16
Updated: 2026-04-16
Tags: Lua编程语言游戏工具游戏开发

Lua 游戏配置文件模板

概述

local T = {...} return T骨架的 Lua 游戏数据文件约定,每文件返回一个 table,作为游戏实体配置模块使用。

关键内容

  1. 模块骨架约定:每个配置文件定义一个局部 table(local Battle = {...})并在末尾 return Battle,文件本身即模块,调用方通过 requiredofile 加载得到该 table。这是 Lua 游戏项目中最常见的数据组织惯用法。
  2. 五类核心模板
  3. battle:战场配置,含 id/key/name/desc、战斗配置(type/mode/round_limit/time_limit)、attacker/defender 双方阵营、scene 场景、win/lose 条件、waves 波次、phases 阶段、rewards 奖励。
  4. unit:单位配置,含基础信息、unit_type/camp/race/job、展示资源(model/icon/portrait)、等级/品质、attr 基础属性(hp/atk/def/spd/cri/ten/hit/dodge/rage)、growth 成长属性、skills 技能组(normal/active/passive/ultimate)、buffs/traits、ai 策略、battle 站位参数、drops 掉落。
  5. skill技能配置,含技能类型、cost(mp/rage/cd/sp)、cast(cast_type/cast_time/channel_time/interruptible)、target 目标规则(target_type/count/range/select_rule/camp_rule)、effects 效果列表(含 formula/chance/duration)、triggers 触发器、hit 命中表现、cooldown 冷却、limit 使用限制、关联 buffs。
  6. buff:增益/减益配置,含 buff_type/priority/stack_type/max_stack、duration(round/turn/time)、interval/delay、modifiers 属性修改(attr/mode=add|pct|set/value/formula)、effects 周期效果、triggers(on_add/on_remove/on_tick/on_hit/on_be_hit/on_dead)、control(dispellable/stealable/refreshable/replace_rule/immune_tags)、view 表现。
  7. event:事件配置,含 event_type/priority、trigger(trigger_type/timing/condition[])、actions[](action_type/target/params)、limit(count/per_round/per_turn/cooldown)、refs 关联资源(units/skills/buffs/battles)、view 表现。
  8. 通用字段约定:所有五类模板末尾均含 tags = {} / params = {} / ext = {} 三个扩展字段,作为未来需求的预留槽位,避免频繁改动已有字段。
  9. 嵌套 table 结构:复杂属性用嵌套 table 表达(如 attr = { hp=0, atk=0, ... }),数组型字段用整数下标注释示例(-- [1] = {...})便于策划填表理解。
  10. 返回单 table vs 返回多值:此模式返回单一 table,而非多个字段分散定义,便于工具链做序列化、热重载和版本 diff。

来源

相关