骑马与砍杀中文站论坛

 找回密码
 注册(Register!)

QQ登录

只需一步,快速开始

搜索
购买CDKEY 小黑盒加速器
查看: 1219|回复: 2

[经验与教程] [骑砍2]通过xslt修改游戏的xml配置文件

[复制链接]

28

主题

219

回帖

179

积分

见习骑士

Rank: 3

UID
2758789
第纳尔
2118
精华
0
互助
19
荣誉
1
贡献
0
魅力
171
注册时间
2016-7-18
鲜花(18) 鸡蛋(0)
发表于 2024-4-8 17:23:00 | 显示全部楼层 |阅读模式
本帖最后由 路过的罗格 于 2024-4-8 17:30 编辑

又是一个基础教程,这玩意这两天也是跑通了,过来写一下.主要是烤肉社那个网站上给出的xslt教程那叫一个烂,都给我看麻了.



简介:你也不想公布一个mod的时候,还让别人去替换游戏原本的xml配置文件来实现修改吧?xslt是一个在不破坏原有的文件的前提下,修改游戏配置文件的方法,现在你可以把你修改过的配置放在自己的mod文件夹里,而不用让别人折腾游戏原本的配置.
错误示例:https://bbs.mountblade.com.cn/thread-2095937-1-1.html 像这个垃圾教程里就是直接跑去修改游戏原本的文件,搞得改错了还没备份的话,就得去把文件删了然后重新验证完整性下载原文件.


