使用powershell修改流星蝴蝶剑所有关卡的武器
背景介绍
由于本人爱玩流行蝴蝶剑,且最喜欢使用剑,因此写了一个脚本修改所有关卡的初始武器。该脚本功能很简单,当参数为"-h"时输出各种属性的武器代号。当参数为两个整数时,修改每个关卡初始武器。
使用说明
如果无法运行powershell脚本,需要设置允许执行powershell脚本,方法是打开powershell,输入命令Set-ExecutionPolicy Unrestricted

假设脚本文件名为ChangeMetor.ps1,首先执行 .\ChangeMetor.ps1 -h,如下图会显示

假如我们需要将初始武器设置成高攻长剑和高攻长枪,则执行.\ChangeMetor.ps1 15 16

代码实现(如需使用可将里面的流星蝴蝶剑目录替换成自己的安装目录)
$NormalMap = [ordered]@{
"飞镖" = 1
"飞轮" = 2
"火铳" = 3
"双刺" = 4
"匕首" = 5
"长剑" = 6
"长枪" = 7
"大刀" = 8
"大锤" = 9
"乾坤刀" = 47
"指虎" = 51
"忍刀" = 55
}
if ("$($args[0])" -eq "-h") {
[string]::Format("{0,-3}`t{1, -4}`t{2, -4}`t{3, -4}`t{4, -4}", " " , "中庸", "高攻", "高防", "高敏")
$NormalMap.GetEnumerator() | ForEach-Object {
if ($($_.Value) -lt 10) {
$highAttack = $($_.Value) + 9
$highFang = $($_.Value) + 18
$highSpeed = $($_.Value) + 27
} else {
$highAttack = $($_.Value) + 1
$highFang = $($_.Value) + 2
$highSpeed = $($_.Value) + 3
}
[string]::Format("{0,-3}`t{1, -4}`t{2, -4}`t{3, -4}`t{4, -4}", $($_.Key) , $($_.Value), $highAttack, $highFang, $highSpeed)
}
exit
}
$wp1 = $($args[0])
$wp2 = $($args[1])
if (-not($wp1 -is [int]) -or -not($wp2 -is [int])) {
echo "wp1 or wp2 is not integer"
exit
}
if ($wp1 -lt 0 -or $wp2 -lt 0) {
echo "wp1 or wp2 is smaller than 0"
exit
}
$curDir=Split-Path -Parent $PSCommandPath
$targetDir="E:\Game\流星蝴蝶剑\Level"
cd $targetDir
$allFiles=Get-ChildItem -File -Name
foreach($file in $allFiles) {
if ($file -match "^sn\d+_.pst$") {
if (-not (Test-Path "$file.bak")) {
Copy-Item -Path "$file" -Destination "$file.bak" -Force
}
echo "try handle $file"
$c = Get-Content -Path $file -Raw
$c = $c -replace '(?m)^int\s+PlayerWeapon\s*=\s*\d+\s*;', "int PlayerWeapon=$wp1;"
$c = $c -replace '(?m)^int\s+PlayerWeapon2\s*=\s*\d+\s*;', "int PlayerWeapon2=$wp2;"
Set-Content -Path $file -Value $c
}
}
cd $curDir

浙公网安备 33010602011771号