public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry)
        {
            bool      enable = BooleanTag.TryFor(entry.GetArgumentObject(queue, 1)).Internal;
            EntityTag entity = EntityTag.For(entry.GetArgumentObject(queue, 0));

            if (entity == null)
            {
                queue.HandleError(entry, "Invalid entity!");
                return;
            }
            ZombieTag zombie;

            if (entity.TryGetZombie(out zombie))
            {
                zombie.Internal.UFM_AIDisabled = !enable;
                if (entry.ShouldShowGood(queue))
                {
                    entry.Good(queue, "AI for a zombie " + (enable ? "enabled!" : "disabled!"));
                }
                return;
            }
            AnimalTag animal;

            if (entity.TryGetAnimal(out animal))
            {
                animal.Internal.UFM_AIDisabled = !enable;
                if (entry.ShouldShowGood(queue))
                {
                    entry.Good(queue, "AI for an animal " + (enable ? "enabled!" : "disabled!"));
                }
                return;
            }
            queue.HandleError(entry, "That entity doesn't have AI!");
        }
        public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry)
        {
            PlayerTag player = PlayerTag.For(entry.GetArgument(queue, 0));

            if (player == null)
            {
                queue.HandleError(entry, "Invalid player!");
                return;
            }
            ItemAssetTag item = ItemAssetTag.For(entry.GetArgument(queue, 1));

            if (item == null)
            {
                queue.HandleError(entry, "Invalid item!");
                return;
            }
            byte amount = 1;

            if (entry.Arguments.Count > 2)
            {
                amount = (byte)Utilities.StringToUInt(entry.GetArgument(queue, 2));
            }
            if (ItemTool.tryForceGiveItem(player.Internal.player, item.Internal.id, amount))
            {
                if (entry.ShouldShowGood(queue))
                {
                    entry.Good(queue, "Successfully gave a " + TagParser.Escape(item.Internal.name) + "!");
                }
            }
            else
            {
                queue.HandleError(entry, "Failed to give item (is the inventory full?)!");
            }
        }
Example #3
0
 public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry)
 {
     try
     {
         IntegerTag num = IntegerTag.TryFor(entry.GetArgumentObject(queue, 1));
         if (num == null)
         {
             queue.HandleError(entry, "Invalid amount number!");
             return;
         }
         PlayerTag player = PlayerTag.For(entry.GetArgument(queue, 0));
         if (player == null)
         {
             queue.HandleError(entry, "Invalid player!");
             return;
         }
         player.Internal.player.life.askWarm((uint)num.Internal);
         if (entry.ShouldShowGood(queue))
         {
             entry.Good(queue, "Successfully adjusted the warmth level of a player!");
         }
     }
     catch (Exception ex) // TODO: Necessity?
     {
         queue.HandleError(entry, "Failed to adjust player's warmth level: " + ex.ToString());
     }
 }
Example #4
0
        public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry)
        {
            bool      enable = BooleanTag.TryFor(entry.GetArgumentObject(queue, 1)).Internal;
            EntityTag entity = EntityTag.For(entry.GetArgumentObject(queue, 0));

            if (entity == null)
            {
                queue.HandleError(entry, "Invalid entity!");
                return;
            }
            BarricadeTag barricadeTag;
            byte         x;
            byte         y;
            ushort       plant;
            ushort       index;

            if (entity.TryGetBarricade(out barricadeTag, out x, out y, out plant, out index))
            {
                UnityEngine.GameObject obj  = barricadeTag.Internal.gameObject;
                InteractableDoor       door = obj.GetComponent <InteractableDoor>();
                if (door != null)
                {
                    SendMessage("tellToggleDoor", x, y, plant, index, !door.isOpen);
                    barricadeTag.InternalData.barricade.state[16] = (byte)(!door.isOpen ? 0 : 1);
                    return;
                }
                InteractableFire fire = obj.GetComponent <InteractableFire>();
                if (fire != null)
                {
                    SendMessage("tellToggleFire", x, y, plant, index, !fire.isLit);
                    barricadeTag.InternalData.barricade.state[0] = (byte)(!fire.isLit ? 0 : 1);
                    return;
                }
                InteractableGenerator generator = obj.GetComponent <InteractableGenerator>();
                if (generator != null)
                {
                    SendMessage("tellToggleGenerator", x, y, plant, index, !generator.isPowered);
                    barricadeTag.InternalData.barricade.state[0] = (byte)(!generator.isPowered ? 0 : 1);
                    EffectManager.sendEffect(8, EffectManager.SMALL, barricadeTag.Internal.position);
                    return;
                }
                InteractableSafezone safezone = obj.GetComponent <InteractableSafezone>();
                if (generator != null)
                {
                    SendMessage("tellToggleSafezone", x, y, plant, index, !safezone.isPowered);
                    barricadeTag.InternalData.barricade.state[0] = (byte)(!safezone.isPowered ? 0 : 1);
                    EffectManager.sendEffect(8, EffectManager.SMALL, barricadeTag.Internal.position);
                    return;
                }
                InteractableSpot spot = obj.GetComponent <InteractableSpot>();
                if (spot != null)
                {
                    SendMessage("tellToggleSpot", x, y, plant, index, !spot.isPowered);
                    barricadeTag.InternalData.barricade.state[0] = (byte)(!spot.isPowered ? 0 : 1);
                    EffectManager.sendEffect(8, EffectManager.SMALL, barricadeTag.Internal.position);
                    return;
                }
            }
            queue.HandleError(entry, "That entity isn't powerable!");
        }
Example #5
0
        public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry)
        {
            TemplateObject tcolor = entry.GetArgumentObject(queue, 0);
            ColorTag       color  = ColorTag.For(tcolor);

            if (color == null)
            {
                queue.HandleError(entry, "Invalid color: " + TagParser.Escape(tcolor.ToString()));
                return;
            }
            string    message  = entry.GetArgument(queue, 1);
            EChatMode chatMode = EChatMode.SAY;

            if (entry.Arguments.Count > 2)
            {
                string mode = entry.GetArgument(queue, 2);
                try
                {
                    chatMode = (EChatMode)Enum.Parse(typeof(EChatMode), mode.ToUpper());
                } catch (ArgumentException)
                {
                    queue.HandleError(entry, "Invalid chat mode: " + mode);
                    return;
                }
            }
            ChatManager.manager.channel.send("tellChat", ESteamCall.OTHERS, ESteamPacket.UPDATE_UNRELIABLE_BUFFER, new object[]
            {
                CSteamID.Nil,
                (byte)chatMode,
                color.Internal,
                message
            });
        }
