Construction Bugfixes (#1329)
* Added: CanReach property to AfterAttack events which signals if the attack was within reach. Fixed: You cannot construct/deconstruct things out of reach. Fixed: Construction entities now preserve transform rotation. Fixed: No more exceptions about missing grids when constructing world entities. Fixed: Used the proper intermediate sprite for intermediate entities. Fixed: Issue with missing sprite layers on ghost. * The alligator is greedy, he always eats the bigger number... * Adds a check so that you cannot use tools on entities that are obstructed from view.
This commit is contained in:
@@ -4,6 +4,7 @@ using Content.Server.GameObjects.Components;
|
||||
using Content.Server.GameObjects.Components.Construction;
|
||||
using Content.Server.GameObjects.Components.Interactable;
|
||||
using Content.Server.GameObjects.Components.Stack;
|
||||
using Content.Server.GameObjects.EntitySystems.Click;
|
||||
using Content.Server.Interfaces.GameObjects.Components.Interaction;
|
||||
using Content.Server.Interfaces;
|
||||
using Content.Server.Utility;
|
||||
@@ -78,6 +79,10 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
if(msg.Handled)
|
||||
return;
|
||||
|
||||
// You can only construct/deconstruct things within reach
|
||||
if(!msg.CanReach)
|
||||
return;
|
||||
|
||||
var targetEnt = msg.Attacked;
|
||||
var handEnt = msg.ItemInHand;
|
||||
|
||||
@@ -85,6 +90,10 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
if(targetEnt is null || handEnt is null)
|
||||
return;
|
||||
|
||||
var interaction = Get<InteractionSystem>();
|
||||
if(!interaction.InRangeUnobstructed(handEnt.Transform.MapPosition, targetEnt.Transform.MapPosition, ignoredEnt: targetEnt, ignoreInsideBlocker: true))
|
||||
return;
|
||||
|
||||
// Cannot deconstruct an entity with no prototype.
|
||||
var targetPrototype = targetEnt.MetaData.EntityPrototype;
|
||||
if (targetPrototype is null)
|
||||
@@ -156,7 +165,7 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
else // replace ent with intermediate
|
||||
{
|
||||
// Spawn frame
|
||||
var frame = EntityManager.SpawnEntity("structureconstructionframe", targetEntPos);
|
||||
var frame = SpawnCopyTransform("structureconstructionframe", targetEnt.Transform);
|
||||
var construction = frame.GetComponent<ConstructionComponent>();
|
||||
SetupComponent(construction, prototype);
|
||||
construction.Stage = prototype.Stages.Count - 2;
|
||||
@@ -185,12 +194,20 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
}
|
||||
}
|
||||
|
||||
private IEntity SpawnCopyTransform(string prototypeId, ITransformComponent toReplace)
|
||||
{
|
||||
var frame = EntityManager.SpawnEntity(prototypeId, toReplace.MapPosition);
|
||||
frame.Transform.WorldRotation = toReplace.WorldRotation;
|
||||
frame.Transform.ParentUid = toReplace.ParentUid;
|
||||
return frame;
|
||||
}
|
||||
|
||||
private static void SetupDeconIntermediateSprite(ConstructionComponent constructionComponent, ConstructionPrototype prototype)
|
||||
{
|
||||
if(!constructionComponent.Owner.TryGetComponent<SpriteComponent>(out var spriteComp))
|
||||
return;
|
||||
|
||||
for (var i = prototype.Stages.Count - 1; i < 0; i--)
|
||||
for (var i = prototype.Stages.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (prototype.Stages[i].Icon != null)
|
||||
{
|
||||
@@ -331,12 +348,12 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
if (prototype.Stages.Count == 2)
|
||||
{
|
||||
// Exactly 2 stages, so don't make an intermediate frame.
|
||||
var ent = EntityManager.SpawnEntity(prototype.Result, placingEnt.Transform.GridPosition);
|
||||
var ent = SpawnCopyTransform(prototype.Result, placingEnt.Transform);
|
||||
hands.PutInHandOrDrop(ent.GetComponent<ItemComponent>());
|
||||
}
|
||||
else
|
||||
{
|
||||
var frame = EntityManager.SpawnEntity("structureconstructionframe", placingEnt.Transform.GridPosition);
|
||||
var frame = SpawnCopyTransform("structureconstructionframe", placingEnt.Transform);
|
||||
var construction = frame.GetComponent<ConstructionComponent>();
|
||||
SetupComponent(construction, prototype);
|
||||
|
||||
@@ -379,7 +396,7 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
if (constructionComponent.Stage == constructPrototype.Stages.Count - 1)
|
||||
{
|
||||
// Oh boy we get to finish construction!
|
||||
var ent = EntityManager.SpawnEntity(constructPrototype.Result, transformComponent.GridPosition);
|
||||
var ent = SpawnCopyTransform(constructPrototype.Result, transformComponent);
|
||||
ent.Transform.LocalRotation = transformComponent.LocalRotation;
|
||||
|
||||
ReplaceInContainerOrGround(constructEntity, ent);
|
||||
|
||||
Reference in New Issue
Block a user