public void ProcessCustomInteraction(GameObject Player, RequestHackingInteraction.InteractionWith InteractionType, uint Referenceobject, int PanelInputID, int PanelOutputID) { PlayerScript PlayerScript = Player.GetComponent <PlayerScript>(); if (Validations.CanInteract(PlayerScript, NetworkSide.Server) == false) { return; } switch (InteractionType) { case RequestHackingInteraction.InteractionWith.CutWire: if (Validations.HasItemTrait(PlayerScript.DynamicItemStorage.GetActiveHandSlot().ItemObject, CommonTraits.Instance.Wirecutter) == false) { return; } Cable Cable = null; foreach (var cable in Cables) { if (cable?.cableCoilID == Referenceobject) { Cable = cable; break; } } if (Cable == null) { Logger.LogWarning("No cable was found for cutting", Category.Interaction); return; } Connections[Cable.PanelOutput].Remove(Cable); Cables.Remove(Cable); var Spawned = Spawn.ServerPrefab(OnePeaceCoil.gameObject).GameObject; var Hand = PlayerScript.DynamicItemStorage.GetBestHand(Spawned.GetComponent <Stackable>()); if (Hand == null) { Spawned.GetComponent <CustomNetTransform>().AppearAtPositionServer(PlayerScript.WorldPos - this.GetComponent <RegisterTile>().WorldPositionServer); } else { Inventory.ServerAdd(Spawned, Hand); } OnChangeServer.Invoke(); break; case RequestHackingInteraction.InteractionWith.Cable: //Please cable do not Spare thing if (Validations.HasItemTrait(PlayerScript.DynamicItemStorage.GetActiveHandSlot().ItemObject, CommonTraits.Instance.Cable) == false) { return; } LocalPortData LocalPortOutput = null; foreach (var kPortData in DictionaryCurrentPorts) { if (kPortData.Value.LocalID == PanelOutputID) { LocalPortOutput = kPortData.Value; } } LocalPortData LocalPortInput = null; foreach (var kPortData in DictionaryCurrentPorts) { if (kPortData.Value.LocalID == PanelInputID) { LocalPortInput = kPortData.Value; } } foreach (var cable in Cables) { if (LocalPortInput.LocalAction == cable.PanelInput && LocalPortOutput.LocalAction == cable.PanelOutput) { return; //Cable Already at position } } var stackable = PlayerScript.DynamicItemStorage.GetActiveHandSlot().Item.GetComponent <Stackable>(); stackable.ServerConsume(1); var insertCable = new Cable(); CableID++; insertCable.cableCoilID = CableID; Cables.Add(insertCable); insertCable.PanelInput = LocalPortInput.LocalAction; insertCable.PanelOutput = LocalPortOutput.LocalAction; if (Connections.ContainsKey(insertCable.PanelOutput) == false) { Connections[insertCable.PanelOutput] = new List <Cable>(); } Connections[insertCable.PanelOutput].Add(insertCable); OnChangeServer.Invoke(); break; } }
public void ProcessCustomInteraction(GameObject Player, RequestHackingInteraction.InteractionWith InteractionType, GameObject Referenceobject, int PanelInputID, int PanelOutputID) { PlayerScript PlayerScript = Player.GetComponent <PlayerScript>(); if (Validations.CanInteract(PlayerScript, NetworkSide.Server) == false) { return; } switch (InteractionType) { case RequestHackingInteraction.InteractionWith.CutWire: if (Validations.HasItemTrait(PlayerScript.DynamicItemStorage.GetActiveHandSlot().ItemObject, CommonTraits.Instance.Wirecutter) == false) { return; } Cable Cable = null; foreach (var cable in Cables) { if (cable?.cableCoil.gameObject == Referenceobject) { Cable = cable; break; } } if (Cable == null) { Logger.LogWarning("No cable was found for cutting", Category.Interaction); return; } Connections[Cable.PanelOutput].Remove(Cable); Cables.Remove(Cable); var Hand = PlayerScript.DynamicItemStorage.GetBestHand(Cable.cableCoil.GetComponent <Stackable>()); if (Hand == null) { itemStorage.ServerTryRemove(Cable.cableCoil.gameObject, DroppedAtWorldPosition: (PlayerScript.WorldPos - this.GetComponent <RegisterTile>().WorldPositionServer)); } else { itemStorage.ServerTransferGameObjectToItemSlot(Cable.cableCoil.gameObject, Hand); } OnChangeServer.Invoke(); break; case RequestHackingInteraction.InteractionWith.Cable: //Please cable do not Spare thing if (Validations.HasItemTrait(PlayerScript.DynamicItemStorage.GetActiveHandSlot().ItemObject, CommonTraits.Instance.Cable) == false) { return; } LocalPortData LocalPortOutput = null; foreach (var kPortData in DictionaryCurrentPorts) { if (kPortData.Value.LocalID == PanelOutputID) { LocalPortOutput = kPortData.Value; } } LocalPortData LocalPortInput = null; foreach (var kPortData in DictionaryCurrentPorts) { if (kPortData.Value.LocalID == PanelInputID) { LocalPortInput = kPortData.Value; } } foreach (var cable in Cables) { if (LocalPortInput.LocalAction == cable.PanelInput && LocalPortOutput.LocalAction == cable.PanelOutput) { return; //Cable Already at position } } var stackable = Referenceobject.GetComponent <Stackable>(); var OnePeace = stackable.ServerRemoveOne(); if (OnePeace == stackable.gameObject) { ItemSlot SpareSlot = null; foreach (var TitemSlot in itemStorage.GetItemSlots()) { if (TitemSlot.Item == null) { SpareSlot = TitemSlot; break; } } Inventory.ServerTransfer(PlayerScript.DynamicItemStorage.GetActiveHandSlot(), SpareSlot); } else { AddObjectToItemStorage(OnePeace); } var newCable = OnePeace.GetComponent <CableCoil>(); var insertCable = new Cable(); insertCable.cableCoil = newCable; Cables.Add(insertCable); insertCable.PanelInput = LocalPortInput.LocalAction; insertCable.PanelOutput = LocalPortOutput.LocalAction; if (Connections.ContainsKey(insertCable.PanelOutput) == false) { Connections[insertCable.PanelOutput] = new List <Cable>(); } Connections[insertCable.PanelOutput].Add(insertCable); OnChangeServer.Invoke(); break; } }