perks/PerkBanishShare.cs

A Perk class (PerkBanishShare) for a multiplayer game that, when the owner banishes, has a chance to spawn a banish item for nearby teammates. It defines rarity, visuals, chance scaling by level, and iterates alive players to potentially spawn items and trigger short visual/animation effects.

NetworkingFile Access
using System;
using Sandbox;

[Perk( Rarity.Mythic, disabled: true,multiplayerMode: MultiplayerMode.OnlyMultiplayer, locked: true, alwaysOfferDebug: false, IncludedCategories = new[] { PerkCategory.Aoe })]
public class PerkBanishShare : Perk
{
	private enum Mod { Chance };

	private const float RADIUS = 300f;


	public override float ImportanceMultiplier => 0.75f;

	static PerkBanishShare()
	{
		//Register<PerkBanishShare>(
		//	name: "Banish Sharing",
		//	imagePath: "textures/icons/vector/banish_sharing.png",
		//	description: level => $"When you banish, {GetValue( level, Mod.Chance, true )}% chance for nearby players to get +1 banish-item",
		//	upgradeDescription: level => $"When you banish, {GetValue( level - 1, Mod.Chance, true )}%→{GetValue( level, Mod.Chance, true )}% chance for nearby players to get +1 banish-item"
		//);
	}
	
	public override void Start()
	{
		base.Start();

		HighlightColor = new Color( 0.2f, 0.2f, 1f );
		HighlightDuration = 0.4f;
		HighlightOpacity = 2f;
	}

	public override void Refresh()
	{
		base.Refresh();

	}

	private static float GetValue( int level, Mod mod, bool isPercent = false )
	{
		switch ( mod )
		{
			case Mod.Chance:
			default:
				return isPercent
					? 15f + 15f * level
					: 0.15f + 0.15f * level;
		}
	}

	public override void OnBanish()
	{
		base.OnBanish();

		Vector2 pos = Player.Position2D;
		float radius = RADIUS * Player.Stats[PlayerStat.RadiusMultiplier];
		float chance = GetValue( Level, Mod.Chance );

		foreach ( var player in Manager.Instance.AlivePlayers )
		{
			if ( player == Player )
				continue;

			if ( Game.Random.Float( 0f, 1f ) > chance )
				continue;

			if ( (player.Position2D - pos).LengthSquared < MathF.Pow( radius, 2f ) )
			{
				var targetPos = player.Position2D;
				float time = Game.Random.Float( 0.5f, 0.75f );
				float height = time * 175f * Game.Random.Float( 0.9f, 1.1f );

				Manager.Instance.SpawnItemRpc( "banish_item", Player.Position2D, player, time, height );

				Highlight();

				var dir = (player.Position2D - Player.Position2D).Normal;
				Player.DodgeDuckRpc( dir, time: Game.Random.Float( 0.1f, 0.125f ) );
			}
		}
	}
}