Skip to content

Commit 6688fce

Browse files
committed
Add Ability to Block Shrimp Takeover
- Taking over one of the starting shrimp can grief the Alien team - Provides a new preference Grief_BlockShrimpTakeOver (default: false) - When enabled, alien players will be blocked from taking over a shrimp
1 parent 5eac1c6 commit 6688fce

File tree

1 file changed

+47
-3
lines changed

1 file changed

+47
-3
lines changed

Si_AntiGrief/Si_AntiGrief.cs

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ You should have received a copy of the GNU General Public License
3535
using System.Linq;
3636
using UnityEngine;
3737

38-
[assembly: MelonInfo(typeof(AntiGrief), "Anti-Grief", "1.2.4", "databomb", "https://github.com/data-bomb/Silica")]
38+
[assembly: MelonInfo(typeof(AntiGrief), "Anti-Grief", "1.3.0", "databomb", "https://github.com/data-bomb/Silica")]
3939
[assembly: MelonGame("Bohemia Interactive", "Silica")]
4040
[assembly: MelonOptionalDependencies("Admin Mod")]
4141

@@ -47,6 +47,7 @@ public class AntiGrief : MelonMod
4747
static MelonPreferences_Entry<int> _NegativeKillsThreshold = null!;
4848
static MelonPreferences_Entry<bool> _NegativeKills_Penalty_Ban = null!;
4949
static MelonPreferences_Entry<bool> _StructureAntiGrief_IgnoreNodes = null!;
50+
static MelonPreferences_Entry<bool> _BlockShrimpControllers = null!;
5051

5152
private const string ModCategory = "Silica";
5253

@@ -56,13 +57,15 @@ public override void OnInitializeMelon()
5657
_NegativeKillsThreshold ??= _modCategory.CreateEntry<int>("Grief_NegativeKills_Threshold", -125);
5758
_NegativeKills_Penalty_Ban ??= _modCategory.CreateEntry<bool>("Grief_NegativeKills_Penalty_Ban", true);
5859
_StructureAntiGrief_IgnoreNodes ??= _modCategory.CreateEntry<bool>("Grief_IgnoreFriendlyNodesDestroyed", true);
60+
_BlockShrimpControllers ??= _modCategory.CreateEntry<bool>("Grief_BlockShrimpTakeOver", true);
5961
}
6062

6163

6264
public override void OnLateInitializeMelon()
6365
{
64-
//subscribing to the event
66+
//subscribing to the events
6567
Event_Roles.OnRoleChanged += OnRoleChanged;
68+
Event_Units.OnRequestEnterUnit += OnRequestEnterUnit;
6669

6770
#if NET6_0
6871
bool QListLoaded = RegisteredMelons.Any(m => m.Info.Name == "QList");
@@ -243,6 +246,48 @@ public static void Postfix(MP_Strategy __instance, Structure __0, EDamageType __
243246
}
244247
}
245248

249+
public void OnRequestEnterUnit(object? sender, OnRequestEnterUnitArgs args)
250+
{
251+
try
252+
{
253+
if (args == null)
254+
{
255+
return;
256+
}
257+
258+
if (!_BlockShrimpControllers.Value)
259+
{
260+
return;
261+
}
262+
263+
Player player = args.Player;
264+
Unit unit = args.Unit;
265+
266+
if (player == null || player.Team == null || unit == null)
267+
{
268+
return;
269+
}
270+
271+
// if the player isn't on the alien team, we can skip this check
272+
if (player.Team.Index != (int)SiConstants.ETeam.Alien)
273+
{
274+
return;
275+
}
276+
277+
// is it a shrimp?
278+
if (unit.IsResourceHolder)
279+
{
280+
MelonLogger.Msg("Found " + player.PlayerName + " trying to use an Alien shrimp.");
281+
HelperMethods.SendChatMessageToPlayer(player, HelperMethods.chatPrefix, " use of shrimp is not permitted on this server.");
282+
args.Block = true;
283+
}
284+
}
285+
catch (Exception error)
286+
{
287+
HelperMethods.PrintError(error, "Failed to run OnRequestEnterUnit");
288+
}
289+
}
290+
246291
// hook DestroyAllUnitsForPlayer pre and override game code to prevent aliens from dying
247292
public void OnRoleChanged(object? sender, OnRoleChangedArgs args)
248293
{
@@ -301,7 +346,6 @@ public void OnRoleChanged(object? sender, OnRoleChangedArgs args)
301346
{
302347
HelperMethods.PrintError(error, "Failed to run OnRoleChanged");
303348
}
304-
305349
}
306350

307351
public static bool IsHighValueAlienUnit(Unit unit)

0 commit comments

Comments
 (0)