mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2026-11-19 17:05:20 +08:00
The game-constant centralization attached wrong names to many item IDs, such as Steel for Titanium Alloy (1107) and HydrogenFuelRod for the Electromagnetic Matrix (6001). Every remaining usage relies on the IDs, which match the items in the belt-signal proliferation tips, the matrix metadata types, and the Dark Fog buy-out definitions. Rename the constants after their actual items and current Dark Fog item names, and remove the mislabeled constants that only the retired proliferator source table used. Item groups and compiled values are unchanged.
173 lines
7.1 KiB
C#
173 lines
7.1 KiB
C#
using System;
|
|
using System.Linq;
|
|
using UXAssist.Common;
|
|
using UXAssist.Common.GameConstants;
|
|
using UXAssist.Common.ModFeatures;
|
|
|
|
namespace CheatEnabler.Functions;
|
|
|
|
[ModFeature("PlayerFunctions")]
|
|
public static class PlayerFunctions
|
|
{
|
|
public static void Init()
|
|
{
|
|
}
|
|
|
|
public static void TeleportToOuterSpace()
|
|
{
|
|
var maxSqrDistance = 0.0;
|
|
var starPosition = VectorLF3.zero;
|
|
if (GameMain.galaxy == null) return;
|
|
foreach (var star in GameMain.galaxy.stars)
|
|
{
|
|
var sqrDistance = star.position.sqrMagnitude;
|
|
if (sqrDistance > maxSqrDistance)
|
|
{
|
|
maxSqrDistance = sqrDistance;
|
|
starPosition = star.position;
|
|
}
|
|
}
|
|
if (starPosition == VectorLF3.zero) return;
|
|
var distance = Math.Sqrt(maxSqrDistance);
|
|
GameMain.mainPlayer.controller.actionSail.StartFastTravelToUPosition((starPosition + starPosition.normalized * 50) * GalaxyData.LY);
|
|
}
|
|
|
|
public static void TeleportToSelectedAstronomical()
|
|
{
|
|
var starmap = UIRoot.instance?.uiGame?.starmap;
|
|
if (starmap == null) return;
|
|
if (starmap.focusPlanet != null)
|
|
{
|
|
GameMain.mainPlayer.controller.actionSail.StartFastTravelToPlanet(starmap.focusPlanet.planet);
|
|
return;
|
|
}
|
|
var targetUPos = VectorLF3.zero;
|
|
if (starmap.focusStar != null)
|
|
{
|
|
var star = starmap.focusStar.star;
|
|
targetUPos = star.uPosition + VectorLF3.unit_x * star.physicsRadius;
|
|
}
|
|
else if (starmap.focusHive != null)
|
|
{
|
|
var hive = starmap.focusHive.hive;
|
|
var id = hive.hiveAstroId - 1000000;
|
|
if (id > 0 && id < starmap.spaceSector.astros.Length)
|
|
{
|
|
ref var astro = ref starmap.spaceSector.astros[id];
|
|
targetUPos = astro.uPos + VectorLF3.unit_x * astro.uRadius;
|
|
}
|
|
}
|
|
GameMain.mainPlayer.controller.actionSail.StartFastTravelToUPosition(targetUPos);
|
|
}
|
|
|
|
private static void PurgePropertySystem(PropertySystem propertySystem)
|
|
{
|
|
var propertyDatas = propertySystem.propertyDatas;
|
|
for (var i = 0; i < propertyDatas.Count;)
|
|
{
|
|
if (propertyDatas[i].totalProduction.Any(idcnt => idcnt.count > 0) || propertyDatas[i].totalConsumption.Any(idcnt => idcnt.count > 0))
|
|
{
|
|
i++;
|
|
}
|
|
else
|
|
{
|
|
propertyDatas.RemoveAt(i);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void RemoveAllMetadataConsumptions()
|
|
{
|
|
var propertySystem = DSPGame.propertySystem;
|
|
if (propertySystem == null) return;
|
|
PurgePropertySystem(propertySystem);
|
|
var itemCnt = new int[ItemIds.UniverseMatrix - ItemIds.ElectromagneticMatrix + 1];
|
|
foreach (var cons in propertySystem.propertyDatas.SelectMany(data => data.totalConsumption.Where(cons => cons.id is >= ItemIds.ElectromagneticMatrix and <= ItemIds.UniverseMatrix)))
|
|
{
|
|
itemCnt[cons.id - ItemIds.ElectromagneticMatrix] += cons.count;
|
|
}
|
|
|
|
if (itemCnt.All(cnt => cnt == 0))
|
|
{
|
|
UIMessageBox.Show(Localization.RemoveAllMetadataConsumptionRecords.Translate(), Localization.NoMetadataConsumptionRecord.Translate(), Localization.OK.Translate(), UIMessageBox.INFO);
|
|
return;
|
|
}
|
|
var msg = Localization.ClearAllMetadataConsumptionDetails.Translate();
|
|
for (var i = 0; i < itemCnt.Length; i++)
|
|
{
|
|
if (itemCnt[i] > 0)
|
|
{
|
|
msg += $"\n {LDB.items.Select(i + ItemIds.ElectromagneticMatrix).propertyName} x{itemCnt[i]}";
|
|
}
|
|
}
|
|
UIMessageBox.Show(Localization.RemoveAllMetadataConsumptionRecords.Translate(), msg, Localization.Cancel.Translate(), Localization.OK.Translate(), UIMessageBox.QUESTION, null, () =>
|
|
{
|
|
foreach (var data in propertySystem.propertyDatas)
|
|
{
|
|
for (var i = 0; i < data.totalConsumption.Count; i++)
|
|
{
|
|
if (data.totalConsumption[i].count == 0) continue;
|
|
var id = data.totalConsumption[i].id;
|
|
data.totalConsumption[i] = new IDCNT(id, 0);
|
|
}
|
|
}
|
|
PurgePropertySystem(propertySystem);
|
|
propertySystem.SaveToFile();
|
|
});
|
|
}
|
|
|
|
public static void RemoveCurrentMetadataConsumptions()
|
|
{
|
|
var propertySystem = DSPGame.propertySystem;
|
|
if (propertySystem == null) return;
|
|
PurgePropertySystem(propertySystem);
|
|
var itemCnt = new int[ItemIds.UniverseMatrix - ItemIds.ElectromagneticMatrix + 1];
|
|
var seedKey = DSPGame.GameDesc.seedKey64;
|
|
var clusterPropertyData = propertySystem.propertyDatas.FirstOrDefault(cpd => cpd.seedKey == seedKey);
|
|
if (clusterPropertyData == null)
|
|
{
|
|
UIMessageBox.Show(Localization.RemoveMetadataConsumptionRecordInCurrentGame.Translate(), Localization.NoMetadataConsumptionRecord.Translate(), Localization.OK.Translate(), UIMessageBox.INFO);
|
|
return;
|
|
}
|
|
var currentGamePropertyData = GameMain.data.history.propertyData;
|
|
foreach (var cons in currentGamePropertyData.totalConsumption.Where(cons => cons.id is >= ItemIds.ElectromagneticMatrix and <= ItemIds.UniverseMatrix))
|
|
{
|
|
itemCnt[cons.id - ItemIds.ElectromagneticMatrix] += cons.count;
|
|
}
|
|
|
|
if (itemCnt.All(cnt => cnt == 0))
|
|
{
|
|
UIMessageBox.Show(Localization.RemoveMetadataConsumptionRecordInCurrentGame.Translate(), Localization.NoMetadataConsumptionRecord.Translate(), Localization.OK.Translate(), UIMessageBox.INFO);
|
|
return;
|
|
}
|
|
var msg = Localization.ClearCurrentMetadataConsumptionDetails.Translate();
|
|
for (var i = 0; i < itemCnt.Length; i++)
|
|
{
|
|
if (itemCnt[i] > 0)
|
|
{
|
|
msg += $"\n {LDB.items.Select(i + ItemIds.ElectromagneticMatrix).propertyName} x{itemCnt[i]}";
|
|
}
|
|
}
|
|
UIMessageBox.Show(Localization.RemoveMetadataConsumptionRecordInCurrentGame.Translate(), msg, Localization.Cancel.Translate(), Localization.OK.Translate(), UIMessageBox.QUESTION, null, () =>
|
|
{
|
|
for (var i = 0; i < clusterPropertyData.totalConsumption.Count; i++)
|
|
{
|
|
if (clusterPropertyData.totalConsumption[i].count == 0) continue;
|
|
var id = clusterPropertyData.totalConsumption[i].id;
|
|
if (id < ItemIds.ElectromagneticMatrix || id > ItemIds.UniverseMatrix) continue;
|
|
var currentGameCount = itemCnt[id - ItemIds.ElectromagneticMatrix];
|
|
if (currentGameCount == 0) continue;
|
|
var totalCount = clusterPropertyData.totalConsumption[i].count;
|
|
clusterPropertyData.totalConsumption[i] = new IDCNT(id, totalCount > currentGameCount ? totalCount - currentGameCount : 0);
|
|
}
|
|
PurgePropertySystem(propertySystem);
|
|
propertySystem.SaveToFile();
|
|
});
|
|
}
|
|
|
|
public static void ClearMetadataBanAchievements()
|
|
{
|
|
GameMain.history.hasUsedPropertyBanAchievement = false;
|
|
}
|
|
}
|