Skip to content

Commit

Permalink
fix store interaction and take first
Browse files Browse the repository at this point in the history
  • Loading branch information
stilnat committed Jan 1, 2025
1 parent d1c6062 commit c58c0b2
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ MeshFilter:
m_Mesh: {fileID: 5709868560514540240, guid: b7735b41af47b164f841a513161d8f07, type: 3}
--- !u!95 &7807247313645579261
Animator:
serializedVersion: 4
serializedVersion: 5
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
Expand All @@ -104,7 +104,8 @@ Animator:
m_WarningMessage:
m_HasTransformHierarchy: 1
m_AllowConstantClipSamplingOptimization: 1
m_KeepAnimatorControllerStateOnDisable: 0
m_KeepAnimatorStateOnDisable: 0
m_WriteDefaultValuesOnDisable: 0
--- !u!114 &3401307552301717060
MonoBehaviour:
m_ObjectHideFlags: 0
Expand All @@ -117,7 +118,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: e8cac635f24954048aad3a6ff9110beb, type: 3}
m_Name:
m_EditorClassIdentifier:
_componentIndexCache: 3
_componentIndexCache: 4
_addedNetworkObject: {fileID: 4819234911439508660}
_networkObjectCache: {fileID: 4819234911439508660}
IgnoredParameters: []
Expand Down Expand Up @@ -176,6 +177,7 @@ GameObject:
- component: {fileID: 8613419490928921116}
- component: {fileID: 2689380027240677461}
- component: {fileID: 7692858249744895666}
- component: {fileID: 6349042502534451669}
m_Layer: 10
m_Name: BikeHorn
m_TagString: Untagged
Expand Down Expand Up @@ -220,8 +222,6 @@ MonoBehaviour:
_weight: 1
_startingTraits: []
_rigidbody: {fileID: 6351433192589740835}
AttachmentPoint: {fileID: 4619531351315044860}
AttachmentPointAlt: {fileID: 0}
_container: {fileID: 0}
_animator: {fileID: 7807247313645579261}
_honkIcon: {fileID: 21300000, guid: 03812e70c708b3047b20e316b16f1896, type: 3}
Expand All @@ -244,6 +244,7 @@ MonoBehaviour:
- {fileID: 5398674181771020985}
- {fileID: 6573417749823381685}
- {fileID: -1808419688812875912}
- {fileID: 7692858249744895666}
- {fileID: 3401307552301717060}
<ParentNetworkObject>k__BackingField: {fileID: 0}
<ChildNetworkObjects>k__BackingField: []
Expand Down Expand Up @@ -338,7 +339,7 @@ MeshCollider:
m_Mesh: {fileID: 5709868560514540240, guid: b7735b41af47b164f841a513161d8f07, type: 3}
--- !u!95 &6183259094829508424
Animator:
serializedVersion: 4
serializedVersion: 5
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
Expand All @@ -355,7 +356,8 @@ Animator:
m_WarningMessage:
m_HasTransformHierarchy: 1
m_AllowConstantClipSamplingOptimization: 1
m_KeepAnimatorControllerStateOnDisable: 0
m_KeepAnimatorStateOnDisable: 0
m_WriteDefaultValuesOnDisable: 0
--- !u!114 &-1808419688812875912
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -401,7 +403,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 38640bf88ae0c29409092a258bd36878, type: 3}
m_Name:
m_EditorClassIdentifier:
key: {fileID: 11400000, guid: 71368b829dabc4042bc1ed56eb8afecf, type: 2}
_key: {fileID: 11400000, guid: 71368b829dabc4042bc1ed56eb8afecf, type: 2}
--- !u!114 &7692858249744895666
MonoBehaviour:
m_ObjectHideFlags: 0
Expand All @@ -414,6 +416,26 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 49d37ab5b82ded9419a6e3ab3d05af02, type: 3}
m_Name:
m_EditorClassIdentifier:
_componentIndexCache: 3
_addedNetworkObject: {fileID: 4819234911439508660}
_networkObjectCache: {fileID: 4819234911439508660}
--- !u!114 &6349042502534451669
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6891363543938182813}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 99df7ac2c21c2d944818b5da5be3dd53, type: 3}
m_Name:
m_EditorClassIdentifier:
_componentIndexCache: 255
_addedNetworkObject: {fileID: 4819234911439508660}
_networkObjectCache: {fileID: 0}
_primaryRightHandHold: {fileID: 4619531351315044860}
_primaryLeftHandHold: {fileID: 4619531351315044860}
_secondaryRightHandHold: {fileID: 0}
_secondaryLeftHandHold: {fileID: 0}
_holdableScriptableObject: {fileID: 11400000, guid: f93ccad7cfbe46b4fa3f8cfb8be8a1d9, type: 2}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ private void HandleAtmosTick(float dt)
{
foreach (Entity player in _playersEntities)
{
if (!_previousValuesChunkCenteredPlayers.ContainsKey(player.Owner))
{
return;
}

AtmosContainer atmosTile = _atmosEnvironmentSystem.GetAtmosContainer(player.Position);

if (atmosTile == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public class Hands : NetworkActor, IHandsController
/// <summary>
/// Reference to the inventory linked to Hands.
/// </summary>
[NonSerialized]
private HumanInventory _inventory;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"GUID:eb124556ba20d60469be9771eb1f0360",
"GUID:ee61973a336722c41acef2425d9de4f5",
"GUID:09ed6ceb4221dc3468f1528207ef24d3",
"GUID:ca7dfa56d1d490249a5fe56aee92a13c",
"GUID:92a1e40b8cccf8645adbdd275ac6371a",
"GUID:75469ad4d38634e559750d17036d5f7c",
"GUID:6055be8ebefd69e48b49212b09b47b2f"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public bool AddItem(Item item)
{
Vector2Int itemPosition = new Vector2Int(x, y);

if (AddItemPosition(item, itemPosition))
if (TryAddStoredItem(new(item, itemPosition)))
{
return true;
}
Expand All @@ -105,30 +105,37 @@ public bool AddItem(Item item)
/// <summary>
/// transfer an item from this container to another container at a given position.
/// </summary>
public bool TransferItemToOther(Item item, Vector2Int position, AttachedContainer other)
public bool TransferItemToOther(Item item, AttachedContainer other)
{
if (!FindItem(item, out int index))
{
return false;
}

if (!RemoveStoredItem(index))
if (!TryRemoveStoredItem(index))
{
return false;
}

return other.AddStoredItem(new StoredItem(item, position));
return other.AddItem(item);
}

/// <summary>
/// Tries to add an item at the specified position
/// transfer an item from this container to another container at a given position.
/// </summary>
/// <param name="storedItem">The item to add</param>
/// <param name="position">The target position in the container</param>
/// <returns>If the item was added</returns>
public bool AddItemPosition(Item item, Vector2Int position)
public bool TransferItemToOther(Item item, Vector2Int position, AttachedContainer other)
{
return AddStoredItem(new StoredItem(item, position));
if (!FindItem(item, out int index))
{
return false;
}

if (!TryRemoveStoredItem(index))
{
return false;
}

return other.TryAddStoredItem(new StoredItem(item, position));
}

public bool CanRemoveItem(Item item)
Expand All @@ -144,7 +151,7 @@ public void RemoveItem(Item item)
{
if (FindItem(item, out int index))
{
RemoveStoredItem(index);
TryRemoveStoredItem(index);
}
}

Expand Down Expand Up @@ -194,7 +201,7 @@ public void Dump()

for (int i = _storedItems.Count - 1; i >= 0; i--)
{
RemoveStoredItem(i);
TryRemoveStoredItem(i);
}
}

Expand Down Expand Up @@ -272,13 +279,13 @@ private void HandleStoredItemsChanged(SyncListOperation op, int index, StoredIte
}

case SyncListOperation.RemoveAt:
case SyncListOperation.Clear:
{
changeType = ContainerChangeType.Remove;
HandleItemRemoved(oldItem.Item);
break;
}

case SyncListOperation.Clear:
case SyncListOperation.Insert:
case SyncListOperation.Complete:
break;
Expand All @@ -292,7 +299,7 @@ private void HandleStoredItemsChanged(SyncListOperation op, int index, StoredIte
return;
}

InvokeOnContentChanged(oldItem.Item, newItem.Item, changeType);
OnContentsChanged?.Invoke(this, oldItem.Item, newItem.Item, changeType);
}

[ServerOrClient]
Expand Down Expand Up @@ -348,32 +355,9 @@ private void HandleItemAdded(Item item)
/// Correctly add a storeItem to the container. All adding should use this method, never do it directly.
/// </summary>
/// <param name="newItem"> the item to store.</param>
private bool AddStoredItem(StoredItem newItem)
private bool TryAddStoredItem(StoredItem newItem)
{
// Fail if attempted storage position is out of bounds
if (newItem.Position.x >= Size.x || newItem.Position.y >= Size.y)
{
return false;
}

if (newItem.Position.x < 0 || newItem.Position.y < 0)
{
return false;
}

// Fail if item is already at this position
if (ItemAt(newItem.Position))
{
return false;
}

if (!CanContainItem(newItem.Item))
{
return false;
}

// Fail if it is the same container
if (ReferenceEquals(newItem.Item.Container, this))
if (!CanContainItemAtPosition(newItem.Item, newItem.Position))
{
return false;
}
Expand Down Expand Up @@ -413,7 +397,7 @@ private void ReplaceStoredItem(StoredItem item, int index)
/// Correctly remove a storeItem in the container at the given index. All removing should use this method, never do it directly.
/// </summary>
/// <param name="index">the index in the list at which the storedItem should be removed.</param>
private bool RemoveStoredItem(int index)
private bool TryRemoveStoredItem(int index)
{
StoredItem storedItem = _storedItems[index];

Expand Down Expand Up @@ -469,11 +453,6 @@ private bool IsAreaFree(Vector2Int slotPosition)
return _storedItems.All(storedItem => storedItem.Position != slotPosition);
}

private void InvokeOnContentChanged(Item oldItem, Item newItem, ContainerChangeType changeType)
{
OnContentsChanged?.Invoke(this, oldItem, newItem, changeType);
}

private bool AreSlotCoordinatesInGrid(Vector2Int slotCoordinates)
{
return slotCoordinates.x < Size.x && slotCoordinates.y < Size.y && slotCoordinates.x >= 0 && slotCoordinates.y >= 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public bool CanInteract(InteractionEvent interactionEvent)
return false;
}

IInteractionSource source = interactionEvent.Source;
IInteractionSource source = interactionEvent.Source.GetRootSource();
if (source is not IContainerProvider containerProvider)
{
return false;
Expand All @@ -60,7 +60,7 @@ public bool CanInteract(InteractionEvent interactionEvent)

public bool Start(InteractionEvent interactionEvent, InteractionReference reference)
{
IInteractionSource source = interactionEvent.Source;
IInteractionSource source = interactionEvent.Source.GetRootSource();
if (source is IContainerProvider containerProvider)
{
Item item = containerProvider.Container.Items.First();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public bool Start(InteractionEvent interactionEvent, InteractionReference refere

if (pickupItem != null && interactionEvent.Source is IContainerProvider containerProvider)
{
containerProvider.Container.AddItem(pickupItem);
pickupItem.Container.TransferItemToOther(pickupItem, containerProvider.Container);
}

return false;
Expand Down
2 changes: 1 addition & 1 deletion Builds/Game/Data/Tilemaps/pipemap.json

Large diffs are not rendered by default.

0 comments on commit c58c0b2

Please sign in to comment.