Exemple #1
0
        public void ClientRead(ServerNetObject type, IReadMessage message, float sendingTime)
        {
            bool isBallastFloraUpdate = message.ReadBoolean();

            if (isBallastFloraUpdate)
            {
                BallastFloraBehavior.NetworkHeader header = (BallastFloraBehavior.NetworkHeader)message.ReadByte();
                if (header == BallastFloraBehavior.NetworkHeader.Spawn)
                {
                    string identifier = message.ReadString();
                    float  x          = message.ReadSingle();
                    float  y          = message.ReadSingle();
                    BallastFlora = new BallastFloraBehavior(this, BallastFloraPrefab.Find(identifier), new Vector2(x, y), firstGrowth: true)
                    {
                        PowerConsumptionTimer = message.ReadSingle()
                    };
                }
                else
                {
                    BallastFlora?.ClientRead(message, header);
                }
                return;
            }
            remoteWaterVolume      = message.ReadRangedSingle(0.0f, 1.5f, 8) * Volume;
            remoteOxygenPercentage = message.ReadRangedSingle(0.0f, 100.0f, 8);

            bool hasFireSources = message.ReadBoolean();

            remoteFireSources = new List <Vector3>();
            if (hasFireSources)
            {
                int fireSourceCount = message.ReadRangedInteger(0, 16);
                for (int i = 0; i < fireSourceCount; i++)
                {
                    remoteFireSources.Add(new Vector3(
                                              MathHelper.Clamp(message.ReadRangedSingle(0.0f, 1.0f, 8), 0.05f, 0.95f),
                                              MathHelper.Clamp(message.ReadRangedSingle(0.0f, 1.0f, 8), 0.05f, 0.95f),
                                              message.ReadRangedSingle(0.0f, 1.0f, 8)));
                }
            }

            bool hasExtraData = message.ReadBoolean();

            if (hasExtraData)
            {
                bool hasSectionUpdate = message.ReadBoolean();
                if (hasSectionUpdate)
                {
                    int sectorToUpdate = message.ReadRangedInteger(0, BackgroundSections.Count - 1);
                    int start          = sectorToUpdate * BackgroundSectionsPerNetworkEvent;
                    int end            = Math.Min((sectorToUpdate + 1) * BackgroundSectionsPerNetworkEvent, BackgroundSections.Count - 1);
                    for (int i = start; i < end; i++)
                    {
                        float colorStrength           = message.ReadRangedSingle(0.0f, 1.0f, 8);
                        Color color                   = new Color(message.ReadUInt32());
                        var   remoteBackgroundSection = remoteBackgroundSections.Find(s => s.Index == i);
                        if (remoteBackgroundSection != null)
                        {
                            remoteBackgroundSection.SetColorStrength(colorStrength);
                            remoteBackgroundSection.SetColor(color);
                        }
                        else
                        {
                            remoteBackgroundSections.Add(new BackgroundSection(new Rectangle(0, 0, 1, 1), i, colorStrength, color, 0));
                        }
                    }
                    paintAmount = BackgroundSections.Sum(s => s.ColorStrength);
                }
                else
                {
                    int decalCount = message.ReadRangedInteger(0, MaxDecalsPerHull);
                    if (decalCount == 0)
                    {
                        decals.Clear();
                    }
                    remoteDecals.Clear();
                    for (int i = 0; i < decalCount; i++)
                    {
                        UInt32 decalId        = message.ReadUInt32();
                        int    spriteIndex    = message.ReadByte();
                        float  normalizedXPos = message.ReadRangedSingle(0.0f, 1.0f, 8);
                        float  normalizedYPos = message.ReadRangedSingle(0.0f, 1.0f, 8);
                        float  decalScale     = message.ReadRangedSingle(0.0f, 2.0f, 12);
                        remoteDecals.Add(new RemoteDecal(decalId, spriteIndex, new Vector2(normalizedXPos, normalizedYPos), decalScale));
                    }
                }
            }

            if (serverUpdateDelay > 0.0f)
            {
                return;
            }

            ApplyRemoteState();
        }
Exemple #2
0
 public BallastFloraStateMachine(BallastFloraBehavior parent)
 {
     this.parent = parent;
 }