Example #6
0
        public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry)
        {
            IntegerTag num = IntegerTag.TryFor(entry.GetArgumentObject(queue, 1));

            if (num.Internal <= 0)
            {
                queue.HandleError(entry, "Must provide a number that is greater than 0!");
                return;
            }
            EntityTag entity = EntityTag.For(entry.GetArgumentObject(queue, 0));

            if (entity == null)
            {
                queue.HandleError(entry, "Invalid entity!");
                return;
            }
            ZombieTag zombie;

            if (entity.TryGetZombie(out zombie))
            {
                Zombie inZomb = zombie.Internal;
                inZomb.maxHealth = (ushort)num.Internal;
                if (inZomb.health > inZomb.maxHealth)
                {
                    inZomb.health = inZomb.maxHealth;
                }
                if (entry.ShouldShowGood(queue))
                {
                    entry.Good(queue, "Successfully set health of a zombie to " + inZomb.maxHealth + "!");
                }
                return;
            }
            PlayerTag player;

            if (entity.TryGetPlayer(out player))
            {
                GameObject          playerObj  = player.Internal.player.gameObject;
                UFMHealthController controller = playerObj.GetComponent <UFMHealthController>();
                if (controller == null)
                {
                    controller = playerObj.AddComponent <UFMHealthController>();
                }
                controller.maxHealth = (uint)num.Internal;
                PlayerLife life = player.Internal.player.life;
                byte       curr = life.health;
                controller.health = curr >= controller.maxHealth ? controller.maxHealth : curr;
                life._health      = controller.Translate();
                life.channel.send("tellHealth", ESteamCall.OWNER, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[]
                {
                    life.health
                });
                if (entry.ShouldShowGood(queue))
                {
                    entry.Good(queue, "Successfully set max health of a player to " + controller.maxHealth + "!");
                }
                return;
            }
            queue.HandleError(entry, "That entity can't be healed!");
        }
 public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry)
 {
     try
     {
         LocationTag loc = LocationTag.For(entry.GetArgument(queue, 1));
         if (loc == null)
         {
             queue.HandleError(entry, "Invalid location!");
             return;
         }
         EntityTag entity = EntityTag.For(entry.GetArgumentObject(queue, 0));
         if (entity == null)
         {
             queue.HandleError(entry, "Invalid entity!");
             return;
         }
         PlayerTag player;
         if (entity.TryGetPlayer(out player))
         {
             player.Internal.player.gameObject.AddComponent <LaunchComponent>().LaunchPlayer(loc.ToVector3());
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully launched player " + TagParser.Escape(player.ToString()) + " to " + TagParser.Escape(loc.ToString()) + "!");
             }
             return;
         }
         ZombieTag zombie;
         if (entity.TryGetZombie(out zombie))
         {
             zombie.Internal.gameObject.AddComponent <LaunchComponent>().Launch(loc.ToVector3());
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully launched zombie " + TagParser.Escape(zombie.ToString()) + " to " + TagParser.Escape(loc.ToString()) + "!");
             }
             return;
         }
         AnimalTag animal;
         if (entity.TryGetAnimal(out animal))
         {
             animal.Internal.gameObject.AddComponent <LaunchComponent>().Launch(loc.ToVector3());
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully launched animal " + TagParser.Escape(animal.ToString()) + " to " + TagParser.Escape(loc.ToString()) + "!");
             }
             return;
         }
         ItemEntityTag item;
         if (entity.TryGetItem(out item))
         {
             // TODO: Find some way to teleport items, barricades, etc without voiding the InstanceID?
         }
         queue.HandleError(entry, "That entity can't be launched!");
     }
     catch (Exception ex) // TODO: Necessity?
     {
         queue.HandleError(entry, "Failed to launch entity: " + ex.ToString());
     }
 }
Example #8
0
        public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry)
        {
            PlayerTag player = PlayerTag.For(entry.GetArgument(queue, 0));

            if (player == null)
            {
                queue.HandleError(entry, "Invalid player!");
                return;
            }
            ItemAssetTag item = ItemAssetTag.For(entry.GetArgument(queue, 1));

            if (item == null)
            {
                queue.HandleError(entry, "Invalid item!");
                return;
            }
            byte amount = 1;

            if (entry.Arguments.Count > 2)
            {
                amount = (byte)Utilities.StringToUInt(entry.GetArgument(queue, 2));
            }
            PlayerInventory inventory       = player.Internal.player.inventory;
            byte            remainingAmount = amount;
            InventorySearch search;

            while (remainingAmount > 0 && (search = inventory.has(item.Internal.id)) != null) // TODO: Less awkward code!?
            {
                if (search.jar.item.amount <= remainingAmount)
                {
                    inventory.removeItem(search.page, inventory.getIndex(search.page, search.jar.x, search.jar.y));
                    remainingAmount -= search.jar.item.amount;
                }
                else
                {
                    inventory.sendUpdateAmount(search.page, search.jar.x, search.jar.y, (byte)(search.jar.item.amount - remainingAmount));
                    remainingAmount = 0;
                }
            }
            if (remainingAmount == 0)
            {
                if (entry.ShouldShowGood(queue))
                {
                    entry.Good(queue, "Successfully took " + amount + " " + TagParser.Escape(item.Internal.name) + "!");
                }
            }
            else if (remainingAmount < amount)
            {
                if (entry.ShouldShowGood(queue))
                {
                    entry.Good(queue, "Successfully took " + (amount - remainingAmount) + " " + TagParser.Escape(item.Internal.name) + "! (" + remainingAmount + " more not found!)");
                }
            }
            else
            {
                queue.HandleError(entry, "Failed to take item (does the inventory contain any?)!");
            }
        }
        public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry)
        {
            IntegerTag itag = IntegerTag.TryFor(entry.GetArgumentObject(queue, 0));
            uint       ti   = (uint)itag.Internal;

            SDG.Unturned.LightingManager.time = ti;
            if (entry.ShouldShowGood(queue))
            {
                entry.Good(queue, "World time set to " + ti + "!");
            }
        }
