Skip to content

Commit

Permalink
Anti-Grief will Ignore Nodes (Fixes #33)
Browse files Browse the repository at this point in the history
- Adds new preference Grief_IgnoreFriendlyNodesDestroyed (default: true) to prevent the broadcast message for when Nodes are killed by Alien players
- Thanks to @ZefSilica for reporting this issue
  • Loading branch information
data-bomb committed Mar 17, 2024
1 parent f3d80dd commit a154f9f
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions Si_AntiGrief/Si_AntiGrief.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ You should have received a copy of the GNU General Public License
using SilicaAdminMod;
using System.Linq;

[assembly: MelonInfo(typeof(AntiGrief), "Anti-Grief", "1.1.5", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonInfo(typeof(AntiGrief), "Anti-Grief", "1.1.6", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonGame("Bohemia Interactive", "Silica")]
[assembly: MelonOptionalDependencies("Admin Mod")]

Expand All @@ -45,6 +45,7 @@ public class AntiGrief : MelonMod
static MelonPreferences_Category _modCategory = null!;
static MelonPreferences_Entry<int> _NegativeKillsThreshold = null!;
static MelonPreferences_Entry<bool> _NegativeKills_Penalty_Ban = null!;
static MelonPreferences_Entry<bool> _StructureAntiGrief_IgnoreNodes = null!;

private const string ModCategory = "Silica";

Expand All @@ -53,6 +54,7 @@ public override void OnInitializeMelon()
_modCategory ??= MelonPreferences.CreateCategory(ModCategory);
_NegativeKillsThreshold ??= _modCategory.CreateEntry<int>("Grief_NegativeKills_Threshold", -125);
_NegativeKills_Penalty_Ban ??= _modCategory.CreateEntry<bool>("Grief_NegativeKills_Penalty_Ban", true);
_StructureAntiGrief_IgnoreNodes ??= _modCategory.CreateEntry<bool>("Grief_IgnoreFriendlyNodesDestroyed", true);
}

#if NET6_0
Expand Down Expand Up @@ -217,10 +219,16 @@ public static void Postfix(MP_Strategy __instance, Structure __0, EDamageType __
return;
}

string structName = GetStructureDisplayName(__0.ToString());
string structureName = GetStructureDisplayName(__0.ToString());

MelonLogger.Msg(attackerPlayer.PlayerName + " team killed a structure " + structName);
HelperMethods.ReplyToCommand_Player(attackerPlayer, "killed a friendly structure (" + HelperMethods.GetTeamColor(attackerPlayer) + structName + HelperMethods.defaultColor + ")");
// should we ignore the message for this particular type of structure?
if (!DisplayTeamKillForStructure(structureName))
{
return;
}

MelonLogger.Msg(attackerPlayer.PlayerName + " team killed a structure " + structureName);
HelperMethods.ReplyToCommand_Player(attackerPlayer, "killed a friendly structure (" + HelperMethods.GetTeamColor(attackerPlayer) + structureName + HelperMethods.defaultColor + ")");
}
catch (Exception error)
{
Expand All @@ -229,6 +237,20 @@ public static void Postfix(MP_Strategy __instance, Structure __0, EDamageType __
}
}

private static bool DisplayTeamKillForStructure(string structureName)
{
// has the server set it so Nodes should be ignored?
if (_StructureAntiGrief_IgnoreNodes.Value)
{
if (structureName == "Node")
{
return false;
}
}

return true;
}

private static string GetStructureDisplayName(string structureFullName)
{
if (structureFullName.Contains('_'))
Expand Down

0 comments on commit a154f9f

Please sign in to comment.