Skip to content

Commit be2d9fb

Browse files
committed
Updated zap functionality (cleaned)
Updated PrawnSelfDefenseModule Added a bunch of patches for the PrawnSelfDefenseModule Ready for release. WAITING FOR A SMLHELPER UPDATE !!!
1 parent 25dba22 commit be2d9fb

7 files changed

+141
-38
lines changed

AlterraWeaponry/AlterraWeaponry.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@
100100
<Compile Include="behaviours\ZapFunctionalityBehaviour.cs" />
101101
<Compile Include="items\PrawnSelfDefenseModule.cs" />
102102
<Compile Include="patches\ExosuitTorpedoArm_OpenTorpedoStorageExternal_Patch.cs" />
103+
<Compile Include="patches\GameSettings_SaveAsync_Patch.cs" />
103104
<Compile Include="patches\SeamothTorpedo_OnEnergyDepleted_Patch.cs" />
105+
<Compile Include="patches\Vehicle_ChargeModule_Patch.cs" />
106+
<Compile Include="patches\Vehicle_GetSlotCharge_Patch.cs" />
104107
<Compile Include="patches\Vehicle_OnUpgradeModuleChange_Patch.cs" />
105108
<Compile Include="patches\Vehicle_OnUpgradeModuleUse_Patch.cs" />
106109
<Compile Include="utils\ExplosiveTorpedoInitializer.cs" />

AlterraWeaponry/behaviours/ZapFunctionalityBehaviour.cs

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
using System.Collections;
33
using System.Collections.Generic;
44
using System.Linq;
5+
using System.Runtime.CompilerServices;
56
using System.Text;
67
using System.Threading.Tasks;
78
using UWE;
9+
using static VehicleUpgradeConsoleInput;
10+
using static VFXParticlesPool;
811

912
namespace VELD.AlterraWeaponry.behaviours;
1013

@@ -14,25 +17,10 @@ internal class ZapFunctionalityBehaviour : MonoBehaviour // Thanks to ECM and Pr
1417

1518
public static GameObject ElectricalDefensePrefab => seamothElectricalDefensePrefab;
1619

17-
private const float EnergyCostPerZap = 5;
18-
private const float ZapPower = 6f;
19-
private const float BaseCharge = 2f;
20-
private const float BaseRadius = 1f;
20+
public const float ZapCooldown = 5f;
2121

22-
public const float ZapCooldown = 10f;
23-
public static float timeNextZap = 0;
24-
private static float DamageMultiplier => 1f;
25-
private static float DirectZapDamage = (BaseRadius + ZapPower * BaseCharge) * DamageMultiplier * 0.5f;
26-
// Calculations and initial values based off ElectricalDefense component
27-
28-
public static bool AbleToZap(Vehicle vehicle)
29-
{
30-
vehicle.energyInterface.GetValues(out float charge, out float capacity);
31-
if (GameModeManager.GetOption<bool>(GameOption.TechnologyRequiresPower) && charge < EnergyCostPerZap)
32-
return false;
33-
34-
return true;
35-
}
22+
public float Overcharge { get; private set; }
23+
public float OverchargeScalar { get; private set; }
3624

3725
public static IEnumerator UpdateDefensePrefab()
3826
{
@@ -44,35 +32,27 @@ public static IEnumerator UpdateDefensePrefab()
4432

4533
seamothElectricalDefensePrefab = prefab?.GetComponent<SeaTruckUpgrades>().electricalDefensePrefab;
4634
}
47-
48-
public bool Zap(Vehicle vehicle)
35+
public bool Zap(Vehicle vehicle, int usedSlotID)
4936
{
50-
CoroutineHost.StartCoroutine(UpdateDefensePrefab());
51-
if (Time.time < timeNextZap)
52-
return true;
5337

54-
if (!AbleToZap(vehicle))
55-
return false;
38+
float charge = vehicle.quickSlotCharge[usedSlotID];
39+
float slotCharge = vehicle.GetSlotCharge(usedSlotID);
40+
this.Overcharge = charge;
41+
this.OverchargeScalar = slotCharge;
42+
CoroutineHost.StartCoroutine(UpdateDefensePrefab());
5643

5744
ZapRadius(vehicle);
58-
59-
timeNextZap = Time.time + ZapCooldown;
6045
return true;
6146
}
6247

63-
private static void ZapRadius(Vehicle vehicle)
48+
private void ZapRadius(Vehicle vehicle)
6449
{
6550
if (vehicle == null)
6651
return;
6752

6853
GameObject gameObject = Utils.SpawnZeroedAt(ElectricalDefensePrefab, vehicle.transform, false);
6954
ElectricalDefense defenseComponent = gameObject.GetComponent<ElectricalDefense>();
70-
defenseComponent.charge = ZapPower;
71-
defenseComponent.chargeScalar = ZapPower;
72-
defenseComponent.radius *= ZapPower;
73-
defenseComponent.chargeRadius *= ZapPower;
74-
75-
if (GameModeManager.GetOption<bool>(GameOption.TechnologyRequiresPower))
76-
vehicle.energyInterface.ConsumeEnergy(EnergyCostPerZap);
55+
defenseComponent.charge = this.Overcharge;
56+
defenseComponent.chargeScalar = this.OverchargeScalar;
7757
}
7858
}

