A tossed lava projectile class derived from TossedProjectile, it sets up rotation, spin speed and impact properties, updates local rotation each frame, and on ground impact spawns a lava puddle via Manager RPC with parameters based on difficulty.
using System;
using Sandbox;
public class TossedLavaBlob : TossedProjectile
{
public float PuddleRadius { get; set; }
public EnemyType EnemyType { get; set; }
//private Vector3 _lastPos;
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, 0.25f, 0f);
_height = Game.Random.Float( 150f, 220f );
//_lastPos = WorldPosition;
}
protected override void OnUpdate()
{
base.OnUpdate();
//Model.LocalRotation = Model.LocalRotation.RotateAroundAxis( Velocity.Normal, 500f * Time.Delta );
Model.LocalRotation = Model.LocalRotation.RotateAroundAxis( ((Vector3)TargetPos2D - WorldPosition).Normal, _rotSpeed * Time.Delta );
if ( IsProxy )
return;
//var dir = WorldPosition - _lastPos;
//WorldRotation = Rotation.LookAt( dir );
//LocalScale = new Vector3( 3f, 0.5f, 0.5f );
//_lastPos = WorldPosition;
}
protected override void HitGround()
{
base.HitGround();
var lifetime = Utils.Select( Manager.Instance.Difficulty, 10f, 15f, 25f );
if ( Manager.Instance.Difficulty >= 2 )
{
Manager.Instance.SpawnLavaPuddleRpc(
pos: Position2D,
damage: 3f,
radius: PuddleRadius,
lifetime: lifetime * Game.Random.Float( 0.9f, 1.2f ),
colorA: new Color( 1f, 0f, 0f ) * 1.2f,
colorB: new Color( 0.7f, 0.15f, 0f ) * 1.2f,
alphaMax: 1f,
enemySource: null,
enemyType: EnemyType
);
}
else
{
Manager.Instance.SpawnLavaPuddleRpc(
pos: Position2D,
damage: 2.5f,
radius: PuddleRadius,
lifetime: lifetime * Game.Random.Float( 0.9f, 1.1f ),
colorA: new Color( 1f, 0f, 0f ),
colorB: new Color( 0.55f, 0.1f, 0f ),
alphaMax: 0.8f,
enemySource: null,
enemyType : EnemyType
);
}
}
protected override void Remove( bool shouldSpawnEffects )
{
base.Remove( shouldSpawnEffects: false );
//Manager.Instance.SpawnBulletImpactParticles( WorldPosition.WithZ( Math.Max( WorldPosition.z, 10f ) ), Vector3.Up, _impactParticleColor );
if ( IsProxy )
return;
}
}