コード例 #1
0
 public int GetItemTypeFromTrapStyle(TrapStyle trapStyle) {
   switch (trapStyle) {
     case TrapStyle.DartTrap:
       return ItemID.DartTrap;
     case TrapStyle.SuperDartTrap:
       return ItemID.SuperDartTrap;
     case TrapStyle.FlameTrap:
       return ItemID.FlameTrap;
     case TrapStyle.SpikyBallTrap:
       return ItemID.SpikyBallTrap;
     case TrapStyle.SpearTrap:
       return ItemID.SpearTrap;
     default:
       return ItemID.None;
   }
 }
コード例 #2
0
 public TrapConfigKey(TrapStyle trapStyle, PaintColor paint) : this()
 {
     this.TrapStyle = trapStyle;
     this.Paint     = paint;
 }
コード例 #3
0
        public static Configuration Read(string filePath)
        {
            XmlReaderSettings configReaderSettings = new XmlReaderSettings {
                ValidationType  = ValidationType.Schema,
                ValidationFlags = XmlSchemaValidationFlags.ProcessIdentityConstraints | XmlSchemaValidationFlags.ReportValidationWarnings
            };

            string configSchemaPath = Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath) + ".xsd");

            configReaderSettings.Schemas.Add(null, configSchemaPath);

            XmlDocument document = new XmlDocument();

            using (XmlReader configReader = XmlReader.Create(filePath, configReaderSettings))
                document.Load(configReader);

            // Before validating using the schema, first check if the configuration file's version matches with the supported version.
            XmlElement rootElement = document.DocumentElement;
            string     fileVersionRaw;

            if (rootElement.HasAttribute("Version"))
            {
                fileVersionRaw = rootElement.GetAttribute("Version");
            }
            else
            {
                fileVersionRaw = "1.0";
            }

            if (fileVersionRaw != Configuration.CurrentVersion)
            {
                throw new FormatException(string.Format(
                                              "The configuration file is either outdated or too new. Expected version was: {0}. File version is: {1}",
                                              Configuration.CurrentVersion, fileVersionRaw
                                              ));
            }

            Configuration resultingConfig = new Configuration(false);

            resultingConfig.OverrideVanillaCircuits = BoolEx.ParseEx(rootElement["OverrideVanillaCircuits"].InnerXml);
            resultingConfig.AdvancedCircuitsEnabled = BoolEx.ParseEx(rootElement["AdvancedCircuitsEnabled"].InnerText);
            resultingConfig.MaxTrapsPerCircuit      = int.Parse(rootElement["MaxTrapsPerCircuit"].InnerText);
            resultingConfig.MaxStatuesPerCircuit    = int.Parse(rootElement["MaxStatuesPerCircuit"].InnerText);
            resultingConfig.MaxPumpsPerCircuit      = int.Parse(rootElement["MaxPumpsPerCircuit"].InnerText);
            resultingConfig.MaxCircuitLength        = int.Parse(rootElement["MaxCircuitLength"].InnerText);
            if (string.IsNullOrWhiteSpace(rootElement["MaxTimerActivityTime"].InnerText))
            {
                resultingConfig.MaxTimerActivityTime = TimeSpan.Zero;
            }
            else
            {
                TimeSpan maxTimerActivityTime;
                if (TimeSpanEx.TryParseShort(rootElement["MaxTimerActivityTime"].InnerText, out maxTimerActivityTime))
                {
                    resultingConfig.MaxTimerActivityTime = maxTimerActivityTime;
                }
            }
            resultingConfig.SignConfig           = SignConfig.FromXmlElement(rootElement["SignConfig"]);
            resultingConfig.BlockActivatorConfig = BlockActivatorConfig.FromXmlElement(rootElement["BlockActivatorConfig"]);

            XmlElement pumpConfigsNode = rootElement["PumpConfigs"];

            foreach (XmlNode pumpConfigNode in pumpConfigsNode.ChildNodes)
            {
                XmlElement pumpConfigElement = (pumpConfigNode as XmlElement);
                if (pumpConfigElement == null)
                {
                    continue;
                }

                PaintColor paintColor = (PaintColor)Enum.Parse(typeof(PaintColor), pumpConfigElement.Attributes["Paint"].Value);
                resultingConfig.PumpConfigs.Add(paintColor, PumpConfig.FromXmlElement(pumpConfigElement));
            }

            XmlElement trapConfigsNode = rootElement["TrapConfigs"];

            foreach (XmlNode trapConfigNode in trapConfigsNode.ChildNodes)
            {
                XmlElement trapConfigElement = (trapConfigNode as XmlElement);
                if (trapConfigElement == null)
                {
                    continue;
                }

                TrapStyle  trapStyle  = (TrapStyle)Enum.Parse(typeof(TrapStyle), trapConfigElement.Attributes["TrapType"].Value);
                PaintColor paintColor = (PaintColor)Enum.Parse(typeof(PaintColor), trapConfigElement.Attributes["Paint"].Value);
                resultingConfig.TrapConfigs.Add(new TrapConfigKey(trapStyle, paintColor), TrapConfig.FromXmlElement(trapConfigElement));
            }

            /*XmlElement explosivesConfigsNode = rootElement["ExplosivesConfigs"];
             * foreach (XmlNode explosivesConfigNode in explosivesConfigsNode.ChildNodes) {
             * XmlElement explosivesConfigElement = (explosivesConfigNode as XmlElement);
             * if (explosivesConfigElement == null)
             *  continue;
             *
             * ComponentConfigProfile componentConfigProfile = (ComponentConfigProfile)Enum.Parse(typeof(ComponentConfigProfile), explosivesConfigElement.Attributes["Profile"].Value);
             * resultingConfig.explosivesConfigs.Add(componentConfigProfile, ExplosivesConfig.FromXmlElement(explosivesConfigElement));
             * }*/

            XmlElement wirelessTransmitterConfigsNode = rootElement["WirelessTransmitterConfigs"];

            foreach (XmlNode wirelessTransmitterConfigNode in wirelessTransmitterConfigsNode.ChildNodes)
            {
                XmlElement wirelessTransmitterConfigElement = (wirelessTransmitterConfigNode as XmlElement);
                if (wirelessTransmitterConfigElement == null)
                {
                    continue;
                }

                PaintColor paintColor = (PaintColor)Enum.Parse(typeof(PaintColor), wirelessTransmitterConfigElement.Attributes["Paint"].Value);
                resultingConfig.WirelessTransmitterConfigs.Add(paintColor, WirelessTransmitterConfig.FromXmlElement(wirelessTransmitterConfigElement));
            }

            XmlElement statueConfigsNode = rootElement["StatueConfigs"];

            foreach (XmlNode statueConfigNode in statueConfigsNode.ChildNodes)
            {
                XmlElement statueConfigElement = (statueConfigNode as XmlElement);
                if (statueConfigElement == null)
                {
                    continue;
                }

                StatueStyle statueStyle = (StatueStyle)Enum.Parse(typeof(StatueStyle), statueConfigElement.Attributes["StatueType"].Value);
                resultingConfig.StatueConfigs.Add(statueStyle, StatueConfig.FromXmlElement(statueConfigElement));
            }

            return(resultingConfig);
        }
