コード例 #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));
 }
        private static void Postfix(Structure __result, ref Structure ____hasSpawnedWreckage)
        {
            if (WorldManager.Instance.GameMode == GameMode.Creative)
            {
                int buildst  = __result.BuildStates.Count - 1;
                int colorcan = -1;                    //default color
                foreach (var chel in Human.AllHumans) //catch idea of search in lists from liz's AtomicBatteryPatch
                {
                    if (chel.OwnerSteamId == __result.OwnerSteamId)
                    {
                        Human parentHuman = null;
                        parentHuman = chel;
                        bool suitis = (parentHuman.Suit == null || parentHuman == null);
                        if (!suitis)
                        {
                            //Debug.LogError("Builder catched");

                            buildst = (int)(Math.Round(parentHuman.Suit.OutputTemperature - 293.15f));     //temperature +20C = CurrentBuildState 0

                            if (buildst >= __result.BuildStates.Count)
                            {
                                buildst = __result.BuildStates.Count - 1;
                            }

                            if (buildst > -1 && __result.BrokenBuildStates.Count > 0)
                            {
                                buildst = -1;
                                //  bool val = Traverse.Create(Structure.Get()).Field("_hasSpawnedWreckage").GetValue() as bool;
                                //  ____hasSpawnedWreckage = false;
                            }
                            else if (buildst > -1)
                            {
                                buildst = 0;
                            }

                            //Pipe pipe = __result.mission.GetThing(__result) as Pipe;
                            //bool flag2 = pipe == null;
                            ///TODOrecognize pipes and cables and spawn their break versions at -1
                            ///from BurstPipeEventAction and BreakCableEventAction

                            colorcan = (int)(Math.Round(parentHuman.Suit.OutputSetting - 51f)); //pressure 50 =  CustomColorIndex -1 default
                            if (colorcan > 11)
                            {
                                colorcan = 11;
                            }
                            else if (colorcan < -1)
                            {
                                colorcan = -1;
                            }
                        }
                    }
                }
                __result.UpdateBuildStateAndVisualizer(buildst, 0);
                //thanks to inaki for missed lib com.unity.multiplayer-hlapi.Runtime.dll

                if (__result.PaintableMaterial != null)
                {
                    OnServer.SetCustomColor(__result, colorcan);
                }
            }
        }
        private static bool Prefix(NetworkInstanceId parentId, ulong ownerSteamId, string prefabName)
        {
            DynamicThing dynamicThing  = NetworkThing.Find(parentId) as DynamicThing;
            DynamicThing dynamicThing2 = (DynamicThing)Thing.FindPrefab(prefabName);
            bool         flag          = !dynamicThing2;

            if (!flag)
            {
                Vector3      vector        = dynamicThing.RigidBody.worldCenterOfMass + dynamicThing.ThingTransform.forward * 1f;
                Quaternion   rotation      = Quaternion.AngleAxis(180f, dynamicThing.ThingTransform.up);
                DynamicThing dynamicThing3 = OnServer.Create(dynamicThing2, vector, rotation, ownerSteamId, null);
                Stackable    stackable     = dynamicThing3 as Stackable;
                bool         flag2         = stackable;
                if (flag2)
                {
                    stackable.NetworkQuantity = stackable.MaxQuantity;
                }
                BatteryCell batteryCell = dynamicThing3 as BatteryCell;
                bool        flag3       = batteryCell;
                if (flag3)
                {
                    batteryCell.PowerStored = batteryCell.PowerMaximum;
                }
                Ingot ingot = dynamicThing3 as Ingot;
                bool  flag4 = ingot;
                if (flag4)
                {
                    ingot.NetworkQuantity = ingot.MaxQuantity;
                }
                CreditCard creditCard = dynamicThing3 as CreditCard;
                bool       flag5      = creditCard;
                if (flag5)
                {
                    creditCard.Currency = 8000f;
                }
                DirtCanister dirtCanister = dynamicThing3 as DirtCanister;
                bool         flag6        = dirtCanister;
                if (flag6)
                {
                    dirtCanister.AddDirtCheat(8000f);
                }

                //Creative mode addition
                if (WorldManager.Instance.GameMode == GameMode.Creative)
                {
                    int colorcan = -1;
                    foreach (var chel in Human.AllHumans) //catch idea of search in lists from liz's AtomicBatteryPatch
                    {
                        if (chel.OwnerSteamId == dynamicThing3.OwnerSteamId)
                        {
                            Human parentHuman = null;
                            parentHuman = chel;
                            bool suitis = (parentHuman.Suit == null || parentHuman == null);
                            if (!suitis)
                            {
                                //Debug.LogError("Builder catched");
                                colorcan = (int)(Math.Round(parentHuman.Suit.OutputSetting - 51f)); //pressure 50 = CustomColorIndex -1 default
                                if (colorcan > 11)
                                {
                                    colorcan = 11;
                                }
                                else if (colorcan < -1)
                                {
                                    colorcan = -1;
                                }
                            }
                        }
                    }
                    if (dynamicThing3.PaintableMaterial != null)
                    {
                        OnServer.SetCustomColor(dynamicThing3, colorcan);
                    }
                }
            }


            return(false);
        }
コード例 #7
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();
            }
        }