Open RubensKj opened 6 months ago
The suggestion is to add this ifs on the source code to not call the events again:
public class PlaceItemInHolder : ReleaseProcessor { protected override void HandleProcess(ReleaseContext ctx, ReleaseState finalState) { var selectedItemHolder = ctx.SelectedItemHolder; var selectedInventoryItem = ctx.PickupState.Item; var itemTable = selectedInventoryItem.ItemTable; if (CheckIfSameHolder(ctx) == true) { finalState.Placed = false; return; } var equippableMessages = selectedItemHolder.TryEquipItem(itemTable); if (ctx.Debug) { Debug.Log(("Placing item in holder. Holder: " + selectedItemHolder + " Status: " + equippableMessages) .DraggableSystem()); } finalState.Placed = equippableMessages == HolderResponse.Equipped; } // Add this code to validate if is the same holder private bool CheckIfSameHolder(ReleaseContext ctx) { var previousItemHolder = ctx.PickupState.Item.ItemTable.CurrentItemHolder; var selectedItemHolder = ctx.SelectedItemHolder; if (previousItemHolder.Equals(selectedItemHolder)) { return true; } return false; } public class PlaceItemInGrid : ReleaseProcessor { protected override void HandleProcess(ReleaseContext ctx, ReleaseState finalState) { var selectedAbstractGrid = ctx.SelectedAbstractGrid; var selectedInventoryItem = ctx.PickupState.Item; var itemTable = selectedInventoryItem.ItemTable; var gridTable = selectedAbstractGrid.Grid; var ctxTileGridPosition = GetTileGridPosition(ctx); if (!ctxTileGridPosition.HasValue || CheckIfSamePosition(ctxTileGridPosition, ctx) == true) { finalState.Placed = false; return; } var posX = ctxTileGridPosition.Value.x; var posY = ctxTileGridPosition.Value.y; var inventoryMessages = gridTable.PlaceItem(itemTable, posX, posY); if (ctx.Debug) { Debug.Log(("Placing item in grid. Grid: " + selectedAbstractGrid + " Status: " + inventoryMessages) .DraggableSystem()); } finalState.Placed = inventoryMessages == GridResponse.Inserted; } // Add this code to validate if is the grid position private bool CheckIfSamePosition(Vector2Int? ctxTileGridPosition, ReleaseContext ctx) { Vector2Int? oldPos = new Vector2Int(ctx.PickupState.Item.ItemTable.OnGridPositionX, ctx.PickupState.Item.ItemTable.OnGridPositionY); if (oldPos.Equals(ctxTileGridPosition)) { return true; } return false; }
Cases:
/cc @rubenskj (grids,holders,items)
The suggestion is to add this ifs on the source code to not call the events again:
Cases: