Exemplo n.º 1
0
        public Fabricator(Item item, XElement element)
            : base(item, element)
        {
            foreach (XElement subElement in element.Elements())
            {
                if (subElement.Name.ToString().Equals("fabricableitem", StringComparison.OrdinalIgnoreCase))
                {
                    DebugConsole.ThrowError("Error in item " + item.Name + "! Fabrication recipes should be defined in the craftable item's xml, not in the fabricator.");
                    break;
                }
            }

            foreach (ItemPrefab itemPrefab in ItemPrefab.Prefabs)
            {
                foreach (FabricationRecipe recipe in itemPrefab.FabricationRecipes)
                {
                    if (recipe.SuitableFabricatorIdentifiers.Length > 0)
                    {
                        if (!recipe.SuitableFabricatorIdentifiers.Any(i => item.prefab.Identifier == i || item.HasTag(i)))
                        {
                            continue;
                        }
                    }
                    fabricationRecipes.Add(recipe);
                }
            }

            state = FabricatorState.Stopped;

            InitProjSpecific();
        }
Exemplo n.º 2
0
        public void ClientRead(ServerNetObject type, IReadMessage msg, float sendingTime)
        {
            FabricatorState newState          = (FabricatorState)msg.ReadByte();
            float           newTimeUntilReady = msg.ReadSingle();
            int             itemIndex         = msg.ReadRangedInteger(-1, fabricationRecipes.Count - 1);
            UInt16          userID            = msg.ReadUInt16();
            Character       user = Entity.FindEntityByID(userID) as Character;

            State          = newState;
            timeUntilReady = newTimeUntilReady;

            if (newState == FabricatorState.Stopped || itemIndex == -1 || user == null)
            {
                CancelFabricating();
            }
            else if (newState == FabricatorState.Active || newState == FabricatorState.Paused)
            {
                //if already fabricating the selected item, return
                if (fabricatedItem != null && fabricationRecipes.IndexOf(fabricatedItem) == itemIndex)
                {
                    return;
                }
                if (itemIndex < 0 || itemIndex >= fabricationRecipes.Count)
                {
                    return;
                }

                SelectItem(user, fabricationRecipes[itemIndex]);
                StartFabricating(fabricationRecipes[itemIndex], user);
            }
        }
Exemplo n.º 3
0
        public void ServerWrite(IWriteMessage msg, Client c, object[] extraData = null)
        {
            FabricatorState stateAtEvent = (FabricatorState)extraData[3];

            msg.Write((byte)stateAtEvent);
            msg.Write(timeUntilReady);
            int itemIndex = fabricatedItem == null ? -1 : fabricationRecipes.IndexOf(fabricatedItem);

            msg.WriteRangedInteger(itemIndex, -1, fabricationRecipes.Count - 1);
            UInt16 userID = fabricatedItem == null || user == null ? (UInt16)0 : user.ID;

            msg.Write(userID);
        }