AttackBy with an EventArg object for a parameter
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.GameObjects.Components.Interactable.Tools;
|
||||
using Content.Server.GameObjects.Components.Sound;
|
||||
using Content.Server.GameObjects.Components.Stack;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Shared.Construction;
|
||||
@@ -18,7 +17,7 @@ using static Content.Shared.Construction.ConstructionStepTool;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Construction
|
||||
{
|
||||
public class ConstructionComponent : Component, IAttackby
|
||||
public class ConstructionComponent : Component, IAttackBy
|
||||
{
|
||||
public override string Name => "Construction";
|
||||
|
||||
@@ -41,11 +40,11 @@ namespace Content.Server.GameObjects.Components.Construction
|
||||
random = new Random();
|
||||
}
|
||||
|
||||
public bool Attackby(IEntity user, IEntity attackwith)
|
||||
public bool AttackBy(AttackByEventArgs eventArgs)
|
||||
{
|
||||
var stage = Prototype.Stages[Stage];
|
||||
|
||||
if (TryProcessStep(stage.Forward, attackwith))
|
||||
if (TryProcessStep(stage.Forward, eventArgs.AttackWith))
|
||||
{
|
||||
Stage++;
|
||||
if (Stage == Prototype.Stages.Count - 1)
|
||||
@@ -65,7 +64,7 @@ namespace Content.Server.GameObjects.Components.Construction
|
||||
}
|
||||
}
|
||||
|
||||
else if (TryProcessStep(stage.Backward, attackwith))
|
||||
else if (TryProcessStep(stage.Backward, eventArgs.AttackWith))
|
||||
{
|
||||
Stage--;
|
||||
if (Stage == 0)
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Content.Server.GameObjects.Components.Interactable
|
||||
/// <summary>
|
||||
/// Component that represents a handheld lightsource which can be toggled on and off.
|
||||
/// </summary>
|
||||
internal class HandheldLightComponent : Component, IUse, IExamine, IAttackby
|
||||
internal class HandheldLightComponent : Component, IUse, IExamine, IAttackBy
|
||||
{
|
||||
public const float Wattage = 10;
|
||||
[ViewVariables] private ContainerSlot _cellContainer;
|
||||
@@ -41,15 +41,15 @@ namespace Content.Server.GameObjects.Components.Interactable
|
||||
[ViewVariables]
|
||||
public bool Activated { get; private set; }
|
||||
|
||||
bool IAttackby.Attackby(IEntity user, IEntity attackwith)
|
||||
bool IAttackBy.AttackBy(AttackByEventArgs eventArgs)
|
||||
{
|
||||
if (!attackwith.HasComponent<PowerCellComponent>()) return false;
|
||||
if (!eventArgs.AttackWith.HasComponent<PowerCellComponent>()) return false;
|
||||
|
||||
if (Cell != null) return false;
|
||||
|
||||
user.GetComponent<IHandsComponent>().Drop(attackwith, _cellContainer);
|
||||
eventArgs.User.GetComponent<IHandsComponent>().Drop(eventArgs.AttackWith, _cellContainer);
|
||||
|
||||
return _cellContainer.Insert(attackwith);
|
||||
return _cellContainer.Insert(eventArgs.AttackWith);
|
||||
}
|
||||
|
||||
string IExamine.Examine()
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Content.Server.GameObjects
|
||||
/// <summary>
|
||||
/// Storage component for containing entities within this one, matches a UI on the client which shows stored entities
|
||||
/// </summary>
|
||||
public class ServerStorageComponent : SharedStorageComponent, IAttackby, IUse, IActivate
|
||||
public class ServerStorageComponent : SharedStorageComponent, IAttackBy, IUse, IActivate
|
||||
{
|
||||
private Container storage;
|
||||
|
||||
@@ -131,25 +131,25 @@ namespace Content.Server.GameObjects
|
||||
/// <param name="user"></param>
|
||||
/// <param name="attackwith"></param>
|
||||
/// <returns></returns>
|
||||
bool IAttackby.Attackby(IEntity user, IEntity attackwith)
|
||||
bool IAttackBy.AttackBy(AttackByEventArgs eventArgs)
|
||||
{
|
||||
_ensureInitialCalculated();
|
||||
Logger.DebugS("Storage", "Storage (UID {0}) attacked by user (UID {1}) with entity (UID {2}).", Owner.Uid, user.Uid, attackwith.Uid);
|
||||
Logger.DebugS("Storage", "Storage (UID {0}) attacked by user (UID {1}) with entity (UID {2}).", Owner.Uid, eventArgs.User.Uid, eventArgs.AttackWith.Uid);
|
||||
|
||||
if (!user.TryGetComponent(out HandsComponent hands))
|
||||
if (!eventArgs.User.TryGetComponent(out HandsComponent hands))
|
||||
return false;
|
||||
|
||||
//Check that we can drop the item from our hands first otherwise we obviously cant put it inside
|
||||
if (CanInsert(hands.GetActiveHand.Owner) && hands.Drop(hands.ActiveIndex))
|
||||
{
|
||||
if (Insert(attackwith))
|
||||
if (Insert(eventArgs.AttackWith))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Owner.PopupMessage(user, "Can't insert.");
|
||||
Owner.PopupMessage(eventArgs.User, "Can't insert.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -324,5 +324,10 @@ namespace Content.Server.GameObjects
|
||||
|
||||
_storageInitialCalculated = true;
|
||||
}
|
||||
|
||||
public bool Attackby(AttackByEventArgs eventArgs)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,13 +8,14 @@ using SS14.Shared.Interfaces.GameObjects;
|
||||
using Content.Server.GameObjects.Components.Interactable.Tools;
|
||||
using SS14.Shared.Interfaces.GameObjects.Components;
|
||||
using SS14.Shared.ViewVariables;
|
||||
using System;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Power
|
||||
{
|
||||
/// <summary>
|
||||
/// Component to transfer power to nearby components, can create powernets and connect to nodes
|
||||
/// </summary>
|
||||
public class PowerTransferComponent : Component, IAttackby
|
||||
public class PowerTransferComponent : Component, IAttackBy
|
||||
{
|
||||
public override string Name => "PowerTransfer";
|
||||
|
||||
@@ -133,9 +134,9 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
return Parent != null && Parent.Dirty == false && !Regenerating;
|
||||
}
|
||||
|
||||
public bool Attackby(IEntity user, IEntity attackwith)
|
||||
public bool AttackBy(AttackByEventArgs eventArgs)
|
||||
{
|
||||
if (attackwith.TryGetComponent(out WirecutterComponent wirecutter))
|
||||
if (eventArgs.AttackWith.TryGetComponent(out WirecutterComponent wirecutter))
|
||||
{
|
||||
Owner.Delete();
|
||||
return true;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using Content.Server.GameObjects.Components.Sound;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Server.Interfaces.GameObjects;
|
||||
@@ -23,7 +23,7 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
/// <summary>
|
||||
/// Component that represents a wall light. It has a light bulb that can be replaced when broken.
|
||||
/// </summary>
|
||||
public class PoweredLightComponent : Component, IAttackHand, IAttackby
|
||||
public class PoweredLightComponent : Component, IAttackHand, IAttackBy
|
||||
{
|
||||
public override string Name => "PoweredLight";
|
||||
|
||||
@@ -50,9 +50,9 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
}
|
||||
}
|
||||
|
||||
bool IAttackby.Attackby(IEntity user, IEntity attackwith)
|
||||
bool IAttackBy.AttackBy(AttackByEventArgs eventArgs)
|
||||
{
|
||||
return InsertBulb(attackwith);
|
||||
return InsertBulb(eventArgs.AttackWith);
|
||||
}
|
||||
|
||||
bool IAttackHand.Attackhand(IEntity user)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using SS14.Shared.GameObjects;
|
||||
using SS14.Shared.Interfaces.GameObjects;
|
||||
using SS14.Shared.Interfaces.Reflection;
|
||||
using SS14.Shared.IoC;
|
||||
using SS14.Shared.Serialization;
|
||||
@@ -10,7 +9,7 @@ using SS14.Shared.ViewVariables;
|
||||
namespace Content.Server.GameObjects.Components.Stack
|
||||
{
|
||||
// TODO: Naming and presentation and such could use some improvement.
|
||||
public class StackComponent : Component, IAttackby, IExamine
|
||||
public class StackComponent : Component, IAttackBy, IExamine
|
||||
{
|
||||
private const string SerializationCache = "stack";
|
||||
private int _count = 50;
|
||||
@@ -97,9 +96,9 @@ namespace Content.Server.GameObjects.Components.Stack
|
||||
StackType = stackType;
|
||||
}
|
||||
|
||||
public bool Attackby(IEntity user, IEntity attackwith)
|
||||
public bool AttackBy(AttackByEventArgs eventArgs)
|
||||
{
|
||||
if (attackwith.TryGetComponent<StackComponent>(out var stack))
|
||||
if (eventArgs.AttackWith.TryGetComponent<StackComponent>(out var stack))
|
||||
{
|
||||
if (!stack.StackType.Equals(StackType))
|
||||
{
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
using Content.Shared.GameObjects;
|
||||
using Content.Shared.GameObjects;
|
||||
using SS14.Server.GameObjects.EntitySystems;
|
||||
using SS14.Shared.Audio;
|
||||
using SS14.Shared.GameObjects.EntitySystemMessages;
|
||||
using SS14.Shared.Interfaces.GameObjects;
|
||||
using SS14.Shared.Interfaces.GameObjects.Components;
|
||||
using SS14.Shared.Interfaces.Physics;
|
||||
using SS14.Shared.Interfaces.Timing;
|
||||
using SS14.Shared.IoC;
|
||||
@@ -12,15 +11,15 @@ using SS14.Shared.Maths;
|
||||
using SS14.Shared.Physics;
|
||||
using SS14.Shared.Serialization;
|
||||
using System;
|
||||
using Content.Server.GameObjects.Components.Sound;
|
||||
using SS14.Shared.GameObjects;
|
||||
using Content.Server.GameObjects.Components.Sound;
|
||||
using SS14.Shared.GameObjects;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Server.GameObjects.Components.Power;
|
||||
using Content.Shared.Interfaces;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Weapon.Ranged.Hitscan
|
||||
{
|
||||
public class HitscanWeaponComponent : Component, IAttackby
|
||||
public class HitscanWeaponComponent : Component, IAttackBy
|
||||
{
|
||||
private const float MaxLength = 20;
|
||||
public override string Name => "HitscanWeapon";
|
||||
@@ -60,15 +59,15 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Hitscan
|
||||
rangedWeapon.FireHandler = Fire;
|
||||
}
|
||||
|
||||
public bool Attackby(IEntity user, IEntity attackwith)
|
||||
public bool AttackBy(AttackByEventArgs eventArgs)
|
||||
{
|
||||
if (!attackwith.TryGetComponent(out PowerStorageComponent component))
|
||||
if (!eventArgs.AttackWith.TryGetComponent(out PowerStorageComponent component))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (capacitorComponent.Full)
|
||||
{
|
||||
Owner.PopupMessage(user, "Capacitor at max charge");
|
||||
Owner.PopupMessage(eventArgs.User, "Capacitor at max charge");
|
||||
return false;
|
||||
}
|
||||
capacitorComponent.FillFrom(component);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using Content.Server.GameObjects.Components.Sound;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Shared.GameObjects;
|
||||
@@ -6,17 +6,15 @@ using Content.Shared.GameObjects.Components.Weapons.Ranged;
|
||||
using Content.Shared.Interfaces;
|
||||
using SS14.Server.GameObjects;
|
||||
using SS14.Server.GameObjects.Components.Container;
|
||||
using SS14.Server.GameObjects.EntitySystems;
|
||||
using SS14.Shared.Audio;
|
||||
using SS14.Shared.Interfaces.GameObjects;
|
||||
using SS14.Shared.IoC;
|
||||
using SS14.Shared.Maths;
|
||||
using SS14.Shared.Serialization;
|
||||
using SS14.Shared.Utility;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile
|
||||
{
|
||||
public class BallisticMagazineWeaponComponent : BallisticWeaponComponent, IUse, IAttackby
|
||||
public class BallisticMagazineWeaponComponent : BallisticWeaponComponent, IUse, IAttackBy
|
||||
{
|
||||
public override string Name => "BallisticMagazineWeapon";
|
||||
|
||||
@@ -202,26 +200,26 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Attackby(IEntity user, IEntity attackwith)
|
||||
public bool AttackBy(AttackByEventArgs eventArgs)
|
||||
{
|
||||
if (!attackwith.TryGetComponent(out BallisticMagazineComponent component))
|
||||
if (!eventArgs.AttackWith.TryGetComponent(out BallisticMagazineComponent component))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Magazine != null)
|
||||
{
|
||||
Owner.PopupMessage(user, "Already got a magazine.");
|
||||
Owner.PopupMessage(eventArgs.User, "Already got a magazine.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (component.MagazineType != MagazineType || component.Caliber != Caliber)
|
||||
{
|
||||
Owner.PopupMessage(user, "Magazine doesn't fit.");
|
||||
Owner.PopupMessage(eventArgs.User, "Magazine doesn't fit.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return InsertMagazine(attackwith);
|
||||
return InsertMagazine(eventArgs.AttackWith);
|
||||
}
|
||||
|
||||
private void _magazineAmmoCountChanged()
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using Content.Server.Interfaces.GameObjects;
|
||||
using SS14.Server.Interfaces.GameObjects;
|
||||
using SS14.Shared.GameObjects;
|
||||
using SS14.Shared.GameObjects.Systems;
|
||||
using SS14.Shared.Interfaces.GameObjects;
|
||||
@@ -10,7 +9,6 @@ using Content.Shared.Input;
|
||||
using SS14.Shared.Input;
|
||||
using SS14.Shared.Log;
|
||||
using SS14.Shared.Map;
|
||||
using SS14.Server.GameObjects;
|
||||
using SS14.Server.GameObjects.EntitySystems;
|
||||
using SS14.Server.Interfaces.Player;
|
||||
using SS14.Shared.Interfaces.GameObjects.Components;
|
||||
@@ -21,7 +19,7 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
/// <summary>
|
||||
/// This interface gives components behavior when being clicked on or "attacked" by a user with an object in their hand
|
||||
/// </summary>
|
||||
public interface IAttackby
|
||||
public interface IAttackBy
|
||||
{
|
||||
/// <summary>
|
||||
/// Called when using one object on another
|
||||
@@ -29,7 +27,13 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
/// <param name="user"></param>
|
||||
/// <param name="attackwith"></param>
|
||||
/// <returns></returns>
|
||||
bool Attackby(IEntity user, IEntity attackwith);
|
||||
bool AttackBy(AttackByEventArgs eventArgs);
|
||||
}
|
||||
|
||||
public class AttackByEventArgs : EventArgs
|
||||
{
|
||||
public IEntity User { get; set; }
|
||||
public IEntity AttackWith { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -263,11 +267,11 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
/// <param name="attacked"></param>
|
||||
public static void Interaction(IEntity user, IEntity weapon, IEntity attacked, GridCoordinates clicklocation)
|
||||
{
|
||||
List<IAttackby> interactables = attacked.GetAllComponents<IAttackby>().ToList();
|
||||
List<IAttackBy> interactables = attacked.GetAllComponents<IAttackBy>().ToList();
|
||||
|
||||
for (var i = 0; i < interactables.Count; i++)
|
||||
{
|
||||
if (interactables[i].Attackby(user, weapon)) //If an attackby returns a status completion we finish our attack
|
||||
if (interactables[i].AttackBy(new AttackByEventArgs { User = user, AttackWith = weapon })) //If an attackby returns a status completion we finish our attack
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user