Exemplo n.º 1
0
    public bool IsObjectWired(ObjectMeasureData measureData, WireColor wireColor, out DPoint firstWireLocation) {
      foreach (DPoint tileLocation in this.EnumerateObjectTileLocations(measureData)) {
        ITile tile = TerrariaUtils.Tiles[tileLocation];
        if (tile.HasWire(wireColor)) {
          firstWireLocation = tileLocation;
          return true;
        }
      }

      firstWireLocation = DPoint.Empty;
      return false;
    }
Exemplo n.º 2
0
        public bool HandleSendData(SendDataEventArgs e)
        {
            if (e.MsgId == PacketTypes.TileSendSquare && e.number == 1)
            {
                DPoint tileLocation = new DPoint((int)e.number2, (int)e.number3);
                if (TerrariaUtils.Tiles.IsValidCoord(tileLocation))
                {
                    ITile tile = TerrariaUtils.Tiles[tileLocation];
                    if (tile.type == TileID.LogicSensor && !tile.HasWire())
                    {
                        this.ProcessCircuit(TSPlayer.Server, tileLocation, null, false);
                    }
                }
            }

            return(false);
        }
Exemplo n.º 3
0
    public bool IsObjectWired(DPoint originTileLocation, DPoint size, out DPoint firstWirePosition) {
      for (int tx = 0; tx < size.X; tx++) {
        for (int ty = 0; ty < size.Y; ty++) {
          int ax = originTileLocation.X + tx;
          int ay = originTileLocation.Y + ty;

          ITile tile = TerrariaUtils.Tiles[ax, ay];
          if (tile.HasWire()) {
            firstWirePosition = new DPoint(ax, ay);
            return true;
          }
        }
      }

      firstWirePosition = DPoint.Empty;
      return false;
    }
        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);
        }