Files
tbd-station-14/Content.Server/GameObjects/Components/Weapon/Melee/MeleeWeaponComponent.cs
Pieter-Jan Briers 147aad5064 Some work on the mess that is this power code.
Jesus.

Tons of fixes, refactors and other things.
The powernet's code is still awful though.
2018-05-27 16:44:50 +02:00

53 lines
1.8 KiB
C#

using System;
using SS14.Shared.GameObjects;
using SS14.Shared.GameObjects.Serialization;
using Content.Server.GameObjects.EntitySystems;
using SS14.Shared.Interfaces.GameObjects;
using SS14.Shared.Map;
using SS14.Shared.IoC;
using SS14.Server.GameObjects;
using SS14.Shared.Maths;
using SS14.Server.Interfaces.GameObjects;
using SS14.Shared.Interfaces.Timing;
using SS14.Shared.GameObjects.EntitySystemMessages;
namespace Content.Server.GameObjects.Components.Weapon.Melee
{
public class MeleeWeaponComponent : Component, IAfterAttack
{
public override string Name => "MeleeWeapon";
public int Damage = 1;
public float Range = 1;
public float ArcWidth = 90;
public override void ExposeData(EntitySerializer serializer)
{
base.ExposeData(serializer);
serializer.DataField(ref Damage, "damage", 5);
serializer.DataField(ref Range, "damage", 1);
serializer.DataField(ref ArcWidth, "damage", 90);
}
void IAfterAttack.Afterattack(IEntity user, LocalCoordinates clicklocation, IEntity attacked)
{
var location = user.GetComponent<TransformComponent>().LocalPosition;
var angle = new Angle(clicklocation.ToWorld().Position - location.ToWorld().Position);
var entities = IoCManager.Resolve<IServerEntityManager>().GetEntitiesInArc(user.GetComponent<TransformComponent>().LocalPosition, Range, angle, ArcWidth);
foreach (var entity in entities)
{
if (!entity.GetComponent<TransformComponent>().IsMapTransform || entity == user)
continue;
if (entity.TryGetComponent(out DamageableComponent damagecomponent))
{
damagecomponent.TakeDamage(DamageType.Brute, Damage);
}
}
}
}
}