Example #10
0
        public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry)
        {
            LocationTag loc = LocationTag.For(entry.GetArgument(queue, 1));

            if (loc == null)
            {
                queue.HandleError(entry, "Invalid location!");
                return;
            }
            EntityTag entity = EntityTag.For(entry.GetArgumentObject(queue, 0));

            if (entity == null)
            {
                queue.HandleError(entry, "Invalid entity!");
                return;
            }
            ZombieTag zombie;

            if (entity.TryGetZombie(out zombie))
            {
                zombie.Internal.target.position  = loc.ToVector3();
                zombie.Internal.seeker.canMove   = true;
                zombie.Internal.seeker.canSearch = true;
                zombie.Internal.path             = EZombiePath.RUSH; // TODO: Option for this?
                if (!zombie.Internal.isTicking)
                {
                    zombie.Internal.isTicking = true;
                    ZombieManager.tickingZombies.Add(zombie.Internal);
                }
                if (entry.ShouldShowGood(queue))
                {
                    entry.Good(queue, "Successfully started a zombie walking to " + TagParser.Escape(loc.ToString()) + "!");
                }
                return;
            }
            AnimalTag animal;

            if (entity.TryGetAnimal(out animal))
            {
                animal.Internal.target = loc.ToVector3();
                if (!animal.Internal.isTicking)
                {
                    animal.Internal.isTicking = true;
                    AnimalManager.tickingAnimals.Add(animal.Internal);
                }
                if (entry.ShouldShowGood(queue))
                {
                    entry.Good(queue, "Successfully started an animal walking to " + TagParser.Escape(loc.ToString()) + "!");
                }
                return;
            }
            queue.HandleError(entry, "That entity can't be made to walk!");
        }
 public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry)
 {
     try
     {
         BooleanTag boolean = BooleanTag.TryFor(entry.GetArgumentObject(queue, 1));
         if (boolean == null)
         {
             queue.HandleError(entry, "Invalid boolean!");
             return;
         }
         PlayerTag player = PlayerTag.For(entry.GetArgument(queue, 0));
         if (player == null)
         {
             queue.HandleError(entry, "Invalid player!");
             return;
         }
         bool       value = boolean.Internal;
         PlayerLife life  = player.Internal.player.life;
         if (life.isBroken != value)
         {
             if (value)
             {
                 life.breakLegs();
             }
             else
             {
                 life._isBroken = false;
                 life.channel.send("tellBroken", ESteamCall.OWNER, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[]
                 {
                     life._isBroken
                 });
             }
             entry.Good(queue, "Successfully adjusted the broken legs of player " + TagParser.Escape(player.ToString()) + " to " + TagParser.Escape(boolean.ToString()) + "!");
         }
         else
         {
             entry.Good(queue, "Player " + TagParser.Escape(player.ToString()) + " already has their broken legs set to " + TagParser.Escape(boolean.ToString()) + "!");
         }
     }
     catch (Exception ex) // TODO: Necessity?
     {
         queue.HandleError(entry, "Failed to adjust player's broken legs: " + ex.ToString());
     }
 }
Example #12
0
        public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry)
        {
            IntegerTag num = IntegerTag.TryFor(entry.GetArgumentObject(queue, 2));

            if (num == null)
            {
                queue.HandleError(entry, "Invalid amount number!");
                return;
            }
            PlayerTag player = PlayerTag.For(entry.GetArgument(queue, 0));

            if (player == null)
            {
                queue.HandleError(entry, "Invalid player!");
                return;
            }
            bool award = entry.GetArgument(queue, 1) == "award";

            if (num.Internal > 0)
            {
                PlayerSkills skills = player.Internal.player.skills;
                if (award)
                {
                    skills._experience += (uint)num.Internal;
                }
                else
                {
                    skills._experience -= (uint)num.Internal;
                }
                skills.channel.send("tellExperience", ESteamCall.OWNER, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[]
                {
                    skills.experience
                });
            }
            else
            {
                queue.HandleError(entry, "Amount must be positive!");
                return;
            }
            if (entry.ShouldShowGood(queue))
            {
                entry.Good(queue, "Successfully " + (award ? "awarded experience to" : "took experience from") + " a player!");
            }
        }
        /// <summary>Handles an error as appropriate to the situation, in the current queue, from the current command.</summary>
        /// <param name="queue">The associated queue.</param>
        /// <param name="entry">The command entry that errored.</param>
        /// <param name="message">The error message.</param>
        public void HandleError(CommandQueue queue, CommandEntry entry, string message)
        {
            StringBuilder stacktrace = new();

            stacktrace.Append("ERROR: " + message + "\n    in script '" + entry.ScriptName + "' at line " + (entry.ScriptLine + 1)
                              + ": (" + entry.Name + ")\n");
            queue.WaitingOn = null;
            CompiledCommandRunnable runnable = queue.RunningStack.Count > 0 ? queue.RunningStack.Peek() : null;
            DebugMode dbmode = runnable == null ? DebugMode.FULL : runnable.Debug;

            while (runnable != null)
            {
                for (int i = runnable.Index; i < runnable.Entry.Entries.Length; i++)
                {
                    CommandEntry entr = runnable.Entry.Entries[i];
                    if (entr.Command is TryCommand &&
                        entr.IsCallback)
                    {
                        entry.GoodOutput(queue, "Force-exiting try block.");
                        // TODO: queue.SetVariable("stack_trace", new TextTag(stacktrace.ToString().Substring(0, stacktrace.Length - 1)));
                        runnable.Index = i + 2;
                        throw new ErrorInducedException();
                    }
                }
                runnable.Index = runnable.Entry.Entries.Length + 1;
                queue.RunningStack.Pop();
                if (queue.RunningStack.Count > 0)
                {
                    runnable = queue.RunningStack.Peek();
                    queue.CurrentRunnable = runnable;
                    if (runnable.Index <= runnable.Entry.Entries.Length)
                    {
                        stacktrace.Append("    in script '" + runnable.Entry.Entries[runnable.Index - 1].ScriptName + "' at line " + (runnable.Entry.Entries[runnable.Index - 1].ScriptLine + 1)
                                          + ": (" + runnable.Entry.Entries[runnable.Index - 1].Name + ")\n");
                    }
                }
                else
                {
                    runnable = null;
                    break;
                }
            }
            message = stacktrace.ToString()[..(stacktrace.Length - 1)];
        protected override void execute(CSteamID executorID, string parameter)
        {
            FreneticScript.CommandSystem.CommandQueue queue = ExecScript.ToQueue(UnturnedFreneticMod.Instance.CommandSystem.System);
            MapTag map = new MapTag();

            if (executorID == CSteamID.Nil)
            {
                map.Internal["is_server"] = new BooleanTag(true);
            }
            else
            {
                map.Internal["player"]    = new PlayerTag(PlayerTool.getSteamPlayer(executorID));
                map.Internal["is_server"] = new BooleanTag(false);
            }
            map.Internal["raw_arguments"] = new TextTag(parameter);
            queue.SetVariable("context", map);
            queue.CommandStack.Peek().Debug = DebugMode.MINIMAL; // Just in case
            queue.Execute();
        }
Example #15
0
 /// <summary>Displays the usage information on a command to the console.</summary>
 /// <param name="queue">The associated queue.</param>
 /// <param name="entry">The CommandEntry data to show usage help to.</param>
 /// <param name="doError">Whether to end with an error.</param>
 /// <param name="cmd">The command to show help for - if unspecified, will get from the entry.</param>
 public static void ShowUsage(CommandQueue queue, CommandEntry entry, bool doError = true, AbstractCommand cmd = null)
 {
     if (cmd == null)
     {
         cmd = entry.Command;
     }
     if (entry.ShouldShowGood(queue))
     {
         entry.InfoOutput(queue, TextStyle.Separate + cmd.Meta.Name + TextStyle.Base + ": " + cmd.Meta.Description);
         entry.InfoOutput(queue, TextStyle.Commandhelp + "Usage: /" + cmd.Meta.Name + " " + cmd.Meta.Arguments);
         if (cmd.Meta.IsDebug)
         {
             entry.InfoOutput(queue, "Note: This command is intended for debugging purposes.");
         }
     }
     if (doError)
     {
         queue.HandleError(entry, "Invalid arguments or not enough arguments!");
     }
 }
Example #16
0
        public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry)
        {
            if (entry.Arguments[0].ToString() == "\0CALLBACK")
            {
                return;
            }
            if (entry.Arguments.Count < 3)
            {
                ShowUsage(queue, entry);
                return;
            }
            bool   servermode = entry.GetArgument(queue, 0).ToLowerFast() == "server";
            string name       = entry.GetArgument(queue, 1).ToLowerFast();
            string help       = entry.GetArgument(queue, 2);

            if (entry.InnerCommandBlock == null)
            {
                queue.HandleError(entry, "Event command invalid: No block follows!");
                return;
            }
            // NOTE: Commands are compiled!
            CommandScript script = new CommandScript("ut_command_" + name, entry.InnerCommandBlock, entry.BlockStart, queue.CurrentEntry.Types, true)
            {
                Debug = DebugMode.MINIMAL
            };
            UnturnedCustomCommand ucc = new UnturnedCustomCommand(name, help, script);

            if (servermode)
            {
                Commander.commands.Insert(1, ucc);
            }
            else
            {
                UnturnedFreneticMod.Instance.PlayerCommands.Add(ucc);
            }
            if (entry.ShouldShowGood(queue))
            {
                entry.Good(queue, "Registered command!");
            }
        }
        public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry)
        {
            PlayerTag player  = PlayerTag.For(entry.GetArgument(queue, 0));
            bool      primary = entry.GetArgument(queue, 1) == "primary";
            bool      start   = BooleanTag.TryFor(entry.GetArgumentObject(queue, 2)).Internal;

            if (player.Internal.player.equipment.useable == null)
            {
                entry.Bad(queue, "Failed to use item, holding nothing.");
                return;
            }
            if (primary)
            {
                if (start)
                {
                    player.Internal.player.equipment.useable.startPrimary();
                }
                else
                {
                    player.Internal.player.equipment.useable.stopPrimary();
                }
            }
            else
            {
                if (start)
                {
                    player.Internal.player.equipment.useable.startSecondary();
                }
                else
                {
                    player.Internal.player.equipment.useable.stopSecondary();
                }
            }
            player.Internal.player.equipment.useable.tick();
            player.Internal.player.equipment.useable.tock(player.Internal.player.input.clock);
            if (entry.ShouldShowGood(queue))
            {
                entry.Good(queue, "Player is " + (start ? "now" : "no longer") + " using the " + (primary ? "primary" : "secondary") + " mode on their held item!");
            }
        }
