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 override void Process(WeldAction packet) { GameObject gameObject = NitroxEntity.RequireObjectFrom(packet.Id); if (!simulationOwnership.HasAnyLockType(packet.Id)) { Log.Error($"Got WeldAction packet for {packet.Id} but did not find the lock corresponding to it"); return; } LiveMixin liveMixin = gameObject.GetComponent <LiveMixin>(); if (!liveMixin) { Log.Error($"Did not find LiveMixin for GameObject {packet.Id} even though it was welded."); return; } // If we add other player sounds/animations, this is the place to do it for welding liveMixin.AddHealth(packet.HealthAdded); }
private static void SpawnBabiesIfSimulating(IncubatorEgg egg) { SimulationOwnership simulationOwnership = NitroxServiceLocator.LocateService <SimulationOwnership>(); NitroxEntity serverKnownParent = egg.GetComponentInParent <NitroxEntity>(); Validate.NotNull(serverKnownParent, "Could not find a server known parent for incubator egg"); // Only spawn the babies if we are simulating the main incubator platform. if (simulationOwnership.HasAnyLockType(serverKnownParent.Id)) { GameObject baby = UnityEngine.Object.Instantiate <GameObject>(egg.seaEmperorBabyPrefab); baby.transform.position = egg.attachPoint.transform.position; baby.transform.localRotation = Quaternion.identity; NitroxId babyId = NitroxEntity.GetId(baby); Entity entity = new(baby.transform.position.ToDto(), baby.transform.rotation.ToDto(), baby.transform.localScale.ToDto(), TechType.SeaEmperorBaby.ToDto(), 3, "09883a6c-9e78-4bbf-9561-9fa6e49ce766", true, babyId, null); NitroxServiceLocator.LocateService <Entities>().BroadcastEntitySpawnedByClient(entity); } }
public static float AddHealthOverride(LiveMixin live, float addHealth, Welder welder) { float result = 0f; if ((live.IsAlive() || live.canResurrect) && live.health < live.maxHealth) { float num = live.health; float newHealth = Math.Min(live.health + addHealth, live.maxHealth); result = newHealth - num; SimulationOwnership simulationOwnership = NitroxServiceLocator.LocateService <SimulationOwnership>(); NitroxId id = NitroxEntity.GetId(live.gameObject); // For now, we only control the LiveMixin for vehicles (not even repair nodes at a cyclops) // If we change that, this if should be removed! Vehicle vehicle = live.GetComponent <Vehicle>(); if (vehicle) { if (simulationOwnership.HasAnyLockType(id)) { result = live.AddHealth(addHealth); } else { // Another player simulates this entity. Send the weld info Log.Debug($"Broadcast weld action for {id}"); NitroxServiceLocator.LocateService <LocalPlayer>().BroadcastWeld(id, addHealth); } } else { result = live.AddHealth(addHealth); } } return(result); }