MonsterDef (怪物定义)

MonsterDef 用于定义游戏中的怪物实体。它继承了基础的实体定义 EntityDef,并在此基础上增加了怪物特有的武器配置。

根元素: <Define>

DefName: 必需,全局唯一的字符串,用于标识特定的怪物定义。

Label: 可选,字符串,用于在游戏中显示的怪物名称。

Description: 可选,字符串,对怪物的详细描述。


参数说明

MonsterDef 继承了 EntityDef 的所有参数:

  • <attributes>: 怪物的基础属性,这是一个 AttributesDef 类型的匿名定义
  • <drawingOrder>: 怪物的绘制指令,这是一个 DrawingOrderDef 类型的匿名定义
  • <behaviorTree>: 怪物的行为逻辑树,这是一个 BehaviorTreeDef 类型的匿名定义
  • <affiliation>: 怪物的所属阵营,可以引用一个现有的 AffiliationDefdefName,或在此处进行匿名定义
  • <eventDef>: 怪物特定事件触发的行为,这是一个 EntityEventDef 类型的匿名定义
  • <colliderSize>: 字符串,定义角色的碰撞体大小,通常为 "宽,高" 格式。例如 "1.0,1.0"。
  • <colliderPosition>: 字符串,定义角色的碰撞体相对角色中心的位置偏移,通常为 "x,y" 格式。例如 "0.0,0.5"。
  • <insideDimensionDef>: 引用一个 DimensionDefdefName,指定当怪物进行“体内场景”战斗时所使用的维度定义。

除了继承的参数外,MonsterDef 还有一个特有的参数:

<weapon>

定义怪物默认持有的武器。这是一个 WeaponDef 类型的匿名定义

WeaponDef 包含的字段说明:

  • <type>: 字符串,武器的类型。"Melee" (近战武器) 或 "Ranged" (远程武器)。默认为 "Melee"。
  • <attributes>: 武器提供的额外属性加成或改变。这是一个 AttributesDef 类型的匿名定义,与怪物自身的 attributes 结构相同,用于修正武器相关的属性,例如武器的攻击力、攻击速度和攻击范围。 示例:
    <attributes>
        <attack>5</attack>
        <attackSpeed>1.5</attackSpeed>
        <attackRange>2</attackRange>
    </attributes>
    
  • <bullet>: 如果武器类型为“Ranged”,则需要定义发射的子弹。可以引用一个现有的 BulletDefdefName,或者直接在此处进行匿名定义作为引用:
    <bullet>ArrowBullet</bullet> <!-- 引用名为 "ArrowBullet" 的 BulletDef -->
    
    作为匿名定义:
    <bullet>
        <defName>FireballWeaponBullet</defName> <!-- 匿名定义也需要defName -->
        <image>Bullet_Fireball</image>
        <speed>10</speed>
        <damage>15</damage>
    </bullet>
    
  • <attackAnimation>: 字符串数组,指定武器的攻击动画帧。每个 <li> 元素内是一个贴图的 defName示例:
    <attackAnimation>
        <li>Weapon_Sword_Swing_1</li>
        <li>Weapon_Sword_Swing_2</li>
    </attackAnimation>
    
  • <attackDetectionTime>: 浮点数,攻击判定发生的时间点,相对攻击动画开始的秒数。默认为0。
  • <useEntityAttackAnimation>: 布尔值,如果为 true,则优先使用怪物自身的攻击动画,武器的 attackAnimation 将被忽略。默认为 true

示例

<MonsterDef>
    <defName>chicken</defName>
    <label>不大聪明</label>
    <description>一只弱小的鸡,但可能很狡猾。</description>

    <attributes>
        <health>20</health>
        <moveSpeed>1.5</moveSpeed>
        <attack>5</attack>
        <defense>0</defense>
    </attributes>

    <drawingOrder>
        <!-- 鸡的各种状态绘制,此处省略具体细节 -->
        <idle_down>
            <textures><li>Chicken_Idle_0</li></textures>
        </idle_down>
        <walk_down>
            <FPS>8.0</FPS>
            <textures>
                <li>Chicken_Walk_0</li>
                <li>Chicken_Walk_1</li>
                <li>Chicken_Walk_2</li>
            </textures>
        </walk_down>
        <meleeAttack_down>
            <textures><li>Chicken_Attack_0</li><li>Chicken_Attack_1</li></textures>
            <FPS>10.0</FPS>
        </meleeAttack_down>
    </drawingOrder>

    <behaviorTree>
        <className>ThinkNode_Selector</className>
        <childTree>
            <!-- 发现敌人则攻击 -->
            <li>
                <className>ThinkNode_Conditional</className>
                <value>HasTarget()</value>
                <childTree>
                    <li><className>JobGiver_AttackJob</className></li>
                </childTree>
            </li>
            <!-- 否则随机漫游 -->
            <li>
                <className>ThinkNode_Sequence</className>
                <childTree>
                    <li><className>JobGiver_Wander</className></li>
                    <li><className>JobGiver_Idle</className></li>
                </childTree>
            </li>
        </childTree>
    </behaviorTree>

    <affiliation>monster</affiliation>

    <colliderSize>0.8,0.8</colliderSize>
    <colliderPosition>0.0,0.4</colliderPosition>

    <!-- 怪物默认持有的武器的匿名定义 -->
    <weapon>
        <type>Melee</type>
        <attributes>
            <attack>2</attack> <!-- 武器提供2点额外攻击力 -->
            <attackRange>0.8</attackRange> <!-- 武器的攻击范围 -->
            <attackSpeed>1.0</attackSpeed>
        </attributes>
        <!-- 鸡的攻击使用自身的动画,不单独定义武器动画 -->
        <useEntityAttackAnimation>true</useEntityAttackAnimation> 
        <attackDetectionTime>0.2</attackDetectionTime> <!-- 攻击动画播放0.2秒后进行判定 -->
    </weapon>
</MonsterDef>