AfterAttack with an EventArg object for a parameter
This commit is contained in:
@@ -31,14 +31,14 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee
|
||||
serializer.DataField(ref Damage, "damage", DamageType.Brute);
|
||||
}
|
||||
|
||||
void IAfterAttack.Afterattack(IEntity user, GridCoordinates clicklocation, IEntity attacked)
|
||||
void IAfterAttack.AfterAttack(AfterAttackEventArgs eventArgs)
|
||||
{
|
||||
if (attacked == null)
|
||||
if (eventArgs.Attacked == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!attacked.TryGetComponent(out DamageableComponent damagecomponent)) return;
|
||||
if (!eventArgs.Attacked.TryGetComponent(out DamageableComponent damagecomponent)) return;
|
||||
if (Owner.TryGetComponent(out StackComponent stackComponent))
|
||||
{
|
||||
if (!stackComponent.Use(1))
|
||||
|
||||
@@ -25,14 +25,14 @@ namespace Content.Server.GameObjects.Components.Interactable.Tools
|
||||
IoCManager.InjectDependencies(this);
|
||||
}
|
||||
|
||||
public void Afterattack(IEntity user, GridCoordinates clicklocation, IEntity attacked)
|
||||
public void AfterAttack(AfterAttackEventArgs eventArgs)
|
||||
{
|
||||
var tile = clicklocation.Grid.GetTile(clicklocation);
|
||||
var tile = eventArgs.ClickLocation.Grid.GetTile(eventArgs.ClickLocation);
|
||||
var tileDef = (ContentTileDefinition) tile.TileDef;
|
||||
if (tileDef.CanCrowbar)
|
||||
{
|
||||
var underplating = _tileDefinitionManager["underplating"];
|
||||
clicklocation.Grid.SetTile(clicklocation, underplating.TileId);
|
||||
eventArgs.ClickLocation.Grid.SetTile(eventArgs.ClickLocation, underplating.TileId);
|
||||
_entitySystemManager.GetEntitySystem<AudioSystem>().Play("/Audio/items/crowbar.ogg", Owner);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Text;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Shared.GameObjects.Components.Power;
|
||||
@@ -11,18 +11,18 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
{
|
||||
public class PowerDebugTool : SharedPowerDebugTool, IAfterAttack
|
||||
{
|
||||
void IAfterAttack.Afterattack(IEntity user, GridCoordinates clicklocation, IEntity attacked)
|
||||
void IAfterAttack.AfterAttack(AfterAttackEventArgs eventArgs)
|
||||
{
|
||||
if (attacked == null)
|
||||
if (eventArgs.Attacked == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder.AppendFormat("Entity: {0} ({1})\n", attacked.Name, attacked.Uid);
|
||||
builder.AppendFormat("Entity: {0} ({1})\n", eventArgs.Attacked.Name, eventArgs.Attacked.Uid);
|
||||
|
||||
if (attacked.TryGetComponent<PowerNodeComponent>(out var node))
|
||||
if (eventArgs.Attacked.TryGetComponent<PowerNodeComponent>(out var node))
|
||||
{
|
||||
builder.AppendFormat("Power Node:\n");
|
||||
if (node.Parent == null)
|
||||
@@ -50,7 +50,7 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
}
|
||||
}
|
||||
|
||||
if (attacked.TryGetComponent<PowerDeviceComponent>(out var device))
|
||||
if (eventArgs.Attacked.TryGetComponent<PowerDeviceComponent>(out var device))
|
||||
{
|
||||
builder.AppendFormat(@"Power Device:
|
||||
Load: {0} W
|
||||
@@ -75,7 +75,7 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
}
|
||||
}
|
||||
|
||||
if (attacked.TryGetComponent<PowerStorageNetComponent>(out var storage))
|
||||
if (eventArgs.Attacked.TryGetComponent<PowerStorageNetComponent>(out var storage))
|
||||
{
|
||||
var stateSeconds = (DateTime.Now - storage.LastChargeStateChange).TotalSeconds;
|
||||
builder.AppendFormat(@"Power Storage:
|
||||
@@ -84,14 +84,14 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
", storage.Capacity, storage.Charge, storage.ChargeRate, storage.DistributionRate, storage.ChargePowernet, storage.LastChargeState, storage.GetChargeState(), stateSeconds);
|
||||
}
|
||||
|
||||
if (attacked.TryGetComponent<PowerTransferComponent>(out var transfer))
|
||||
if (eventArgs.Attacked.TryGetComponent<PowerTransferComponent>(out var transfer))
|
||||
{
|
||||
builder.AppendFormat(@"Power Transfer:
|
||||
Powernet: {0}
|
||||
", transfer.Parent.Uid);
|
||||
}
|
||||
|
||||
OpenDataWindowClientSide(user, builder.ToString());
|
||||
OpenDataWindowClientSide(eventArgs.User, builder.ToString());
|
||||
}
|
||||
|
||||
private void OpenDataWindowClientSide(IEntity user, string data)
|
||||
|
||||
@@ -32,15 +32,15 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee
|
||||
serializer.DataField(ref ArcWidth, "arcwidth", 90);
|
||||
}
|
||||
|
||||
void IAfterAttack.Afterattack(IEntity user, GridCoordinates clicklocation, IEntity attacked)
|
||||
void IAfterAttack.AfterAttack(AfterAttackEventArgs eventArgs)
|
||||
{
|
||||
var location = user.GetComponent<ITransformComponent>().GridPosition;
|
||||
var angle = new Angle(clicklocation.ToWorld().Position - location.ToWorld().Position);
|
||||
var entities = IoCManager.Resolve<IServerEntityManager>().GetEntitiesInArc(user.GetComponent<ITransformComponent>().GridPosition, Range, angle, ArcWidth);
|
||||
var location = eventArgs.User.GetComponent<ITransformComponent>().GridPosition;
|
||||
var angle = new Angle(eventArgs.ClickLocation.ToWorld().Position - location.ToWorld().Position);
|
||||
var entities = IoCManager.Resolve<IServerEntityManager>().GetEntitiesInArc(eventArgs.User.GetComponent<ITransformComponent>().GridPosition, Range, angle, ArcWidth);
|
||||
|
||||
foreach (var entity in entities)
|
||||
{
|
||||
if (!entity.GetComponent<ITransformComponent>().IsMapTransform || entity == user)
|
||||
if (!entity.GetComponent<ITransformComponent>().IsMapTransform || entity == eventArgs.User)
|
||||
continue;
|
||||
|
||||
if (entity.TryGetComponent(out DamageableComponent damagecomponent))
|
||||
|
||||
@@ -88,7 +88,14 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
/// <param name="user"></param>
|
||||
/// <param name="clicklocation"></param>
|
||||
/// <param name="attacked">The entity that was clicked on out of range. May be null if no entity was clicked on.true</param>
|
||||
void Afterattack(IEntity user, GridCoordinates clicklocation, IEntity attacked);
|
||||
void AfterAttack(AfterAttackEventArgs eventArgs);
|
||||
}
|
||||
|
||||
public class AfterAttackEventArgs : EventArgs
|
||||
{
|
||||
public IEntity User { get; set; }
|
||||
public GridCoordinates ClickLocation { get; set; }
|
||||
public IEntity Attacked { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -266,7 +273,7 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
|
||||
for (var i = 0; i < afterattacks.Count; i++)
|
||||
{
|
||||
afterattacks[i].Afterattack(user, clicklocation, null);
|
||||
afterattacks[i].AfterAttack(new AfterAttackEventArgs { User = user, ClickLocation = clicklocation });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -297,7 +304,7 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
|
||||
for (var i = 0; i < afterattacks.Count; i++)
|
||||
{
|
||||
afterattacks[i].Afterattack(user, clicklocation, attacked);
|
||||
afterattacks[i].AfterAttack(new AfterAttackEventArgs { User = user, ClickLocation = clicklocation, Attacked = attacked });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -383,7 +390,7 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
//See if we have a ranged attack interaction
|
||||
for (var i = 0; i < afterattacks.Count; i++)
|
||||
{
|
||||
afterattacks[i].Afterattack(user, clicklocation, attacked);
|
||||
afterattacks[i].AfterAttack(new AfterAttackEventArgs { User = user, ClickLocation = clicklocation, Attacked = attacked });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user