public override void OnDeserialize(BitBuffer d)
 {
     this.levelIndex = d.ReadByte();
     this.count      = (int)d.ReadUShort();
     this.type       = PhysicsParticle.ConvertNetType((byte)d.ReadBits(typeof(byte), 4));
     this.data       = d.ReadBitBuffer();
 }
Esempio n. 2
0
 public void RemoveParticle(PhysicsParticle p)
 {
     if (!this._particles.ContainsKey(p.netIndex))
     {
         return;
     }
     this.removedParticles.Add(p);
 }
Esempio n. 3
0
        public void Update(NetworkConnection c)
        {
            foreach (KeyValuePair <ushort, PhysicsParticle> particle in this._particles)
            {
                PhysicsParticle physicsParticle = particle.Value;
                if (physicsParticle.isLocal)
                {
                    this.GetSendList(c, physicsParticle.GetType()).Add(physicsParticle);
                }
            }
            if (this.removedParticles.Count > 0)
            {
                for (int index = 0; index < this.removedParticles.Count; ++index)
                {
                    foreach (NetworkConnection connection in Network.connections)
                    {
                        if (this.removedParticles[index].isLocal)
                        {
                            this.GetSendRemoveList(connection).Add(this.removedParticles[index].netIndex);
                        }
                    }
                    this._particles.Remove(this.removedParticles[index].netIndex);
                    Level.Remove((Thing)this.removedParticles[index]);
                }
                this.removedParticles.Clear();
            }
            using (Dictionary <System.Type, List <NMParticles> > .Enumerator enumerator = this.GetParticlePairs(c).GetEnumerator())
            {
label_22:
                while (enumerator.MoveNext())
                {
                    KeyValuePair <System.Type, List <NMParticles> > current = enumerator.Current;
                    int num = 0;
                    while (true)
                    {
                        if (num < 3 && current.Value.Count > 0)
                        {
                            Send.Message((NetMessage)current.Value[0], NetMessagePriority.UnreliableUnordered, c);
                            current.Value.RemoveAt(0);
                            ++num;
                        }
                        else
                        {
                            goto label_22;
                        }
                    }
                }
            }
            List <NMRemovedParticles> particleRemoveList = this.GetParticleRemoveList(c);

            for (int index = 0; index < Math.Min(particleRemoveList.Count, 3); index = index - 1 + 1)
            {
                Send.Message((NetMessage)particleRemoveList[index], NetMessagePriority.Volatile, c);
                particleRemoveList.RemoveAt(index);
            }
        }
Esempio n. 4
0
        public void OnMessage(NetMessage m)
        {
            switch (m)
            {
            case NMRemovedParticles _:
                NMRemovedParticles removedParticles = m as NMRemovedParticles;
                for (int index = 0; index < removedParticles.count; ++index)
                {
                    ushort          key             = removedParticles.data.ReadUShort();
                    PhysicsParticle physicsParticle = (PhysicsParticle)null;
                    if (this._particles.TryGetValue(key, out physicsParticle))
                    {
                        this.removedParticles.Add(physicsParticle);
                        this.removedParticleIndexes.Add(physicsParticle.netIndex);
                    }
                }
                break;

            case NMParticles _:
                NMParticles nmParticles = m as NMParticles;
                if ((int)nmParticles.levelIndex != (int)DuckNetwork.levelIndex)
                {
                    break;
                }
                for (int index = 0; index < nmParticles.count; ++index)
                {
                    System.Type     type            = nmParticles.type;
                    ushort          key             = nmParticles.data.ReadUShort();
                    PhysicsParticle physicsParticle = (PhysicsParticle)null;
                    if (!this._particles.TryGetValue(key, out physicsParticle))
                    {
                        if (type == typeof(SmallFire))
                        {
                            physicsParticle = (PhysicsParticle)SmallFire.New(-999f, -999f, 0.0f, 0.0f, canMultiply: false, network: true);
                        }
                        else if (type == typeof(ExtinguisherSmoke))
                        {
                            physicsParticle = (PhysicsParticle) new ExtinguisherSmoke(-999f, -999f, true);
                        }
                        physicsParticle.netIndex = key;
                        physicsParticle.isLocal  = false;
                        if (!this.removedParticleIndexes.Contains(key))
                        {
                            this._particles[key] = physicsParticle;
                            Level.Add((Thing)physicsParticle);
                        }
                    }
                    physicsParticle.NetDeserialize(nmParticles.data);
                }
                break;
            }
        }
Esempio n. 5
0
 public void AddLocalParticle(PhysicsParticle p)
 {
     p.connection = DuckNetwork.localConnection;
     p.netIndex   = (ushort)((uint)this.GetParticleIndex() + (uint)(DuckNetwork.localDuckIndex * 5000));
     this._particles[p.netIndex] = p;
 }