Ejemplo n.º 1
0
    /**
     * Converts the XML into the drop info needed.
     */

    public override bool ParseXmlAttribute(XmlAttribute _attribute)
    {
        bool flag = base.ParseXmlAttribute(_attribute);

        if (!flag)
        {
            string name = _attribute.Name;
            if (name == "block_name")
            {
                this.blockName = _attribute.Value;
                return(true);
            }

            if (name == "range")
            {
                this.range = StringHelpers.WriteStringToVector3i(_attribute.Value);
                if (range == Vector3i.zero)
                {
                    return(false);
                }
            }

            if (name == "require_materials")
            {
                bool requireMaterials;
                if (!StringParsers.TryParseBool(_attribute.Value, out requireMaterials))
                {
                    throw new Exception("Could not parse value as an boolean.");
                }
                this.requireMaterials = requireMaterials;
            }
        }
        return(flag);
    }
    /**
     * Checks whether the block requires power and parses the power sources.
     */

    protected void CheckRequiresPower()
    {
        if (!this.blockTransformerBlock.Block.Properties.Values.ContainsKey(propRequirePower))
        {
            this.requirePower = false;
            this.powerSources = new List <string>()
            {
                "electricwirerelay"
            };
            return;
        }

        string requirePowerValue = blockTransformerBlock.Block.Properties.Values[propRequirePower].ToString();
        bool   requirePower;

        this.requirePower = (StringParsers.TryParseBool(requirePowerValue, out requirePower) ? requirePower : false);

        this.powerSources = new List <string>();
        if (!this.blockTransformerBlock.Block.Properties.Values.ContainsKey(propPowerSources))
        {
            this.powerSources.Add("electricwirerelay");
        }
        else
        {
            this.powerSources = StringHelpers.WriteStringToList(this.blockTransformerBlock.Block.Properties.Values[propPowerSources]);
        }

        this.CheckBlocksDefined(this.powerSources);
    }
    /**
     * Checks whether block requires heat and parses the heat sources.
     */

    protected void CheckRequiresHeat()
    {
        if (!this.blockTransformerBlock.Block.Properties.Values.ContainsKey(propRequireHeat))
        {
            this.requireHeat = false;
            this.heatSources = new List <string>()
            {
                "campfire"
            };
            return;
        }

        string requireHeatValue = blockTransformerBlock.Block.Properties.Values[propRequireHeat].ToString();
        bool   requireHeat;

        this.requireHeat = (StringParsers.TryParseBool(requireHeatValue, out requireHeat) ? requireHeat : false);

        this.heatSources = new List <string>();
        if (!this.blockTransformerBlock.Block.Properties.Values.ContainsKey(propHeatSources))
        {
            this.heatSources.Add("canpfire");
        }
        else
        {
            this.heatSources = StringHelpers.WriteStringToList(this.blockTransformerBlock.Block.Properties.Values[propHeatSources]);
        }

        this.CheckBlocksDefined(this.heatSources);
    }
    /**
     * Reads the data from a string.
     */

    public static TransformationJob Read(string _s, bool fromHash = false)
    {
        Match jobExists = TransformationQueue.queueEntryParse.Match(_s);

        if (!jobExists.Success)
        {
            throw new Exception("Could not read job string " + _s);
        }

        string timeString = jobExists.Groups[1].ToString();
        string dataString = jobExists.Groups[2].ToString();
        string boolString = jobExists.Groups[3].ToString();

        ulong transformTime;

        if (!StringParsers.TryParseUInt64(timeString, out transformTime))
        {
            throw new Exception("Could not parse time string " + timeString);
        }

        bool inProgress;

        if (!StringParsers.TryParseBool(boolString, out inProgress))
        {
            throw new Exception("Could not parse in progress string " + boolString);
        }

        TransformationData tData = TransformationData.Read(dataString, fromHash);

        return(new TransformationJob(transformTime, tData, inProgress));
    }
    /**
     * Checks whether block requires heat and parses the heat sources.
     */

    protected void CheckRequiresHeat()
    {
        this.requireHeat = false;
        this.heatSources = new List <string>()
        {
            "campfire"
        };

        string requireHeatValue;

        if (!this.PropExists(propRequireHeat, out requireHeatValue))
        {
            return;
        }

        if (!StringParsers.TryParseBool(requireHeatValue, out this.requireHeat))
        {
            throw new Exception("Could not parse require heat parameter as a boolean.");
        }

        this.heatSources = new List <string>();
        string heatSources;

        if (this.PropExists(propHeatSources, out heatSources))
        {
            this.heatSources = StringHelpers.WriteStringToList(heatSources);
            this.CheckBlocksDefined(this.heatSources);
        }
        this.heatSources.Add("campfire");
    }
    /**
     * Checks whether the block requires power and parses the power sources.
     */

    protected void CheckRequiresPower()
    {
        this.requirePower = false;
        this.powerSources = new List <string>()
        {
            "electricwirerelay"
        };

        string requirePowerValue;

        if (!this.PropExists(propRequirePower, out requirePowerValue))
        {
            return;
        }

        if (!StringParsers.TryParseBool(requirePowerValue, out this.requirePower))
        {
            throw new Exception("Require power could noot be parsed as a boolean value.");
        }

        this.powerSources = new List <string>();
        string powerSources;

        if (this.PropExists(propPowerSources, out powerSources))
        {
            this.powerSources = StringHelpers.WriteStringToList(powerSources);
            this.CheckBlocksDefined(this.powerSources);
            return;
        }
        this.powerSources.Add("electricwirerelay");
    }
    /**
     * Checks whether the user is needed to be accessing the block in order for processing to occur.
     */

    protected void CheckRequireUserAccess()
    {
        this.requireUserAccess = false;
        string requireUserAccess;

        if (!this.PropExists(this.propRequireUserAccess, out requireUserAccess))
        {
            return;
        }

        if (!StringParsers.TryParseBool(requireUserAccess, out this.requireUserAccess))
        {
            throw new Exception("Could not parse value as boolean.");
        }
    }
    /**
     * Checks whether nearby blocks are required and parses the nearby block sources.
     */

    protected void CheckRequireBlocksNearby()
    {
        this.requireNearbyBlocks = false;
        this.nearbyBlockRange    = new Vector3i(1, 1, 1);
        this.nearbyBlockCount    = 0;
        this.nearbyBlockNames    = new List <string>();
        this.nearbyBlockTags     = new List <string>();
        this.requireAllTags      = false;

        // Checks whether we need nearby blocks or not. If not, just exit out as we no longer need to specify additional data.
        string requireNearbyBlocks;

        if (!this.PropExists(propRequireNearbyBlocks, out requireNearbyBlocks))
        {
            Log.Warning("Property does not exists for require nearby blocks.");
            return;
        }

        if (!StringParsers.TryParseBool(requireNearbyBlocks, out this.requireNearbyBlocks))
        {
            throw new Exception("Require nearby blocks property needs to be true or false.");
        }
        Log.Out("Nearby Blocks Needed? " + this.requireNearbyBlocks.ToString());


        // Check whether we have a range specified. If so, we need to parse it.
        string nearbyBlockRange;

        if (this.PropExists(propNearbyBlockRange, out nearbyBlockRange))
        {
            List <string> blockRanges = StringHelpers.WriteStringToList(nearbyBlockRange);
            switch (blockRanges.Count)
            {
            case 1:     // Clone the first value twice to make it a list of 3 values.
                blockRanges.Add(blockRanges[0]);
                blockRanges.Add(blockRanges[0]);
                break;

            case 3:
                break;

            default:
                throw new Exception("Block range must either be a single integer or a comma separated list of 3 integers.");
            }

            int rangeX, rangeY, rangeZ;
            if (!int.TryParse(blockRanges[0], out rangeX))
            {
                throw new Exception("Could not parse X range as an int.");
            }
            if (!int.TryParse(blockRanges[1], out rangeY))
            {
                throw new Exception("Could not parse Y range as an int.");
            }
            if (!int.TryParse(blockRanges[2], out rangeZ))
            {
                throw new Exception("Could not parse Z range as an int.");
            }

            if (rangeX < 0 | rangeY < 0 | rangeZ < 0)
            {
                throw new Exception("Ranges for the block to search must be non-negative.");
            }

            this.nearbyBlockRange = new Vector3i(rangeX, rangeY, rangeZ);
        }

        // Check whether we have a count of nearby blocks.
        string nearbyBlocks;

        if (this.PropExists(propNearbyBlockCount, out nearbyBlocks))
        {
            if (!int.TryParse(nearbyBlocks, out this.nearbyBlockCount))
            {
                throw new Exception("Could not parse nearby block count as integer value.");
            }
            if (this.nearbyBlockCount < 0)
            {
                throw new Exception("Nearby block count needs to be non-negative.");
            }
        }

        // Checks whether the blocks specified exist for block names.
        string nearbyBlockNames;

        if (this.PropExists(propNearbyBlockNames, out nearbyBlockNames))
        {
            this.nearbyBlockNames = StringHelpers.WriteStringToList(nearbyBlockNames);
            this.CheckBlocksDefined(this.nearbyBlockNames);
        }

        // Checks block tags.
        string nearbyBlockTags;

        if (this.PropExists(propNearbyBlockTags, out nearbyBlockTags))
        {
            this.nearbyBlockTags = StringHelpers.WriteStringToList(nearbyBlockTags);
        }

        // Checks require all tags.
        string requireAllTags;

        if (this.PropExists(propRequireAllTags, out requireAllTags))
        {
            if (!StringParsers.TryParseBool(requireAllTags, out this.requireAllTags))
            {
                throw new Exception("Could not parse require all tags parameter as a boolean value.");
            }
        }
    }