Weapons/Base/BaseWeapon.Drop.cs
using Opium;
using System;
public partial class BaseWeapon
{
[Property, Category( "Dropping" )] public float DropRandomization { get; set; } = 7f;
[Property, Category( "Dropping" )] public float DropRandomizationPower { get; set; } = 5f;
[Property, Category( "Dropping" )] public float DropForwardPower { get; set; } = 50f;
public WeaponPickup Drop( Vector3 origin, Vector3 position, Vector3 direction )
{
if ( PickupPrefab is not null )
{
var pickup = PickupPrefab.Clone();
pickup.BreakFromPrefab();
var tr = Scene.Trace.Ray( origin, position )
.IgnoreGameObjectHierarchy( GameObject.Root )
.Size( 0f )
.Run();
pickup.Transform.Position = tr.EndPosition;
pickup.Transform.Scale = 1f;
var component = pickup.Components.Get<WeaponPickup>();
if ( this is RangedWeapon rangedWeapon )
{
component.SavedAmmo = rangedWeapon.CurrentAmmo;
}
if ( this is MeleeWeapon melee )
{
component.Durability = melee.Durability;
}
var rb = pickup.Components.GetOrCreate<Rigidbody>();
if ( rb is not null )
{
var mass = rb.PhysicsBody.Mass;
var rotation = Rotation.Random;
rb.ApplyImpulseAt( pickup.Transform.Position + rotation.Forward * mass * DropRandomization, direction.Normal * mass * DropRandomizationPower );
rb.ApplyImpulse( direction.Normal * mass * DropForwardPower );
}
Actor.SetupViewModel( this, false );
// Kill myself
GameObject.Destroy();
return component;
}
Actor.SetupViewModel( this, false );
// Kill myself
GameObject.Destroy();
return null;
}
}