RimWorld模组制作(一)

rimworld进行mod制作的起步难度很低,由于大部分mod功能都是由xml语言进行实现的,因此可以从他人的mod中快速了解mod的基本结构并将自己的想法实现。

下面先介绍mod的主要组成

一个模组(mod)一般含有以下几个文件夹:

1.About:对于mod的简介和版本更新说明等等内容。

2.Defs:mod的核心代码,一般包含mod添加的主要内容

3.Textures:mod添加内容的材质和界面ui

4.Sounds:音效等等声音文件

5.Assemblies:mod添加的底层代码,在riworld原代码结构的基础上添加或修改内容,包含dll文件和c#文件

6.Languages:不同版本的语言包

7.Patches:与其他mod的兼容和联动补丁

 

这里主要介绍代码实现部分

由于一般的模组代码都是由xml组成的,而对象所包含的属性等配置参数

下面是一个自己写的建筑模组的代码样例,包含了一个防御建筑的所有元素,材质路径默认/Textures作为根目录

<?xml version ="1.0" encoding="utf-8"?>
<Defs><ThingDef ParentName="BuildingBase">
    <defName>Bjwhile_BU_bunkerboy_Base</defName><!--定义物品名字-->
    <label>dick boy</label>
    <description>base_tower</description>
    <thingClass>Building_TurretGun</thingClass><!--定义物品分类-->
    <graphicData>
      <texPath>Buildings/Bjwhile_BU_bunkerboy_Base</texPath> <!--定义材质路径-->
      <graphicClass>Graphic_Single</graphicClass>
      <shaderType>Transparent</shaderType>
      <drawSize>(3,3)</drawSize>
      <damageData>
        <rect>(0.05,0.05,0.3,0.3)</rect>
      </damageData>
    </graphicData>
    <size>(1,1)</size> <!--定义物品大小-->
    <passability>PassThroughOnly</passability>
    <pathCost>50</pathCost>
    <castEdgeShadows>true</castEdgeShadows>
    <fillPercent>0.4</fillPercent>
    <hasTooltip>true</hasTooltip>
    <uiIconPath>UI/Bjwhile_UI_bunkerboy_Gun</uiIconPath>
    <uiIconScale>1</uiIconScale>
    <!--物品特效-->
    <rotatable>true</rotatable>
    <altitudeLayer>Building</altitudeLayer>
    <stealable>false</stealable>
    <!--物品分类-->
    <thingCategories>
      <li>BuildingsSecurity</li>
    </thingCategories>
    <minifiedDef>MinifiedThing</minifiedDef><!--可以装卸-->
    <tickerType>Normal</tickerType>
    <!--属性-->
    <statBases>
      <WorkToBuild>6000</WorkToBuild>
      <MaxHitPoints>400</MaxHitPoints>
      <Flammability>0.5</Flammability> 
      <Beauty>0</Beauty>
      <Mass>100</Mass>
      <MarketValue>500</MarketValue>
    </statBases>
    <!--耗材-->
    <!-->
    <stuffCategories>
      <li>Metallic</li>
    </stuffCategories>
    <-->
    <costList>
      <Steel>300</Steel>
      <ComponentIndustrial>5</ComponentIndustrial>
    </costList>
    <!--建筑定义-->
    <building>
      <ai_combatDangerous>true</ai_combatDangerous>
      <turretGunDef>BJ_bunkerboy_gun</turretGunDef>
      <!-->><turretBurstWarmupTime>4.0</turretBurstWarmupTime><-->
      <turretBurstCooldownTime>8.0</turretBurstCooldownTime>
      <buildingTags>
        <li>Artillery</li>
      </buildingTags>
    </building>
    <!--功能-->
    <comps>
    <li Class="CompProperties_Explosive">
      <explosiveRadius>2</explosiveRadius>
      <explosiveDamageType>Bomb</explosiveDamageType>
      <chanceNeverExplodeFromDamage>0.6</chanceNeverExplodeFromDamage>
    </li>
    <li Class="CompProperties_Power">
      <compClass>CompPowerTrader</compClass>
      <basePowerConsumption>200</basePowerConsumption>
    </li>
      <li Class="CompProperties_Forbiddable"/>
      <!-->><li Class="CompProperties_Mannable"/><-->
      <li Class="CompProperties_Flickable"/>
        <li Class="CompProperties_Breakdownable"/>
        <li Class="CompProperties_Glower">
          <glowRadius>10</glowRadius>
          <glowColor>(217,217,180,0)</glowColor>
        </li>
        <li Class="CompProperties_Refuelable">
          <fuelLabel>Shots until barrel change</fuelLabel>
          <fuelGizmoLabel>Barrel durability</fuelGizmoLabel>
          <fuelFilter>
            <thingDefs>
              <li>Steel</li>
            </thingDefs>
          </fuelFilter>
          <fuelCapacity>200</fuelCapacity>
          <initialFuelPercent>1</initialFuelPercent>
          <autoRefuelPercent>0.75</autoRefuelPercent>
          <showFuelGizmo>true</showFuelGizmo>
          <minimumFueledThreshold>1</minimumFueledThreshold>
          <fuelMultiplier>3.75</fuelMultiplier>
          <factorByDifficulty>true</factorByDifficulty>
          <consumeFuelOnlyWhenUsed>true</consumeFuelOnlyWhenUsed>
          <outOfFuelMessage>Cannot shoot: Needs new barrel</outOfFuelMessage>
          <fuelIconPath>UI/Overlays/Barrel</fuelIconPath>
        </li>
      </comps>

      <specialDisplayRadius>28</specialDisplayRadius>
      <constructionSkillPrerequisite>5</constructionSkillPrerequisite>
      <designationCategory>Security</designationCategory>
      <researchPrerequisites>
        <li>Mortars</li>
      <!--><li>Bjwhile_RE_Terran_pro</li><-->
      </researchPrerequisites>
    <!--需要工作人员-->
      <placeWorkers>
        <li>PlaceWorker_TurretTop</li>
        <li>PlaceWorker_ShowTurretRadius</li>
      </placeWorkers>
  </ThingDef>

  <ThingDef ParentName="BaseBullet">
    <defName>BJ_Bullet_bunkerboy</defName>
    <label>dickboy bullet</label>
    <graphicData>
      <texPath>Projectile/BJ_bullet</texPath>
      <graphicClass>Graphic_Single</graphicClass>
    </graphicData>
    <projectile>
      <damageDef>Bullet</damageDef>
      <damageAmountBase>10</damageAmountBase>
      <speed>70</speed>
    </projectile>

  </ThingDef>

  <ThingDef ParentName="BaseWeaponTurret">
    <defName>BJ_bunkerboy_gun</defName>
    <label>turret gun</label>
    <description>A automatic gun made to be mounted on a turret.</description>
    <graphicData>
      <texPath>Buildings/Bjwhile_BU_bunkerboy_Gun</texPath>
      <graphicClass>Graphic_Single</graphicClass>
    </graphicData>
    <soundInteract>Interact_Rifle</soundInteract>
    <statBases>
      <Mass>40</Mass>
      <AccuracyTouch>0.60</AccuracyTouch>
      <AccuracyShort>0.64</AccuracyShort>
      <AccuracyMedium>0.5</AccuracyMedium>
      <AccuracyLong>0.4</AccuracyLong>
      <RangedWeapon_Cooldown>1</RangedWeapon_Cooldown>
    </statBases>
    <verbs>
      <li>
        <verbClass>Verb_Shoot</verbClass>
        <hasStandardCommand>true</hasStandardCommand>
        <defaultProjectile>BJ_Bullet_bunkerboy</defaultProjectile>
        <warmupTime>1</warmupTime>
        <range>35</range>
        <ticksBetweenBurstShots>5</ticksBetweenBurstShots>
        <burstShotCount>6</burstShotCount>
        <soundCast>Shot_AssaultRifle</soundCast>
        <soundCastTail>GunTail_Light</soundCastTail>
        <muzzleFlashScale>9</muzzleFlashScale>
        <consumeFuelPerShot>1</consumeFuelPerShot>
      </li>
    </verbs>
  </ThingDef>
</Defs>

一个建筑模组的基本结构在这段代码里面都包含了。

绝大多数的模组都是以这种形式实现的。

 

posted @ 2020-09-13 17:20  btc  阅读(2183)  评论(3编辑  收藏  举报