public void ClientWrite(IWriteMessage msg, object[] extraData = null) { msg.Write(autoTemp); msg.Write(shutDown); msg.WriteRangedSingle(targetFissionRate, 0.0f, 100.0f, 8); msg.WriteRangedSingle(targetTurbineOutput, 0.0f, 100.0f, 8); correctionTimer = CorrectionDelay; }
public void ServerWrite(IWriteMessage msg, Client c, object[] extraData = null) { msg.Write(autoTemp); msg.Write(_powerOn); msg.WriteRangedSingle(temperature, 0.0f, 100.0f, 8); msg.WriteRangedSingle(targetFissionRate, 0.0f, 100.0f, 8); msg.WriteRangedSingle(targetTurbineOutput, 0.0f, 100.0f, 8); msg.WriteRangedSingle(degreeOfSuccess, 0.0f, 1.0f, 8); }
public void ServerWrite(IWriteMessage msg, Client c) { if (ForceFluctuationStrength > 0.0f) { msg.WriteRangedSingle(MathHelper.Clamp(currentForceFluctuation, 0.0f, 1.0f), 0.0f, 1.0f, 8); } if (stayTriggeredDelay > 0.0f) { msg.WriteRangedSingle(MathHelper.Clamp(triggeredTimer, 0.0f, stayTriggeredDelay), 0.0f, stayTriggeredDelay, 16); } }
public void ServerWrite(IWriteMessage message, Client c, object[] extraData = null) { message.WriteRangedSingle(MathHelper.Clamp(waterVolume / Volume, 0.0f, 1.5f), 0.0f, 1.5f, 8); message.WriteRangedSingle(MathHelper.Clamp(OxygenPercentage, 0.0f, 100.0f), 0.0f, 100.0f, 8); message.Write(FireSources.Count > 0); if (FireSources.Count > 0) { message.WriteRangedInteger(Math.Min(FireSources.Count, 16), 0, 16); for (int i = 0; i < Math.Min(FireSources.Count, 16); i++) { var fireSource = FireSources[i]; Vector2 normalizedPos = new Vector2( (fireSource.Position.X - rect.X) / rect.Width, (fireSource.Position.Y - (rect.Y - rect.Height)) / rect.Height); message.WriteRangedSingle(MathHelper.Clamp(normalizedPos.X, 0.0f, 1.0f), 0.0f, 1.0f, 8); message.WriteRangedSingle(MathHelper.Clamp(normalizedPos.Y, 0.0f, 1.0f), 0.0f, 1.0f, 8); message.WriteRangedSingle(MathHelper.Clamp(fireSource.Size.X / rect.Width, 0.0f, 1.0f), 0, 1.0f, 8); } } message.Write(extraData != null); if (extraData != null) { message.Write((bool)extraData[0]); // Section update if ((bool)extraData[0]) { int sectorToUpdate = (int)extraData[1]; int start = sectorToUpdate * BackgroundSectionsPerNetworkEvent; int end = Math.Min((sectorToUpdate + 1) * BackgroundSectionsPerNetworkEvent, BackgroundSections.Count - 1); message.WriteRangedInteger(sectorToUpdate, 0, BackgroundSections.Count - 1); for (int i = start; i < end; i++) { message.WriteRangedSingle(BackgroundSections[i].ColorStrength, 0.0f, 1.0f, 8); message.Write(BackgroundSections[i].Color.PackedValue); } } else // Decal update { message.WriteRangedInteger(decals.Count, 0, MaxDecalsPerHull); foreach (Decal decal in decals) { message.Write(decal.Prefab.UIntIdentifier); message.Write((byte)decal.SpriteIndex); float normalizedXPos = MathHelper.Clamp(MathUtils.InverseLerp(0.0f, rect.Width, decal.CenterPosition.X), 0.0f, 1.0f); float normalizedYPos = MathHelper.Clamp(MathUtils.InverseLerp(-rect.Height, 0.0f, decal.CenterPosition.Y), 0.0f, 1.0f); message.WriteRangedSingle(normalizedXPos, 0.0f, 1.0f, 8); message.WriteRangedSingle(normalizedYPos, 0.0f, 1.0f, 8); message.WriteRangedSingle(decal.Scale, 0f, 2f, 12); } } } }
public void ServerWrite(IWriteMessage msg, Client c, object[] extraData = null) { msg.WriteRangedInteger((int)(rechargeSpeed / MaxRechargeSpeed * 10), 0, 10); float chargeRatio = MathHelper.Clamp(charge / capacity, 0.0f, 1.0f); msg.WriteRangedSingle(chargeRatio, 0.0f, 1.0f, 8); }
public void ServerWrite(IWriteMessage msg, Client c, object[] extraData = null) { msg.Write((byte)Sections.Length); for (int i = 0; i < Sections.Length; i++) { msg.WriteRangedSingle(Sections[i].damage / MaxHealth, 0.0f, 1.0f, 8); } }
public override void ServerWrite(IWriteMessage msg, Client c, object[] extraData = null) { base.ServerWrite(msg, c, extraData); msg.Write(isOpen); msg.Write(extraData.Length == 3 ? (bool)extraData[2] : false); //forced open msg.WriteRangedSingle(stuck, 0.0f, 100.0f, 8); }
public void ClientWrite(IWriteMessage msg, object[] extraData = null) { msg.WriteRangedSingle(MathHelper.Clamp(waterVolume / Volume, 0.0f, 1.5f), 0.0f, 1.5f, 8); msg.Write(FireSources.Count > 0); if (FireSources.Count > 0) { msg.WriteRangedInteger(Math.Min(FireSources.Count, 16), 0, 16); for (int i = 0; i < Math.Min(FireSources.Count, 16); i++) { var fireSource = FireSources[i]; Vector2 normalizedPos = new Vector2( (fireSource.Position.X - rect.X) / rect.Width, (fireSource.Position.Y - (rect.Y - rect.Height)) / rect.Height); msg.WriteRangedSingle(MathHelper.Clamp(normalizedPos.X, 0.0f, 1.0f), 0.0f, 1.0f, 8); msg.WriteRangedSingle(MathHelper.Clamp(normalizedPos.Y, 0.0f, 1.0f), 0.0f, 1.0f, 8); msg.WriteRangedSingle(MathHelper.Clamp(fireSource.Size.X / rect.Width, 0.0f, 1.0f), 0, 1.0f, 8); } } }
public override void ServerWrite(IWriteMessage msg, Client c, object[] extraData = null) { base.ServerWrite(msg, c, extraData); msg.Write(isOpen); msg.Write(isBroken); msg.Write(extraData.Length == 3 ? (bool)extraData[2] : false); //forced open msg.Write(isStuck); msg.Write(isJammed); msg.WriteRangedSingle(stuck, 0.0f, 100.0f, 8); msg.Write(lastUser == null ? (UInt16)0 : lastUser.ID); }
public void ServerWrite(IWriteMessage msg, Client c, object[] extraData = null) { float MaxVel = NetConfig.MaxPhysicsBodyVelocity; float MaxAngularVel = NetConfig.MaxPhysicsBodyAngularVelocity; msg.Write(SimPosition.X); msg.Write(SimPosition.Y); #if DEBUG if (Math.Abs(FarseerBody.LinearVelocity.X) > MaxVel || Math.Abs(FarseerBody.LinearVelocity.Y) > MaxVel) { DebugConsole.ThrowError($"Entity velocity out of range ({(UserData?.ToString() ?? "null")}, {FarseerBody.LinearVelocity})"); } #endif msg.Write(FarseerBody.Awake); msg.Write(FarseerBody.FixedRotation); if (!FarseerBody.FixedRotation) { msg.WriteRangedSingle(MathUtils.WrapAngleTwoPi(FarseerBody.Rotation), 0.0f, MathHelper.TwoPi, 8); } if (FarseerBody.Awake) { FarseerBody.Enabled = true; FarseerBody.LinearVelocity = new Vector2( MathHelper.Clamp(FarseerBody.LinearVelocity.X, -MaxVel, MaxVel), MathHelper.Clamp(FarseerBody.LinearVelocity.Y, -MaxVel, MaxVel)); msg.WriteRangedSingle(FarseerBody.LinearVelocity.X, -MaxVel, MaxVel, 12); msg.WriteRangedSingle(FarseerBody.LinearVelocity.Y, -MaxVel, MaxVel, 12); if (!FarseerBody.FixedRotation) { FarseerBody.AngularVelocity = MathHelper.Clamp(FarseerBody.AngularVelocity, -MaxAngularVel, MaxAngularVel); msg.WriteRangedSingle(FarseerBody.AngularVelocity, -MaxAngularVel, MaxAngularVel, 8); } } msg.WritePadBits(); }
public void ServerWrite(IWriteMessage msg, Client c, object[] extraData = null) { if (extraData.Length > 2) { msg.Write(!(extraData[2] is Item item) || item.Removed ? ushort.MaxValue : item.ID); msg.WriteRangedSingle(MathHelper.Clamp(rotation, minRotation, maxRotation), minRotation, maxRotation, 16); } else { msg.Write((ushort)0); float wrappedTargetRotation = targetRotation; while (wrappedTargetRotation < minRotation && MathUtils.IsValid(wrappedTargetRotation)) { wrappedTargetRotation += MathHelper.TwoPi; } while (wrappedTargetRotation > maxRotation && MathUtils.IsValid(wrappedTargetRotation)) { wrappedTargetRotation -= MathHelper.TwoPi; } msg.WriteRangedSingle(MathHelper.Clamp(wrappedTargetRotation, minRotation, maxRotation), minRotation, maxRotation, 16); } }
public void ServerWrite(IWriteMessage msg) { List <Affliction> activeAfflictions = afflictions.FindAll(a => a.Strength > 0.0f && a.Strength >= a.Prefab.ActivationThreshold); msg.Write((byte)activeAfflictions.Count); foreach (Affliction affliction in activeAfflictions) { msg.WriteRangedInteger(AfflictionPrefab.List.IndexOf(affliction.Prefab), 0, AfflictionPrefab.List.Count - 1); msg.WriteRangedSingle( MathHelper.Clamp(affliction.Strength, 0.0f, affliction.Prefab.MaxStrength), 0.0f, affliction.Prefab.MaxStrength, 8); } List <Pair <LimbHealth, Affliction> > limbAfflictions = new List <Pair <LimbHealth, Affliction> >(); foreach (LimbHealth limbHealth in limbHealths) { foreach (Affliction limbAffliction in limbHealth.Afflictions) { if (limbAffliction.Strength <= 0.0f || limbAffliction.Strength < limbAffliction.Prefab.ActivationThreshold) { continue; } limbAfflictions.Add(new Pair <LimbHealth, Affliction>(limbHealth, limbAffliction)); } } msg.Write((byte)limbAfflictions.Count); foreach (var limbAffliction in limbAfflictions) { msg.WriteRangedInteger(limbHealths.IndexOf(limbAffliction.First), 0, limbHealths.Count - 1); msg.WriteRangedInteger(AfflictionPrefab.List.IndexOf(limbAffliction.Second.Prefab), 0, AfflictionPrefab.List.Count - 1); msg.WriteRangedSingle( MathHelper.Clamp(limbAffliction.Second.Strength, 0.0f, limbAffliction.Second.Prefab.MaxStrength), 0.0f, limbAffliction.Second.Prefab.MaxStrength, 8); } }
public void ClientWrite(IWriteMessage msg, object[] extraData = null) { msg.Write(extraData != null); if (extraData == null) { msg.WriteRangedSingle(MathHelper.Clamp(waterVolume / Volume, 0.0f, 1.5f), 0.0f, 1.5f, 8); msg.Write(FireSources.Count > 0); if (FireSources.Count > 0) { msg.WriteRangedInteger(Math.Min(FireSources.Count, 16), 0, 16); for (int i = 0; i < Math.Min(FireSources.Count, 16); i++) { var fireSource = FireSources[i]; Vector2 normalizedPos = new Vector2( (fireSource.Position.X - rect.X) / rect.Width, (fireSource.Position.Y - (rect.Y - rect.Height)) / rect.Height); msg.WriteRangedSingle(MathHelper.Clamp(normalizedPos.X, 0.0f, 1.0f), 0.0f, 1.0f, 8); msg.WriteRangedSingle(MathHelper.Clamp(normalizedPos.Y, 0.0f, 1.0f), 0.0f, 1.0f, 8); msg.WriteRangedSingle(MathHelper.Clamp(fireSource.Size.X / rect.Width, 0.0f, 1.0f), 0, 1.0f, 8); } } } else { int sectorToUpdate = (int)extraData[0]; int start = sectorToUpdate * BackgroundSectionsPerNetworkEvent; int end = Math.Min((sectorToUpdate + 1) * BackgroundSectionsPerNetworkEvent, BackgroundSections.Count - 1); msg.WriteRangedInteger(sectorToUpdate, 0, BackgroundSections.Count - 1); for (int i = start; i < end; i++) { msg.WriteRangedSingle(BackgroundSections[i].ColorStrength, 0.0f, 1.0f, 8); msg.Write(BackgroundSections[i].Color.PackedValue); } } }
public void ServerWrite(IWriteMessage msg, Client c) { if (Triggers == null) { return; } if (Prefab.TakeLevelWallDamage) { msg.WriteRangedSingle(MathHelper.Clamp(Health, 0.0f, Prefab.Health), 0.0f, Prefab.Health, 8); } for (int j = 0; j < Triggers.Count; j++) { if (!Triggers[j].UseNetworkSyncing) { continue; } Triggers[j].ServerWrite(msg, c); } }
public void ServerWrite(IWriteMessage msg, Client c, object[] extraData = null) { msg.WriteRangedSingle(Health, 0f, (float)MaxHealth, 8); if (extraData != null && extraData.Length >= 3 && extraData[2] is int offset) { int amountToSend = Math.Min(Vines.Count - offset, VineChunkSize); msg.WriteRangedInteger(offset, -1, MaximumVines); msg.WriteRangedInteger(amountToSend, 0, VineChunkSize); for (int i = offset; i < offset + amountToSend; i++) { VineTile vine = Vines[i]; var(x, y) = vine.Position; msg.WriteRangedInteger((byte)vine.Type, 0b0000, 0b1111); msg.WriteRangedInteger(vine.FlowerConfig.Serialize(), 0, 0xFFF); msg.WriteRangedInteger(vine.LeafConfig.Serialize(), 0, 0xFFF); msg.Write((byte)(x / VineTile.Size)); msg.Write((byte)(y / VineTile.Size)); } } else { msg.WriteRangedInteger(-1, -1, MaximumVines); } }
public void ServerWrite(IWriteMessage message, Client c, object[] extraData = null) { if (extraData != null && extraData.Length >= 2 && extraData[0] is BallastFloraBehavior behavior && extraData[1] is BallastFloraBehavior.NetworkHeader header) { message.Write(true); message.Write((byte)header); switch (header) { case BallastFloraBehavior.NetworkHeader.Spawn: behavior.ServerWriteSpawn(message); break; case BallastFloraBehavior.NetworkHeader.Kill: break; case BallastFloraBehavior.NetworkHeader.BranchCreate when extraData.Length >= 4 && extraData[2] is BallastFloraBranch branch && extraData[3] is int parentId: behavior.ServerWriteBranchGrowth(message, branch, parentId); break; case BallastFloraBehavior.NetworkHeader.BranchDamage when extraData.Length >= 4 && extraData[2] is BallastFloraBranch branch && extraData[3] is float damage: behavior.ServerWriteBranchDamage(message, branch, damage); break; case BallastFloraBehavior.NetworkHeader.BranchRemove when extraData.Length >= 3 && extraData[2] is BallastFloraBranch branch: behavior.ServerWriteBranchRemove(message, branch); break; case BallastFloraBehavior.NetworkHeader.Infect when extraData.Length >= 4 && extraData[2] is UInt16 itemID && extraData[3] is bool infect: BallastFloraBranch infector = null; if (extraData.Length >= 5 && extraData[4] is BallastFloraBranch b) { infector = b; } behavior.ServerWriteInfect(message, itemID, infect, infector); break; } message.Write(behavior.PowerConsumptionTimer); return; } message.Write(false); message.WriteRangedSingle(MathHelper.Clamp(waterVolume / Volume, 0.0f, 1.5f), 0.0f, 1.5f, 8); message.WriteRangedSingle(MathHelper.Clamp(OxygenPercentage, 0.0f, 100.0f), 0.0f, 100.0f, 8); message.Write(FireSources.Count > 0); if (FireSources.Count > 0) { message.WriteRangedInteger(Math.Min(FireSources.Count, 16), 0, 16); for (int i = 0; i < Math.Min(FireSources.Count, 16); i++) { var fireSource = FireSources[i]; Vector2 normalizedPos = new Vector2( (fireSource.Position.X - rect.X) / rect.Width, (fireSource.Position.Y - (rect.Y - rect.Height)) / rect.Height); message.WriteRangedSingle(MathHelper.Clamp(normalizedPos.X, 0.0f, 1.0f), 0.0f, 1.0f, 8); message.WriteRangedSingle(MathHelper.Clamp(normalizedPos.Y, 0.0f, 1.0f), 0.0f, 1.0f, 8); message.WriteRangedSingle(MathHelper.Clamp(fireSource.Size.X / rect.Width, 0.0f, 1.0f), 0, 1.0f, 8); } } message.Write(extraData != null); if (extraData != null) { message.Write((bool)extraData[0]); // Section update if ((bool)extraData[0]) { int sectorToUpdate = (int)extraData[1]; int start = sectorToUpdate * BackgroundSectionsPerNetworkEvent; int end = Math.Min((sectorToUpdate + 1) * BackgroundSectionsPerNetworkEvent, BackgroundSections.Count - 1); message.WriteRangedInteger(sectorToUpdate, 0, BackgroundSections.Count - 1); for (int i = start; i < end; i++) { message.WriteRangedSingle(BackgroundSections[i].ColorStrength, 0.0f, 1.0f, 8); message.Write(BackgroundSections[i].Color.PackedValue); } } else // Decal update { message.WriteRangedInteger(decals.Count, 0, MaxDecalsPerHull); foreach (Decal decal in decals) { message.Write(decal.Prefab.UIntIdentifier); message.Write((byte)decal.SpriteIndex); float normalizedXPos = MathHelper.Clamp(MathUtils.InverseLerp(0.0f, rect.Width, decal.CenterPosition.X), 0.0f, 1.0f); float normalizedYPos = MathHelper.Clamp(MathUtils.InverseLerp(-rect.Height, 0.0f, decal.CenterPosition.Y), 0.0f, 1.0f); message.WriteRangedSingle(normalizedXPos, 0.0f, 1.0f, 8); message.WriteRangedSingle(normalizedYPos, 0.0f, 1.0f, 8); message.WriteRangedSingle(decal.Scale, 0f, 2f, 12); } } } }
public void ServerWrite(IWriteMessage msg) { msg.WriteRangedSingle(Happiness, 0.0f, MaxHappiness, 8); msg.WriteRangedSingle(Hunger, 0.0f, MaxHunger, 8); }