Exemplo n.º 1
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;
            }
            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!");
        }
Exemplo n.º 2
0
        /// <summary>Executes an undefine.</summary>
        /// <param name="queue">The command queue involved.</param>
        /// <param name="entry">Entry to be executed.</param>
        public static void Undefine(CommandEntry entry, CommandQueue queue)
        {
            string name = entry.GetArgument(queue, 1).ToLowerFast();

            if (!queue.Engine.Functions.Remove(name))
            {
                if (BooleanTag.TryFor(entry.GetNamedArgumentObject(queue, "quiet_fail"))?.Internal ?? false)
                {
                    if (entry.ShouldShowGood(queue))
                    {
                        entry.GoodOutput(queue, "Function '" + TextStyle.Separate + name + TextStyle.Base + "' doesn't exist!");
                    }
                }
                else
                {
                    queue.HandleError(entry, "Function '" + TextStyle.Separate + name + TextStyle.Base + "' doesn't exist!");
                }
            }
            else
            {
                if (entry.ShouldShowGood(queue))
                {
                    entry.GoodOutput(queue, "Function '" + TextStyle.Separate + name + TextStyle.Base + "' undefined.");
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>Executes a define.</summary>
        /// <param name="queue">The command queue involved.</param>
        /// <param name="entry">Entry to be executed.</param>
        public static void Define(CommandEntry entry, CommandQueue queue)
        {
            string name = entry.GetArgument(queue, 1).ToLowerFast();

            if (queue.Engine.Functions.ContainsKey(name))
            {
                if (BooleanTag.TryFor(entry.GetNamedArgumentObject(queue, "quiet_fail"))?.Internal ?? false)
                {
                    if (entry.ShouldShowGood(queue))
                    {
                        entry.GoodOutput(queue, "Function '" + TextStyle.Separate + name + TextStyle.Base + "' already exists!");
                    }
                }
                else
                {
                    queue.HandleError(entry, "Function '" + TextStyle.Separate + name + TextStyle.Base + "' already exists!");
                }
            }
            else
            {
                queue.Engine.Functions.Add(name, new CommandScript(name, CommandScript.TYPE_NAME_FUNCTION, entry.InnerCommandBlock, entry.System, entry.BlockStart, entry.DBMode));
                if (entry.ShouldShowGood(queue))
                {
                    entry.GoodOutput(queue, "Function '" + TextStyle.Separate + name + TextStyle.Base + "' defined.");
                }
            }
        }
Exemplo n.º 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!");
        }
Exemplo n.º 5
0
        // TODO: Special compiler to handle type continuation (the "or_else[]" should be treated as returning the type input to both "pass[]" and "or_else[]")

        /// <summary>Handles the 'ternary[]' tag.</summary>
        /// <param name="data">The data to be handled.</param>
        public static TernaryPassTag HandleOne(TagData data)
        {
            bool basevalue = (BooleanTag.TryFor(data.GetModifierObjectCurrent()) ?? BooleanTag.FALSE).Internal;

            return(new TernaryPassTag()
            {
                Passed = basevalue
            });
        }
 /// <summary>Converts a script object type to a specific raw type (if possible) for the ConfigSet command.</summary>
 public static object ConvertForType(Type fieldType, TemplateObject input, CommandQueue queue)
 {
     if (fieldType == typeof(string))
     {
         return(input.ToString());
     }
     else if (fieldType == typeof(bool))
     {
         return(BooleanTag.TryFor(input)?.Internal);
     }
     else if (fieldType == typeof(long))
     {
         return(IntegerTag.TryFor(input)?.Internal);
     }
     else if (fieldType == typeof(int))
     {
         IntegerTag integer = IntegerTag.TryFor(input);
         if (integer is not null)
         {
             return((int)integer.Internal);
         }
     }
     else if (fieldType == typeof(short))
     {
         IntegerTag integer = IntegerTag.TryFor(input);
         if (integer is not null)
         {
             return((short)integer.Internal);
         }
     }
     else if (fieldType == typeof(byte))
     {
         IntegerTag integer = IntegerTag.TryFor(input);
         if (integer is not null)
         {
             return((byte)integer.Internal);
         }
     }
     else if (fieldType == typeof(double))
     {
         return(NumberTag.TryFor(input)?.Internal);
     }
     else if (fieldType == typeof(float))
     {
         NumberTag number = NumberTag.TryFor(input);
         if (number is not null)
         {
             return((float)number.Internal);
         }
     }
     else
     {
         queue.HandleError($"Cannot convert script objects to config type {TextStyle.SeparateVal(fieldType.Name)}");
     }
     return(null);
 }
Exemplo n.º 7
0
 /// <summary>Executes the command.</summary>
 /// <param name="queue">The command queue involved.</param>
 /// <param name="entry">Entry to be executed.</param>
 public static void Execute(CommandQueue queue, CommandEntry entry)
 {
     if (entry.Arguments.Length > 1 && BooleanTag.TryFor(entry.GetArgumentObject(queue, 1)).Internal)
     {
         throw new Exception("FreneticScript induced exception: '" + entry.GetArgument(queue, 0) + "'");
     }
     else
     {
         queue.HandleError(entry, entry.GetArgument(queue, 0));
     }
 }
Exemplo n.º 8
0
        /// <summary>Executes the command.</summary>
        /// <param name="queue">The command queue involved.</param>
        /// <param name="entry">Entry to be executed.</param>
        public static void Execute(CommandQueue queue, CommandEntry entry)
        {
            TemplateObject arg1 = entry.GetArgumentObject(queue, 0);
            BooleanTag     bt   = BooleanTag.TryFor(arg1);

            if (bt == null || !bt.Internal)
            {
                queue.HandleError(entry, "Assertion failed: " + entry.GetArgument(queue, 1));
                return;
            }
            entry.GoodOutput(queue, "Assert command passed, assertion valid!");
        }
Exemplo n.º 9
0
        public override void PrepItem(Entity entity, ItemStack item)
        {
            bool       has = item.SharedAttributes.ContainsKey("charge");
            BooleanTag bt  = has ? BooleanTag.TryFor(item.SharedAttributes["charge"]): null;

            if (!has || bt == null || !bt.Internal)
            {
                item.SharedAttributes.Add("charge", new BooleanTag(true));
                item.SharedAttributes.Add("drawrate", new NumberTag(DrawRate));
                item.SharedAttributes.Add("drawmin", new NumberTag(DrawMinimum));
                item.SharedAttributes.Add("cspeedm", new NumberTag(0.5f));
            }
        }
Exemplo n.º 10
0
 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());
     }
 }
