示例#1
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;
            }
        }
示例#2
0
        public List <PhysicsParticle> GetSendList(NetworkConnection c, System.Type t)
        {
            Dictionary <System.Type, List <NMParticles> > particlePairs = this.GetParticlePairs(c);
            List <NMParticles> nmParticlesList = (List <NMParticles>)null;

            if (!particlePairs.TryGetValue(t, out nmParticlesList))
            {
                nmParticlesList  = new List <NMParticles>();
                particlePairs[t] = nmParticlesList;
            }
            if (nmParticlesList.Count == 0 || nmParticlesList[nmParticlesList.Count - 1].GetParticles().Count > 30)
            {
                NMParticles nmParticles = new NMParticles();
                nmParticlesList.Add(nmParticles);
            }
            return(nmParticlesList[nmParticlesList.Count - 1].GetParticles());
        }