Exemple #1
0
        public static void ExecuteCommand(string input, ref CommandTileEntity entity)
        {
            if (!TestCommand(input, ref entity.commandTileError))
            {
                return;
            }
            entity.commandTileError = "";
            List <string> argsList = SplitString(input);

            for (int i = 0; i < argsList.Count; i++)
            {
                argsList[i] = argsList[i].ToLower();
            }

            string command = argsList[0];

            argsList.RemoveAt(0);
            switch (command)
            {
            case "w":
            case "weather":
                CallWeatherCommand(argsList);
                break;

            case "t":
            case "time":
                CallTimeCommand(argsList);
                break;

            case "i":
            case "item":
                CallItemCommand(argsList);
                break;

            case "s":
            case "say":
                argsList = SplitString(input);
                argsList.RemoveAt(0);
                CallSayCommand(argsList);
                break;

            case "k":
            case "kill":
                CallKillCommand(argsList, entity);
                break;

            case "e":
            case "event":
                CallEventCommand(argsList);
                break;

            case "su":
            case "summon":
                CallSummonCommand(argsList, entity);
                break;
            }
        }
Exemple #2
0
        private static void CallSummonCommand(List <string> args, CommandTileEntity entity)
        {
            bool isNumeric;

            int type = -1;
            int x;
            int y;

            isNumeric = int.TryParse(args[0], out int num);
            if (isNumeric)
            {
                type = num;
            }
            else
            {
                string name = args[0];
                name = name.Replace("\"", "");
                name = name.Replace(" ", "_");
                name = name.ToLower();
                NPC npc = new NPC();
                for (var i = -65; i < NPCLoader.NPCCount; i++)
                {
                    npc.SetDefaults(i);
                    if (name == Lang.GetNPCNameValue(i).ToLower())
                    {
                        type = i;
                        break;
                    }
                }
            }
            x = int.Parse(args[1]);
            y = int.Parse(args[2]);

            int rx = (entity.Position.X + x) * 16;
            int ry = (entity.Position.Y + y) * 16;

            NPC.NewNPC(rx, ry, type);
        }
Exemple #3
0
        private static void CallKillCommand(List <string> args, CommandTileEntity entity)
        {
            switch (args[0])
            {
            case "player":
                if (args[1] == "all")
                {
                    for (var i = 0; i < 255; i++)
                    {
                        Player player = Main.player[i];
                        if (player.active)
                        {
                            player.KillMe(PlayerDeathReason.ByCustomReason("killed by forces unknown!"), 1000, 0, false);
                        }
                    }
                }
                else
                {
                    bool isNumeric = double.TryParse(args[1], out double num);
                    if (isNumeric)
                    {
                        num = Math.Abs(num);
                        num++;
                        Vector2 pos = entity.Position.ToVector2();
                        for (var i = 0; i < 255; i++)
                        {
                            Player player = Main.player[i];
                            if (player.active)
                            {
                                float dist = Vector2.Distance(player.position / 16, pos);
                                dist = Math.Abs(dist);
                                if (dist <= num)
                                {
                                    player.KillMe(PlayerDeathReason.ByCustomReason("killed by forces unknown!"), 1000, 0, false);
                                }
                            }
                        }
                    }
                }
                break;

            case "npc":
                if (args[1] == "all")
                {
                    for (var i = 0; i < Main.npc.Length; i++)
                    {
                        NPC npc = Main.npc[i];
                        if (npc.active)
                        {
                            npc.life = 0;
                            npc.lifeRegen--;
                        }
                    }
                }
                else
                {
                    bool isNumeric = double.TryParse(args[1], out double num);
                    if (isNumeric)
                    {
                        num = Math.Abs(num);
                        num++;
                        Vector2 pos = entity.Position.ToVector2();
                        for (var i = 0; i < Main.npc.Length; i++)
                        {
                            NPC npc = Main.npc[i];
                            if (npc.active)
                            {
                                float dist = Vector2.Distance(npc.position / 16, pos);
                                dist = Math.Abs(dist);
                                if (dist <= num)
                                {
                                    npc.life = 0;
                                    npc.lifeRegen--;
                                }
                            }
                        }
                    }
                }
                break;
            }
        }
 public CommandTileInterface(CommandTile tile, CommandTileEntity tileEntity, KhaiosPlayer caller)
 {
     this.tile       = tile;
     this.tileEntity = tileEntity;
     this.caller     = caller;
 }