Example #18
0
        public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry)
        {
            ListTag        players = ListTag.For(entry.GetArgument(queue, 0));
            TemplateObject tcolor  = entry.GetArgumentObject(queue, 1);
            ColorTag       color   = ColorTag.For(tcolor);

            if (color == null)
            {
                queue.HandleError(entry, "Invalid color: " + TagParser.Escape(tcolor.ToString()));
                return;
            }
            string    tchatter = entry.GetArgument(queue, 2);
            PlayerTag chatter  = PlayerTag.For(tchatter);

            if (chatter == null)
            {
                queue.HandleError(entry, "Invalid chatting player: " + TagParser.Escape(tchatter));
                return;
            }
            string message = entry.GetArgument(queue, 3);

            foreach (TemplateObject tplayer in players.ListEntries)
            {
                PlayerTag player = PlayerTag.For(tplayer.ToString());
                if (player == null)
                {
                    queue.HandleError(entry, "Invalid player: " + TagParser.Escape(tplayer.ToString()));
                    continue;
                }
                ChatManager.manager.channel.send("tellChat", player.Internal.playerID.steamID, ESteamPacket.UPDATE_UNRELIABLE_BUFFER,
                                                 chatter.Internal.playerID.steamID, (byte)0 /* TODO: Configurable mode? */, color.Internal, message);
                if (entry.ShouldShowGood(queue))
                {
                    entry.Good(queue, "Successfully sent a message.");
                }
            }
        }
Example #19
0
 public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry)
 {
     try
     {
         IntegerTag num = IntegerTag.TryFor(entry.GetArgumentObject(queue, 1));
         if (num == null)
         {
             queue.HandleError(entry, "Invalid amount number!");
             return;
         }
         PlayerTag player = PlayerTag.For(entry.GetArgument(queue, 0));
         if (player == null)
         {
             queue.HandleError(entry, "Invalid player!");
             return;
         }
         int        amount = (int)num.Internal;
         PlayerLife life   = player.Internal.player.life;
         if (amount >= 0)
         {
             life.askRest((byte)amount);
         }
         else
         {
             life.askTire((byte)-amount);
         }
         if (entry.ShouldShowGood(queue))
         {
             entry.Good(queue, "Successfully adjusted the stamina level of a player!");
         }
     }
     catch (Exception ex) // TODO: Necessity?
     {
         queue.HandleError(entry, "Failed to adjust player's stamina level: " + ex.ToString());
     }
 }
        public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry)
        {
            LocationTag loc = LocationTag.For(entry.GetArgument(queue, 1));

            if (loc == null)
            {
                queue.HandleError(entry, "Invalid location!");
                return;
            }
            string         targetAssetType = entry.GetArgument(queue, 0).ToLower();
            EffectAssetTag effectType      = EffectAssetTag.For(targetAssetType);

            if (effectType == null)
            {
                queue.HandleError(entry, "Invalid effect type!");
                return;
            }
            EffectManager.sendEffect(effectType.Internal.id, EffectManager.INSANE, loc.ToVector3());
            // TODO: radius option instead of always 512 units (INSANE)!
            if (entry.ShouldShowGood(queue))
            {
                entry.Good(queue, "Played effect " + TagParser.Escape(effectType.ToString()) + " at " + TagParser.Escape(loc.ToString()) + "!");
            }
        }
