コード例 #1
0
 public override void OnCustomImportFinished()
 {
     base.OnCustomImportFinished();
     if (!!GameManager.IsServer)
     {
         if (ImportingThing)
         {
             foreach (Slot slot in Slots)
             {
                 bool isInteractable = slot.IsInteractable;
                 if (!isInteractable)
                 {
                     if (!slot.Occupant)
                     {
                         OnServer.MoveToSlot(ImportingThing, slot);
                         break;
                     }
                 }
             }
         }
         OnServer.Interact(InteractImport, 0, false);
         if (!(GameManager.GameState != GameState.Running))
         {
             if (!CurrentSlot.Occupant)
             {
                 PlanForward();
             }
         }
     }
 }
コード例 #2
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);
                }
            }
        }
コード例 #3
0
        private IEnumerator WaitSetRequestFromHash(int hash)
        {
            int index = SetRequestFromHash(hash);

            if (index >= 2)
            {
                while (!Powered || IsLocked)
                {
                    yield return(_waitForFrame);
                }
                OnServer.Interact(InteractLock, 1, false);
                NetworkCurrentIndex = index;
                yield return(_waitForDelay);

                OnServer.MoveToSlot(CurrentSlot.Occupant, ExportSlot);
                OnServer.Interact(InteractExport, 1, false);
                RequestedHash = 0;
                OnServer.Interact(InteractLock, 0, false);
            }
            yield break;
        }
コード例 #4
0
 public override DelayedActionInstance InteractWith(Interactable interactable, Interaction interaction, bool doAction = true)
 {
     if (interactable.Action == InteractableType.Activate || interactable.Action == InteractableType.Button1 || interactable.Action == InteractableType.Button2)
     {
         DelayedActionInstance delayedActionInstance = new DelayedActionInstance {
             Duration      = 0f,
             ActionMessage = interactable.ContextualName
         };
         bool isLocked = IsLocked;
         if (isLocked)
         {
             return(delayedActionInstance.Fail(HelpTextDevice.DeviceLocked));
         }
         if (!IsAuthorized(interaction.SourceThing))
         {
             return(delayedActionInstance.Fail(Localization.ParseTooltip("Unable to interact as you do not have the required {SLOT:AccessCard}", false)));
         }
         if (!OnOff)
         {
             return(delayedActionInstance.Fail(HelpTextDevice.DeviceNotOn));
         }
         if (!Powered)
         {
             return(delayedActionInstance.Fail(HelpTextDevice.DeviceNoPower));
         }
         if (Exporting != 0)
         {
             return(delayedActionInstance.Fail(HelpTextDevice.DeviceLocked));
         }
         if (interactable.Action == InteractableType.Activate)
         {
             if (!CurrentSlot.Occupant || !HasSomething)
             {
                 return(delayedActionInstance.Fail("Nothing selected to dispense"));
             }
             if (!doAction)
             {
                 return(delayedActionInstance.Succeed());
             }
             bool isServer = GameManager.IsServer;
             if (isServer)
             {
                 OnServer.MoveToSlot(CurrentSlot.Occupant, ExportSlot);
                 OnServer.Interact(InteractExport, 1, false);
             }
             return(delayedActionInstance.Succeed());
         }
         else
         {
             if ((interactable.Action == InteractableType.Button1 || interactable.Action == InteractableType.Button2) && KeyManager.GetButton(KeyMap.QuantityModifier))
             {
                 if (!HasSomething)
                 {
                     delayedActionInstance.ActionMessage = "Access Inventory List";
                     return(delayedActionInstance.Fail("Nothing inside to list"));
                 }
                 if (!doAction)
                 {
                     return(delayedActionInstance.Succeed());
                 }
                 foreach (int key in InputPrefabs.PrefabReferences.Keys)
                 {
                     InputPrefabs.PrefabReferences[key].SetVisible(false);
                 }
                 if (InputPrefabs.ShowInputPanel("Vending Machine", null, GetDynamicThings(), MachineTier.Max))
                 {
                     InputPrefabs.OnSubmit += InputFinished;
                 }
                 return(delayedActionInstance.Succeed());
             }
             else if (interactable.Action == InteractableType.Button1)
             {
                 if (!HasSomething)
                 {
                     delayedActionInstance.ActionMessage = ActionStrings.Down;
                     return(delayedActionInstance.Fail("Nothing inside to change too"));
                 }
                 Slot slot = SamplePlanBackward();
                 delayedActionInstance.StateMessage = string.Format(InterfaceStrings.ChangeSettingTo, slot.Occupant ? slot.Occupant.ToTooltip() : CurrentSlot.ToTooltip());
                 if (!doAction)
                 {
                     return(delayedActionInstance.Succeed());
                 }
                 bool isServer2 = GameManager.IsServer;
                 if (isServer2)
                 {
                     PlanBackward();
                 }
                 return(delayedActionInstance.Succeed());
             }
             else if (interactable.Action == InteractableType.Button2)
             {
                 if (!HasSomething)
                 {
                     delayedActionInstance.ActionMessage = ActionStrings.Up;
                     return(delayedActionInstance.Fail("Nothing inside to change too"));
                 }
                 Slot slot2 = SamplePlanForward();
                 delayedActionInstance.StateMessage = string.Format(InterfaceStrings.ChangeSettingTo, slot2.Occupant ? slot2.Occupant.ToTooltip() : CurrentSlot.ToTooltip());
                 if (!doAction)
                 {
                     return(delayedActionInstance.Succeed());
                 }
                 bool isServer3 = GameManager.IsServer;
                 if (isServer3)
                 {
                     PlanForward();
                 }
                 return(delayedActionInstance.Succeed());
             }
         }
     }
     return(base.InteractWith(interactable, interaction, doAction));
 }
コード例 #5
0
        static void PatchedOnCustomImportFinished(VendingMachine __instance)
        {
            VendingMachineOnCustomImportFinishedPatch.CallBaseCustomImportFinished(__instance);

            if (!GameManager.IsServer)
            {
                return;
            }

            if (__instance.ImportingThing)
            {
                var importing   = __instance.ImportingThing;
                var skipNewSlot = false;

                var importingStackable = __instance.ImportingThing as Stackable;
                if (importingStackable)
                {
                    foreach (Slot slot in __instance.Slots)
                    {
                        if (slot.IsInteractable)
                        {
                            continue;
                        }

                        var occupant = slot.Occupant as Stackable;
                        if (!occupant)
                        {
                            continue;
                        }

                        if (occupant.PrefabName != importingStackable.PrefabName)
                        {
                            continue;
                        }

                        OnServer.Merge(occupant, importingStackable);
                        if (importingStackable.NetworkQuantity == 0)
                        {
                            // Skip adding the now-empty item if we are empty.
                            // The empty stack was already deleted when its quantity was set to zero.
                            skipNewSlot = true;
                        }
                        else
                        {
                            // It is possible for us to not be empty, in which case a new slot should be started.
                        }

                        break;
                    }
                }

                if (!skipNewSlot)
                {
                    foreach (Slot slot in __instance.Slots)
                    {
                        if (!slot.IsInteractable && !slot.Occupant)
                        {
                            OnServer.MoveToSlot(__instance.ImportingThing, slot);
                            break;
                        }
                    }
                }
            }

            OnServer.Interact(__instance.InteractImport, 0, false);

            if (GameManager.GameState == GameState.Running && !__instance.CurrentSlot.Occupant)
            {
                __instance.PlanForward();
            }
        }