public static bool Prefix(DockedVehicleHandTarget __instance, GUIHand hand)
        {
            vehicleDockingBay = __instance.dockingBay;
            Vehicle vehicle = vehicleDockingBay.GetDockedVehicle();

            if (skipPrefix || vehicle == null)
            {
                return(true);
            }

            dockedVehicle = __instance;
            guiHand       = hand;

            SimulationOwnership simulationOwnership = NitroxServiceLocator.LocateService <SimulationOwnership>();

            NitroxId id = NitroxEntity.GetId(vehicle.gameObject);

            if (simulationOwnership.HasExclusiveLock(id))
            {
                Log.Debug($"Already have an exclusive lock on this vehicle: {id}");
                return(true);
            }

            simulationOwnership.RequestSimulationLock(id, SimulationLockType.EXCLUSIVE, ReceivedSimulationLockResponse);

            return(false);
        }
示例#2
0
        public override void Process(SimulationOwnershipChange simulationOwnershipChange)
        {
            foreach (SimulatedEntity simulatedEntity in simulationOwnershipChange.Entities)
            {
                if (multiplayerSession.Reservation.PlayerId == simulatedEntity.PlayerId)
                {
                    if (simulatedEntity.ChangesPosition)
                    {
                        StartBroadcastingEntityPosition(simulatedEntity.Id);
                    }

                    simulationOwnershipManager.SimulateEntity(simulatedEntity.Id, SimulationLockType.TRANSIENT);
                }
                else if (simulationOwnershipManager.HasAnyLockType(simulatedEntity.Id))
                {
                    // The server has forcibly removed this lock from the client.  This is generally fine for
                    // transient locks because it is only broadcasting position.  However, exclusive locks may
                    // need additional cleanup (such as a person piloting a vehicle - they need to be kicked out)
                    // We can later add a forcibly removed callback but as of right now we have no use-cases for
                    // forcibly removing an exclusive lock.  Just log it if it happens....

                    if (simulationOwnershipManager.HasExclusiveLock(simulatedEntity.Id))
                    {
                        Log.Warn("The server has forcibly revoked an exlusive lock - this may cause undefined behaviour.  GUID: " + simulatedEntity.Id);
                    }

                    simulationOwnershipManager.StopSimulatingEntity(simulatedEntity.Id);
                    EntityPositionBroadcaster.StopWatchingEntity(simulatedEntity.Id);
                }
            }
        }
        public static bool Prefix(PilotingChair __instance, GUIHand hand)
        {
            if (skipPrefix)
            {
                return(true);
            }

            SimulationOwnership simulationOwnership = NitroxServiceLocator.LocateService <SimulationOwnership>();

            SubRoot subRoot = __instance.GetComponentInParent <SubRoot>();

            Validate.NotNull(subRoot, "PilotingChair cannot find it's corresponding SubRoot!");
            NitroxId id = NitroxEntity.GetId(subRoot.gameObject);

            if (simulationOwnership.HasExclusiveLock(id))
            {
                Log.Debug($"Already have an exclusive lock on the piloting chair: {id}");
                return(true);
            }

            HandInteraction <PilotingChair> context = new HandInteraction <PilotingChair>(__instance, hand);
            LockRequest <HandInteraction <PilotingChair> > lockRequest = new LockRequest <HandInteraction <PilotingChair> >(id, SimulationLockType.EXCLUSIVE, ReceivedSimulationLockResponse, context);

            simulationOwnership.RequestSimulationLock(lockRequest);

            return(false);
        }
        public static bool Prefix(DockedVehicleHandTarget __instance, GUIHand hand)
        {
            Vehicle vehicle = __instance.dockingBay.GetDockedVehicle();

            if (skipPrefix || vehicle == null)
            {
                return(true);
            }

            SimulationOwnership simulationOwnership = NitroxServiceLocator.LocateService <SimulationOwnership>();

            NitroxId id = NitroxEntity.GetId(vehicle.gameObject);

            if (simulationOwnership.HasExclusiveLock(id))
            {
                Log.Debug($"Already have an exclusive lock on this vehicle: {id}");
                return(true);
            }

            HandInteraction <DockedVehicleHandTarget> context = new HandInteraction <DockedVehicleHandTarget>(__instance, hand);
            LockRequest <HandInteraction <DockedVehicleHandTarget> > lockRequest = new LockRequest <HandInteraction <DockedVehicleHandTarget> >(id, SimulationLockType.EXCLUSIVE, ReceivedSimulationLockResponse, context);

            simulationOwnership.RequestSimulationLock(lockRequest);

            return(false);
        }