Example #21
0
        public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry)
        {
            string    animation = entry.GetArgument(queue, 1).ToUpperInvariant();
            EntityTag entity    = EntityTag.For(entry.GetArgumentObject(queue, 0));

            if (entity == null)
            {
                queue.HandleError(entry, "Invalid entity!");
                return;
            }
            PlayerTag player;

            if (entity.TryGetPlayer(out player))
            {
                try
                {
                    player.Internal.player.animator.sendGesture((EPlayerGesture)Enum.Parse(typeof(EPlayerGesture), animation), true);
                    //player.Internal.player.animator.askGesture(player.Internal.playerID.steamID, (byte)((EPlayerGesture)Enum.Parse(typeof(EPlayerGesture), animation)));
                }
                catch (ArgumentException)
                {
                    queue.HandleError(entry, "Invalid animation specified!");
                    return;
                }
                if (entry.ShouldShowGood(queue))
                {
                    entry.Good(queue, "Animated a player!");
                }
                return;
            }
            ZombieTag zombie;

            if (entity.TryGetZombie(out zombie))
            {
                int    ind   = animation.IndexOf('_');
                string after = animation.Substring(ind + 1);
                animation = animation.Substring(0, ind);
                if (animation == "STARTLE")
                {
                    ZombieManager.sendZombieStartle(zombie.Internal, (byte)IntegerTag.TryFor(after).Internal);
                }
                else if (animation == "STUN")
                {
                    ZombieManager.sendZombieStun(zombie.Internal, (byte)IntegerTag.TryFor(after).Internal);
                }
                else if (animation == "ATTACK")
                {
                    ZombieManager.sendZombieAttack(zombie.Internal, (byte)IntegerTag.TryFor(after).Internal);
                }
                else
                {
                    queue.HandleError(entry, "Invalid animation specified!");
                    return;
                }
                if (entry.ShouldShowGood(queue))
                {
                    entry.Good(queue, "Animated an animal!");
                }
                return;
            }
            AnimalTag animal;

            if (entity.TryGetAnimal(out animal))
            {
                if (animation == "STARTLE")
                {
                    AnimalManager.sendAnimalStartle(animal.Internal);
                }
                else if (animation == "PANIC")
                {
                    AnimalManager.sendAnimalPanic(animal.Internal);
                }
                else if (animation == "ATTACK")
                {
                    AnimalManager.sendAnimalAttack(animal.Internal);
                }
                else
                {
                    queue.HandleError(entry, "Invalid animation specified!");
                    return;
                }
                if (entry.ShouldShowGood(queue))
                {
                    entry.Good(queue, "Animated an animal!");
                }
                return;
            }
            queue.HandleError(entry, "That entity can't be animated!");
        }
 /// <summary>Run this command stack.</summary>
 /// <param name="queue">The queue to run under.</param>
 /// <param name="runnable">The runnable to run.</param>
 /// <returns>Whether to continue looping.</returns>
 public CommandStackRetVal Run(CommandQueue queue, CompiledCommandRunnable runnable)
 {
     runnable.CurrentQueue = queue;
     try
     {
         runnable.Run(queue);
         runnable.Index++;
         if (queue.Delayable && ((queue.Wait > 0f) || queue.WaitingOn != null))
         {
             return(CommandStackRetVal.BREAK);
         }
         runnable.Callback?.Invoke();
         if (queue.RunningStack.Count == 0)
         {
             return(CommandStackRetVal.BREAK);
         }
         if (queue.RunningStack.Peek() != runnable)
         {
             return(CommandStackRetVal.CONTINUE);
         }
         if (runnable.Index >= Entries.Length)
         {
             queue.RunningStack.Pop();
         }
         if (queue.RunningStack.Count == 0)
         {
             return(CommandStackRetVal.STOP);
         }
         return(CommandStackRetVal.CONTINUE);
     }
     catch (Exception ex)
     {
         FreneticScriptUtilities.CheckException(ex);
         if (!(ex is ErrorInducedException eie && string.IsNullOrEmpty(eie.Message)))
         {
             try
             {
                 if (ex is ErrorInducedException)
                 {
                     queue.HandleError(Entries[runnable.Index], ex.Message);
                 }
                 else
                 {
                     queue.HandleError(Entries[runnable.Index], "Internal exception:\n------\n" + ex.ToString() + "\n------");
                 }
             }
             catch (Exception ex2)
             {
                 if (ex2 is ThreadAbortException)
                 {
                     throw;
                 }
                 if (ex2 is not ErrorInducedException)
                 {
                     string message = ex2.ToString();
                     if (runnable.Debug <= DebugMode.MINIMAL)
                     {
                         queue.Engine.Context.BadOutput(message);
                         if (queue.Outputsystem != null)
                         {
                             queue.Outputsystem.Invoke(message, MessageType.BAD);
                         }
                         runnable.Index = Entries.Length + 1;
                         queue.RunningStack.Clear();
                     }
                 }
             }
         }
         if (queue.RunningStack.Count > 0)
         {
             if (queue.RunningStack.Peek() == runnable)
             {
                 queue.RunningStack.Pop();
             }
             return(CommandStackRetVal.CONTINUE);
         }
         return(CommandStackRetVal.STOP);
     }
     finally
     {
         runnable.CurrentQueue = null;
     }
 }
 public override void UnknownCommand(FreneticScript.CommandSystem.CommandQueue queue, string basecommand, string[] arguments)
 {
     Bad("Invalid command: " + TagParser.Escape(basecommand) + "!", queue.CommandStack.Count > 0 ? queue.CommandStack.Peek().Debug : DebugMode.FULL);
 }
