mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2025-12-09 06:13:36 +08:00
Add OCBatchBuild
This commit is contained in:
27
OCBatchBuild/OCBatchBuild.csproj
Normal file
27
OCBatchBuild/OCBatchBuild.csproj
Normal file
@@ -0,0 +1,27 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<AssemblyName>OCBatchBuild</AssemblyName>
|
||||
<BepInExPluginGuid>org.soardev.ocbatchbuild</BepInExPluginGuid>
|
||||
<Description>DSP MOD - OCBatchBuild</Description>
|
||||
<Version>1.0.0</Version>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<LangVersion>latest</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BepInEx.Core" Version="5.*" />
|
||||
<PackageReference Include="BepInEx.PluginInfoProps" Version="1.*" />
|
||||
<PackageReference Include="DysonSphereProgram.GameLibs" Version="0.9.26.13026-r.0" />
|
||||
<PackageReference Include="UnityEngine.Modules" Version="2018.4.12" IncludeAssets="compile" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFramework.TrimEnd(`0123456789`))' == 'net'">
|
||||
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2" PrivateAssets="all" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||
<Exec Command="del /F /Q package\$(ProjectName)-$(Version).zip
zip -9 -j package/$(ProjectName)-$(Version).zip $(TargetPath) package/icon.png package/manifest.json README.md" />
|
||||
</Target>
|
||||
</Project>
|
||||
99
OCBatchBuild/OrbitalCollectorBatchBuild.cs
Normal file
99
OCBatchBuild/OrbitalCollectorBatchBuild.cs
Normal file
@@ -0,0 +1,99 @@
|
||||
using System;
|
||||
using BepInEx;
|
||||
using BepInEx.Configuration;
|
||||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
|
||||
namespace OCBatchBuild;
|
||||
|
||||
[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
|
||||
public class OrbitalCollectorBatchBuild : BaseUnityPlugin
|
||||
{
|
||||
private new static readonly BepInEx.Logging.ManualLogSource Logger =
|
||||
BepInEx.Logging.Logger.CreateLogSource(PluginInfo.PLUGIN_NAME);
|
||||
|
||||
private bool _cfgEnabled = true;
|
||||
private static int _maxBuildCount;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_cfgEnabled = Config.Bind("General", "Enabled", _cfgEnabled, "enable/disable this plugin").Value;
|
||||
_maxBuildCount = Config.Bind("General", "MaxBuildCount", _maxBuildCount,
|
||||
new ConfigDescription("Maximum Orbital Collectors to build once, set to 0 to build as many as possible",
|
||||
new AcceptableValueRange<int>(0, 40), new {}))
|
||||
.Value;
|
||||
Harmony.CreateAndPatchAll(typeof(OrbitalCollectorBatchBuild));
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(BuildTool_Click), "CreatePrebuilds")]
|
||||
private static void CreatePrebuilds(BuildTool_Click __instance)
|
||||
{
|
||||
/* Check Gas Planet */
|
||||
if (__instance.planet.type != EPlanetType.Gas) return;
|
||||
if (__instance.buildPreviews.Count == 0) return;
|
||||
|
||||
var buildPreview = __instance.buildPreviews[0];
|
||||
/* Check if is collector station */
|
||||
if (!buildPreview.desc.isCollectStation) return;
|
||||
|
||||
var factory = __instance.factory;
|
||||
var stationPool = factory.transport.stationPool;
|
||||
var entityPool = factory.entityPool;
|
||||
var stationCursor = factory.transport.stationCursor;
|
||||
var pos = buildPreview.lpos;
|
||||
var pos2 = buildPreview.lpos2;
|
||||
var itemId = buildPreview.item.ID;
|
||||
var countToBuild = _maxBuildCount - 1;
|
||||
for (var i = 0; i < 39 && countToBuild != 0; i++)
|
||||
{
|
||||
/* rotate for 1/40 on sphere */
|
||||
pos = Maths.RotateLF(0.0, 1.0, 0.0, Math.PI / 40.0, pos);
|
||||
pos2 = Maths.RotateLF(0.0, 1.0, 0.0, Math.PI / 40.0, pos2);
|
||||
|
||||
/* Check for collision */
|
||||
var collide = false;
|
||||
for (var j = 1; j < stationCursor; j++)
|
||||
{
|
||||
if (stationPool[j] == null || stationPool[j].id != j) continue;
|
||||
if ((entityPool[stationPool[j].entityId].pos - pos).sqrMagnitude >= 14297f) continue;
|
||||
collide = true;
|
||||
break;
|
||||
}
|
||||
if (collide) continue;
|
||||
|
||||
var player = __instance.player;
|
||||
if (player.inhandItemId == itemId && player.inhandItemCount > 0)
|
||||
{
|
||||
player.UseHandItems(1, out var _);
|
||||
}
|
||||
else
|
||||
{
|
||||
var count = 1;
|
||||
player.package.TakeTailItems(ref itemId, ref count, out var _);
|
||||
if (count == 0) break;
|
||||
}
|
||||
|
||||
var rot = Maths.SphericalRotation(pos, 0f);
|
||||
var rot2 = Maths.SphericalRotation(pos2, 0f);
|
||||
var prebuild = default(PrebuildData);
|
||||
prebuild.protoId = (short)buildPreview.item.ID;
|
||||
prebuild.modelIndex = (short)buildPreview.desc.modelIndex;
|
||||
prebuild.pos = pos;
|
||||
prebuild.pos2 = pos2;
|
||||
prebuild.rot = rot;
|
||||
prebuild.rot2 = rot2;
|
||||
prebuild.pickOffset = (short)buildPreview.inputOffset;
|
||||
prebuild.insertOffset = (short)buildPreview.outputOffset;
|
||||
prebuild.recipeId = buildPreview.recipeId;
|
||||
prebuild.filterId = buildPreview.filterId;
|
||||
prebuild.InitParametersArray(buildPreview.paramCount);
|
||||
for (var j = 0; j < buildPreview.paramCount; j++)
|
||||
{
|
||||
prebuild.parameters[j] = buildPreview.parameters[j];
|
||||
}
|
||||
factory.AddPrebuildDataWithComponents(prebuild);
|
||||
countToBuild--;
|
||||
}
|
||||
}
|
||||
}
|
||||
14
OCBatchBuild/README.md
Normal file
14
OCBatchBuild/README.md
Normal file
@@ -0,0 +1,14 @@
|
||||
# OrbitalCollectorBatchBuild
|
||||
|
||||
#### Batch build Orbital Collectors
|
||||
#### 轨道采集器快速批量建造
|
||||
|
||||
## Usage
|
||||
* Build any orbital collector on a Gas Giant to trigger building all placable orbital collectors.
|
||||
* Can set maximum orbital collectors to build once in config.
|
||||
* Note: They are placed as prebuilt status, you still need to fly around the Gas Giant to complete building. This is designed not to break much game logic.
|
||||
|
||||
## 使用说明
|
||||
* 在气态星球上建造任何一个轨道采集器触发所有可建造采集器的放置。
|
||||
* 可以在设置文件中配置一次批量建造的最大轨道采集器数量。
|
||||
* 提示:轨道采集器会处于待建造状态,你仍然需要绕行气态行星一圈以完成建造。这个机制是为了尽可能减少对原有游戏逻辑的破坏。
|
||||
BIN
OCBatchBuild/package/icon.png
Normal file
BIN
OCBatchBuild/package/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 53 KiB |
9
OCBatchBuild/package/manifest.json
Normal file
9
OCBatchBuild/package/manifest.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "OrbitalCollectorBatchBuild",
|
||||
"version_number": "1.0.0",
|
||||
"website_url": "https://github.com/soarqin/DSP_Mods/tree/master/OCBatchBuild",
|
||||
"description": "Batch build Orbital Collectors / 轨道采集器快速批量建造",
|
||||
"dependencies": [
|
||||
"xiaoye97-BepInEx-5.4.17"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user