示例#5
0
        public static bool Prefix(PilotingChair __instance, GUIHand hand)
        {
            if (skipPrefix)
            {
                return(true);
            }

            pilotingChair = __instance;
            guiHand       = hand;

            SimulationOwnership simulationOwnership = NitroxServiceLocator.LocateService <SimulationOwnership>();

            SubRoot subRoot = __instance.GetComponentInParent <SubRoot>();

            Validate.NotNull(subRoot, "PilotingChair cannot find it's corresponding SubRoot!");
            string guid = GuidHelper.GetGuid(subRoot.gameObject);

            if (simulationOwnership.HasExclusiveLock(guid))
            {
                Log.Debug($"Already have an exclusive lock on the piloting chair: {guid}");
                return(true);
            }

            simulationOwnership.RequestSimulationLock(guid, SimulationLockType.EXCLUSIVE, ReceivedSimulationLockResponse);

            return(false);
        }
示例#6
0
        public static bool Prefix(Bench __instance, GUIHand hand)
        {
            if (skipPrefix)
            {
                return(true);
            }

            NitroxId id = NitroxEntity.GetId(__instance.gameObject);

            if (simulationOwnership.HasExclusiveLock(id))
            {
                Log.Debug($"Already have an exclusive lock on the bench/chair: {id}");
                return(true);
            }

            HandInteraction <Bench> context = new(__instance, hand);
            LockRequest <HandInteraction <Bench> > lockRequest = new(id, SimulationLockType.EXCLUSIVE, ReceivedSimulationLockResponse, context);

            simulationOwnership.RequestSimulationLock(lockRequest);

            return(false);
        }
        public static bool Prefix(Vehicle __instance, GUIHand hand)
        {
            if (skipPrefix)
            {
                return(true);
            }

            SimulationOwnership simulationOwnership = NitroxServiceLocator.LocateService <SimulationOwnership>();

            NitroxId id = NitroxEntity.GetId(__instance.gameObject);

            if (simulationOwnership.HasExclusiveLock(id))
            {
                Log.Debug($"Already have an exclusive lock on the vehicle: {id}");
                return(true);
            }

            HandInteraction <Vehicle> context = new(__instance, hand);
            LockRequest <HandInteraction <Vehicle> > lockRequest = new(id, SimulationLockType.EXCLUSIVE, ReceivedSimulationLockResponse, context);

            simulationOwnership.RequestSimulationLock(lockRequest);

            return(false);
        }
示例#8
0
        public static bool Prefix(Vehicle __instance, GUIHand hand)
        {
            if (skipPrefix)
            {
                return(true);
            }

            vehicle = __instance;
            guiHand = hand;

            SimulationOwnership simulationOwnership = NitroxServiceLocator.LocateService <SimulationOwnership>();

            string guid = GuidHelper.GetGuid(__instance.gameObject);

            if (simulationOwnership.HasExclusiveLock(guid))
            {
                Log.Debug($"Already have an exclusive lock on the vehicle: {guid}");
                return(true);
            }

            simulationOwnership.RequestSimulationLock(guid, SimulationLockType.EXCLUSIVE, ReceivedSimulationLockResponse);

            return(false);
        }
        public static bool Prefix(PropulsionCannon __instance, GameObject target)
        {
            if (skipPrefixPatch)
            {
                return(true);
            }

            SimulationOwnership simulationOwnership = NitroxServiceLocator.LocateService <SimulationOwnership>();

            NitroxId id = NitroxEntity.GetId(target);

            if (simulationOwnership.HasExclusiveLock(id))
            {
                Log.Debug($"Already have an exclusive lock on the grabbed propulsion cannon object: {id}");
                return(true);
            }

            PropulsionGrab context = new(__instance, target);
            LockRequest <PropulsionGrab> lockRequest = new(id, SimulationLockType.EXCLUSIVE, ReceivedSimulationLockResponse, context);

            simulationOwnership.RequestSimulationLock(lockRequest);

            return(false);
        }