Пример #1
0
        public void WriteSpawnData(IWriteMessage msg, UInt16 entityID, UInt16 originalInventoryID, byte originalItemContainerIndex)
        {
            if (GameMain.Server == null)
            {
                return;
            }

            msg.Write(Prefab.OriginalName);
            msg.Write(Prefab.Identifier);
            msg.Write(Description != prefab.Description);
            if (Description != prefab.Description)
            {
                msg.Write(Description);
            }

            msg.Write(entityID);

            if (ParentInventory == null || ParentInventory.Owner == null || originalInventoryID == 0)
            {
                msg.Write((ushort)0);

                msg.Write(Position.X);
                msg.Write(Position.Y);
                msg.Write(Submarine != null ? Submarine.ID : (ushort)0);
            }
            else
            {
                msg.Write(originalInventoryID);
                msg.Write(originalItemContainerIndex);

                int slotIndex = ParentInventory.FindIndex(this);
                msg.Write(slotIndex < 0 ? (byte)255 : (byte)slotIndex);
            }

            msg.Write(body == null ? (byte)0 : (byte)body.BodyType);
            msg.Write(SpawnedInOutpost);

            byte teamID = 0;

            foreach (WifiComponent wifiComponent in GetComponents <WifiComponent>())
            {
                teamID = (byte)wifiComponent.TeamID;
                break;
            }

            msg.Write(teamID);
            bool tagsChanged = tags.Count != prefab.Tags.Count || !tags.All(t => prefab.Tags.Contains(t));

            msg.Write(tagsChanged);
            if (tagsChanged)
            {
                msg.Write(Tags);
            }
        }
Пример #2
0
        public void WriteSpawnData(NetBuffer msg)
        {
            if (GameMain.Server == null)
            {
                return;
            }

            msg.Write(Prefab.OriginalName);
            msg.Write(Prefab.Identifier);
            msg.Write(Description != prefab.Description);
            if (Description != prefab.Description)
            {
                msg.Write(Description);
            }

            msg.Write(ID);

            if (ParentInventory == null || ParentInventory.Owner == null)
            {
                msg.Write((ushort)0);

                msg.Write(Position.X);
                msg.Write(Position.Y);
                msg.Write(Submarine != null ? Submarine.ID : (ushort)0);
            }
            else
            {
                msg.Write(ParentInventory.Owner.ID);

                //find the index of the ItemContainer this item is inside to get the item to
                //spawn in the correct inventory in multi-inventory items like fabricators
                byte containerIndex = 0;
                if (Container != null)
                {
                    for (int i = 0; i < Container.components.Count; i++)
                    {
                        if (Container.components[i] is ItemContainer container &&
                            container.Inventory == ParentInventory)
                        {
                            containerIndex = (byte)i;
                            break;
                        }
                    }
                }
                msg.Write(containerIndex);

                int slotIndex = ParentInventory.FindIndex(this);
                msg.Write(slotIndex < 0 ? (byte)255 : (byte)slotIndex);
            }

            byte teamID = 0;

            foreach (WifiComponent wifiComponent in GetComponents <WifiComponent>())
            {
                teamID = (byte)wifiComponent.TeamID;
                break;
            }

            msg.Write(teamID);
            bool tagsChanged = tags.Count != prefab.Tags.Count || !tags.All(t => prefab.Tags.Contains(t));

            msg.Write(tagsChanged);
            if (tagsChanged)
            {
                msg.Write(Tags);
            }
        }
Пример #3
0
        public void WriteSpawnData(IWriteMessage msg, UInt16 entityID, UInt16 originalInventoryID, byte originalItemContainerIndex)
        {
            if (GameMain.Server == null)
            {
                return;
            }

            msg.Write(Prefab.OriginalName);
            msg.Write(Prefab.Identifier);
            msg.Write(Description != prefab.Description);
            if (Description != prefab.Description)
            {
                msg.Write(Description);
            }

            msg.Write(entityID);

            if (ParentInventory == null || ParentInventory.Owner == null || originalInventoryID == 0)
            {
                msg.Write((ushort)0);

                msg.Write(Position.X);
                msg.Write(Position.Y);
                msg.Write(Submarine != null ? Submarine.ID : (ushort)0);
            }
            else
            {
                msg.Write(originalInventoryID);
                msg.Write(originalItemContainerIndex);

                int slotIndex = ParentInventory.FindIndex(this);
                msg.Write(slotIndex < 0 ? (byte)255 : (byte)slotIndex);
            }

            msg.Write(body == null ? (byte)0 : (byte)body.BodyType);
            msg.Write(SpawnedInOutpost);
            msg.Write(AllowStealing);
            msg.WriteRangedInteger(Quality, 0, Items.Components.Quality.MaxQuality);

            byte teamID = 0;

            foreach (WifiComponent wifiComponent in GetComponents <WifiComponent>())
            {
                teamID = (byte)wifiComponent.TeamID;
                break;
            }
            if (teamID == 0)
            {
                foreach (IdCard idCard in GetComponents <IdCard>())
                {
                    teamID = (byte)idCard.TeamID;
                    break;
                }
            }

            msg.Write(teamID);
            bool tagsChanged = tags.Count != prefab.Tags.Count || !tags.All(t => prefab.Tags.Contains(t));

            msg.Write(tagsChanged);
            if (tagsChanged)
            {
                string[] splitTags = Tags.Split(',');
                msg.Write(string.Join(',', splitTags.Where(t => !prefab.Tags.Contains(t))));
                msg.Write(string.Join(',', prefab.Tags.Where(t => !splitTags.Contains(t))));
            }
            var nameTag = GetComponent <NameTag>();

            msg.Write(nameTag != null);
            if (nameTag != null)
            {
                msg.Write(nameTag.WrittenName ?? "");
            }
        }