Пример #1
0
        public void Undock()
        {
            if (dockingTarget == null || !docked)
            {
                return;
            }

#if CLIENT
            PlaySound(ActionType.OnUse, item.WorldPosition);
#endif

            dockingTarget.item.Submarine.DockedTo.Remove(item.Submarine);
            item.Submarine.DockedTo.Remove(dockingTarget.item.Submarine);

            //remove all waypoint links between this sub and the dockingtarget
            foreach (WayPoint wp in WayPoint.WayPointList)
            {
                if (wp.Submarine != item.Submarine || wp.SpawnType != SpawnType.Path)
                {
                    continue;
                }

                for (int i = wp.linkedTo.Count - 1; i >= 0; i--)
                {
                    var wp2 = wp.linkedTo[i] as WayPoint;
                    if (wp2 == null)
                    {
                        continue;
                    }

                    if (wp.Submarine == dockingTarget.item.Submarine)
                    {
                        wp.linkedTo.RemoveAt(i);
                        wp2.linkedTo.Remove(wp);
                    }
                }
            }

            item.linkedTo.Clear();

            docked = false;

            dockingTarget.Undock();
            dockingTarget = null;

            if (doorBody != null)
            {
                GameMain.World.RemoveBody(doorBody);
                doorBody = null;
            }

            var wire = item.GetComponent <Wire>();
            if (wire != null)
            {
                wire.Drop(null);
            }

            if (joint != null)
            {
                GameMain.World.RemoveJoint(joint);
                joint = null;
            }

            if (hulls != null)
            {
                hulls[0].Remove();
                hulls[1].Remove();
                hulls = null;
            }

            if (gap != null)
            {
                gap.Remove();
                gap = null;
            }

            hullIds[0] = null;
            hullIds[1] = null;

            gapId = null;

            if (bodies != null)
            {
                foreach (Body body in bodies)
                {
                    if (body == null)
                    {
                        continue;
                    }
                    GameMain.World.RemoveBody(body);
                }
                bodies = null;
            }

            if (GameMain.Server != null)
            {
                item.CreateServerEvent(this);
            }
        }
Пример #2
0
        public void Undock()
        {
            if (dockingTarget == null || !docked)
            {
                return;
            }

#if CLIENT
            PlaySound(ActionType.OnUse, item.WorldPosition);
#endif

            dockingTarget.item.Submarine.DockedTo.Remove(item.Submarine);
            item.Submarine.DockedTo.Remove(dockingTarget.item.Submarine);

            if (door != null && dockingTarget.door != null)
            {
                WayPoint myWayPoint     = WayPoint.WayPointList.Find(wp => door.LinkedGap == wp.ConnectedGap);
                WayPoint targetWayPoint = WayPoint.WayPointList.Find(wp => dockingTarget.door.LinkedGap == wp.ConnectedGap);

                if (myWayPoint != null && targetWayPoint != null)
                {
                    myWayPoint.linkedTo.Remove(targetWayPoint);
                    targetWayPoint.linkedTo.Remove(myWayPoint);
                }
            }

            item.linkedTo.Clear();

            docked = false;

            dockingTarget.Undock();
            dockingTarget = null;

            if (doorBody != null)
            {
                GameMain.World.RemoveBody(doorBody);
                doorBody = null;
            }

            var wire = item.GetComponent <Wire>();
            if (wire != null)
            {
                wire.Drop(null);
            }

            if (joint != null)
            {
                GameMain.World.RemoveJoint(joint);
                joint = null;
            }

            hulls[0]?.Remove(); hulls[0] = null;
            hulls[1]?.Remove(); hulls[1] = null;

            if (gap != null)
            {
                gap.Remove();
                gap = null;
            }

            if (bodies != null)
            {
                foreach (Body body in bodies)
                {
                    if (body == null)
                    {
                        continue;
                    }
                    GameMain.World.RemoveBody(body);
                }
                bodies = null;
            }

            if (GameMain.Server != null)
            {
                item.CreateServerEvent(this);
            }
        }