RimWorld模組教程之武器

源始鏈接: 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) -> 射擊 -> 等待點射間隔計時 -> ... -> 等待冷卻計時 -> 轉到等待預熱計時.


測試:


結論:



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章