static void UseSuccessCallback(MySyncControllableEntity sync, ref UseObject_UseMsg msg, MyNetworkClient sender)
        {
            MyEntity controlledEntity;

            if (MyEntities.TryGetEntityById <MyEntity>(msg.UsedByEntityId, out controlledEntity))
            {
                var controllableEntity = controlledEntity as IMyControllableEntity;
                Debug.Assert(controllableEntity != null, "Controllable entity needs to get control from another controllable entity");

                if (controllableEntity != null)
                {
                    MyRelationsBetweenPlayerAndBlock relation = MyRelationsBetweenPlayerAndBlock.FactionShare;
                    var cubeBlock = sync.Entity as MyCubeBlock;
                    if (cubeBlock != null && controllableEntity.ControllerInfo.Controller != null)
                    {
                        relation = cubeBlock.GetUserRelationToOwner(controllableEntity.ControllerInfo.Controller.Player.Identity.IdentityId);
                    }

                    if (relation == MyRelationsBetweenPlayerAndBlock.FactionShare || relation == MyRelationsBetweenPlayerAndBlock.Owner)
                    {
                        sync.RaiseUseSuccess(msg.UseAction, controllableEntity);
                    }
                    else
                    {
                        sync.RaiseUseFailure(msg.UseAction, msg.UseResult, controllableEntity);
                    }
                }
            }
        }
        static void UseFailureCallback(MySyncControllableEntity sync, ref UseObject_UseMsg msg, MyNetworkClient sender)
        {
            MyEntity controlledEntity;
            bool     userFound = MyEntities.TryGetEntityById <MyEntity>(msg.UsedByEntityId, out controlledEntity);

            Debug.Assert(userFound);
            IMyControllableEntity controllableEntity = controlledEntity as IMyControllableEntity;

            Debug.Assert(controllableEntity != null, "Controllable entity needs to get control from another controllable entity");
            sync.RaiseUseFailure(msg.UseAction, msg.UseResult, controllableEntity);
        }
        public virtual void RequestUse(UseActionEnum actionEnum, IMyControllableEntity usedBy)
        {
            Debug.Assert(Entity is IMyUsableEntity, "Entity must implement IMyUsableEntity to use it");

            UseObject_UseMsg msg = new UseObject_UseMsg();

            msg.EntityId       = SyncedEntityId;
            msg.UseAction      = actionEnum;
            msg.UsedByEntityId = usedBy.Entity.EntityId;

            MySession.Static.SyncLayer.SendMessageToServer(ref msg);
        }
        static void UseRequestCallback(MySyncEntity sync, ref UseObject_UseMsg msg, MyNetworkClient sender)
        {
            var      usableEntity = sync.Entity as IMyUsableEntity;
            MyEntity controlledEntity;
            bool     entityExists = MyEntities.TryGetEntityById <MyEntity>(msg.UsedByEntityId, out controlledEntity);
            IMyControllableEntity controllableEntity = controlledEntity as IMyControllableEntity;

            Debug.Assert(controllableEntity != null, "Controllable entity needs to get control from another controllable entity");
            Debug.Assert(entityExists && usableEntity != null);

            if (entityExists && usableEntity != null && (msg.UseResult = usableEntity.CanUse(msg.UseAction, controllableEntity)) == UseActionResult.OK)
            {
                MySession.Static.SyncLayer.SendMessageToAll(ref msg, MyTransportMessageEnum.Success);
                UseSuccessCallback(sync as MySyncControllableEntity, ref msg, Sync.Clients.LocalClient);
            }
            else
            {
                MySession.Static.SyncLayer.SendMessage(ref msg, sender.SteamUserId, MyTransportMessageEnum.Failure);
            }
        }
        static void UseSuccessCallback(MySyncControllableEntity sync, ref UseObject_UseMsg msg, MyNetworkClient sender)
        {
            MyEntity controlledEntity;
            if (MyEntities.TryGetEntityById<MyEntity>(msg.UsedByEntityId, out controlledEntity))
            {
                var controllableEntity = controlledEntity as IMyControllableEntity;
                Debug.Assert(controllableEntity != null, "Controllable entity needs to get control from another controllable entity");

                if (controllableEntity != null)
                {
                    MyRelationsBetweenPlayerAndBlock relation = MyRelationsBetweenPlayerAndBlock.NoOwnership;
                    var cubeBlock = sync.Entity as MyCubeBlock;
                    if (cubeBlock != null && controllableEntity.ControllerInfo.Controller != null)
                    {
                        relation = cubeBlock.GetUserRelationToOwner(controllableEntity.ControllerInfo.Controller.Player.Identity.IdentityId);
                    }

                    if (relation.IsFriendly())
                    {
                        sync.RaiseUseSuccess(msg.UseAction, controllableEntity);
                    }
                    else
                    {
                        sync.RaiseUseFailure(msg.UseAction, msg.UseResult, controllableEntity);
                    }
                }
            }
        }
 static void UseFailureCallback(MySyncControllableEntity sync, ref UseObject_UseMsg msg, MyNetworkClient sender)
 {
     MyEntity controlledEntity;
     bool userFound = MyEntities.TryGetEntityById<MyEntity>(msg.UsedByEntityId, out controlledEntity);
     Debug.Assert(userFound);
     IMyControllableEntity controllableEntity = controlledEntity as IMyControllableEntity;
     Debug.Assert(controllableEntity != null, "Controllable entity needs to get control from another controllable entity");
     sync.RaiseUseFailure(msg.UseAction, msg.UseResult, controllableEntity);
 }
        static void UseRequestCallback(MySyncEntity sync, ref UseObject_UseMsg msg, MyNetworkClient sender)
        {
            var usableEntity = sync.Entity as IMyUsableEntity;
            MyEntity controlledEntity;
            bool entityExists = MyEntities.TryGetEntityById<MyEntity>(msg.UsedByEntityId, out controlledEntity);
            IMyControllableEntity controllableEntity = controlledEntity as IMyControllableEntity;
            Debug.Assert(controllableEntity != null, "Controllable entity needs to get control from another controllable entity");
            Debug.Assert(entityExists && usableEntity != null);

            if (entityExists && usableEntity != null && (msg.UseResult = usableEntity.CanUse(msg.UseAction, controllableEntity)) == UseActionResult.OK)
            {
                MySession.Static.SyncLayer.SendMessageToAll(ref msg, MyTransportMessageEnum.Success);
                UseSuccessCallback(sync as MySyncControllableEntity, ref msg, Sync.Clients.LocalClient);
            }
            else
            {
                MySession.Static.SyncLayer.SendMessage(ref msg, sender.SteamUserId, MyTransportMessageEnum.Failure);
            }
        }
        public virtual void RequestUse(UseActionEnum actionEnum, IMyControllableEntity usedBy)
        {
            Debug.Assert(Entity is IMyUsableEntity, "Entity must implement IMyUsableEntity to use it");

            UseObject_UseMsg msg = new UseObject_UseMsg();
            msg.EntityId = SyncedEntityId;
            msg.UseAction = actionEnum;
            msg.UsedByEntityId = usedBy.Entity.EntityId;

            MySession.Static.SyncLayer.SendMessageToServer(ref msg);
        }