Example #1
0
    private void OnItemSelected(Ground item, BaseItem occupant = null)
    {
        if (item == null)
        {
            return;
        }

        BaseItem playerDestination = null;
        var      isQueue           = false;

        if (player.isMoving /* || warehouseManager.HasMovingItems*/)
        {
            isQueue           = true;
            playerDestination = player.warehouseDestination ?? player.parent;
        }
        else
        {
            playerDestination = player;
        }

        var distanceFromDestination = item.Distance(playerDestination);
        var intendedMovement        = distanceFromDestination.AsMovementType();

        if (intendedMovement == null ||
            item?.WarehouseIndex == null)
        {
            Debug.Log($"Player movement-queue failed sanity check ({distanceFromDestination.ToString()})");
            return;
        }

        var destination     = item.WarehouseIndex.Value;
        var inboundOccupant = this.warehouseManager.GetInboundOccupant(destination);

        if (inboundOccupant != null ||
            !this.warehouseManager.IsTraversable(destination, intendedMovement.Value, player.PushStrength))
        {
            Debug.Log($"Player movement-queue failed traversable check ({inboundOccupant?.gameObject?.name ?? destination.ToString()})");
            return;
        }

        Debug.Log($"Movement from player {intendedMovement.ToString()} ({(isQueue ? "Queue: " : "")}{distanceFromDestination.ToString()})");

        if (isQueue)
        {
            player.warehouseDestinationQueue = item;
        }
        else
        {
            player.warehouseDestination = item;
        }
    }