Example #24
0
 /// <summary>
 /// Called to properly handle an unknown command.
 /// Only used if <see cref="ShouldErrorOnInvalidCommand"/> returns true.
 /// </summary>
 /// <param name="queue">The queue firing this unknown command.</param>
 /// <param name="basecommand">The command that wasn't recognized.</param>
 /// <param name="arguments">The commands arguments.</param>
 public virtual void UnknownCommand(CommandQueue queue, string basecommand, string[] arguments)
 {
     throw new NotImplementedException("Unknown command: " + basecommand);
 }
        public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry)
        {
            EntityTag entity = EntityTag.For(entry.GetArgumentObject(queue, 0));

            if (entity == null)
            {
                queue.HandleError(entry, "Invalid entity!");
                return;
            }
            EPlayerKill kill; // for use with "out EPlayerKill" parameters
            PlayerTag   player;

            if (entity.TryGetPlayer(out player))
            {
                PlayerLife life = player.Internal.player.life;
                life.askDamage(life.health, Vector3.zero, EDeathCause.KILL, ELimb.SPINE, CSteamID.Nil, out kill, null);
                if (entry.ShouldShowGood(queue))
                {
                    entry.Good(queue, "Successfully killed a player!");
                }
                return;
            }
            ZombieTag zombie;

            if (entity.TryGetZombie(out zombie))
            {
                while (!zombie.Internal.isDead)
                {
                    uint xp;
                    zombie.Internal.askDamage((byte)zombie.Internal.health, Vector3.zero, out kill, out xp);
                }
                if (entry.ShouldShowGood(queue))
                {
                    entry.Good(queue, "Successfully killed a zombie!");
                }
                return;
            }
            AnimalTag animal;

            if (entity.TryGetAnimal(out animal))
            {
                while (!animal.Internal.isDead)
                {
                    uint xp;
                    animal.Internal.askDamage((byte)animal.Internal.health, Vector3.zero, out kill, out xp);
                }
                if (entry.ShouldShowGood(queue))
                {
                    entry.Good(queue, "Successfully killed an animal!");
                }
                return;
            }
            BarricadeTag barricade;

            if (entity.TryGetBarricade(out barricade))
            {
                // TODO: Use BarricadeManager?
                barricade.InternalData.barricade.askDamage(barricade.InternalData.barricade.health);
                if (entry.ShouldShowGood(queue))
                {
                    entry.Good(queue, "Successfully destroyed a barricade!");
                }
                return;
            }
            ResourceTag resource;

            if (entity.TryGetResource(out resource))
            {
                // TODO: Use ResourceManager?
                resource.Internal.askDamage(resource.Internal.health);
                if (entry.ShouldShowGood(queue))
                {
                    entry.Good(queue, "Successfully destroyed a resource!");
                }
                return;
            }
            StructureTag structure;

            if (entity.TryGetStructure(out structure))
            {
                // TODO: Use StructureManager?
                structure.InternalData.structure.askDamage(structure.InternalData.structure.health);
                if (entry.ShouldShowGood(queue))
                {
                    entry.Good(queue, "Successfully destroyed a structure!");
                }
                return;
            }
            VehicleTag vehicle;

            if (entity.TryGetVehicle(out vehicle))
            {
                vehicle.Internal.askDamage(vehicle.Internal.health, false);
                if (entry.ShouldShowGood(queue))
                {
                    entry.Good(queue, "Successfully destroyed a vehicle!");
                }
                return;
            }
            queue.HandleError(entry, "That entity can't be damaged!");
        }
        public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry)
        {
            try
            {
                TemplateObject spawned = null;
                LocationTag    loc     = LocationTag.For(entry.GetArgument(queue, 1));
                if (loc == null)
                {
                    queue.HandleError(entry, "Invalid location!");
                    return;
                }
                string     targetAssetType = entry.GetArgument(queue, 0).ToLowerFast();
                EntityType etype           = EntityType.ValueOf(targetAssetType);
                if (etype == null)
                {
                    queue.HandleError(entry, "Invalid entity type!");
                    return;
                }
                if (etype.Type == EntityAssetType.ZOMBIE)
                {
                    Vector3 vec3    = loc.ToVector3();
                    byte    reg     = 0; // TODO: Optionally specifiable
                    float   closest = float.MaxValue;
                    for (int r = 0; r < LevelZombies.zombies.Length; r++)
                    {
                        for (int i = 0; i < LevelZombies.zombies[r].Count; i++)
                        {
                            float dist = (LevelZombies.zombies[r][i].point - vec3).sqrMagnitude;
                            if (dist < closest)
                            {
                                closest = dist;
                                reg     = (byte)r;
                            }
                        }
                    }
                    ZombieManager.manager.addZombie(reg, 0, 0, 0, 0, 0, 0, 0, 0, vec3, 0, false);
                    Zombie zombie = ZombieManager.regions[reg].zombies[ZombieManager.regions[reg].zombies.Count - 1];
                    // TODO: Make this actually work! (See complaints file!)

                    /*
                     * foreach (SteamPlayer player in PlayerTool.getSteamPlayers())
                     * {
                     *  ZombieManager.manager.channel.openWrite();
                     *  ZombieManager.manager.channel.write(reg);
                     *  ZombieManager.manager.channel.write((ushort)1);
                     *  ZombieManager.manager.channel.write(new object[]
                     *      {
                     *          zombie.type,
                     *          (byte)zombie.speciality,
                     *          zombie.shirt,
                     *          zombie.pants,
                     *          zombie.hat,
                     *          zombie.gear,
                     *          zombie.move,
                     *          zombie.idle,
                     *          zombie.transform.position,
                     *          MeasurementTool.angleToByte(zombie.transform.rotation.eulerAngles.y),
                     *          zombie.isDead
                     *      });
                     *  ZombieManager.manager.channel.closeWrite("tellZombies", player.playerID.steamID, ESteamPacket.UPDATE_RELIABLE_CHUNK_BUFFER);
                     * }
                     */
                    if (entry.ShouldShowGood(queue))
                    {
                        entry.Good(queue, "Successfully spawned a zombie at " + TagParser.Escape(loc.ToString()) + "! (WARNING: IT WILL BE INVISIBLE CURRENTLY - SEE THE COMPLAINTS FILE)");
                    }
                    spawned = new ZombieTag(zombie);
                }
                else if (etype.Type == EntityAssetType.ANIMAL)
                {
                    AnimalAssetTag asset = AnimalAssetTag.For(targetAssetType);
                    if (asset == null)
                    {
                        queue.HandleError(entry, "Invalid animal type!");
                        return;
                    }
                    // TODO: Make this bit optional!
                    RaycastHit rch;
                    while (Physics.Raycast(loc.ToVector3(), new Vector3(0, 1, 0), out rch, 5))
                    {
                        loc.Y += 3;
                    }
                    // END TODO
                    AnimalManager.manager.addAnimal(asset.Internal.id, loc.ToVector3(), 0, false);
                    Animal animal = AnimalManager.animals[AnimalManager.animals.Count - 1];
                    foreach (SteamPlayer player in PlayerTool.getSteamPlayers())
                    {
                        AnimalManager.manager.channel.openWrite();
                        AnimalManager.manager.channel.write((ushort)1);
                        AnimalManager.manager.channel.write(new object[]
                        {
                            animal.id,
                            animal.transform.position,
                            MeasurementTool.angleToByte(animal.transform.rotation.eulerAngles.y),
                            animal.isDead
                        });
                        AnimalManager.manager.channel.closeWrite("tellAnimals", player.playerID.steamID, ESteamPacket.UPDATE_RELIABLE_CHUNK_BUFFER);
                    }
                    if (entry.ShouldShowGood(queue))
                    {
                        entry.Good(queue, "Successfully spawned a " + TagParser.Escape(asset.ToString()) + " at " + TagParser.Escape(loc.ToString()) + "! (" + animal.gameObject.GetInstanceID() + ")");
                    }
                    spawned = new AnimalTag(animal);
                }
                else if (etype.Type == EntityAssetType.VEHICLE)
                {
                    VehicleAssetTag asset = VehicleAssetTag.For(targetAssetType);
                    if (asset == null)
                    {
                        queue.HandleError(entry, "Invalid vehicle type!");
                        return;
                    }
                    // TODO: Make this bit optional!
                    RaycastHit rch;
                    while (Physics.Raycast(loc.ToVector3(), new Vector3(0, 1, 0), out rch, 5))
                    {
                        loc.Y += 3;
                    }
                    // END TODO
                    VehicleManager.spawnVehicle(asset.Internal.id, loc.ToVector3(), Quaternion.identity);
                    if (entry.ShouldShowGood(queue))
                    {
                        entry.Good(queue, "Successfully spawned a " + TagParser.Escape(asset.ToString()) + " at " + TagParser.Escape(loc.ToString()) + "!");
                    }
                    // TODO: Get the vehicle entity!
                }
                else if (etype.Type == EntityAssetType.WORLD_OBJECT)
                {
                    WorldObjectAssetTag asset = WorldObjectAssetTag.For(targetAssetType);
                    if (asset == null)
                    {
                        queue.HandleError(entry, "Invalid world object type!");
                        return;
                    }
                    LevelObjects.addObject(loc.ToVector3(), Quaternion.identity, Vector3.one, asset.Internal.id, asset.Internal.name, asset.Internal.GUID, ELevelObjectPlacementOrigin.MANUAL);
                    // TODO: Network!
                    entry.Good(queue, "Successfully spawned a " + TagParser.Escape(asset.ToString()) + " at " + TagParser.Escape(loc.ToString()) + "! (WARNING: IT WILL BE INVISIBLE CURRENTLY - SEE THE COMPLAINTS FILE)");
                    // TODO: Get the world entity!
                }
                else if (etype.Type == EntityAssetType.ITEM)
                {
                    ItemAssetTag asset = ItemAssetTag.For(targetAssetType);
                    if (asset == null)
                    {
                        queue.HandleError(entry, "Invalid item type!");
                        return;
                    }
                    byte x;
                    byte y;
                    if (Regions.tryGetCoordinate(loc.ToVector3(), out x, out y))
                    {
                        Item     item = new Item(asset.Internal.id, 1, asset.Internal.quality);
                        ItemData data = new ItemData(item, ++ItemManager.instanceCount, loc.ToVector3(), Dedicator.isDedicated);
                        ItemManager.regions[x, y].items.Add(data);
                        ItemModelTracker.Track(data, loc.ToVector3());
                        ItemManager.manager.channel.send("tellItem", ESteamCall.CLIENTS, x, y, ItemManager.ITEM_REGIONS, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[]
                        {
                            x,
                            y,
                            item.id,
                            item.amount,
                            item.quality,
                            item.state,
                            loc.ToVector3()
                        });
                        if (entry.ShouldShowGood(queue))
                        {
                            entry.Good(queue, "Successfully spawned a " + TagParser.Escape(asset.ToString()) + " at " + TagParser.Escape(loc.ToString()) + "!");
                        }
                        // TODO: Get the item entity!
                    }
                    else
                    {
                        queue.HandleError(entry, "Trying to spawn item outside any valid item regions!");
                    }
                }
                else if (etype.Type == EntityAssetType.BARRICADE)
                {
                    ItemAssetTag asset = ItemAssetTag.For(targetAssetType.Substring("barricade_".Length));
                    if (asset == null || !(asset.Internal is ItemBarricadeAsset))
                    {
                        queue.HandleError(entry, "Invalid item barricade type!");
                        return;
                    }
                    Barricade barric = new Barricade(asset.Internal.id);
                    BarricadeManager.dropBarricade(barric, null, loc.ToVector3(), 0f, 0f, 0f, CSteamID.Nil.m_SteamID, CSteamID.Nil.m_SteamID);
                    if (entry.ShouldShowGood(queue))
                    {
                        entry.Good(queue, "Successfully spawned a " + TagParser.Escape(asset.ToString()) + " at " + TagParser.Escape(loc.ToString()) + "!");
                    }
                    // TODO: Get the game object!
                }
                else if (etype.Type == EntityAssetType.STRUCTURE)
                {
                    ItemAssetTag asset = ItemAssetTag.For(targetAssetType.Substring("structure_".Length));
                    if (asset == null || !(asset.Internal is ItemStructureAsset))
                    {
                        queue.HandleError(entry, "Invalid item structure type!");
                        return;
                    }
                    StructureManager.dropStructure(new Structure(asset.Internal.id), loc.ToVector3(), 0f, 0f, 0f, CSteamID.Nil.m_SteamID, CSteamID.Nil.m_SteamID);
                    if (entry.ShouldShowGood(queue))
                    {
                        entry.Good(queue, "Successfully spawned a " + TagParser.Escape(asset.ToString()) + " at " + TagParser.Escape(loc.ToString()) + "!");
                    }
                    // TODO: Get the game object!
                }
                else
                {
                    queue.HandleError(entry, "Invalid or unspawnable entity type!");
                    return;
                }
                if (spawned != null)
                {
                    queue.SetVariable("spawned", spawned);
                }
            }
            catch (Exception ex) // TODO: Necessity?
            {
                queue.HandleError(entry, "Failed to spawn entity: " + ex.ToString());
            }
        }
 /// <summary>
 /// Generates an appropriate queue + entry error handling action. Use this to retain an error handler after command execution. Otherwise, use <see cref="CommandQueue.Error"/>.
 /// </summary>
 /// <param name="queue">The queue for the context.</param>
 /// <returns>The Action object.</returns>
 public Action <string> ContextualErrorHandler(CommandQueue queue)
 {
     return((s) => queue.HandleError(this, s));
 }
