Esempio n. 1
0
 public static void ClearObjects(int x, int y, int x2, int y2)
 {
     ClearSigns(x, y, x2, y2, false);
     ClearChests(x, y, x2, y2, false);
     for (int i = x; i <= x2; i++)
     {
         for (int j = y; j <= y2; j++)
         {
             if (TEItemFrame.Find(i, j) != -1)
             {
                 TEItemFrame.Kill(i, j);
             }
             if (TELogicSensor.Find(i, j) != -1)
             {
                 TELogicSensor.Kill(i, j);
             }
             if (TETrainingDummy.Find(i, j) != -1)
             {
                 TETrainingDummy.Kill(i, j);
             }
         }
     }
 }
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 override void Execute()
        {
            if (!CanUseCommand())
            {
                return;
            }
            Tools.PrepareUndo(x, y, x2, y2, plr);
            int signs = 0, frames = 0, chests = 0, sensors = 0, dummies = 0;

            foreach (Sign sign in Main.sign)
            {
                if (sign == null)
                {
                    continue;
                }
                ushort type = Main.tile[sign.x, sign.y].type;
                if (!Main.tile[sign.x, sign.y].active() ||
                    ((type != TileID.Signs) &&
                     (type != TileID.Tombstones) &&
                     (type != TileID.AnnouncementBox)))
                {
                    Sign.KillSign(sign.x, sign.y);
                    signs++;
                }
            }
            for (int i = x; i <= x2; i++)
            {
                for (int j = y; j <= y2; j++)
                {
                    int ID = TEItemFrame.Find(i, j);
                    if (ID == -1)
                    {
                        continue;
                    }
                    if (!Main.tile[i, j].active() ||
                        (Main.tile[i, j].type != TileID.ItemFrame))
                    {
                        TEItemFrame.Kill(i, j);
                        frames++;
                    }
                }
            }
            foreach (Chest chest in Main.chest)
            {
                if (chest == null)
                {
                    continue;
                }
                ushort type = Main.tile[chest.x, chest.y].type;
                if (!Main.tile[chest.x, chest.y].active() ||
                    ((type != TileID.Containers) &&
                     (type != TileID.Containers2) &&
                     (type != TileID.Dressers)))
                {
                    Chest.DestroyChest(chest.x, chest.y);
                    chests++;
                }
            }
            for (int i = x; i <= x2; i++)
            {
                for (int j = y; j <= y2; j++)
                {
                    int ID = TELogicSensor.Find(i, j);
                    if (ID == -1)
                    {
                        continue;
                    }
                    if (!Main.tile[i, j].active() ||
                        (Main.tile[i, j].type != TileID.LogicSensor))
                    {
                        TELogicSensor.Kill(i, j);
                        sensors++;
                    }
                }
            }
            for (int i = x; i <= x2; i++)
            {
                for (int j = y; j <= y2; j++)
                {
                    int ID = TETrainingDummy.Find(i, j);
                    if (ID == -1)
                    {
                        continue;
                    }
                    if (!Main.tile[i, j].active() ||
                        (Main.tile[i, j].type != TileID.TargetDummy))
                    {
                        TETrainingDummy.Kill(i, j);
                        dummies++;
                    }
                }
            }
            ResetSection();

            List <string> ghosts = new List <string>();

            if (signs > 0)
            {
                ghosts.Add($"signs ({signs})");
            }
            if (frames > 0)
            {
                ghosts.Add($"item frames ({frames})");
            }
            if (chests > 0)
            {
                ghosts.Add($"chests ({chests})");
            }
            if (sensors > 0)
            {
                ghosts.Add($"logic sensors ({sensors})");
            }
            if (dummies > 0)
            {
                ghosts.Add($"target dummies ({dummies})");
            }

            if (ghosts.Count > 0)
            {
                plr.SendSuccessMessage($"Fixed ghost {string.Join(", ", ghosts)}.");
            }
            else
            {
                plr.SendSuccessMessage("There are no ghost objects in this area.");
            }
        }
Esempio n. 4
0
        public void ProcessTile(ITile tile, int x, int y)
        {
            Tiles[x, y] = new Tile();
            if (tile != null)
            {
                Tiles[x, y].CopyFrom(tile);
            }

            if (!tile.active())
            {
                return;
            }

            var actualX = x + X;
            var actualY = y + Y;

            switch (tile.type)
            {
            case TileID.Signs:
            case TileID.AnnouncementBox:
            case TileID.Tombstones:
                if (tile.frameX % 36 == 0 && tile.frameY == 0)
                {
                    var id = Sign.ReadSign(actualX, actualY, false);
                    if (id != -1)
                    {
                        Signs.Add(new SignData
                        {
                            Text = Main.sign[id].text,
                            X    = x,
                            Y    = y
                        });
                    }
                }
                break;

            case TileID.ItemFrame:
                if (tile.frameX % 36 == 0 && tile.frameY == 0)
                {
                    var id = TEItemFrame.Find(actualX, actualY);
                    if (id != -1)
                    {
                        var frame = (TEItemFrame)TileEntity.ByID[id];
                        ItemFrames.Add(new ItemFrameData
                        {
                            Item = new NetItem(frame.item.netID, frame.item.stack, frame.item.prefix),
                            X    = x,
                            Y    = y
                        });
                    }
                }
                break;

            case TileID.Containers:
            case TileID.Dressers:
                if (tile.frameX % 36 == 0 && tile.frameY == 0)
                {
                    var id = Chest.FindChest(actualX, actualY);
                    if (id != -1)
                    {
                        var chest = Main.chest[id];
                        if (chest.item != null)
                        {
                            var items = chest.item.Select(item => new NetItem(item.netID, item.stack, item.prefix)).ToArray();
                            Chests.Add(new ChestData
                            {
                                Items = items,
                                X     = x,
                                Y     = y
                            });
                        }
                    }
                }
                break;

            case TileID.LogicSensor:
            {
                var id = TELogicSensor.Find(actualX, actualY);
                if (id != -1)
                {
                    var sensor = (TELogicSensor)TileEntity.ByID[id];
                    LogicSensors.Add(new LogicSensorData
                        {
                            X    = x,
                            Y    = y,
                            Type = sensor.logicCheck
                        });
                }
                break;
            }

            case TileID.TargetDummy:
                if (tile.frameX % 36 == 0 && tile.frameY == 0)
                {
                    var id = TETrainingDummy.Find(actualX, actualY);
                    if (id != -1)
                    {
                        TrainingDummies.Add(new TrainingDummyData()
                        {
                            X = x,
                            Y = y
                        });
                    }
                }
                break;
            }
        }