Esempio n. 1
0
        private void AddTerrariaTileEntity(ITileEntity tileEntity)
        {
            int id;
            var x = tileEntity.Position.X;
            var y = tileEntity.Position.Y;

            lock (_tileEntityLock)
            {
                switch (tileEntity)
                {
                case ItemFrame itemFrame:
                    var item = itemFrame.Item;
                    id = TEItemFrame.Place(x, y);
                    TEItemFrame.TryPlacing(x, y, item.Type, item.Prefix, item.StackSize);
                    break;

                case LogicSensor logicSensor:
                    id = TELogicSensor.Place(x, y);
                    var terrariaLogicSensor = (TELogicSensor)TileEntity.ByID[id];
                    terrariaLogicSensor.CountedData = logicSensor.Data;
                    terrariaLogicSensor.logicCheck  = (TELogicSensor.LogicCheckType)logicSensor.Type;
                    terrariaLogicSensor.On          = logicSensor.IsEnabled;
                    break;

                case TrainingDummy _:
                    id = TETrainingDummy.Place(x, y);
                    ((TETrainingDummy)TileEntity.ByID[id]).Activate();
                    break;

                default:
                    return;
                }
            }
            NetMessage.SendData(86, -1, -1, null, id, x, y);
        }
Esempio n. 2
0
        public override void Execute()
        {
            if (!CanUseCommand())
            {
                return;
            }
            Tools.PrepareUndo(x, y, x2, y2, plr);
            int noMsg = 0;

            #region Signs

            if ((_action == 255) || (_action == 0))
            {
                int success = 0, failure = 0;
                for (int i = x; i <= x2; i++)
                {
                    for (int j = y; j <= y2; j++)
                    {
                        if ((Main.tile[i, j].type == TileID.Signs ||
                             Main.tile[i, j].type == TileID.Tombstones ||
                             Main.tile[i, j].type == TileID.AnnouncementBox) &&
                            Main.tile[i, j].frameX % 36 == 0 &&
                            Main.tile[i, j].frameY == 0 &&
                            Sign.ReadSign(i, j, false) == -1)
                        {
                            int sign = Sign.ReadSign(i, j);
                            if (sign == -1)
                            {
                                failure++;
                            }
                            else
                            {
                                success++;
                            }
                        }
                    }
                }
                if (success > 0 || failure > 0)
                {
                    plr.SendSuccessMessage("Activated signs. ({0}){1}", success,
                                           failure > 0 ? " Failed to activate signs. (" + failure + ")" : "");
                }
                else
                {
                    noMsg++;
                }
            }

            #endregion
            #region Chests

            if ((_action == 255) || (_action == 1))
            {
                int success = 0, failure = 0;
                for (int i = x; i <= x2; i++)
                {
                    for (int j = y; j <= y2; j++)
                    {
                        if ((Main.tile[i, j].type == TileID.Containers ||
                             Main.tile[i, j].type == TileID.Containers2 ||
                             Main.tile[i, j].type == TileID.Dressers) &&
                            Main.tile[i, j].frameX % 36 == 0 &&
                            Main.tile[i, j].frameY == 0 &&
                            Chest.FindChest(i, j) == -1)
                        {
                            int chest = Chest.CreateChest(i, j);
                            if (chest == -1)
                            {
                                failure++;
                            }
                            else
                            {
                                success++;
                            }
                        }
                    }
                }
                if (success > 0 || failure > 0)
                {
                    plr.SendSuccessMessage("Activated chests. ({0}){1}", success,
                                           failure > 0 ? " Failed to activate chests. (" + failure + ")" : "");
                }
                else
                {
                    noMsg++;
                }
            }

            #endregion
            #region ItemFrames

            if ((_action == 255) || (_action == 2))
            {
                int success = 0, failure = 0;
                for (int i = x; i <= x2; i++)
                {
                    for (int j = y; j <= y2; j++)
                    {
                        if (Main.tile[i, j].type == TileID.ItemFrame &&
                            Main.tile[i, j].frameX % 36 == 0 &&
                            Main.tile[i, j].frameY == 0 &&
                            TEItemFrame.Find(i, j) == -1)
                        {
                            int frame = TEItemFrame.Place(i, j);
                            if (frame == -1)
                            {
                                failure++;
                            }
                            else
                            {
                                success++;
                            }
                        }
                    }
                }
                if (success > 0 || failure > 0)
                {
                    plr.SendSuccessMessage("Activated item frames. ({0}){1}", success,
                                           failure > 0 ? " Failed to activate item frames. (" + failure + ")" : "");
                }
                else
                {
                    noMsg++;
                }
            }

            #endregion
            #region LogicSensors

            if ((_action == 255) || (_action == 3))
            {
                int success = 0, failure = 0;
                for (int i = x; i <= x2; i++)
                {
                    for (int j = y; j <= y2; j++)
                    {
                        if (Main.tile[i, j].type == TileID.LogicSensor &&
                            TELogicSensor.Find(i, j) == -1)
                        {
                            int sensor = TELogicSensor.Place(i, j);
                            if (sensor == -1)
                            {
                                failure++;
                            }
                            else
                            {
                                ((TELogicSensor)TELogicSensor.ByID[sensor]).logicCheck =
                                    (TELogicSensor.LogicCheckType)((Main.tile[i, j].frameY / 18) + 1);
                                success++;
                            }
                        }
                    }
                }
                if (success > 0 || failure > 0)
                {
                    plr.SendSuccessMessage("Activated logic sensors. ({0}){1}", success,
                                           failure > 0 ? " Failed to activate logic sensors. (" + failure + ")" : "");
                }
                else
                {
                    noMsg++;
                }
            }

            #endregion
            #region TargetDummies

            if ((_action == 255) || (_action == 4))
            {
                int success = 0, failure = 0;
                for (int i = x; i <= x2; i++)
                {
                    for (int j = y; j <= y2; j++)
                    {
                        if (Main.tile[i, j].type == TileID.TargetDummy &&
                            Main.tile[i, j].frameX % 36 == 0 &&
                            Main.tile[i, j].frameY == 0 &&
                            TETrainingDummy.Find(i, j) == -1)
                        {
                            int dummy = TETrainingDummy.Place(i, j);
                            if (dummy == -1)
                            {
                                failure++;
                            }
                            else
                            {
                                success++;
                            }
                        }
                    }
                }
                if (success > 0 || failure > 0)
                {
                    plr.SendSuccessMessage("Activated target dummies. ({0}){1}", success,
                                           failure > 0 ? " Failed to activate target dummies. (" + failure + ")" : "");
                }
                else
                {
                    noMsg++;
                }
            }

            #endregion
            if (noMsg == 5)
            {
                plr.SendSuccessMessage("There are no objects to activate in this area.");
            }
            ResetSection();
        }
