Adds click attacks

This commit is contained in:
Víctor Aguilera Puerto
2020-08-31 18:55:42 +02:00
parent 9d5278ab0d
commit 69bd44c94c
7 changed files with 167 additions and 66 deletions

View File

@@ -176,7 +176,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
if (userEntity.TryGetComponent(out CombatModeComponent combatMode) && combatMode.IsInCombatMode)
{
DoAttack(userEntity, coords);
DoAttack(userEntity, coords, true);
}
return true;
@@ -198,7 +198,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
if (entity.TryGetComponent(out CombatModeComponent combatMode) && combatMode.IsInCombatMode)
{
DoAttack(entity, coords);
DoAttack(entity, coords, false);
}
else
{
@@ -229,7 +229,10 @@ namespace Content.Server.GameObjects.EntitySystems.Click
return true;
}
UserInteraction(userEntity, coords, uid);
if(userEntity.TryGetComponent(out CombatModeComponent combat) && combat.IsInCombatMode)
DoAttack(userEntity, coords, false, uid);
else
UserInteraction(userEntity, coords, uid);
return true;
}
@@ -790,7 +793,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
}
}
private void DoAttack(IEntity player, GridCoordinates coordinates)
private void DoAttack(IEntity player, GridCoordinates coordinates, bool wideAttack, EntityUid target = default)
{
// Verify player is on the same map as the entity he clicked on
if (_mapManager.GetGrid(coordinates.GridID).ParentMapId != player.Transform.MapID)
@@ -800,12 +803,13 @@ namespace Content.Server.GameObjects.EntitySystems.Click
return;
}
if (!ActionBlockerSystem.CanAttack(player))
if (!ActionBlockerSystem.CanAttack(player) ||
(!wideAttack && !InRangeUnobstructed(player.Transform.MapPosition, coordinates.ToMap(_mapManager), ignoreInsideBlocker:true)))
{
return;
}
var eventArgs = new AttackEventArgs(player, coordinates);
var eventArgs = new AttackEventArgs(player, coordinates, wideAttack, target);
// Verify player has a hand, and find what object he is currently holding in his active hand
if (player.TryGetComponent<IHandsComponent>(out var hands))
@@ -814,22 +818,20 @@ namespace Content.Server.GameObjects.EntitySystems.Click
if (item != null)
{
var attacked = false;
foreach (var attackComponent in item.GetAllComponents<IAttack>())
{
attackComponent.Attack(eventArgs);
attacked = true;
}
if (attacked)
{
return;
if(wideAttack ? attackComponent.WideAttack(eventArgs) : attackComponent.ClickAttack(eventArgs))
return;
}
}
}
foreach (var attackComponent in player.GetAllComponents<IAttack>())
{
attackComponent.Attack(eventArgs);
if (wideAttack)
attackComponent.WideAttack(eventArgs);
else
attackComponent.ClickAttack(eventArgs);
}
}
}