コード例 #1
0
ファイル: Replica.cs プロジェクト: cuzitsjonny/Quicksicle
        public BaseReplicaComponent GetComponent(ReplicaComponentId componentId)
        {
            BaseReplicaComponent c = null;

            foreach (BaseReplicaComponent component in components)
            {
                if (component.ComponentId == componentId)
                {
                    c = component;
                }
            }

            return(c);
        }
コード例 #2
0
ファイル: Replica.cs プロジェクト: cuzitsjonny/Quicksicle
        public void Serialize(WriteOnlyBitStream packetStream, bool isInitialUpdate)
        {
            if (isInitialUpdate)
            {
                packetStream.Write(ObjectId);
                packetStream.Write(Template);
                packetStream.Write((byte)Name.Length);

                if (Name.Length > 0)
                {
                    packetStream.WriteWideString(Name, Name.Length);
                }

                packetStream.Write((uint)DateTime.Now.Subtract(Creation).TotalSeconds);

                packetStream.Write0(); // config data
                packetStream.Write0(); // trigger id

                if (SpawnerId != 0)
                {
                    packetStream.Write1();
                    packetStream.Write(SpawnerId);
                }
                else
                {
                    packetStream.Write0();
                }

                if (SpawnerNodeId != -1)
                {
                    packetStream.Write1();
                    packetStream.Write(SpawnerNodeId);
                }
                else
                {
                    packetStream.Write0();
                }

                if (Scale != 1.0f)
                {
                    packetStream.Write1();
                    packetStream.Write(Scale);
                }
                else
                {
                    packetStream.Write0();
                }

                if (ObjectWorldState != ObjectWorldState.InWorld)
                {
                    packetStream.Write1();
                    packetStream.Write((byte)ObjectWorldState);
                }
                else
                {
                    packetStream.Write0();
                }

                if (GmLevel != 0)
                {
                    packetStream.Write1();
                    packetStream.Write(GmLevel);
                }
                else
                {
                    packetStream.Write0();
                }
            }

            packetStream.Write1();

            if (ParentId != 0)
            {
                packetStream.Write1();
                packetStream.Write(ParentId);
                packetStream.Write(UpdatePositionWithParent);
            }
            else
            {
                packetStream.Write0();
            }

            long[] childIds = ChildIds;

            if (childIds.Length > 0)
            {
                packetStream.Write1();
                packetStream.Write((ushort)childIds.Length);

                for (int i = 0; i < childIds.Length; i++)
                {
                    packetStream.Write(childIds[i]);
                }
            }
            else
            {
                packetStream.Write0();
            }

            bool statsComponentWritten          = false;
            BaseReplicaComponent statsComponent = GetComponent(ReplicaComponentId.Stats);

            for (int i = 0; i < SerializationOrder.Length; i++)
            {
                ReplicaComponentId currentComponentId = SerializationOrder[i];

                foreach (BaseReplicaComponent component in components)
                {
                    if (component.ComponentId == currentComponentId)
                    {
                        if (!statsComponentWritten && statsComponent != null && (currentComponentId == ReplicaComponentId.COLLECTIBLE || currentComponentId == ReplicaComponentId.QUICKBUILD))
                        {
                            statsComponent.ToBitStream(packetStream, isInitialUpdate);
                            statsComponentWritten = true;
                        }

                        component.ToBitStream(packetStream, isInitialUpdate);

                        if (!statsComponentWritten && statsComponent != null && (currentComponentId == ReplicaComponentId.Destroyable))
                        {
                            statsComponent.ToBitStream(packetStream, isInitialUpdate);
                            statsComponentWritten = true;
                        }
                    }
                }
            }
        }
コード例 #3
0
ファイル: Replica.cs プロジェクト: cuzitsjonny/Quicksicle
 public void RemoveComponent(BaseReplicaComponent component)
 {
     components.Remove(component);
 }
コード例 #4
0
ファイル: Replica.cs プロジェクト: cuzitsjonny/Quicksicle
 public void AddComponent(BaseReplicaComponent component)
 {
     components.Add(component);
 }