Skip to content

Commit

Permalink
Adds Siege Defender Structure Healing
Browse files Browse the repository at this point in the history
- Adds structure healing for Siege Defenders
- Removes debug messages for vehicle healing
  • Loading branch information
data-bomb committed Nov 17, 2024
1 parent 047eab9 commit a379778
Showing 1 changed file with 39 additions and 4 deletions.
43 changes: 39 additions & 4 deletions Si_RepairFacility/Si_RepairFacility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ You should have received a copy of the GNU General Public License
using System.Collections.Generic;
using System.Text;

[assembly: MelonInfo(typeof(RepairFacility), "Repair Facility", "1.1.2", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonInfo(typeof(RepairFacility), "Repair Facility", "1.2.0", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonGame("Bohemia Interactive", "Silica")]
[assembly: MelonOptionalDependencies("Admin Mod")]

Expand All @@ -55,6 +55,7 @@ public class RepairFacility : MelonMod
static MelonPreferences_Entry<float> _Pref_Aliens_Structure_HealRate = null!;
static MelonPreferences_Entry<float> _Pref_Aliens_Queen_HealRate = null!;
static MelonPreferences_Entry<float> _Pref_Humans_Infantry_HealRate = null!;
static MelonPreferences_Entry<float> _Pref_SiegeDefenders_Structure_HealRate = null!;
static MelonPreferences_Entry<bool> _Pref_Repair_Notification = null!;

public override void OnInitializeMelon()
Expand All @@ -70,6 +71,7 @@ public override void OnInitializeMelon()
_Pref_Aliens_Queen_HealRate ??= _modCategory.CreateEntry<float>("RepairFacility_Alien_Queen_HealRate", 0.01f);

_Pref_Aliens_Structure_HealRate ??= _modCategory.CreateEntry<float>("RepairFacility_Alien_Structure_HealRate", 0.01f);
_Pref_SiegeDefenders_Structure_HealRate ??= _modCategory.CreateEntry<float>("RepairFacility_SiegeDefender_Structure_HealRate", 0.025f);

_Pref_Repair_Notification ??= _modCategory.CreateEntry<bool>("RepairFacility_ChatNotifications", false);

Expand All @@ -94,6 +96,7 @@ private static void Postfix(MusicJukeboxHandler __instance)

CleanRepairList();

// repair vehicles for all gamemodes
foreach (Unit vehicle in vehiclesAtRepairShop)
{
float healAmount = vehicle.DamageManager.MaxHealth * (vehicle.IsFlyingType ? _Pref_Humans_Aircraft_HealRate.Value : _Pref_Humans_Vehicle_HealRate.Value);
Expand All @@ -102,7 +105,7 @@ private static void Postfix(MusicJukeboxHandler __instance)
{
if (_Pref_Repair_Notification.Value && vehicle.ControlledBy != null)
{
HelperMethods.SendChatMessageToPlayer(vehicle.ControlledBy, HelperMethods.chatPrefix, " Debug Info: (Skipping) Health[" + vehicle.DamageManager.Health + "] MaxHP[" + vehicle.DamageManager.MaxHealth + "] HealAmt[" + healAmount + "]");
//HelperMethods.SendChatMessageToPlayer(vehicle.ControlledBy, HelperMethods.chatPrefix, " Debug Info: (Skipping) Health[" + vehicle.DamageManager.Health + "] MaxHP[" + vehicle.DamageManager.MaxHealth + "] HealAmt[" + healAmount + "]");
}

continue;
Expand All @@ -116,7 +119,7 @@ private static void Postfix(MusicJukeboxHandler __instance)

if (_Pref_Repair_Notification.Value && vehicle.ControlledBy != null)
{
HelperMethods.SendChatMessageToPlayer(vehicle.ControlledBy, HelperMethods.chatPrefix, " Debug Info: (Max) Health[" + vehicle.DamageManager.Health + "] MaxHP[" + vehicle.DamageManager.MaxHealth + "] HealAmt[" + healAmount + "]");
//HelperMethods.SendChatMessageToPlayer(vehicle.ControlledBy, HelperMethods.chatPrefix, " Debug Info: (Max) Health[" + vehicle.DamageManager.Health + "] MaxHP[" + vehicle.DamageManager.MaxHealth + "] HealAmt[" + healAmount + "]");
}
}
else
Expand All @@ -127,10 +130,42 @@ private static void Postfix(MusicJukeboxHandler __instance)

if (_Pref_Repair_Notification.Value && vehicle.ControlledBy != null)
{
HelperMethods.SendChatMessageToPlayer(vehicle.ControlledBy, HelperMethods.chatPrefix, " Debug Info: (Incremental) Health[" + vehicle.DamageManager.Health + "] MaxHP[" + vehicle.DamageManager.MaxHealth + "] HealAmt[" + healAmount + "]");
//HelperMethods.SendChatMessageToPlayer(vehicle.ControlledBy, HelperMethods.chatPrefix, " Debug Info: (Incremental) Health[" + vehicle.DamageManager.Health + "] MaxHP[" + vehicle.DamageManager.MaxHealth + "] HealAmt[" + healAmount + "]");
}
}
}

// repair defending structures for Siege
if (GameMode.CurrentGameMode is MP_TowerDefense)
{
foreach (Structure structure in Team.Teams[(int)SiConstants.ETeam.Sol].Structures)
{
if (!structure.DamageManager || structure.DamageManager.IsDestroyed)
{
continue;
}

float healAmount = structure.DamageManager.MaxHealth * _Pref_SiegeDefenders_Structure_HealRate.Value;

if (structure.DamageManager.Health == structure.DamageManager.MaxHealth)
{
continue;
}

float newHealthUnclamped = structure.DamageManager.Health + healAmount;

if (newHealthUnclamped >= structure.DamageManager.MaxHealth)
{
structure.DamageManager.SetHealth01(1f);
}
else
{
float newHealth = Mathf.Clamp(newHealthUnclamped, 0.0f, structure.DamageManager.MaxHealth);

structure.DamageManager.SetHealth(newHealth);
}
}
}
}
}
catch (Exception error)
Expand Down

0 comments on commit a379778

Please sign in to comment.