public void AttachToWall() { if (!attachable) { return; } //outside hulls/subs -> we need to check if the item is being attached on a structure outside the sub if (item.CurrentHull == null && item.Submarine == null) { Structure attachTarget = Structure.GetAttachTarget(item.WorldPosition); if (attachTarget != null) { if (attachTarget.Submarine != null) { //set to submarine-relative position item.SetTransform(ConvertUnits.ToSimUnits(item.WorldPosition - attachTarget.Submarine.Position), 0.0f, false); } item.Submarine = attachTarget.Submarine; } else { attachTargetCell = GetAttachTargetCell(150.0f); if (attachTargetCell != null) { IsActive = true; } } } var containedItems = item.OwnInventory?.Items; if (containedItems != null) { foreach (Item contained in containedItems) { if (contained == null) { continue; } if (contained.body == null) { continue; } contained.SetTransform(item.SimPosition, contained.body.Rotation); } } body.Enabled = false; item.body = null; DisplayMsg = prevMsg; PickKey = prevPickKey; requiredItems = new Dictionary <RelatedItem.RelationType, List <RelatedItem> >(prevRequiredItems); Attached = true; }
protected override void RemoveComponentSpecific() { base.RemoveComponentSpecific(); attachTargetCell = null; if (Pusher != null) { Pusher.Remove(); Pusher = null; } body = null; }
public void DeattachFromWall() { if (!attachable) { return; } Attached = false; attachTargetCell = null; //make the item pickable with the default pick key and with no specific tools/items when it's deattached requiredItems.Clear(); DisplayMsg = ""; PickKey = InputType.Select; }
private void Drop(bool dropConnectedWires, Character dropper) { if (dropConnectedWires) { DropConnectedWires(dropper); } if (attachable) { DeattachFromWall(); if (body != null) { item.body = body; } } if (Pusher != null) { Pusher.Enabled = false; } if (item.body != null) { item.body.Enabled = true; } IsActive = false; attachTargetCell = null; if (picker == null || picker.Removed) { if (dropper == null || dropper.Removed) { return; } picker = dropper; } if (picker.Inventory == null) { return; } item.Submarine = picker.Submarine; if (item.body != null) { if (item.body.Removed) { DebugConsole.ThrowError( "Failed to drop the Holdable component of the item \"" + item.Name + "\" (body has been removed" + (item.Removed ? ", item has been removed)" : ")")); } else { item.body.ResetDynamics(); Limb heldHand, arm; if (picker.Inventory.IsInLimbSlot(item, InvSlotType.LeftHand)) { heldHand = picker.AnimController.GetLimb(LimbType.LeftHand); arm = picker.AnimController.GetLimb(LimbType.LeftArm); } else { heldHand = picker.AnimController.GetLimb(LimbType.RightHand); arm = picker.AnimController.GetLimb(LimbType.RightArm); } if (heldHand != null && !heldHand.Removed && arm != null && !arm.Removed) { //hand simPosition is actually in the wrist so need to move the item out from it slightly Vector2 diff = new Vector2( (heldHand.SimPosition.X - arm.SimPosition.X) / 2f, (heldHand.SimPosition.Y - arm.SimPosition.Y) / 2.5f); item.SetTransform(heldHand.SimPosition + diff, 0.0f); } else { item.SetTransform(picker.SimPosition, 0.0f); } } } picker.DeselectItem(item); picker.Inventory.RemoveItem(item); picker = null; }