Adds weapons (#48)
* Adds weapons - Adds melee weapons - Adds projectile weapons - Adds hitscan weapons (like lasers) * Adds a separate sprite for projectile weapons
This commit is contained in:
committed by
Pieter-Jan Briers
parent
63b5d83728
commit
128728bfcb
@@ -0,0 +1,61 @@
|
||||
using SS14.Server.GameObjects;
|
||||
using SS14.Server.GameObjects.EntitySystems;
|
||||
using SS14.Shared.GameObjects;
|
||||
using SS14.Shared.GameObjects.EntitySystemMessages;
|
||||
using SS14.Shared.Interfaces.GameObjects;
|
||||
using SS14.Shared.Interfaces.Physics;
|
||||
using SS14.Shared.Interfaces.Timing;
|
||||
using SS14.Shared.IoC;
|
||||
using SS14.Shared.Map;
|
||||
using SS14.Shared.Maths;
|
||||
using SS14.Shared.Physics;
|
||||
using System;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Weapon.Ranged.Hitscan
|
||||
{
|
||||
public class HitscanWeaponComponent : RangedWeaponComponent
|
||||
{
|
||||
public override string Name => "HitscanWeapon";
|
||||
|
||||
string spritename = "laser";
|
||||
|
||||
protected override void Fire(IEntity user, LocalCoordinates clicklocation)
|
||||
{
|
||||
var userposition = user.GetComponent<TransformComponent>().WorldPosition; //Remember world positions are ephemeral and can only be used instantaneously
|
||||
var angle = new Angle(clicklocation.Position - userposition);
|
||||
var theta = angle.Theta;
|
||||
|
||||
var ray = new Ray(userposition, angle.ToVec());
|
||||
var raycastresults = IoCManager.Resolve<ICollisionManager>().IntersectRay(ray, 20, Owner.GetComponent<TransformComponent>().GetMapTransform().Owner);
|
||||
|
||||
Hit(raycastresults);
|
||||
AfterEffects(user, raycastresults, theta);
|
||||
}
|
||||
|
||||
protected virtual void Hit(RayCastResults ray)
|
||||
{
|
||||
if(ray.HitEntity != null && ray.HitEntity.TryGetComponent(out DamageableComponent damage))
|
||||
{
|
||||
damage.TakeDamage(DamageType.Heat, 10);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void AfterEffects(IEntity user, RayCastResults ray, double theta)
|
||||
{
|
||||
var time = IoCManager.Resolve<IGameTiming>().CurTime;
|
||||
EffectSystemMessage message = new EffectSystemMessage
|
||||
{
|
||||
EffectSprite = spritename,
|
||||
Born = time,
|
||||
DeathTime = time + TimeSpan.FromSeconds(1),
|
||||
Size = new Vector2(ray.Distance, 1f),
|
||||
Coordinates = user.GetComponent<TransformComponent>().LocalPosition,
|
||||
//Rotated from east facing
|
||||
Rotation = (float)theta,
|
||||
ColorDelta = new Vector4(0, 0, 0, -1500f),
|
||||
Color = new Vector4(255,255,255,750)
|
||||
};
|
||||
IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<EffectSystem>().CreateParticle(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using SS14.Shared.GameObjects;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using SS14.Shared.Interfaces.GameObjects;
|
||||
using SS14.Shared.Map;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Weapon.Ranged
|
||||
{
|
||||
public class RangedWeaponComponent : Component, IAfterAttack
|
||||
{
|
||||
public override string Name => "RangedWeapon";
|
||||
|
||||
void IAfterAttack.Afterattack(IEntity user, LocalCoordinates clicklocation)
|
||||
{
|
||||
if(UserCanFire(user) && WeaponCanFire())
|
||||
{
|
||||
Fire(user, clicklocation);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual bool WeaponCanFire()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected virtual bool UserCanFire(IEntity user)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected virtual void Fire(IEntity user, LocalCoordinates clicklocation)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user