前置知识需求:xml入门,比如能完成上面错误示例中的修改.xslt的知识可以不需要,我这边试了一下,基础的修改需求可以直接丢给包括百度那个在内的GPT大语言模型来完成.
需要的mod进度:已经有一个正常建好的SubModule.xml,差不多就是用插件新建工程的状态,编辑器版游戏新建mod的状态应该也一样
(插件:https://github.com/BUTR/Bannerlord.Module.Template)
工具,好像要梯子,谁有国内能用的来一个:在线 XSLT 测试工具 (xslttest.appspot.com)

咱们通过一个具体的示例来说明这个xslt怎么使用,比如完成一下类似上面那个错误示例的修改,给双手剑的剑柄里添加一些长杆配件,让咱们能做一把剑枪,并且把它的攻击动作改一下,让它的突刺动作,改为长杆的动作,我是嫌弃双手剑突刺动作不好用的.
首先,确定要修改的文件,是Native/ModuleData/weapon_descriptions.xml和item_usage_sets.xml和crafting_templates.xml
weapon_descriptions/crafting_templates管的其中之一是一个类的武器可以使用哪些配件,我们把双手锤的杆配件添加到双手剑的握柄里
item_usage_sets是管动作模组,修改攻击时使用哪个动作靠的是这里
所以,在我们的mod文件夹里,对应的去新建一下ModuleData文件夹,并且新建几个xslt文件,用于处理对应的xml.方便起见,保持文件名为item_usage_sets.xslt和weapon_descriptions.xslt和crafting_templates.xslt
然后还需要新建一个名为project.mbproj的文件,当然实际建议直接把Native/ModuleData目录下的project.mbproj复制过来,然后对他进行修改.
1.png
接着先不去写xslt,先把让xslt生效的环境配置好,也就是修改SubModule.xml和project.mbproj.
这两个东西都可以用文本编辑器打开,(注:这一步的资料是混乱且缺失的,只能说照着官方原文件抄)理论上编辑SubModule.xml或project.mbproj任选其一即可,但实际上因为没有资料,所以两个都得改
SubModule.xml里添加这一段,声明一下这两个文件的调用.如果已经有Xmls标签了,就只用在里面添加这两个XmlNode标签及内容即可.这里要保证path="xxxxx"中的字符串,是你ModuleData文件夹下对应模块的文件名.(也就是文件名你可以随便改,但是在这里你要对应上)
2.png
然后是project.mbproj文件,因为是直接复制的,所以现在要给他删的只剩我们要修改的文件.老样子注意文件名的对应,这里是name="ModuleData/item_usage_sets.xml",需要填入文件在你mod文件夹中的路径.文件名可以自定义,但是后缀保持.xml
3.png

到这里,已经完成了xslt的声明,现在这几个文件里的东西可以被游戏调用了.
继续完成我们的双手剑枪的制作.
先是给双手剑添加长杆,之前说了直接用GPT,所以我们只需要描述清除我们要进行的操作就好了,先是crafting_templates文件

[url=https://yiyan.baidu.com/share/nTWsI9RHAc]使用xslt的方法,修改xml.具体来说:在CraftingTemplates标签下的CraftingTemplate标签里,当CraftingTemplate标签的属性id="TwoHandedSword"时,给CraftingTemplate标签下的UsablePieces标签里,添加[/url]

因为xslt这个东西并不是骑砍独有的,所以准确率还行.刚才让他随便输入了一个配件,现在把那个随便输入的配件改成我们需要的长杆(这里使用的时标枪杆)

  1. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">  
  2.     <xsl:output method="xml" indent="yes"/>  
  3.     <xsl:strip-space elements="*"/>  
  4.   
  5.     <!-- 复制所有内容,除非另有说明 -->  
  6.     <xsl:template match="@*|node()">  
  7.         <xsl:copy>  
  8.             <xsl:apply-templates select="@*|node()"/>  
  9.         </xsl:copy>  
  10.     </xsl:template>  
  11.   
  12.     <!-- 当遇到CraftingTemplate元素且其id属性为"TwoHandedSword"时 -->  
  13.     <xsl:template match="CraftingTemplate[@id='TwoHandedSword']">  
  14.         <!-- 复制当前CraftingTemplate元素 -->  
  15.         <xsl:copy>  
  16.             <!-- 复制所有属性 -->  
  17.             <xsl:apply-templates select="@*"/>  
  18.             <!-- 复制所有子元素 -->  
  19.             <xsl:apply-templates select="node()"/>  
  20.             <!-- 在UsablePieces元素内添加新的UsablePiece元素 -->  
  21.             <xsl:if test="UsablePieces">  
  22.                 <UsablePieces>  
  23.                     <xsl:apply-templates select="UsablePieces/node()"/>  
  24.                     <UsablePiece piece_id="spear_handle_2" />  
  25.                     <UsablePiece piece_id="spear_handle_9" />  
  26.                     <UsablePiece piece_id="spear_handle_10" />  
  27.                     <UsablePiece piece_id="spear_handle_11" />  
  28.                     <UsablePiece piece_id="spear_handle_12" />  
  29.                 </UsablePieces>  
  30.             </xsl:if>  
  31.         </xsl:copy>  
  32.     </xsl:template>  
  33. </xsl:stylesheet>
复制代码
[color=rgba(0, 0, 0, 0.85)]


类似的,完成weapon_descriptions文件的部分
继续完成类似的操作,这次需要在WeaponDescriptions标签下的WeaponDescription标签里,当WeaponDescription的属性id="TwoHandedSword"时,在WeaponDescription下的AvailablePieces标签里,添加
  1. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">  
  2.     <xsl:output method="xml" indent="yes"/>  
  3.     <xsl:strip-space elements="*"/>  
  4.   
  5.     <!-- 复制所有内容,除非另有说明 -->  
  6.     <xsl:template match="@*|node()">  
  7.         <xsl:copy>  
  8.             <xsl:apply-templates select="@*|node()"/>  
  9.         </xsl:copy>  
  10.     </xsl:template>  
  11.   
  12.     <!-- 当遇到WeaponDescriptions/WeaponDescription元素且其id属性为"TwoHandedSword"时 -->  
  13.     <xsl:template match="WeaponDescriptions/WeaponDescription[@id='TwoHandedSword']">  
  14.         <xsl:copy>  
  15.             <xsl:apply-templates select="@*"/>  
  16.             <xsl:apply-templates select="node()"/>  
  17.             <xsl:if test="AvailablePieces">  
  18.                 <AvailablePieces>  
  19.                     <xsl:apply-templates select="AvailablePieces/node()"/>  
  20.                     <!-- 添加新的AvailablePiece元素 -->  
  21.                     <AvailablePiece id="spear_handle_2"/>  
  22.                     <AvailablePiece id="spear_handle_9"/>  
  23.                     <AvailablePiece id="spear_handle_10"/>  
  24.                     <AvailablePiece id="spear_handle_11"/>  
  25.                     <AvailablePiece id="spear_handle_12"/>  
  26.                 </AvailablePieces>  
  27.             </xsl:if>  
  28.             <xsl:if test="not(AvailablePieces)">  
  29.                 <!-- 如果没有AvailablePieces元素,则创建一个并添加新的AvailablePiece元素 -->  
  30.                 <AvailablePieces>  
  31.                     <AvailablePiece id="spear_handle_2"/>  
  32.                     <AvailablePiece id="spear_handle_9"/>  
  33.                     <AvailablePiece id="spear_handle_10"/>  
  34.                     <AvailablePiece id="spear_handle_11"/>  
  35.                     <AvailablePiece id="spear_handle_12"/>  
  36.                 </AvailablePieces>  
  37.             </xsl:if>  
  38.         </xsl:copy>  
  39.     </xsl:template>  
  40. </xsl:stylesheet>
复制代码


现在可以进游戏试试,你的打造界面的双手剑模块里,剑柄部分已经有了几个标枪杆,拿来做剑枪已经有最基础的效果了.

然后处理动作的部分,这里我试了几次才差不多
使用xslt的方法,修改xml.具体来说:在CraftingTemplates标签下的CraftingTemplate标签里,当CraftingTemplate标签的属性id="TwoHandedSword"时,给CraftingTemplate标签下的UsablePieces标签里,添加
  1. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">  
  2.     <xsl:output method="xml" indent="yes"/>  
  3.     <xsl:strip-space elements="*"/>  
  4.   
  5.     <!-- 复制所有内容,除非另有说明 -->  
  6.     <xsl:template match="@*|node()">  
  7.         <xsl:copy>  
  8.             <xsl:apply-templates select="@*|node()"/>  
  9.         </xsl:copy>  
  10.     </xsl:template>  
  11.   
  12.     <!-- 当遇到item_usage_sets/item_usage_set,且其id属性为"twohanded_block_swing_thrust"时 -->  
  13.     <xsl:template match="item_usage_sets/item_usage_set[@id='twohanded_block_swing_thrust']">  
  14.         <xsl:copy>  
  15.             <!-- 复制item_usage_set的所有属性 -->  
  16.             <xsl:apply-templates select="@*"/>  
  17.             <!-- 复制item_usage_set下的所有子元素,除了usages -->  
  18.             <xsl:apply-templates select="node()[not(self::usages)]"/>  
  19.             <!-- 如果usages存在,则复制它但移除其下的所有usage元素 -->  
  20.             <xsl:if test="usages">  
  21.                 <usages>  
  22.                   <xsl:apply-templates select="usages/usage[@style!='attack_down']"/>  
  23.                     <!-- 添加两个新的usage元素 -->  
  24.                     <usage
  25.                       style="attack_down"
  26.                       ready_action="act_ready_thrust_staff_horseback"
  27.                       quick_release_action="act_quick_release_thrust_staff_horseback"
  28.                       release_action="act_release_thrust_staff_horseback"
  29.                       quick_blocked_action="act_quick_blocked_thrust_staff_horseback"
  30.                       blocked_action="act_blocked_thrust_staff_horseback"
  31.                       is_mounted="True"
  32.                       quick_stuck_action="act_quick_stuck_thrust_staff"
  33.                       stuck_action="act_stuck_thrust_staff"
  34.                       require_free_left_hand="True"
  35.                       strike_type="thrust"
  36.                       begin_hand_position="0,-0.6,-0.1"
  37.                       begin_hand_rotation="0,-90"
  38.                       begin_arm_rotation="0,0"
  39.                       begin_arm_length="0"
  40.                       end_hand_position="0,1.3,-0.1"
  41.                       end_hand_rotation="0,-90"
  42.                       end_arm_rotation="0,0"
  43.                       end_arm_length="0" />
  44.                     <usage
  45.                       style="attack_down"
  46.                       ready_action="act_ready_thrust_staff"
  47.                       quick_release_action="act_quick_release_thrust_staff"
  48.                       release_action="act_release_thrust_staff"
  49.                       quick_blocked_action="act_quick_blocked_thrust_staff"
  50.                       blocked_action="act_blocked_thrust_staff"
  51.                       quick_stuck_action="act_quick_stuck_thrust_staff"
  52.                       stuck_action="act_stuck_thrust_staff"
  53.                       is_mounted="False"
  54.                       require_free_left_hand="True"
  55.                       strike_type="thrust"
  56.                       begin_hand_position="0,-0.6,-0.1"
  57.                       begin_hand_rotation="0,-90"
  58.                       begin_arm_rotation="0,0"
  59.                       begin_arm_length="0"
  60.                       end_hand_position="0,1.3,-0.1"
  61.                       end_hand_rotation="0,-90"
  62.                       end_arm_rotation="0,0"
  63.                       end_arm_length="0" />
  64.                     <usage
  65.                       style="attack_down"
  66.                       ready_action="act_ready_thrust_staff_left_stance"
  67.                       quick_release_action="act_quick_release_thrust_staff_left_stance"
  68.                       release_action="act_release_thrust_staff_left_stance"
  69.                       quick_blocked_action="act_quick_blocked_thrust_staff_left_stance"
  70.                       blocked_action="act_blocked_thrust_staff_left_stance"
  71.                       is_mounted="False"
  72.                       quick_stuck_action="act_quick_stuck_thrust_staff_left_stance"
  73.                       stuck_action="act_stuck_thrust_staff_left_stance"
  74.                       require_free_left_hand="True"
  75.                       is_left_stance="True"
  76.                       strike_type="thrust"
  77.                       begin_hand_position="0,-0.6,-0.1"
  78.                       begin_hand_rotation="0,-90"
  79.                       begin_arm_rotation="0,0"
  80.                       begin_arm_length="0"
  81.                       end_hand_position="0,1.3,-0.1"
  82.                       end_hand_rotation="0,-90"
  83.                       end_arm_rotation="0,0"
  84.                       end_arm_length="0" />
  85.                     <usage
  86.                       style="attack_down"
  87.                       ready_action="act_ready_thrust_1h_lance"
  88.                       quick_release_action="act_quick_release_thrust_1h_lance"
  89.                       release_action="act_release_thrust_1h_lance"
  90.                       quick_blocked_action="act_quick_blocked_thrust_1h_lance"
  91.                       blocked_action="act_blocked_thrust_1h_lance"
  92.                       is_mounted="False"
  93.                       quick_stuck_action="act_quick_stuck_thrust_1h_lance"
  94.                       stuck_action="act_stuck_thrust_1h_lance"
  95.                       require_free_left_hand="False"
  96.                       strike_type="thrust"
  97.                       begin_hand_position="0,-0.6,-0.3"
  98.                       begin_hand_rotation="0,-90"
  99.                       begin_arm_rotation="0,0"
  100.                       begin_arm_length="0"
  101.                       end_hand_position="0,1.3,-0.3"
  102.                       end_hand_rotation="0,-90"
  103.                       end_arm_rotation="0,0"
  104.                       end_arm_length="0" />
  105.                     <usage
  106.                       style="attack_down"
  107.                       ready_action="act_ready_thrust_1h_lance_left_stance"
  108.                       quick_release_action="act_quick_release_thrust_1h_lance_left_stance"
  109.                       release_action="act_release_thrust_1h_lance_left_stance"
  110.                       quick_blocked_action="act_quick_blocked_thrust_1h_lance_left_stance"
  111.                       blocked_action="act_blocked_thrust_1h_lance_left_stance"
  112.                       is_mounted="False"
  113.                       quick_stuck_action="act_quick_stuck_thrust_1h_lance_left_stance"
  114.                       stuck_action="act_stuck_thrust_1h_lance_left_stance"
  115.                       require_free_left_hand="False"
  116.                       is_left_stance="True"
  117.                       strike_type="thrust"
  118.                       begin_hand_position="0,-0.6,-0.3"
  119.                       begin_hand_rotation="0,-90"
  120.                       begin_arm_rotation="0,0"
  121.                       begin_arm_length="0"
  122.                       end_hand_position="0,1.3,-0.3"
  123.                       end_hand_rotation="0,-90"
  124.                       end_arm_rotation="0,0"
  125.                       end_arm_length="0" />
  126.                     <usage
  127.                       style="attack_down"
  128.                       ready_action="act_ready_thrust_1h_lance"
  129.                       quick_release_action="act_quick_release_thrust_1h_lance_horseback"
  130.                       release_action="act_release_thrust_1h_lance_horseback"
  131.                       quick_blocked_action="act_quick_blocked_thrust_1h_lance"
  132.                       blocked_action="act_blocked_thrust_1h_lance"
  133.                       is_mounted="True"
  134.                       quick_stuck_action="act_quick_stuck_thrust_1h_lance"
  135.                       stuck_action="act_stuck_thrust_1h_lance"
  136.                       require_free_left_hand="False"
  137.                       strike_type="thrust"
  138.                       begin_hand_position="0,-0.6,-0.3"
  139.                       begin_hand_rotation="0,-90"
  140.                       begin_arm_rotation="0,0"
  141.                       begin_arm_length="0"
  142.                       end_hand_position="0,1.3,-0.3"
  143.                       end_hand_rotation="0,-90"
  144.                       end_arm_rotation="0,0"
  145.                       end_arm_length="0" />

  146.                 </usages>  
  147.             </xsl:if>  
  148.         </xsl:copy>  
  149.     </xsl:template>
  150. </xsl:stylesheet>
  151.    
复制代码


至此完事,去游戏里建一下武器,不过我感觉还是应该用长杆,这短杆看着也太丑了
xslt这东西主要还是怎么声明这一点比较麻烦,比较GPT也不知道你骑砍内部是怎么定义的.到了真用xslt的部分反而直接丢给GPT去简单处理了.
如果有更高级的需求,还是需要学一下xslt的语法什么的,不过现在看GPT写了几个功能,两个增,一个删改,也差不多能看懂了吧
4.png
5.png

评分

参与人数 1第纳尔 +20 互助 +1 魅力 +20 收起 理由
Aomine Daiki + 20 + 1 + 20 您的帖子很有价值!

查看全部评分

28

主题

4156

回帖

3130

积分

子爵[版主]

世纪风云制作组[程序]

圣殿骑士团[KT]
战团ID:Epig

中级术士

Rank: 7Rank: 7Rank: 7

UID
1706215
第纳尔
34958
精华
3
互助
157
荣誉
79
贡献
2005
魅力
207
注册时间
2013-12-8

骑砍中文站APP会员勋章原版正版勋章战团正版勋章火与剑正版勋章拿破仑正版勋章维京征服正版勋章汉匈决战正版勋章骑士美德之英勇勋章[杰出会员活跃勋章]骑士美德之仁慈勋章[杰出会员互助勋章]骑士美德之谦恭勋章[杰出会员财富勋章]骑士美德之公正勋章[杰出会员高级财富勋章]骑士美德之正义勋章[杰出会员荣誉勋章]骑士精神之文韬勋章杰出版主勋章骑士美德之奉献勋章骑士美德之高贵勋章骑砍中文站微博会员勋章骑砍中文站微信会员勋章骑友真人秀勋章汉匈决战荣誉用户勋章元老骑士勋章霸主正版勋章

鲜花(2039) 鸡蛋(904)
发表于 7 天前 | 显示全部楼层
联机的适用性有试过吗?
童鞋们,欢迎来到骑马与砍杀学院,我是你们的科任老师,猪猪老师,由我来为童鞋们介绍以下课程:
1、人间五十年life50 2.0测试版
2、永恒世界4.5.5公测版
3、永恒世界网页端 UCP2.0
4、大逃杀1.0公测版
5、永恒世界4.5特别版
6、常见PY报错解决方案

28

主题

219

回帖

179

积分

见习骑士

Rank: 3

UID
2758789
第纳尔
2118
精华
0
互助
19
荣誉
1
贡献
0
魅力
171
注册时间
2016-7-18
鲜花(18) 鸡蛋(0)
 楼主| 发表于 7 天前 | 显示全部楼层
恶猪 发表于 2024-4-23 12:44
联机的适用性有试过吗?

没有,只管单机。英文官网论坛那边倒是看到过配置服务器的帖子好像可以改,方法都是类似的,只不过联机那边要整服务器
您需要登录后才可以回帖 登录 | 注册(Register!)

本版积分规则

Archiver|手机版|小黑屋|骑马与砍杀中文站

GMT+8, 2024-4-30 20:47 , Processed in 0.119078 second(s), 22 queries , Gzip On, MemCached On.

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表