A perk class for a game that grants a shield to enemies that hit the player. When the player is hit (and not invincible), if the attacker enemy is valid and not already shielded, the enemy receives a shield that deals a configured damage when it breaks. It also triggers a visual highlight and randomizes icon scale/angle.
using System;
using Sandbox;
[Perk( Rarity.Unique, curse: true, alwaysOfferDebug: false )]
public class CurseHurtEnemyGainShield : Perk
{
private enum Mod { ShieldDamage };
static CurseHurtEnemyGainShield()
{
Register<CurseHurtEnemyGainShield>(
name: "Oppressing Shield",
imagePath: "textures/icons/vector/curse_hurt_enemy_gain_shield.png",
description: level => $"Enemies that hit you\nget a shield that does\n[-]{(int)GetValue( level, Mod.ShieldDamage )}[/-] dmg when it breaks"
);
}
public override void Start()
{
base.Start();
HighlightColor = new Color( 1f, 0.7f, 0f );
HighlightDuration = 0.15f;
HighlightOpacity = 1.6f;
}
public override void Refresh()
{
base.Refresh();
}
public override void OnHit( float amount, DamageType damageType, bool isSelfInflicted, Vector2 dir, float force, Enemy enemySource, EnemyType enemyType, float previousHealth )
{
base.OnHit( amount, damageType, isSelfInflicted, dir, force, enemySource, enemyType, previousHealth );
if ( Player.IsInvincible )
return;
if ( enemySource.IsValid() && !enemySource.IsShielded )
{
enemySource.GainShield( breakDmg: GetValue( Level, Mod.ShieldDamage ) );
Highlight();
IconScale = Game.Random.Float( 1.1f, 1.15f );
IconAngleOffset = Game.Random.Float( 5f, 8f ) * (Game.Random.Int( 0, 1 ) == 0 ? -1f : 1f);
}
}
private static float GetValue( int level, Mod mod, bool isPercent = false )
{
switch ( mod )
{
case Mod.ShieldDamage:
default:
return 10f;
//switch ( level )
//{
// case 1: default: return 10f;
// case 2: return 50f;
//}
}
}
}