Exemplo n.º 11
0
        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!");
            }
        }
Exemplo n.º 12
0
        public static TemplateObject TOFor(Server tserver, string type, string content)
        {
            switch (type)
            {
            case "text":
                return(new TextTag(content));

            //case "item":
            //    return ItemTag.For(tserver, content);
            case "numb":
                return(NumberTag.TryFor(content));

            case "inte":
                return(IntegerTag.TryFor(content));

            case "bool":
                return(BooleanTag.TryFor(content));

            default:
                return(new TextTag(content));    // Disregard errors and just make it text anyway. Probably just bad user input.
            }
        }
Exemplo n.º 13
0
        public void SetMoveSpeed(CharacterController cc, UserInputSet uis)
        {
            float speedmod = (float)new Vector2(uis.XMove, uis.YMove).Length() * 2;

            speedmod *= (1f + uis.SprintOrWalk * 0.5f);
            if (Click)
            {
                ItemStack  item = TheClient.GetItemForSlot(TheClient.QuickBarPos);
                bool       has  = item.SharedAttributes.ContainsKey("charge");
                BooleanTag bt   = has ? BooleanTag.TryFor(item.SharedAttributes["charge"]) : null;
                if (bt != null && bt.Internal && item.SharedAttributes.ContainsKey("cspeedm"))
                {
                    NumberTag nt = NumberTag.TryFor(item.SharedAttributes["cspeedm"]);
                    if (nt != null)
                    {
                        speedmod *= (float)nt.Internal;
                    }
                }
            }
            RigidTransform transf = new RigidTransform(Vector3.Zero, Body.Orientation);
            BoundingBox    box;

            cc.Body.CollisionInformation.Shape.GetBoundingBox(ref transf, out box);
            Location pos = new Location(cc.Body.Position) + new Location(0, 0, box.Min.Z);
            Material mat = TheRegion.GetBlockMaterial(pos + new Location(0, 0, -0.05f));

            speedmod         *= (float)mat.GetSpeedMod();
            cc.StandingSpeed  = CBStandSpeed * speedmod;
            cc.CrouchingSpeed = CBCrouchSpeed * speedmod;
            float frictionmod = 1f;

            frictionmod     *= (float)mat.GetFrictionMod();
            cc.SlidingForce  = CBSlideForce * frictionmod * Mass;
            cc.AirForce      = CBAirForce * frictionmod * Mass;
            cc.TractionForce = CBTractionForce * frictionmod * Mass;
            cc.VerticalMotionConstraint.MaximumGlueForce = CBGlueForce * Mass;
        }
