-
Notifications
You must be signed in to change notification settings - Fork 378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix PseudoItems #821
Merged
Merged
Fix PseudoItems #821
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
Content.Client/Nyanotrasen/Item/PseudoItem/PseudoItemSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
using Content.Shared.Nyanotrasen.Item.PseudoItem; | ||
|
||
namespace Content.Client.Nyanotrasen.Item.PseudoItem; | ||
|
||
public sealed class PseudoItemSystem : SharedPseudoItemSystem | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
165 changes: 165 additions & 0 deletions
165
Content.Shared/Nyanotrasen/Item/PseudoItem/SharedPseudoItemSystem.Checks.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
using Content.Shared.Item; | ||
using Content.Shared.Storage; | ||
|
||
namespace Content.Shared.Nyanotrasen.Item.PseudoItem; | ||
|
||
/// <summary> | ||
/// Almost all of this is code taken from other systems, but adapted to use PseudoItem. | ||
/// I couldn't use the original functions because the resolve would fuck shit up, even if I passed a constructed itemcomp | ||
/// | ||
/// This is horrible, and I hate it. But such is life | ||
/// </summary> | ||
public partial class SharedPseudoItemSystem | ||
{ | ||
protected bool CheckItemFits(Entity<PseudoItemComponent?> itemEnt, Entity<StorageComponent?> storageEnt) | ||
{ | ||
if (!Resolve(itemEnt, ref itemEnt.Comp) || !Resolve(storageEnt, ref storageEnt.Comp)) | ||
return false; | ||
|
||
if (Transform(itemEnt).Anchored) | ||
return false; | ||
|
||
if (storageEnt.Comp.Whitelist?.IsValid(itemEnt, EntityManager) == false) | ||
return false; | ||
|
||
if (storageEnt.Comp.Blacklist?.IsValid(itemEnt, EntityManager) == true) | ||
return false; | ||
|
||
var maxSize = _storage.GetMaxItemSize(storageEnt); | ||
if (_item.GetSizePrototype(itemEnt.Comp.Size) > maxSize) | ||
return false; | ||
|
||
// The following is shitfucked together straight from TryGetAvailableGridSpace, but eh, it works | ||
|
||
var itemComp = new ItemComponent | ||
{ Size = itemEnt.Comp.Size, Shape = itemEnt.Comp.Shape, StoredOffset = itemEnt.Comp.StoredOffset }; | ||
|
||
var storageBounding = storageEnt.Comp.Grid.GetBoundingBox(); | ||
|
||
Angle startAngle; | ||
if (storageEnt.Comp.DefaultStorageOrientation == null) | ||
startAngle = Angle.FromDegrees(-itemComp.StoredRotation); // PseudoItem doesn't support this | ||
else | ||
{ | ||
if (storageBounding.Width < storageBounding.Height) | ||
{ | ||
startAngle = storageEnt.Comp.DefaultStorageOrientation == StorageDefaultOrientation.Horizontal | ||
? Angle.Zero | ||
: Angle.FromDegrees(90); | ||
} | ||
else | ||
{ | ||
startAngle = storageEnt.Comp.DefaultStorageOrientation == StorageDefaultOrientation.Vertical | ||
? Angle.Zero | ||
: Angle.FromDegrees(90); | ||
} | ||
} | ||
|
||
for (var y = storageBounding.Bottom; y <= storageBounding.Top; y++) | ||
{ | ||
for (var x = storageBounding.Left; x <= storageBounding.Right; x++) | ||
{ | ||
for (var angle = startAngle; angle <= Angle.FromDegrees(360 - startAngle); angle += Math.PI / 2f) | ||
{ | ||
var location = new ItemStorageLocation(angle, (x, y)); | ||
if (ItemFitsInGridLocation(itemEnt, storageEnt, location.Position, location.Rotation)) | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
private bool ItemFitsInGridLocation( | ||
Entity<PseudoItemComponent?> itemEnt, | ||
Entity<StorageComponent?> storageEnt, | ||
Vector2i position, | ||
Angle rotation) | ||
{ | ||
if (!Resolve(itemEnt, ref itemEnt.Comp) || !Resolve(storageEnt, ref storageEnt.Comp)) | ||
return false; | ||
|
||
var gridBounds = storageEnt.Comp.Grid.GetBoundingBox(); | ||
if (!gridBounds.Contains(position)) | ||
return false; | ||
|
||
var itemShape = GetAdjustedItemShape(itemEnt, rotation, position); | ||
|
||
foreach (var box in itemShape) | ||
{ | ||
for (var offsetY = box.Bottom; offsetY <= box.Top; offsetY++) | ||
{ | ||
for (var offsetX = box.Left; offsetX <= box.Right; offsetX++) | ||
{ | ||
var pos = (offsetX, offsetY); | ||
|
||
if (!IsGridSpaceEmpty(itemEnt, storageEnt, pos, itemShape)) | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
private IReadOnlyList<Box2i> GetAdjustedItemShape(Entity<PseudoItemComponent?> entity, Angle rotation, | ||
Vector2i position) | ||
{ | ||
if (!Resolve(entity, ref entity.Comp)) | ||
return new Box2i[] { }; | ||
|
||
var shapes = entity.Comp.Shape ?? _item.GetSizePrototype(entity.Comp.Size).DefaultShape; | ||
var boundingShape = shapes.GetBoundingBox(); | ||
var boundingCenter = ((Box2) boundingShape).Center; | ||
var matty = Matrix3.CreateTransform(boundingCenter, rotation); | ||
var drift = boundingShape.BottomLeft - matty.TransformBox(boundingShape).BottomLeft; | ||
|
||
var adjustedShapes = new List<Box2i>(); | ||
foreach (var shape in shapes) | ||
{ | ||
var transformed = matty.TransformBox(shape).Translated(drift); | ||
var floored = new Box2i(transformed.BottomLeft.Floored(), transformed.TopRight.Floored()); | ||
var translated = floored.Translated(position); | ||
|
||
adjustedShapes.Add(translated); | ||
} | ||
|
||
return adjustedShapes; | ||
} | ||
|
||
private bool IsGridSpaceEmpty(Entity<PseudoItemComponent?> itemEnt, Entity<StorageComponent?> storageEnt, | ||
Vector2i location, IReadOnlyList<Box2i> shape) | ||
{ | ||
if (!Resolve(storageEnt, ref storageEnt.Comp)) | ||
return false; | ||
|
||
var validGrid = false; | ||
foreach (var grid in storageEnt.Comp.Grid) | ||
{ | ||
if (grid.Contains(location)) | ||
{ | ||
validGrid = true; | ||
break; | ||
} | ||
} | ||
|
||
if (!validGrid) | ||
return false; | ||
|
||
foreach (var (ent, storedItem) in storageEnt.Comp.StoredItems) | ||
{ | ||
if (ent == itemEnt.Owner) | ||
continue; | ||
|
||
var adjustedShape = shape; | ||
foreach (var box in adjustedShape) | ||
{ | ||
if (box.Contains(location)) | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
creating a new component to pass into :
im guessing this is just to make it so a felenid cant be picked up instantly, would be better to just have that be an event raised for ItemComponent that felenids cancel, so they still reuse all the logic but cant just left click to pick up like a mouse
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pseudoitems lack the itemcomponent when they're not inside a container because it brings a ton of unwanted features along with it. Even just adding it to run the check could result in weird shit happening if someone knew enough. This approach works "fine" for what its supposed to do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The entire reason I cant use the original functions as is is because they expect the item to have an itemcomponent, and theres no way to tell it to use anything else, even if it doesn't directly do anything with said component