1
0
mirror of https://github.com/soarqin/DSP_Mods.git synced 2025-12-09 05:33:37 +08:00

Dustbin: WIP

This commit is contained in:
2023-10-19 23:07:40 +08:00
parent 932e8c189b
commit 0b16ae8424
3 changed files with 34 additions and 41 deletions

View File

@@ -1,6 +1,6 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using BepInEx;
using crecheng.DSPModSave;
@@ -22,8 +22,7 @@ public class Dustbin : BaseUnityPlugin, IModCanSave, IMultiplayerMod
BepInEx.Logging.Logger.CreateLogSource(PluginInfo.PLUGIN_NAME);
private bool _cfgEnabled = true;
public static readonly int[] SandsFactors = { 0, 1, 5, 10, 100 };
public static bool[] IsFluid;
public static readonly int[] SandsFactors = new int[12001];
public bool CheckVersion(string hostVersion, string clientVersion)
{
@@ -33,11 +32,15 @@ public class Dustbin : BaseUnityPlugin, IModCanSave, IMultiplayerMod
private void Awake()
{
_cfgEnabled = Config.Bind("General", "Enabled", _cfgEnabled, "enable/disable this plugin").Value;
SandsFactors[1] = Config.Bind("General", "SandsPerItem", SandsFactors[1], "Sands gathered from normal items").Value;
SandsFactors[0] = Config.Bind("General", "SandsPerFluid", SandsFactors[0], "Sands gathered from fluids").Value;
SandsFactors[2] = Config.Bind("General", "SandsPerStone", SandsFactors[2], "Sands gathered from stones").Value;
SandsFactors[3] = Config.Bind("General", "SandsPerSilicon", SandsFactors[3], "Sands gathered from silicon ores").Value;
SandsFactors[4] = Config.Bind("General", "SandsPerFractal", SandsFactors[4], "Sands gathered from fractal silicon ores").Value;
var sandsFactorsStr = Config.Bind("General", "SandsFactors", "", "Sands get from different items\nFormat: id1:value1|id2:value2|...").Value;
foreach (var s in sandsFactorsStr.Split('|'))
{
var sp = s.Split(':');
if (sp.Length < 2) continue;
if (!int.TryParse(sp[0], out var id) || id > 12000) continue;
if (!int.TryParse(sp[1], out var factor)) continue;
SandsFactors[id] = factor;
}
Harmony.CreateAndPatchAll(typeof(Dustbin));
Harmony.CreateAndPatchAll(typeof(StoragePatch));
Harmony.CreateAndPatchAll(typeof(TankPatch));
@@ -54,16 +57,6 @@ public class Dustbin : BaseUnityPlugin, IModCanSave, IMultiplayerMod
TankPatch.Reset();
}
[HarmonyPostfix]
[HarmonyPatch(typeof(VFPreload), "InvokeOnLoadWorkEnded")]
private static void VFPreload_InvokeOnLoadWorkEnded_Postfix()
{
var maxId = ItemProto.fluids.Max();
IsFluid = new bool[maxId + 1];
foreach (var id in ItemProto.fluids)
IsFluid[id] = true;
}
public void Export(BinaryWriter w)
{
w.Write(ModSaveVersion);

View File

@@ -6,8 +6,7 @@
## Changelog
* 1.3.0
* Reworked dustbin support for Tanks, to improve performance and resolve known bugs.
* Support for [Nebula Mupltiplayer Mod](https://dsp.thunderstore.io/package/nebula/NebulaMultiplayerMod/).
* Adopted bug fixes from [ModFixerOne](https://dsp.thunderstore.io/package/starfi5h/ModFixerOne/) by [starfi5h](https://github.com/starfi5h/).
* [Nebula Mupltiplayer Mod](https://dsp.thunderstore.io/package/nebula/NebulaMultiplayerMod/) and bug fixes from [ModFixerOne](https://dsp.thunderstore.io/package/starfi5h/ModFixerOne/) by [starfi5h](https://github.com/starfi5h/).
* 1.2.1
* Fix dynamic array bug in codes, which causes various bugs and errors.
@@ -22,21 +21,32 @@
* Rewrite whole plugin, make a checkbox on UI so that you can turn storages into dustbin by just ticking it.
* Can turn tank into dustbin now.
* 1.0.1
* Remove a debug log
## Usage
* A checkbox is added to Storages and Tanks UI, which turns them into dustbins.
* Items sent into dustbins are removed immediately.
* Can get sands from destroyed items (with factors configurable):
* Get 10/100 sands from each silicon/fractal silicon ore
* Get 1 sand from any other normal item but fluid
* Can get sands from destroyed items, configurable through a json encoded config entry.
## 更新日志
* 1.3.0
* 重写了储液罐的垃圾桶实现以提高性能并解决已知的bug
* [Nebula Mupltiplayer Mod](https://dsp.thunderstore.io/package/nebula/NebulaMultiplayerMod/)支持和Bug修正来自[starfi5h](https://github.com/starfi5h/)的[ModFixerOne](https://dsp.thunderstore.io/package/starfi5h/ModFixerOne/)
* 1.2.1
* 修正了代码中的动态数组Bug该Bug可能导致各种问题
* 1.2.0
* 现在使用[DSPModSave](https://dsp.thunderstore.io/package/CommonAPI/DSPModSave/)来保存垃圾桶的数据,修正了[#1](https://github.com/soarqin/DSP_Mods/issues/1)
* 修正了多星球上的储物仓问题
* 修正了多层储液罐的问题
* 在README中添加了一个已知储液罐Bug的说明
* 1.1.0
* 重写了整个插件现在可以在仓储类建筑的UI上勾选来将其转变为垃圾桶
* 现在可以将储液罐转变为垃圾桶
## 使用说明
* 在储物仓和储液罐上增加一个垃圾桶的勾选框。
* 送进垃圾桶的物品会立即被移除。
* 可以从移除的物品中获得沙子(可配置,下为默认值):
* 从硅石和分形硅石中获得10/100个沙子。
* 从普通物品中获得1个沙子但液体不会给沙子。
* 可以从移除的物品中获得沙子可以通过json编码的设置项进行配置。

View File

@@ -131,17 +131,7 @@ public static class StoragePatch
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static int DustbinAddItem(int itemId, int count)
{
var fluidArr = Dustbin.IsFluid;
var sandIndex = itemId < fluidArr.Length && fluidArr[itemId]
? 0
: itemId switch
{
1005 => 2,
1003 => 3,
1013 => 4,
_ => 1,
};
var sandsPerItem = Dustbin.SandsFactors[sandIndex];
var sandsPerItem = itemId <= 12000 ? 0 : Dustbin.SandsFactors[itemId];
if (sandsPerItem <= 0) return count;
var player = GameMain.mainPlayer;
var addCount = count * sandsPerItem;