-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The Prawn Self Defense Module is now working.
Started working on custom triggerboxes for custom story goal assignments with"callback"/action expressions
- Loading branch information
Showing
6 changed files
with
199 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Linq.Expressions; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace VELD.AlterraWeaponry.behaviours; | ||
|
||
public class CustomTriggerStoryGoalAssigner : MonoBehaviour | ||
{ | ||
public StoryGoal storyGoal { get; private set; } | ||
public string id { get; private set; } | ||
|
||
public Action action { get; private set; } | ||
|
||
public CustomTriggerStoryGoalAssigner(StoryGoal storyGoal, string id, Action action = null) | ||
{ | ||
this.storyGoal = storyGoal; | ||
this.id = id; | ||
this.action = action; | ||
} | ||
|
||
private void Start() | ||
{ | ||
bool flag = this.GetComponentInParent<BoxCollider>(); | ||
if(!flag) | ||
{ | ||
throw new Exception($"The CustomTriggerEventAssigner monobehaviour of parent CustomEventTrigger has no Collider."); | ||
} | ||
|
||
bool flag2 = this.storyGoal != null; | ||
if(!flag2) | ||
{ | ||
throw new Exception($"The StoryGoal of the CustomTriggerEventAssigner is undefined."); | ||
} | ||
} | ||
|
||
private void OnTriggerEnter(Collision collision) | ||
{ | ||
Main.logger.LogInfo("Custom collider triggered."); | ||
bool flag = this.storyGoal != null; | ||
if(!flag) | ||
{ | ||
Main.logger.LogWarning($"TriggerBox {this.id} has no StoryGoal to play."); | ||
return; | ||
} | ||
|
||
Main.logger.LogInfo($"Trying to play storyGoal {this.storyGoal.key}"); | ||
this.storyGoal.Trigger(); | ||
Main.logger.LogInfo($"Has finished playing storyGoal {this.storyGoal.key}"); | ||
|
||
bool flag2 = this.action != null; | ||
if(flag2) { | ||
Main.logger.LogInfo("Trigger Callback is trying to invoke Action..."); | ||
this.action.Invoke(); | ||
Main.logger.LogInfo("Trigger Callback has successfully executed Action"); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using UWE; | ||
|
||
namespace VELD.AlterraWeaponry.behaviours; | ||
|
||
internal class ZapFunctionalityBehaviour : MonoBehaviour // Thanks to ECM and PrimeSonic 👌 | ||
{ | ||
private static GameObject seamothElectricalDefensePrefab = null; | ||
|
||
public static GameObject ElectricalDefensePrefab => seamothElectricalDefensePrefab; | ||
|
||
private const float EnergyCostPerZap = 5; | ||
private const float ZapPower = 6f; | ||
private const float BaseCharge = 2f; | ||
private const float BaseRadius = 1f; | ||
|
||
public const float ZapCooldown = 10f; | ||
public static float timeNextZap = 0; | ||
private static float DamageMultiplier => 1f; | ||
private static float DirectZapDamage = (BaseRadius + ZapPower * BaseCharge) * DamageMultiplier * 0.5f; | ||
// Calculations and initial values based off ElectricalDefense component | ||
|
||
public static bool AbleToZap(Vehicle vehicle) | ||
{ | ||
vehicle.energyInterface.GetValues(out float charge, out float capacity); | ||
if (GameModeManager.GetOption<bool>(GameOption.TechnologyRequiresPower) && charge < EnergyCostPerZap) | ||
return false; | ||
|
||
return true; | ||
} | ||
|
||
public static IEnumerator UpdateDefensePrefab() | ||
{ | ||
if (seamothElectricalDefensePrefab) yield break; | ||
|
||
var task = CraftData.GetPrefabForTechTypeAsync(TechType.SeaTruck); | ||
yield return task; | ||
var prefab = task.GetResult(); | ||
|
||
seamothElectricalDefensePrefab = prefab?.GetComponent<SeaTruckUpgrades>().electricalDefensePrefab; | ||
} | ||
|
||
public bool Zap(Vehicle vehicle) | ||
{ | ||
CoroutineHost.StartCoroutine(UpdateDefensePrefab()); | ||
if (Time.time < timeNextZap) | ||
return true; | ||
|
||
if (!AbleToZap(vehicle)) | ||
return false; | ||
|
||
ZapRadius(vehicle); | ||
|
||
timeNextZap = Time.time + ZapCooldown; | ||
return true; | ||
} | ||
|
||
private static void ZapRadius(Vehicle vehicle) | ||
{ | ||
if (vehicle == null) | ||
return; | ||
|
||
GameObject gameObject = Utils.SpawnZeroedAt(ElectricalDefensePrefab, vehicle.transform, false); | ||
ElectricalDefense defenseComponent = gameObject.GetComponent<ElectricalDefense>(); | ||
defenseComponent.charge = ZapPower; | ||
defenseComponent.chargeScalar = ZapPower; | ||
defenseComponent.radius *= ZapPower; | ||
defenseComponent.chargeRadius *= ZapPower; | ||
|
||
if (GameModeManager.GetOption<bool>(GameOption.TechnologyRequiresPower)) | ||
vehicle.energyInterface.ConsumeEnergy(EnergyCostPerZap); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
AlterraWeaponry/patches/Vehicle_OnUpgradeModuleChange_Patch.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace VELD.AlterraWeaponry.patches; | ||
|
||
[HarmonyPatch(typeof(Vehicle))] | ||
internal class Vehicle_OnUpgradeModuleChange_Patch | ||
{ | ||
[HarmonyPostfix] | ||
[HarmonyPatch(nameof(Vehicle.OnUpgradeModuleChange))] | ||
public static void OnUpgradeModuleChange(TechType techType, bool added, Vehicle __instance) | ||
{ | ||
if(techType == PrawnSelfDefenseModule.techType) | ||
{ | ||
if(added) | ||
{ | ||
Main.logger.LogInfo("Adding component ZapFunctionality to Vehicle."); | ||
__instance.gameObject.AddComponent<ZapFunctionalityBehaviour>(); | ||
Main.logger.LogInfo("Added successfully ZapFunctionality to Vehicle."); | ||
} | ||
else | ||
{ | ||
__instance.TryGetComponent<ZapFunctionalityBehaviour>(out ZapFunctionalityBehaviour defenseMono); | ||
if (defenseMono != null) | ||
UnityEngine.Object.Destroy(defenseMono); | ||
} | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
AlterraWeaponry/patches/Vehicle_OnUpgradeModuleUse_Patch.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace VELD.AlterraWeaponry.patches; | ||
|
||
[HarmonyPatch(typeof(Vehicle))] | ||
public class Vehicle_OnUpgradeModuleUse_Patch | ||
{ | ||
[HarmonyPostfix] | ||
[HarmonyPatch(nameof(Vehicle.OnUpgradeModuleUse))] | ||
public static void OnUpgradeModuleUse(TechType techType, int slotID, Vehicle __instance) | ||
{ | ||
if(techType == PrawnSelfDefenseModule.techType) | ||
{ | ||
Main.logger.LogInfo($"OnUpgradeModuleUse input received on slot {slotID}"); | ||
if (!__instance.TryGetComponent(out ZapFunctionalityBehaviour defenseMono)) | ||
return; | ||
defenseMono.Zap(__instance); | ||
} | ||
} | ||
} |