XML 정의하기 - solaris0115/RimWorldModGuide GitHub Wiki

XML 정의하기

이 챕터에서는 XML로 정의하는 방법에 대해 다룹니다.

정의는 어떤 개체에 대해 이것이 무엇인지, 무엇으로부터 파생되었는지, 값은 얼마인지를 정하는 일입니다. 예를들어 리볼버 권총은 권총탄을 쓰며 가격은 얼마이고 데미지는 얼마이고 발사속도,사거리,재료,필요한 연구 등 다양한 정보를 갖고 있습니다.

게임내 존재하는 모든것들은 정의를 갖고 있습니다. 아이템부터 바닥,토네이도, 림들의 기분, 림의 종족, 세력 등 셀수없이 많습니다.
더 자세한 정의(Def)에 관한것은 Def에서 확인 하실 수 있습니다.

이제 새로 만들 역병모드에 쓰일 정의를 만들어 것입니다.

1. 정의하기

이제 ...\Defs\ThingDefs 폴더에 RangedWeapon_PlagueGun.xml 파일을 만듭니다.
이 파일에서는 두가지 정의를 할것입니다. 역병총과 역병탄환

우선 맨위 XML문서임을 알리는 코드를 적습니다.

    <?xml version="1.0" encoding="utf-8"?>

그리고 앞으로 적힐 데이터가 정의 임을 알리는 코드를 달아줍니다.

    <?xml version="1.0" encoding="utf-8"?>
    <Defs>
    </Defs>

이제 총에 대해 정의할 것인데 무엇이 있는지를 모릅니다. 하지만 우린 게임내 존재하는 총들이 무엇이 존재하는지 알고 있습니다. 다음 위치로 이동합니다.

RimWorld\Mods\Core\Defs\ThingDefs_Misc

해당 위치에는 다양한 개체에 대한 정의가 존재합니다. 그중 우리가 필요한 총에 대한 정의는 Weapons_Guns.xml 입니다. 아래와 리볼버에 대한 내용을 찾습니다. (검색어 revolver)

    <!--==========================총==========================-->
    <ThingDef ParentName="BaseHumanMakeableGun">
        <defName>Gun_Revolver</defName>
        <label>revolver</label>
        <description>Ancient pattern double-action revolver. Somewhat weak, medium range, quick.</description>
        <graphicData>
            <texPath>Things/Item/Equipment/WeaponRanged/Revolver</texPath>
            <graphicClass>Graphic_Single</graphicClass>
        </graphicData>
        <soundInteract>InteractRevolver</soundInteract>
        <statBases>
            <WorkToMake>15000</WorkToMake>
            <Mass>1.4</Mass>
            <AccuracyTouch>0.91</AccuracyTouch>
            <AccuracyShort>0.71</AccuracyShort>
            <AccuracyMedium>0.50</AccuracyMedium>
            <AccuracyLong>0.32</AccuracyLong>
            <RangedWeapon_Cooldown>1.38</RangedWeapon_Cooldown>
            <Weapon_Bulk>0.5</Weapon_Bulk>
        </statBases>
        <weaponTags>
            <li>SimpleGun</li>
        </weaponTags>
        <costList>
            <Steel>30</Steel>
            <Component>2</Component>
        </costList>
        <verbs>
            <li>
                <verbClass>Verb_Shoot</verbClass>
                <hasStandardCommand>true</hasStandardCommand>
                <defaultProjectile>Bullet_Revolver</defaultProjectile>
                <warmupTime>0.3</warmupTime>
                <range>26</range>
                <soundCast>ShotRevolver</soundCast>
                <soundCastTail>GunTail_Light</soundCastTail>
                <muzzleFlashScale>9</muzzleFlashScale>
            </li>
        </verbs>
        <tools>
            <li>
                <label>grip</label>
                <capacities>
                    <li>Blunt</li>
                </capacities>
                <power>8</power>
                <cooldownTime>1.6</cooldownTime>
            </li>
            <li>
                <label>barrel</label>
                <capacities>
                    <li>Blunt</li>
                    <li>Poke</li>
                </capacities>
                <power>8</power>
                <cooldownTime>1.6</cooldownTime>
            </li>
        </tools>
    </ThingDef>
    <!--==========================총알==========================-->
    <ThingDef ParentName="BaseBullet">
        <defName>Bullet_Revolver</defName>
        <label>revolver bullet</label>
        <graphicData>
            <texPath>Things/Projectile/Bullet_Small</texPath>
            <graphicClass>Graphic_Single</graphicClass>
        </graphicData>
        <projectile>
            <flyOverhead>false</flyOverhead>
            <damageDef>Bullet</damageDef>
            <damageAmountBase>11</damageAmountBase>
            <speed>55</speed>
        </projectile>
    </ThingDef>

찾으셨다면 위 <Defs>사이에 넣어줍니다. 넣으셨다면 아래와 같이 되었을 것입니다.

    <?xml version="1.0" encoding="utf-8"?>
    <Defs>
        <!--==========================총==========================-->
        <ThingDef ParentName="BaseHumanMakeableGun">
           ...
        </ThingDef>
        <!--==========================총알==========================-->
        <ThingDef ParentName="BaseBullet">
           ...
        </ThingDef>
    </Defs>

이제 역병총과 역병탄을 정의 내려봅시다.
이름,가격,데미지,정확도,사거리,재료 등등..

    <!--==========================총==========================-->
    <ThingDef ParentName="BaseHumanMakeableGun">
        <defName>PlagueGun</defName>
        <label>plagueGun</label>
        <description>When hit the target, Go to Heroes of the storm.</description>
           ...
    </ThingDef>

마찬가지로 총알도 작업을 해줍니다.

    <!--==========================총알==========================-->
    <ThingDef ParentName="BaseBullet">
        <defName>PlagueGun_Bullet</defName>
        <label>plagueGun bullet</label>
        <graphicData>
            <texPath>Things/Projectile/Bullet_Small</texPath>
            <graphicClass>Graphic_Single</graphicClass>
        </graphicData>
             ...
    </ThingDef>

좋습니다. 이제 당신의 커스텀 역병총과 역병탄이 만들어졌습니다.
PlagueGun의 defaultProjectile 항목도 잊지말고 새로 만든 PlagueGun_Bullet을 적어 연결을 해줍니다. 하지만 이것은 이름과 숫자만 조금 바뀐 일반 총 일뿐 아직은 특별한 기능을 갖고 있지 않습니다.

다음 문서에서 이 커스텀 총에 특별한 기능을 부여할 것 입니다.

다음: XML과 C# 연결하기

⚠️ **GitHub.com Fallback** ⚠️