Example #28
0
 public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry)
 {
     try
     {
         IntegerTag num = IntegerTag.TryFor(entry.GetArgumentObject(queue, 1));
         if (num.Internal < 0)
         {
             queue.HandleError(entry, "Must provide a non-negative number!");
             return;
         }
         EntityTag entity = EntityTag.For(entry.GetArgumentObject(queue, 0));
         if (entity == null)
         {
             queue.HandleError(entry, "Invalid entity!");
             return;
         }
         PlayerTag player;
         if (entity.TryGetPlayer(out player))
         {
             UFMHealthController healthController = player.Internal.player.gameObject.GetComponent <UFMHealthController>();
             uint amount = (uint)num.Internal;
             if (healthController != null)
             {
                 healthController.Heal(amount);
                 amount = (uint)(((double)amount / healthController.maxHealth) * 100.0);
             }
             PlayerLife life = player.Internal.player.life;
             life._health = healthController.Translate();
             life.channel.send("tellHealth", ESteamCall.OWNER, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[]
             {
                 life.health
             });
             if (entry.ShouldShowGood(queue))
             {
                 uint finalHealth = healthController != null ? healthController.health : life.health;
                 entry.Good(queue, "Successfully healed a player to a new health value of " + finalHealth + "!");
             }
             return;
         }
         ZombieTag zombie;
         if (entity.TryGetZombie(out zombie))
         {
             Zombie inZomb = zombie.Internal;
             inZomb.health += (ushort)num.Internal;
             if (inZomb.health > inZomb.maxHealth)
             {
                 inZomb.health = inZomb.maxHealth;
             }
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully healed a zombie to a new health value of " + inZomb.health + "!");
             }
             return;
         }
         AnimalTag animal;
         if (entity.TryGetAnimal(out animal))
         {
             Animal inAnimal = animal.Internal;
             inAnimal.health += (ushort)num.Internal;
             if (inAnimal.health > inAnimal.asset.health)
             {
                 inAnimal.health = inAnimal.asset.health;
             }
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully healed an animal to a new health value of " + inAnimal.health + "!");
             }
             return;
         }
         BarricadeTag barricade;
         if (entity.TryGetBarricade(out barricade))
         {
             Barricade inBarricade = barricade.InternalData.barricade;
             inBarricade.health += (ushort)num.Internal;
             ushort max = ((ItemBarricadeAsset)Assets.find(EAssetType.ITEM, inBarricade.id)).health;
             if (inBarricade.health > max)
             {
                 inBarricade.health = max;
             }
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully healed a barricade to a new health value of " + inBarricade.health + "!");
             }
             return;
         }
         ResourceTag resource;
         if (entity.TryGetResource(out resource))
         {
             ResourceSpawnpoint inResource = resource.Internal;
             inResource.health += (ushort)num.Internal;
             ushort max = ((ResourceAsset)Assets.find(EAssetType.RESOURCE, inResource.id)).health;
             if (inResource.health > max)
             {
                 inResource.health = max;
             }
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully healed a resource to a new health value of " + inResource.health + "!");
             }
             return;
         }
         StructureTag structure;
         if (entity.TryGetStructure(out structure))
         {
             Structure inStructure = structure.InternalData.structure;
             inStructure.health += (ushort)num.Internal;
             ushort max = ((ItemStructureAsset)Assets.find(EAssetType.ITEM, inStructure.id)).health;
             if (inStructure.health > max)
             {
                 inStructure.health = max;
             }
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully healed a structure to a new health value of " + inStructure.health + "!");
             }
             return;
         }
         VehicleTag vehicle;
         if (entity.TryGetVehicle(out vehicle))
         {
             vehicle.Internal.askRepair((ushort)num.Internal);
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully healed a vehicle to a new health value of " + vehicle.Internal.health + "!");
             }
             return;
         }
         queue.HandleError(entry, "That entity can't be healed!");
     }
     catch (Exception ex) // TODO: Necessity?
     {
         queue.HandleError(entry, ("Failed to heal entity: " + ex.ToString()));
     }
 }
 public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry)
 {
     try
     {
         IntegerTag num = IntegerTag.TryFor(entry.GetArgumentObject(queue, 1));
         if (num.Internal < 0)
         {
             queue.HandleError(entry, "Must provide a non-negative number!");
             return;
         }
         EntityTag entity = EntityTag.For(entry.GetArgumentObject(queue, 0));
         if (entity == null)
         {
             queue.HandleError(entry, "Invalid entity!");
             return;
         }
         EPlayerKill kill; // for use with "out EPlayerKill" parameters
         PlayerTag   player;
         if (entity.TryGetPlayer(out player))
         {
             PlayerLife          life             = player.Internal.player.life;
             UFMHealthController healthController = player.Internal.player.GetComponent <UFMHealthController>();
             uint health = healthController != null ? healthController.health : life.health;
             if (num.Internal >= health)
             {
                 uint amount = (uint)num.Internal;
                 if (healthController != null)
                 {
                     healthController.health = 0;
                 }
                 if (amount >= byte.MaxValue) // TODO: better handling
                 {
                     life._health = 0;
                     amount       = 1;
                 }
                 life.askDamage((byte)amount, Vector3.zero, EDeathCause.KILL, ELimb.SPINE, CSteamID.Nil, out kill, null);
             }
             else
             {
                 uint amount = (uint)num.Internal;
                 if (healthController != null)
                 {
                     healthController.Damage((uint)num.Internal);
                 }
                 life._health = healthController.Translate();
                 life.channel.send("tellHealth", ESteamCall.OWNER, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[]
                 {
                     life.health
                 });
             }
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully damaged a player by " + TagParser.Escape(num.ToString()) + "!");
             }
             return;
         }
         ZombieTag zombie;
         if (entity.TryGetZombie(out zombie))
         {
             uint xp;
             zombie.Internal.askDamage((byte)num.Internal, Vector3.zero, out kill, out xp);
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully damaged a zombie by " + TagParser.Escape(num.ToString()) + "!");
             }
             return;
         }
         AnimalTag animal;
         if (entity.TryGetAnimal(out animal))
         {
             uint xp;
             animal.Internal.askDamage((byte)num.Internal, Vector3.zero, out kill, out xp);
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully damaged an animal by " + TagParser.Escape(num.ToString()) + "!");
             }
             return;
         }
         BarricadeTag barricade;
         if (entity.TryGetBarricade(out barricade))
         {
             // TODO: Use BarricadeManager?
             barricade.InternalData.barricade.askDamage((ushort)num.Internal);
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully damaged a barricade by " + TagParser.Escape(num.ToString()) + "!");
             }
             return;
         }
         ResourceTag resource;
         if (entity.TryGetResource(out resource))
         {
             // TODO: Use ResourceManager?
             resource.Internal.askDamage((ushort)num.Internal);
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully damaged a resource by " + TagParser.Escape(num.ToString()) + "!");
             }
             return;
         }
         StructureTag structure;
         if (entity.TryGetStructure(out structure))
         {
             // TODO: Use StructureManager?
             structure.InternalData.structure.askDamage((ushort)num.Internal);
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully damaged a structure by " + TagParser.Escape(num.ToString()) + "!");
             }
             return;
         }
         VehicleTag vehicle;
         if (entity.TryGetVehicle(out vehicle))
         {
             vehicle.Internal.askDamage((ushort)num.Internal, false);
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully damaged a vehicle by " + TagParser.Escape(num.ToString()) + "!");
             }
             return;
         }
         queue.HandleError(entry, "That entity can't be damaged!");
     }
     catch (Exception ex) // TODO: Necessity?
     {
         queue.HandleError(entry, "Failed to damage entity: " + ex.ToString());
     }
 }
 /// <summary>Constructs the event args.</summary>
 /// <param name="queue">The relevant queue.</param>
 public CommandQueueEventArgs(CommandQueue queue)
 {
     Queue = queue;
 }