Fix some things setting StackComponent count manually.
This commit is contained in:
@@ -3,6 +3,7 @@ using System;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Content.Server.GameObjects.Components.Stack;
|
using Content.Server.GameObjects.Components.Stack;
|
||||||
using Content.Shared.Construction;
|
using Content.Shared.Construction;
|
||||||
|
using Content.Shared.GameObjects.EntitySystems;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.Log;
|
using Robust.Shared.Log;
|
||||||
@@ -19,14 +20,9 @@ namespace Content.Server.Construction.Completions
|
|||||||
public async Task PerformAction(IEntity entity, IEntity? user)
|
public async Task PerformAction(IEntity entity, IEntity? user)
|
||||||
{
|
{
|
||||||
if (entity.Deleted) return;
|
if (entity.Deleted) return;
|
||||||
if(!entity.TryGetComponent(out StackComponent? stackComponent)) return;
|
if(!entity.HasComponent<StackComponent>()) return;
|
||||||
|
|
||||||
stackComponent.Count = Math.Min(stackComponent.MaxCount, Amount);
|
entity.EntityManager.EventBus.RaiseLocalEvent(entity.Uid, new StackChangeCountEvent(Amount), false);
|
||||||
|
|
||||||
if (Amount > stackComponent.MaxCount)
|
|
||||||
{
|
|
||||||
Logger.Warning("StackCount is bigger than maximum stack capacity, for entity " + entity.Name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Content.Server.GameObjects.Components.Stack;
|
using Content.Server.GameObjects.Components.Stack;
|
||||||
using Content.Shared.Construction;
|
using Content.Shared.Construction;
|
||||||
|
using Content.Shared.GameObjects.EntitySystems;
|
||||||
using Content.Shared.Utility;
|
using Content.Shared.Utility;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
@@ -27,10 +28,8 @@ namespace Content.Server.Construction.Completions
|
|||||||
|
|
||||||
if (EntityPrototypeHelpers.HasComponent<StackComponent>(Prototype))
|
if (EntityPrototypeHelpers.HasComponent<StackComponent>(Prototype))
|
||||||
{
|
{
|
||||||
var _entity = entityManager.SpawnEntity(Prototype, coordinates);
|
var stack = entityManager.SpawnEntity(Prototype, coordinates);
|
||||||
StackComponent stackComponent = _entity.GetComponent<StackComponent>();
|
stack.EntityManager.EventBus.RaiseLocalEvent(stack.Uid, new StackChangeCountEvent(Amount), false);
|
||||||
|
|
||||||
stackComponent.Count = Math.Min(stackComponent.MaxCount, Amount);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using System.Threading.Tasks;
|
|||||||
using Content.Server.GameObjects.Components.Interactable;
|
using Content.Server.GameObjects.Components.Interactable;
|
||||||
using Content.Server.GameObjects.Components.Stack;
|
using Content.Server.GameObjects.Components.Stack;
|
||||||
using Content.Shared.GameObjects.Components.Interactable;
|
using Content.Shared.GameObjects.Components.Interactable;
|
||||||
|
using Content.Shared.GameObjects.EntitySystems;
|
||||||
using Content.Shared.Interfaces.GameObjects.Components;
|
using Content.Shared.Interfaces.GameObjects.Components;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
@@ -58,8 +59,10 @@ namespace Content.Server.GameObjects.Components.Construction
|
|||||||
{
|
{
|
||||||
var droppedEnt = Owner.EntityManager.SpawnEntity(result, resultPosition);
|
var droppedEnt = Owner.EntityManager.SpawnEntity(result, resultPosition);
|
||||||
|
|
||||||
if (droppedEnt.TryGetComponent<StackComponent>(out var stackComp))
|
// TODO: If something has a stack... Just use a prototype with a single thing in the stack.
|
||||||
stackComp.Count = 1;
|
// This is not a good way to do it.
|
||||||
|
if (droppedEnt.HasComponent<StackComponent>())
|
||||||
|
Owner.EntityManager.EventBus.RaiseLocalEvent(droppedEnt.Uid, new StackChangeCountEvent(1), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Content.Server.GameObjects.Components.Stack;
|
using Content.Server.GameObjects.Components.Stack;
|
||||||
using Content.Server.GameObjects.EntitySystems;
|
using Content.Server.GameObjects.EntitySystems;
|
||||||
|
using Content.Shared.GameObjects.EntitySystems;
|
||||||
using Content.Shared.Utility;
|
using Content.Shared.Utility;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.Serialization.Manager.Attributes;
|
using Robust.Shared.Serialization.Manager.Attributes;
|
||||||
@@ -32,8 +33,7 @@ namespace Content.Server.GameObjects.Components.Destructible.Thresholds.Behavior
|
|||||||
if (EntityPrototypeHelpers.HasComponent<StackComponent>(entityId))
|
if (EntityPrototypeHelpers.HasComponent<StackComponent>(entityId))
|
||||||
{
|
{
|
||||||
var spawned = owner.EntityManager.SpawnEntity(entityId, owner.Transform.MapPosition);
|
var spawned = owner.EntityManager.SpawnEntity(entityId, owner.Transform.MapPosition);
|
||||||
var stack = spawned.GetComponent<StackComponent>();
|
owner.EntityManager.EventBus.RaiseLocalEvent(spawned.Uid, new StackChangeCountEvent(count), false);
|
||||||
stack.Count = count;
|
|
||||||
spawned.RandomOffset(0.5f);
|
spawned.RandomOffset(0.5f);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System.Threading.Tasks;
|
|||||||
using Content.Server.GameObjects.Components.Interactable;
|
using Content.Server.GameObjects.Components.Interactable;
|
||||||
using Content.Server.GameObjects.Components.Stack;
|
using Content.Server.GameObjects.Components.Stack;
|
||||||
using Content.Shared.GameObjects.Components.Interactable;
|
using Content.Shared.GameObjects.Components.Interactable;
|
||||||
|
using Content.Shared.GameObjects.EntitySystems;
|
||||||
using Content.Shared.Interfaces.GameObjects.Components;
|
using Content.Shared.Interfaces.GameObjects.Components;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
@@ -44,8 +45,9 @@ namespace Content.Server.GameObjects.Components.Power
|
|||||||
Owner.Delete();
|
Owner.Delete();
|
||||||
var droppedEnt = Owner.EntityManager.SpawnEntity(_wireDroppedOnCutPrototype, eventArgs.ClickLocation);
|
var droppedEnt = Owner.EntityManager.SpawnEntity(_wireDroppedOnCutPrototype, eventArgs.ClickLocation);
|
||||||
|
|
||||||
if (droppedEnt.TryGetComponent<StackComponent>(out var stackComp))
|
// TODO: Literally just use a prototype that has a single thing in the stack, it's not that complicated...
|
||||||
stackComp.Count = 1;
|
if (droppedEnt.HasComponent<StackComponent>())
|
||||||
|
Owner.EntityManager.EventBus.RaiseLocalEvent(droppedEnt.Uid, new StackChangeCountEvent(1), false);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
4
Resources/Changelog/Parts/stacks.yml
Normal file
4
Resources/Changelog/Parts/stacks.yml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
author: Zumorica
|
||||||
|
changes:
|
||||||
|
- type: Fix # One of the following: Add, Remove, Tweak, Fix
|
||||||
|
message: Fix some bugs with stacks where their appearance and count would be incorrect client-side.
|
||||||
Reference in New Issue
Block a user