Exemplo n.º 1
0
        static void PatchedSplitStack(Stackable __instance, Interaction interaction, int quantity)
        {
            if (!GameManager.IsServer || quantity > __instance.Quantity)
            {
                return;
            }
            __instance.NetworkQuantity = __instance.Quantity - quantity;
            Human parent = interaction.SourceSlot.Parent as Human;

            if (parent == null)
            {
                return;
            }


            Stackable newStack = OnServer.Create(
                __instance.Prefab as DynamicThing,
                __instance.GetSafeDropPosition(
                    interaction.SourceSlot.Parent.CenterPosition,
                    parent.HelmetSlot.Location.forward,
                    interaction.SourceThing.Bounds.size.z + 0.6f
                    ),
                interaction.SourceThing.ThingTransform.rotation,
                __instance.OwnerSteamId,
                __instance.GridController.ParentMothership != null ? __instance.GridController.ParentMothership.RigidBody : null
                ) as Stackable;

            if (newStack != null)
            {
                if (__instance.CustomColor.IsSet)
                {
                    OnServer.SetCustomColor(newStack, __instance.CustomColor.Index);
                }
                newStack.NetworkQuantity = Mathf.Min(quantity, newStack.MaxQuantity);
                __instance.OnSplitStack(newStack);
                Slot destinationSlot   = parent.LeftHandSlot == interaction.SourceSlot ? parent.RightHandSlot : parent.LeftHandSlot;
                var  occupantStackable = destinationSlot.Occupant as Stackable;
                if (occupantStackable != null && occupantStackable.PrefabHash == newStack.PrefabHash)
                {
                    occupantStackable.Merge(newStack);
                }
                else if (destinationSlot.Occupant == null)
                {
                    // Stationeers orignal code:
                    //newStack.MoveToSlot(destinationSlot, newStack, false);
                    // Bug fix for clients not seeing stack moves:
                    OnServer.MoveToSlot(newStack, destinationSlot);
                }
            }
        }