StackSystem uses the EntitySystem proxy methods. (#5699)

This commit is contained in:
Vera Aguilera Puerto
2021-12-14 18:11:26 +01:00
committed by GitHub
parent 8c295d340d
commit d75b384213
2 changed files with 27 additions and 35 deletions

View File

@@ -47,16 +47,16 @@ namespace Content.Server.Stack
// Get a prototype ID to spawn the new entity. Null is also valid, although it should rarely be picked... // Get a prototype ID to spawn the new entity. Null is also valid, although it should rarely be picked...
var prototype = _prototypeManager.TryIndex<StackPrototype>(stack.StackTypeId, out var stackType) var prototype = _prototypeManager.TryIndex<StackPrototype>(stack.StackTypeId, out var stackType)
? stackType.Spawn ? stackType.Spawn
: EntityManager.GetComponent<MetaDataComponent>(stack.Owner).EntityPrototype?.ID; : Prototype(stack.Owner)?.ID;
// Try to remove the amount of things we want to split from the original stack... // Try to remove the amount of things we want to split from the original stack...
if (!Use(uid, amount, stack)) if (!Use(uid, amount, stack))
return default; return default;
// Set the output parameter in the event instance to the newly split stack. // Set the output parameter in the event instance to the newly split stack.
var entity = EntityManager.SpawnEntity(prototype, spawnPosition); var entity = Spawn(prototype, spawnPosition);
if (EntityManager.TryGetComponent(entity, out SharedStackComponent? stackComp)) if (TryComp(entity, out SharedStackComponent? stackComp))
{ {
// Set the split stack's count. // Set the split stack's count.
SetCount(entity, amount, stackComp); SetCount(entity, amount, stackComp);
@@ -73,8 +73,8 @@ namespace Content.Server.Stack
public EntityUid Spawn(int amount, StackPrototype prototype, EntityCoordinates spawnPosition) public EntityUid Spawn(int amount, StackPrototype prototype, EntityCoordinates spawnPosition)
{ {
// Set the output result parameter to the new stack entity... // Set the output result parameter to the new stack entity...
var entity = EntityManager.SpawnEntity(prototype.Spawn, spawnPosition); var entity = Spawn(prototype.Spawn, spawnPosition);
var stack = EntityManager.GetComponent<StackComponent>(entity); var stack = Comp<StackComponent>(entity);
// And finally, set the correct amount! // And finally, set the correct amount!
SetCount(entity, amount, stack); SetCount(entity, amount, stack);
@@ -86,7 +86,7 @@ namespace Content.Server.Stack
if (args.Handled) if (args.Handled)
return; return;
if (!EntityManager.TryGetComponent<StackComponent?>(args.Used, out var otherStack)) if (!TryComp<StackComponent>(args.Used, out var otherStack))
return; return;
if (!otherStack.StackTypeId.Equals(stack.StackTypeId)) if (!otherStack.StackTypeId.Equals(stack.StackTypeId))
@@ -100,7 +100,7 @@ namespace Content.Server.Stack
if (!popupPos.IsValid(EntityManager)) if (!popupPos.IsValid(EntityManager))
{ {
popupPos = EntityManager.GetComponent<TransformComponent>(args.User).Coordinates; popupPos = Transform(args.User).Coordinates;
} }
var filter = Filter.Entities(args.User); var filter = Filter.Entities(args.User);
@@ -131,11 +131,13 @@ namespace Content.Server.Stack
if (!args.CanAccess || !args.CanInteract) if (!args.CanAccess || !args.CanInteract)
return; return;
Verb halve = new(); Verb halve = new()
halve.Text = Loc.GetString("comp-stack-split-halve"); {
halve.Category = VerbCategory.Split; Text = Loc.GetString("comp-stack-split-halve"),
halve.Act = () => UserSplit(uid, args.User, stack.Count / 2, stack); Category = VerbCategory.Split,
halve.Priority = 1; Act = () => UserSplit(uid, args.User, stack.Count / 2, stack),
Priority = 1
};
args.Verbs.Add(halve); args.Verbs.Add(halve);
var priority = 0; var priority = 0;
@@ -144,13 +146,15 @@ namespace Content.Server.Stack
if (amount >= stack.Count) if (amount >= stack.Count)
continue; continue;
Verb verb = new(); Verb verb = new()
verb.Text = amount.ToString(); {
verb.Category = VerbCategory.Split; Text = amount.ToString(),
verb.Act = () => UserSplit(uid, args.User, amount, stack); Category = VerbCategory.Split,
Act = () => UserSplit(uid, args.User, amount, stack),
// we want to sort by size, not alphabetically by the verb text.
Priority = priority
};
// we want to sort by size, not alphabetically by the verb text.
verb.Priority = priority;
priority--; priority--;
args.Verbs.Add(verb); args.Verbs.Add(verb);
@@ -173,22 +177,10 @@ namespace Content.Server.Stack
return; return;
} }
if (EntityManager.TryGetComponent<HandsComponent>(userUid, out var hands)) if (Split(uid, amount, userTransform.Coordinates, stack) is not {} split)
{
if (hands.TryGetActiveHeldEntity(out var heldItem) && heldItem != stack.Owner)
{
return;
}
}
else
{
return;
}
if (Split(uid, amount, userTransform.Coordinates, stack) is not {Valid: true} split)
return; return;
if (EntityManager.TryGetComponent<ItemComponent>(split, out var item)) if (TryComp<HandsComponent>(userUid, out var hands) && TryComp<ItemComponent>(split, out var item))
{ {
hands.PutInHandOrDrop(item); hands.PutInHandOrDrop(item);
} }

View File

@@ -48,10 +48,10 @@ namespace Content.Shared.Stacks
// Queue delete stack if count reaches zero. // Queue delete stack if count reaches zero.
if(component.Count <= 0) if(component.Count <= 0)
EntityManager.QueueDeleteEntity(uid); QueueDel(uid);
// Change appearance data. // Change appearance data.
if (EntityManager.TryGetComponent(uid, out AppearanceComponent? appearance)) if (TryComp(uid, out AppearanceComponent? appearance))
appearance.SetData(StackVisuals.Actual, component.Count); appearance.SetData(StackVisuals.Actual, component.Count);
RaiseLocalEvent(uid, new StackCountChangedEvent(old, component.Count), false); RaiseLocalEvent(uid, new StackCountChangedEvent(old, component.Count), false);
@@ -83,7 +83,7 @@ namespace Content.Shared.Stacks
private void OnStackStarted(EntityUid uid, SharedStackComponent component, ComponentStartup args) private void OnStackStarted(EntityUid uid, SharedStackComponent component, ComponentStartup args)
{ {
if (!EntityManager.TryGetComponent(uid, out AppearanceComponent? appearance)) if (!TryComp(uid, out AppearanceComponent? appearance))
return; return;
appearance.SetData(StackVisuals.Actual, component.Count); appearance.SetData(StackVisuals.Actual, component.Count);