AlterraWeaponry/items/PrawnSelfDefenseModule.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ namespace VELD.AlterraWeaponry.items;
1010
public class PrawnSelfDefenseModule : Equipable
1111
{
1212
public static GameObject prefab;
13+
public static float maxCharge = 10f;
14+
public static float energyCost = 5f;
1315
public static TechType techType { get; private set; } = 0;
1416

1517
public PrawnSelfDefenseModule() : base("PrawnSelfDefenseModule", "PrawnSelfDefenseModule", "Tooltip_PrawnSelfDefenseModule")
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using System.CodeDom;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace VELD.AlterraWeaponry.patches;
9+
10+
[HarmonyPatch(typeof(GameSettings))]
11+
public class GameSettings_SaveAsync_Patch
12+
{
13+
[HarmonyPostfix]
14+
[HarmonyPatch(nameof(GameSettings.SaveAsync))]
15+
public static void SaveAsync(GameSettings.OnSaveDelegate onSave)
16+
{
17+
LanguagesHandler.LanguagePatch();
18+
}
19+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace VELD.AlterraWeaponry.patches;
8+
9+
[HarmonyPatch(typeof(Vehicle))]
10+
public class Vehicle_ChargeModule_Patch
11+
{
12+
[HarmonyPrefix]
13+
[HarmonyPatch(nameof(Vehicle.ChargeModule))]
14+
public static bool ChargeModule(Vehicle __instance, TechType techType, int slotID)
15+
{
16+
float num = __instance.quickSlotCharge[slotID];
17+
float maxCharge = TechData.GetMaxCharge(techType);
18+
19+
// TEMP CODE WAITING FOR SMLHELPER UPDATE
20+
if(techType == PrawnSelfDefenseModule.techType)
21+
maxCharge = PrawnSelfDefenseModule.maxCharge;
22+
23+
float num2;
24+
TechData.GetEnergyCost(techType, out num2);
25+
26+
// TEMP CODE WAITING FOR SMLHELPER UPDATE
27+
if (techType == PrawnSelfDefenseModule.techType)
28+
num2 = PrawnSelfDefenseModule.energyCost;
29+
30+
float num3 = num2 * Time.deltaTime;
31+
float num4 = maxCharge - num;
32+
bool flag = num3 >= num4;
33+
float b = flag ? Mathf.Max(0f, num4) : num3;
34+
int num6;
35+
float num5 = Mathf.Min(__instance.energyInterface.TotalCanProvide(out num6), b);
36+
__instance.ConsumeEnergy(num5);
37+
__instance.quickSlotCharge[slotID] = __instance.quickSlotCharge[slotID] + num5;
38+
if (__instance.quickSlotCharge[slotID] > 0f && (flag || num5 == 0f))
39+
{
40+
__instance.OnUpgradeModuleUse(techType, slotID);
41+
__instance.quickSlotCharge[slotID] = 0f;
42+
}
43+
return false;
44+
}
45+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace VELD.AlterraWeaponry.patches;
8+
9+
10+
[HarmonyPatch(typeof(Vehicle))]
11+
internal class Vehicle_GetSlotCharge_Patch
12+
{
13+
[HarmonyPrefix]
14+
[HarmonyPatch(nameof(Vehicle.GetSlotCharge))]
15+
public static bool GetSlotCharge(Vehicle __instance, int slotID, ref float __result)
16+
{
17+
if (slotID < 0 || slotID >= __instance.slotIDs.Length)
18+
{
19+
__result = 1f;
20+
return false;
21+
}
22+
TechType techType;
23+
QuickSlotType quickSlotType = __instance.GetQuickSlotType(slotID, out techType);
24+
if (quickSlotType == QuickSlotType.Chargeable || quickSlotType == QuickSlotType.SelectableChargeable)
25+
{
26+
float maxCharge = TechData.GetMaxCharge(techType);
27+
28+
// TEMPORARY PATCH, WAITING FOR AN SMLHELPER UPDATE
29+
bool flag = techType == PrawnSelfDefenseModule.techType;
30+
if (flag)
31+
maxCharge = PrawnSelfDefenseModule.maxCharge;
32+
33+
if (maxCharge > 0f)
34+
{
35+
__result = __instance.quickSlotCharge[slotID] / maxCharge;
36+
Main.logger.LogInfo($"Slot charge: {__result}");
37+
return false;
38+
}
39+
}
40+
__result = 1f;
41+
return false;
42+
}
43+
}

AlterraWeaponry/patches/Vehicle_OnUpgradeModuleUse_Patch.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,23 @@ public class Vehicle_OnUpgradeModuleUse_Patch
1313
[HarmonyPatch(nameof(Vehicle.OnUpgradeModuleUse))]
1414
public static void OnUpgradeModuleUse(TechType techType, int slotID, Vehicle __instance)
1515
{
16-
if(techType == PrawnSelfDefenseModule.techType)
16+
if(__instance is not Exosuit)
17+
return;
18+
19+
20+
bool flag = true;
21+
float num = 0f;
22+
if (techType == PrawnSelfDefenseModule.techType)
1723
{
18-
Main.logger.LogInfo($"OnUpgradeModuleUse input received on slot {slotID}");
1924
if (!__instance.TryGetComponent(out ZapFunctionalityBehaviour defenseMono))
2025
return;
21-
defenseMono.Zap(__instance);
26+
defenseMono.Zap(__instance, slotID);
27+
num = ZapFunctionalityBehaviour.ZapCooldown;
28+
}
29+
if (flag)
30+
{
31+
__instance.quickSlotTimeUsed[slotID] = Time.time;
32+
__instance.quickSlotCooldown[slotID] = num;
2233
}
2334
}
2435
}

0 commit comments

Comments
 (0)