private bool RequestControlInternal(EquiEntityControllerComponent controller, EquiPlayerAttachmentComponent.Slot controlled)
        {
            var desiredControlling = new ControlledId(controlled);

            if (_controlledToController.ContainsKey(desiredControlling))
            {
                return(false);
            }

            ControlledId currentlyControlling;

            if (_controllerToControlled.TryGetValue(controller.Entity.EntityId, out currentlyControlling))
            {
                if (currentlyControlling.Equals(controlled))
                {
                    return(true);
                }
                if (!ReleaseControlInternal(controller))
                {
                    return(false);
                }
            }

            return(controller.RequestControlInternal(controlled));
        }
        internal void RaiseControlledChange(EquiEntityControllerComponent controller, EquiPlayerAttachmentComponent.Slot controlledOld,
                                            EquiPlayerAttachmentComponent.Slot controlledNew)
        {
            ControlledChanged?.Invoke(controller, controlledOld, controlledNew);

            if (controller.Entity == MyAPIGateway.Session.ControlledObject)
            {
                CheckAttachedControls();
            }
        }
        private bool ReleaseControlInternal(EquiEntityControllerComponent controller)
        {
            ControlledId currentlyControlling;

            if (!_controllerToControlled.TryGetValue(controller.Entity.EntityId, out currentlyControlling))
            {
                return(false);
            }

            return(controller.ReleaseControlInternal());
        }
 public void ReleaseControl(EquiEntityControllerComponent controller)
 {
     if (controller?.Entity == null || !controller.Entity.InScene)
     {
         return;
     }
     if (!MyMultiplayerModApi.Static.IsServer && controller.Entity != MyAPIGateway.Session.ControlledObject)
     {
         return;
     }
     if (MyAPIGateway.Multiplayer != null)
     {
         MyAPIGateway.Multiplayer.RaiseStaticEvent(x => DelReleaseControlServer, controller.Entity.EntityId);
     }
     else
     {
         ReleaseControlServer(controller.Entity.EntityId);
     }
 }
 public void RequestControl(EquiEntityControllerComponent controller, EquiPlayerAttachmentComponent.Slot controlled)
 {
     if (controller?.Entity == null || !controller.Entity.InScene)
     {
         return;
     }
     if (controlled?.Controllable?.Entity == null || !controlled.Controllable.Entity.InScene)
     {
         return;
     }
     if (!MyMultiplayerModApi.Static.IsServer && controller.Entity != MyAPIGateway.Session.ControlledObject)
     {
         return;
     }
     if (MyAPIGateway.Multiplayer != null)
     {
         MyAPIGateway.Multiplayer.RaiseStaticEvent(x => DelRequestControlServer, controller.Entity.EntityId, controlled.Controllable.Entity.EntityId,
                                                   controlled.Definition.Name);
     }
     else
     {
         RequestControlServer(controller.Entity.EntityId, controlled.Controllable.Entity.EntityId, controlled.Definition.Name);
     }
 }