Esempio n. 3
0
        public static void LoadWorldSection(WorldSectionData Data, int?X = null, int?Y = null, bool Tiles = true)
        {
            int x = (X ?? Data.X), y = (Y ?? Data.Y);

            if (Tiles)
            {
                for (var i = 0; i < Data.Width; i++)
                {
                    for (var j = 0; j < Data.Height; j++)
                    {
                        int _x = i + x, _y = j + y;
                        if (!InMapBoundaries(_x, _y))
                        {
                            continue;
                        }
                        Main.tile[_x, _y] = Data.Tiles[i, j];
                        Main.tile[_x, _y].skipLiquid(true);
                    }
                }
            }

            ClearObjects(x, y, x + Data.Width, y + Data.Height);

            foreach (var sign in Data.Signs)
            {
                var id = Sign.ReadSign(sign.X + x, sign.Y + y);
                if ((id == -1) || !InMapBoundaries(sign.X, sign.Y))
                {
                    continue;
                }
                Sign.TextSign(id, sign.Text);
            }

            foreach (var itemFrame in Data.ItemFrames)
            {
                var id = TEItemFrame.Place(itemFrame.X + x, itemFrame.Y + y);
                if (id == -1)
                {
                    continue;
                }

                var frame = (TEItemFrame)TileEntity.ByID[id];
                if (!InMapBoundaries(frame.Position.X, frame.Position.Y))
                {
                    continue;
                }
                frame.item = new Item();
                frame.item.netDefaults(itemFrame.Item.NetId);
                frame.item.stack  = itemFrame.Item.Stack;
                frame.item.prefix = itemFrame.Item.PrefixId;
            }

            foreach (var chest in Data.Chests)
            {
                int chestX = chest.X + x, chestY = chest.Y + y;

                int id;
                if ((id = Chest.FindChest(chestX, chestY)) == -1 &&
                    (id = Chest.CreateChest(chestX, chestY)) == -1)
                {
                    continue;
                }
                Chest _chest = Main.chest[id];
                if (!InMapBoundaries(chest.X, chest.Y))
                {
                    continue;
                }

                for (var index = 0; index < chest.Items.Length; index++)
                {
                    var netItem = chest.Items[index];
                    var item    = new Item();
                    item.netDefaults(netItem.NetId);
                    item.stack  = netItem.Stack;
                    item.prefix = netItem.PrefixId;
                    Main.chest[id].item[index] = item;
                }
            }

            foreach (var logicSensor in Data.LogicSensors)
            {
                var id = TELogicSensor.Place(logicSensor.X + x, logicSensor.Y + y);
                if (id == -1)
                {
                    continue;
                }
                var sensor = (TELogicSensor)TileEntity.ByID[id];
                if (!InMapBoundaries(sensor.Position.X, sensor.Position.Y))
                {
                    continue;
                }
                sensor.logicCheck = logicSensor.Type;
            }

            foreach (var trainingDummy in Data.TrainingDummies)
            {
                var id = TETrainingDummy.Place(trainingDummy.X + x, trainingDummy.Y + y);
                if (id == -1)
                {
                    continue;
                }
                var dummy = (TETrainingDummy)TileEntity.ByID[id];
                if (!InMapBoundaries(dummy.Position.X, dummy.Position.Y))
                {
                    continue;
                }
                dummy.npc = -1;
            }

            ResetSection(x, y, x + Data.Width, y + Data.Height);
        }