Exemplo n.º 14
0
        /// <summary>Executes the command.</summary>
        /// <param name="queue">The command queue involved.</param>
        /// <param name="entry">Entry to be executed.</param>
        public static void Execute(CommandQueue queue, CommandEntry entry)
        {
            if (entry.IsCallback)
            {
                return;
            }
            string type      = entry.GetArgument(queue, 0).ToLowerFast();
            string eventname = entry.GetArgument(queue, 1).ToLowerFast();

            if (type == "clear" && eventname == "all")
            {
                foreach (KeyValuePair <string, ScriptEvent> evt in queue.Engine.Events)
                {
                    evt.Value.Clear();
                }
                if (entry.ShouldShowGood(queue))
                {
                    entry.GoodOutput(queue, "Cleared all events.");
                }
                return;
            }
            if (!queue.Engine.Events.TryGetValue(eventname, out ScriptEvent theEvent))
            {
                queue.HandleError(entry, "Unknown event '" + TextStyle.Separate + eventname + TextStyle.Base + "'.");
                return;
            }
            if (type == "clear")
            {
                theEvent.Clear();
                if (entry.ShouldShowGood(queue))
                {
                    entry.GoodOutput(queue, "Cleared event '" + TextStyle.Separate + eventname + TextStyle.Base + "' of all handlers.");
                }
            }
            else if (type == "remove")
            {
                if (entry.Arguments.Length < 3)
                {
                    ShowUsage(queue, entry);
                    return;
                }
                string name    = entry.GetArgument(queue, 2).ToLowerFast();
                bool   success = theEvent.RemoveEventHandler(name);
                if (success)
                {
                    if (entry.ShouldShowGood(queue))
                    {
                        entry.GoodOutput(queue, "Removed event handler '" + TextStyle.Separate + name + TextStyle.Base + "'.");
                    }
                }
                else
                {
                    if (BooleanTag.TryFor(entry.GetNamedArgumentObject(queue, "quiet_fail"))?.Internal ?? false)
                    {
                        if (entry.ShouldShowGood(queue))
                        {
                            entry.GoodOutput(queue, "Unknown event handler '" + TextStyle.Separate + name + TextStyle.Base + "'.");
                        }
                    }
                    else
                    {
                        queue.HandleError(entry, "Unknown event handler '" + TextStyle.Separate + name + TextStyle.Base + "'.");
                    }
                }
            }
            else if (type == "add")
            {
                if (entry.Arguments.Length < 3)
                {
                    ShowUsage(queue, entry);
                    return;
                }
                string name = entry.GetArgument(queue, 2).ToLowerFast();
                if (entry.InnerCommandBlock == null)
                {
                    queue.HandleError(entry, "Event command invalid: No block follows!");
                    return;
                }
                if (theEvent.HasHandler(name))
                {
                    if (BooleanTag.TryFor(entry.GetNamedArgumentObject(queue, "quiet_fail"))?.Internal ?? false)
                    {
                        if (entry.ShouldShowGood(queue))
                        {
                            entry.GoodOutput(queue, "Handler '" + TextStyle.Separate + name + TextStyle.Base + "' already exists!");
                        }
                    }
                    else
                    {
                        queue.HandleError(entry, "Handler '" + TextStyle.Separate + name + TextStyle.Base + "' already exists!");
                    }
                }
                double priority = 0;
                if (entry.Arguments.Length > 3)
                {
                    priority = NumberTag.For(entry.GetArgumentObject(queue, 3), queue.Error).Internal;
                }
                List <CommandEntry> entries = new(entry.InnerCommandBlock.Length + 2);
                MapTag expectedContext      = new();
                expectedContext.Internal.Add("context", entry.System.TagTypes.Type_Map.TagForm);
                entries.Add(entry.System.TheRequireCommand.GenerateEntry(expectedContext, entry.ScriptName, entry.ScriptLine));
                entries.AddRange(entry.InnerCommandBlock);
                CommandScript script = new(theEvent.Name + "__handler__" + name,
                                           CommandScript.TYPE_NAME_EVENT, entries.ToArray(), entry.System, entry.BlockStart, DebugMode.MINIMAL);
                theEvent.RegisterEventHandler(priority, script, name);
                entry.GoodOutput(queue, "Handler '" + TextStyle.Separate + name + "" + TextStyle.Base
                                 + "' defined for event '" + TextStyle.Separate + theEvent.Name + TextStyle.Base + "'.");
            }
            else
            {
                ShowUsage(queue, entry);
            }
        }
 public override void UpdateVariables(Dictionary <string, TemplateObject> vars)
 {
     Amount     = NumberTag.TryFor(vars["amount"]);
     Repairable = BooleanTag.TryFor(vars["repairable"]);
     base.UpdateVariables(vars);
 }