Make held entity nullable (#5923)

This commit is contained in:
wrexbe
2021-12-30 18:27:15 -08:00
committed by GitHub
parent 761dfb48af
commit abba1e1c2c
11 changed files with 68 additions and 86 deletions

View File

@@ -68,7 +68,7 @@ namespace Content.Server.Hands.Systems
return;
// Cancel pull if all hands full.
if (component.Hands.All(hand => !hand.IsEmpty))
if (component.Hands.All(hand => hand.HeldEntity != null))
args.Cancelled = true;
}
@@ -92,12 +92,12 @@ namespace Content.Server.Hands.Systems
// and clear it.
foreach (var hand in component.Hands)
{
if (hand.HeldEntity == default
if (hand.HeldEntity == null
|| !EntityManager.TryGetComponent(hand.HeldEntity, out HandVirtualItemComponent? virtualItem)
|| virtualItem.BlockingEntity != args.Pulled.Owner)
continue;
EntityManager.DeleteEntity(hand.HeldEntity);
EntityManager.DeleteEntity(hand.HeldEntity.Value);
break;
}
}
@@ -234,16 +234,16 @@ namespace Content.Server.Hands.Systems
!_actionBlockerSystem.CanThrow(player))
return false;
if (EntityManager.TryGetComponent(throwEnt, out StackComponent? stack) && stack.Count > 1 && stack.ThrowIndividually)
if (EntityManager.TryGetComponent(throwEnt.Value, out StackComponent? stack) && stack.Count > 1 && stack.ThrowIndividually)
{
var splitStack = _stackSystem.Split(throwEnt, 1, EntityManager.GetComponent<TransformComponent>(player).Coordinates, stack);
var splitStack = _stackSystem.Split(throwEnt.Value, 1, EntityManager.GetComponent<TransformComponent>(player).Coordinates, stack);
if (splitStack is not {Valid: true})
return false;
throwEnt = splitStack.Value;
}
else if (!hands.Drop(throwEnt))
else if (!hands.Drop(throwEnt.Value))
return false;
var direction = coords.ToMapPos(EntityManager) - EntityManager.GetComponent<TransformComponent>(player).WorldPosition;
@@ -253,7 +253,7 @@ namespace Content.Server.Hands.Systems
direction = direction.Normalized * Math.Min(direction.Length, hands.ThrowRange);
var throwStrength = hands.ThrowForceMultiplier;
throwEnt.TryThrow(direction, throwStrength, player);
throwEnt.Value.TryThrow(direction, throwStrength, player);
return true;
}