コード例 #4
0
        private bool CheckTilePermission(TSPlayer player, DPoint location, int blockType, int objectStyle, PaintColor paint, bool dropItem = false)
        {
            switch (blockType)
            {
            case TileID.Statues: {
                DPoint originTileLocation = new DPoint(location.X - 1, location.Y - 2);
                if (!TerrariaUtils.Tiles.IsObjectWired(originTileLocation, new DPoint(2, 3)))
                {
                    break;
                }
                StatueStyle  statueStyle = TerrariaUtils.Tiles.GetStatueStyle(objectStyle);
                StatueConfig statueConfig;
                if (!this.Config.StatueConfigs.TryGetValue(statueStyle, out statueConfig) || statueConfig == null)
                {
                    break;
                }

                if (!player.Group.HasPermission(statueConfig.WirePermission))
                {
                    player.SendTileSquareEx(location, 10);

                    if (dropItem)
                    {
                        int itemTypeToDrop;
                        itemTypeToDrop = TerrariaUtils.Tiles.GetItemTypeFromStatueStyle(statueStyle);

                        Item.NewItem(location.X * TerrariaUtils.TileSize, location.Y * TerrariaUtils.TileSize, 0, 0, itemTypeToDrop);
                    }

                    this.TellNoStatueWiringPermission(player, statueStyle);
                    return(false);
                }

                break;
            }

            case TileID.Traps: {
                ITile destTile = TerrariaUtils.Tiles[location];
                if (!destTile.HasWire())
                {
                    break;
                }
                TrapConfig trapConfig;
                TrapStyle  trapStyle = TerrariaUtils.Tiles.GetTrapStyle(destTile.frameY / 18);

                TrapConfigKey configKey = new TrapConfigKey(trapStyle, paint);
                if (!this.Config.TrapConfigs.TryGetValue(configKey, out trapConfig))
                {
                    break;
                }

                if (!player.Group.HasPermission(trapConfig.WirePermission))
                {
                    player.SendTileSquareEx(location, 10);

                    if (dropItem)
                    {
                        int itemTypeToDrop = TerrariaUtils.Tiles.GetItemTypeFromTrapStyle(trapStyle);
                        Item.NewItem(location.X * TerrariaUtils.TileSize, location.Y * TerrariaUtils.TileSize, 0, 0, itemTypeToDrop);
                    }

                    this.TellMissingComponentWiringPermission(player, blockType);
                    return(false);
                }

                break;
            }

            case TileID.Boulder: {
                DPoint originTileLocation = new DPoint(location.X - 1, location.Y - 1);
                if (!TerrariaUtils.Tiles.IsObjectWired(originTileLocation, new DPoint(2, 2)))
                {
                    break;
                }

                if (!player.Group.HasPermission(AdvancedCircuitsPlugin.WireBoulder_Permission))
                {
                    player.SendTileSquareEx(location, 10);

                    if (dropItem)
                    {
                        Item.NewItem(location.X * TerrariaUtils.TileSize, location.Y * TerrariaUtils.TileSize, 0, 0, ItemID.Boulder);
                    }

                    this.TellMissingComponentWiringPermission(player, blockType);
                    return(false);
                }

                break;
            }

            case TileID.Signs: {
                if (!TerrariaUtils.Tiles.IsObjectWired(location, new DPoint(2, 2)))
                {
                    break;
                }

                if (!player.Group.HasPermission(AdvancedCircuitsPlugin.WireSign_Permission))
                {
                    player.SendTileSquareEx(location, 10);

                    if (dropItem)
                    {
                        Item.NewItem(location.X * TerrariaUtils.TileSize, location.Y * TerrariaUtils.TileSize, 0, 0, ItemID.Sign);
                    }

                    this.TellMissingComponentWiringPermission(player, blockType);
                    return(false);
                }

                break;
            }

            case TileID.InletPump:
            case TileID.OutletPump: {
                DPoint originTileLocation = new DPoint(location.X - 1, location.Y - 1);
                if (!TerrariaUtils.Tiles.IsObjectWired(originTileLocation, new DPoint(2, 2)))
                {
                    break;
                }
                PumpConfig pumpConfig;
                if (!this.Config.PumpConfigs.TryGetValue(paint, out pumpConfig))
                {
                    break;
                }
                if (string.IsNullOrEmpty(pumpConfig.WirePermission))
                {
                    break;
                }

                if (!player.Group.HasPermission(pumpConfig.WirePermission))
                {
                    player.SendTileSquareEx(location, 10);

                    if (dropItem)
                    {
                        int itemTypeToDrop = ItemID.OutletPump;
                        if (blockType == ItemID.InletPump)
                        {
                            itemTypeToDrop = ItemID.InletPump;
                        }

                        Item.NewItem(location.X * TerrariaUtils.TileSize, location.Y * TerrariaUtils.TileSize, 0, 0, itemTypeToDrop);
                    }

                    this.TellMissingComponentWiringPermission(player, blockType);
                    return(false);
                }

                break;
            }

            case AdvancedCircuits.BlockType_WirelessTransmitter: {
                if (!AdvancedCircuits.IsComponentWiredByPort(location, new DPoint(1, 1)))
                {
                    break;
                }
                WirelessTransmitterConfig transmitterConfig;
                if (!this.Config.WirelessTransmitterConfigs.TryGetValue(paint, out transmitterConfig))
                {
                    break;
                }

                if (!player.Group.HasPermission(transmitterConfig.WirePermission))
                {
                    player.SendTileSquareEx(location, 1);

                    if (dropItem)
                    {
                        Item.NewItem(location.X * TerrariaUtils.TileSize, location.Y * TerrariaUtils.TileSize, 0, 0, ItemID.AdamantiteOre);
                    }

                    this.TellMissingComponentWiringPermission(player, blockType);
                    return(false);
                }

                break;
            }

            case ItemID.Teleporter: {
                DPoint originTileLocation = new DPoint(location.X - 1, location.Y - 1);
                if (!TerrariaUtils.Tiles.IsObjectWired(originTileLocation, new DPoint(3, 1)))
                {
                    break;
                }

                if (!player.Group.HasPermission(AdvancedCircuitsPlugin.WireTeleporter_Permission))
                {
                    player.SendTileSquareEx(location, 10);

                    if (dropItem)
                    {
                        Item.NewItem(location.X * TerrariaUtils.TileSize, location.Y * TerrariaUtils.TileSize, 0, 0, ItemID.Teleporter);
                    }

                    this.TellMissingComponentWiringPermission(player, blockType);
                    return(false);
                }

                break;
            }
            }

            return(true);
        }
コード例 #5
0
 public TrapConfigKey(TrapStyle trapStyle, PaintColor paint): this() {
   this.TrapStyle = trapStyle;
   this.Paint = paint;
 }
コード例 #6
0
 public ItemType GetItemTypeFromTrapStyle(TrapStyle trapStyle)
 {
     switch (trapStyle) {
     case TrapStyle.DartTrap:
       return ItemType.DartTrap;
     case TrapStyle.SuperDartTrap:
       return ItemType.SuperDartTrap;
     case TrapStyle.FlameTrap:
       return ItemType.FlameTrap;
     case TrapStyle.SpikyBallTrap:
       return ItemType.SpikyBallTrap;
     case TrapStyle.SpearTrap:
       return ItemType.SpearTrap;
     default:
       return ItemType.None;
       }
 }