源始链接: http://rimworldwiki.com/wiki/Modding_Tutorials/Weapons
在本教程里,我们将创建一个新的武器
先决条件:
您应该已经阅读入门章节,它让您快速的了解RimWorld的模组结构.您同时已经熟悉各文件的位置(如About.xml,def XML文件,在哪里放材质贴图等等)
创建目录
如果您尚未按入门章节创建了ThingDef目录,您还需要创建一个新的文件夹保存您的xml文件,在Defs文件夹内创建ThingDefs
文件夹,至此目录创建完成.
创建新武器
在本例中,我们将创建一个新的武器叫Scar-H.
首先,我们需要大纲代码以分类.下面是您的类似代码
<?xml version="1.0" encoding="utf-8" ?>
<ThingDefs>
</ThingDefs>
接着,我们需要创建一个新的ThingDef摘要,作为枪的基础属性.
<ThingDef Name="BaseGun" Abstract="True">
<category>Item</category>
<eType>Equipment</eType>
<thingClass>Equipment</thingClass>
<label>Gun</label>
<equipmentType>Primary</equipmentType>
<isGun>True</isGun>
<pathCost>10</pathCost>
<useStandardHealth>True</useStandardHealth>
<selectable>True</selectable>
<maxHealth>100</maxHealth>
<altitudeLayer>Item</altitudeLayer>
<alwaysHaulable>True</alwaysHaulable>
<tickerType>Never</tickerType>
<techLevel>Midworld</techLevel>
<storeCategories>
<li>Weapons</li>
</storeCategories>
<weaponTags>
<li>Gun</li>
</weaponTags>
<comps>
<li>
<compClass>CompForbiddable</compClass>
</li>
</comps>
<verb>
<id>Nonnative</id>
<verbClass>Verb_Shoot</verbClass>
<cooldownTicks>30</cooldownTicks>
<label>VerbGun</label>
<description>Fire a bullet.</description>
<hasStandardCommand>true</hasStandardCommand>
<targetParams>
<canTargetPawns>true</canTargetPawns>
<canTargetBuildings>true</canTargetBuildings>
<worldObjectTargetsMustBeAutoAttackable>true</worldObjectTargetsMustBeAutoAttackable>
</targetParams>
<canMiss>true</canMiss>
</verb>
</ThingDef>
这样我们就有了枪的属性摘要(abstract,如编程中的基类,译者注),我们还需要另一个作为枪所用的子弹的摘要.
<ThingDef Name="BaseBullet" Abstract="True">
<category>Projectile</category>
<tickerType>Normal</tickerType>
<altitudeLayer>Projectile</altitudeLayer>
<thingClass>Bullet</thingClass>
<label>Bullet</label>
<useStandardHealth>False</useStandardHealth>
<neverMultiSelect>True</neverMultiSelect>
<baseMaterialType>Transparent</baseMaterialType>
</ThingDef>
注意这两段代码,可以不用修改.
现在,我们将创建枪所用的子弹,这是我的Scar-H的子弹def(定义,译者注).
<ThingDef ParentName="BaseBullet">
<defName>Bullet_ScarHC</defName>
<label>7.62×51mm NATO</label>
<texturePath>Things/Projectile/Bullet_Small</texturePath>
<projectile>
<damageType>Bullet</damageType>
<DamageAmountBase>8</DamageAmountBase>
<Speed>85</Speed>
</projectile>
</ThingDef>
现在我们还需要做的就是做枪的def.
<ThingDef ParentName="BaseGun">
<defName>Gun_ScarHC</defName>
<label>ScarH</label>
<description></description>
<texturePath>Things/Item/IRGuns/Gun_ScarH</texturePath>
<interactSound>InteractBoltActionRifle</interactSound>
<purchasable>True</purchasable>
<basePrice>500</basePrice>
<verb>
<projectileDef>Bullet_ScarHC</projectileDef>
<warmupTicks>180</warmupTicks>
<range>39</range>
<accuracy>8</accuracy>
<burstShotCount>4</burstShotCount>
<ticksBetweenBurstShots>6</ticksBetweenBurstShots>
<fireSound>ShotM16Rifle</fireSound>
</verb>
</ThingDef>
走你!你自己的枪!
但愿您阅读Thingdef章节时能理解每个属性的含义.
注意游戏根据以上参数处理武器开火时是这样的:尝试射击 -> 等待预热计时(warmupTicks,毫秒,译者注) -> 射击 -> 等待点射间隔计时(ticksBetweenBurstShots) -> 射击 -> 等待点射间隔计时 -> ... -> 等待冷却计时 -> 转到等待预热计时.
测试:
略
结论:
略