Files
tbd-station-14/Content.Server/GameObjects/Components/Weapon/Ranged/Projectile/ProjectileWeapon.cs
clusterfack 128728bfcb Adds weapons (#48)
* Adds weapons

- Adds melee weapons
- Adds projectile weapons
- Adds hitscan weapons (like lasers)

* Adds a separate sprite for projectile weapons
2018-04-06 00:32:51 +02:00

41 lines
1.6 KiB
C#

using Content.Server.GameObjects.Components.Projectiles;
using SS14.Server.GameObjects;
using SS14.Server.Interfaces.GameObjects;
using SS14.Shared.Interfaces.GameObjects;
using SS14.Shared.IoC;
using SS14.Shared.Map;
using SS14.Shared.Maths;
namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile
{
public class ProjectileWeaponComponent : RangedWeaponComponent
{
public override string Name => "ProjectileWeapon";
private string _ProjectilePrototype = "ProjectileBullet";
private float _velocity = 20f;
protected override void Fire(IEntity user, LocalCoordinates clicklocation)
{
var userposition = user.GetComponent<TransformComponent>().LocalPosition; //Remember world positions are ephemeral and can only be used instantaneously
var angle = new Angle(clicklocation.Position - userposition.Position);
var theta = angle.Theta;
//Spawn the projectileprototype
IEntity 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);
//Give it the velocity this weapon gives to things it fires from itself
projectile.GetComponent<PhysicsComponent>().LinearVelocity = angle.ToVec() * _velocity;
//Rotate the bullets sprite to the correct direction, from north facing I guess
projectile.GetComponent<TransformComponent>().LocalRotation = angle.Theta;
}
}
}