Gun stuff (#132)
* Guns can now be fully automatic. Take that BYOND. * Improve delay handling * Bullet spread * Fix firing guns on pickup
This commit is contained in:
committed by
GitHub
parent
69946c79d8
commit
7ca90d11b3
@@ -1,33 +1,76 @@
|
||||
using Content.Server.GameObjects.Components.Projectiles;
|
||||
using System;
|
||||
using Content.Server.GameObjects.Components.Projectiles;
|
||||
using SS14.Server.GameObjects;
|
||||
using SS14.Server.GameObjects.EntitySystems;
|
||||
using SS14.Server.Interfaces.GameObjects;
|
||||
using SS14.Shared.GameObjects;
|
||||
using SS14.Shared.Interfaces.GameObjects;
|
||||
using SS14.Shared.Interfaces.GameObjects.Components;
|
||||
using SS14.Shared.IoC;
|
||||
using SS14.Shared.Log;
|
||||
using SS14.Shared.Map;
|
||||
using SS14.Shared.Maths;
|
||||
using SS14.Shared.Serialization;
|
||||
using SS14.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile
|
||||
{
|
||||
public class ProjectileWeaponComponent : RangedWeaponComponent
|
||||
public class ProjectileWeaponComponent : Component
|
||||
{
|
||||
public override string Name => "ProjectileWeapon";
|
||||
|
||||
private string _ProjectilePrototype = "ProjectileBullet";
|
||||
|
||||
private float _velocity = 20f;
|
||||
private float _spreadStdDev = 3;
|
||||
private bool _spread = true;
|
||||
|
||||
protected override void Fire(IEntity user, GridLocalCoordinates clicklocation)
|
||||
private Random _spreadRandom;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool Spread
|
||||
{
|
||||
var userposition = user.GetComponent<ITransformComponent>().LocalPosition; //Remember world positions are ephemeral and can only be used instantaneously
|
||||
var angle = new Angle(clicklocation.Position - userposition.Position);
|
||||
get => _spread;
|
||||
set => _spread = value;
|
||||
}
|
||||
|
||||
var theta = angle.Theta;
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float SpreadStdDev
|
||||
{
|
||||
get => _spreadStdDev;
|
||||
set => _spreadStdDev = value;
|
||||
}
|
||||
|
||||
//Spawn the projectileprototype
|
||||
IEntity projectile = IoCManager.Resolve<IServerEntityManager>().ForceSpawnEntityAt(_ProjectilePrototype, userposition);
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
var rangedWeapon = Owner.GetComponent<RangedWeaponComponent>();
|
||||
rangedWeapon.FireHandler = Fire;
|
||||
|
||||
_spreadRandom = new Random(Owner.Uid.GetHashCode() ^ DateTime.Now.GetHashCode());
|
||||
}
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataField(ref _spread, "spread", true);
|
||||
serializer.DataField(ref _spreadStdDev, "spreadstddev", 3);
|
||||
}
|
||||
|
||||
private void Fire(IEntity user, GridLocalCoordinates clickLocation)
|
||||
{
|
||||
var userPosition = user.Transform.LocalPosition; //Remember world positions are ephemeral and can only be used instantaneously
|
||||
var angle = new Angle(clickLocation.Position - userPosition.Position);
|
||||
|
||||
if (Spread)
|
||||
{
|
||||
angle += Angle.FromDegrees(_spreadRandom.NextGaussian(0, SpreadStdDev));
|
||||
}
|
||||
|
||||
//Spawn the projectilePrototype
|
||||
var projectile = IoCManager.Resolve<IServerEntityManager>().ForceSpawnEntityAt(_ProjectilePrototype, userPosition);
|
||||
|
||||
//Give it the velocity we fire from this weapon, and make sure it doesn't shoot our character
|
||||
projectile.GetComponent<ProjectileComponent>().IgnoreEntity(user);
|
||||
@@ -36,7 +79,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile
|
||||
projectile.GetComponent<PhysicsComponent>().LinearVelocity = angle.ToVec() * _velocity;
|
||||
|
||||
//Rotate the bullets sprite to the correct direction, from north facing I guess
|
||||
projectile.GetComponent<ITransformComponent>().LocalRotation = angle.Theta;
|
||||
projectile.Transform.LocalRotation = angle.Theta;
|
||||
|
||||
// Sound!
|
||||
IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<AudioSystem>().Play("/Audio/gunshot_c20.ogg");
|
||||
|
||||
Reference in New Issue
Block a user