A tossed projectile subclass representing a fireball thrown by enemies. It sets visual rotation, spin speed, impact properties, and on ground hit it triggers an explosion and spawns damaging fire ground; it also requests particle cleanup when removed.
using System;
using Sandbox;
public class TossedFireball : TossedProjectile
{
[Property] public GameObject Particles { get; set; }
public Enemy EnemySource { get; set; }
public EnemyType EnemyType { get; set; }
float _rotSpeed;
protected override void OnStart()
{
base.OnStart();
Model.LocalRotation = Rotation.Random;
_rotSpeed = Game.Random.Float( 300f, 600f ) * (Game.Random.Int( 0, 1 ) == 0 ? 1f : -1f);
if ( IsProxy )
return;
_hitForce = 100f;
_impactParticleColor = new Color(1f, 0f, 0.75f);
_height = Game.Random.Float( 150f, 220f );
}
protected override void OnUpdate()
{
base.OnUpdate();
Model.LocalRotation = Model.LocalRotation.RotateAroundAxis( ((Vector3)TargetPos2D - WorldPosition).Normal, _rotSpeed * Time.Delta );
if ( IsProxy )
return;
}
protected override void HitGround()
{
base.HitGround();
var radius = 70f;
// todo: explosion should ignite player
Manager.Instance.CreateExplosionRpc( Position2D, radius, damage: 10f, repelRadius: radius * 1.2f, repelForce: 200f, playerSource: null, enemySource: EnemySource, enemyType: EnemyType, new Color( 1f, 0f, 0.75f ), options: RepelOptions.RepelPlayers | RepelOptions.DamagePlayers | RepelOptions.RepelEnemies | RepelOptions.RepelItems );
var damage = Utils.Select( Manager.Instance.Difficulty, 5f, 8f, 12f );
Manager.Instance.SpawnFireGroundRpc( Position2D, player: null, enemySource: EnemySource, enemyType: EnemyType, damage, lifetime: Game.Random.Float( 10f, 12f ), spreadChance: 0.5f, canStack: false, scale: 1.5f, colorA: Color.Magenta, colorB: Color.Red, hurtPlayers: true, hurtEnemies: false );
}
protected override void Remove( bool shouldSpawnEffects )
{
base.Remove( shouldSpawnEffects );
// todo: should this be done on client or just owner?
Manager.DestroyParticlesWhenFinished( Particles );
if ( IsProxy )
return;
}
}