Example #1
0
        public override void Execute(CommandQueue queue, CommandEntry entry)
        {
            TemplateObject cb = entry.GetArgumentObject(queue, 0);

            if (cb.ToString() == "\0CALLBACK")
            {
                return;
            }
            if (entry.InnerCommandBlock == null)
            {
                queue.HandleError(entry, "Invalid or missing command block!");
                return;
            }
            ListTag          mode  = ListTag.For(cb);
            List <ItemStack> items = new List <ItemStack>();

            for (int i = 1; i < entry.Arguments.Count; i++)
            {
                ItemTag required = ItemTag.For(TheServer, entry.GetArgumentObject(queue, i));
                if (required == null)
                {
                    queue.HandleError(entry, "Invalid required item!");
                    return;
                }
                items.Add(required.Internal);
            }
            TheServer.Recipes.AddRecipe(RecipeRegistry.ModeFor(mode), entry.InnerCommandBlock, entry.BlockStart, items.ToArray());
            queue.CurrentEntry.Index = entry.BlockEnd + 2;
            if (entry.ShouldShowGood(queue))
            {
                entry.Good(queue, "Added recipe!");
            }
        }
Example #2
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 #3
0
 /// <summary>Creates a SystemTag for the given input data.</summary>
 /// <param name="dat">The tag data.</param>
 /// <param name="input">The text input.</param>
 /// <returns>A valid time tag.</returns>
 public static TimeTag CreateFor(TemplateObject input, TagData dat)
 {
     return(input switch
     {
         TimeTag ttag => ttag,
         DynamicTag dtag => CreateFor(dtag.Internal, dat),
         _ => For(input.ToString()),
     });
Example #4
0
 /// <summary>
 /// Converts a generic object to a map tag.
 /// Never null. Will ignore invalid entries.
 /// </summary>
 /// <param name="input">The input object.</param>
 /// <returns>The map represented by the input object.</returns>
 public static MapTag For(TemplateObject input)
 {
     return(input switch
     {
         MapTag itag => itag,
         DynamicTag dtag => For(dtag.Internal),
         _ => For(input.ToString()),
     });
 public static LocationTag For(TemplateObject input)
 {
     if (input == null)
     {
         return null;
     }
     return (input is LocationTag) ? (LocationTag)input : For(input.ToString());
 }
Example #6
0
 /// <summary>Creates a BinaryTag for the given input data.</summary>
 /// <param name="dat">The tag data.</param>
 /// <param name="input">The text input.</param>
 /// <returns>A valid binary tag.</returns>
 public static BinaryTag CreateFor(TemplateObject input, TagData dat)
 {
     return(input switch
     {
         BinaryTag itag => itag,
         DynamicTag dtag => CreateFor(dtag.Internal, dat),
         _ => For(dat, input.ToString()),
     });
 public static LocationTag For(TemplateObject input)
 {
     if (input == null)
     {
         return(null);
     }
     return((input is LocationTag) ? (LocationTag)input : For(input.ToString()));
 }
Example #8
0
 /// <summary>
 /// Get an integer tag relevant to the specified input, erroring on the command system if invalid input is given (Returns 0 in that case).
 /// Never null!
 /// </summary>
 /// <param name="err">Error call if something goes wrong.</param>
 /// <param name="input">The input text to create a integer from.</param>
 /// <returns>The integer tag.</returns>
 public static IntegerTag For(TemplateObject input, Action <string> err)
 {
     return(input switch
     {
         IntegerTag itag => itag,
         IIntegerTagForm itf => new IntegerTag(itf.IntegerForm),
         DynamicTag dtag => For(dtag.Internal, err),
         _ => For(err, input.ToString()),
     });
 /// <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);
 }
        TemplateObject verify(TemplateObject input)
        {
            string low = input.ToString().ToLowerFast();

            if (low == "primary" || low == "secondary")
            {
                return(new TextTag(low));
            }
            return(null);
        }
Example #11
0
        TemplateObject verify(TemplateObject input)
        {
            string low = input.ToString().ToLowerFast();

            if (low == "award" || low == "take")
            {
                return(new TextTag(low));
            }
            return(null);
        }
Example #12
0
        public override TemplateObject Handle(TagData data)
        {
            TemplateObject rdata = data.GetModifierObject(0);
            RecipeTag      rtag  = RecipeTag.For(TheServer, data, rdata);

            if (rtag == null)
            {
                data.Error("Invalid recipe '" + TagParser.Escape(rdata.ToString()) + "'!");
                return(new NullTag());
            }
            return(rtag.Handle(data.Shrink()));
        }
Example #13
0
        public override TemplateObject Handle(TagData data)
        {
            TemplateObject pname = data.GetModifierObject(0);
            ItemTag        ptag  = ItemTag.For(TheServer, pname);

            if (ptag == null)
            {
                data.Error("Invalid player '" + TagParser.Escape(pname.ToString()) + "'!");
                return(new NullTag());
            }
            return(ptag.Handle(data.Shrink()));
        }
Example #14
0
 public static ListTag CreateFor(TemplateObject input)
 {
     return(input switch
     {
         ListTag ltag => ltag,
         IListTagForm lform => lform.ListForm,
         DynamicTag dtag => CreateFor(dtag.Internal),
         TextTag _ => For(input.ToString()),
         _ => new ListTag(new List <TemplateObject>()
         {
             input
         }),
     });
Example #15
0
 public static EntityTag For(TemplateObject input)
 {
     if (input is EntityTag)
     {
         return (EntityTag)input;
     }
     else if (input is ZombieTag)
     {
         return new EntityTag(((ZombieTag)input).Internal.gameObject);
     }
     // TODO: Other common entity types!
     return For(input.ToString());
 }
 public static EntityTag For(TemplateObject input)
 {
     if (input is EntityTag)
     {
         return((EntityTag)input);
     }
     else if (input is ZombieTag)
     {
         return(new EntityTag(((ZombieTag)input).Internal.gameObject));
     }
     // TODO: Other common entity types!
     return(For(input.ToString()));
 }
Example #17
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 #18
0
 public static ItemTag For(Server tserver, TemplateObject input)
 {
     return(input is ItemTag ? (ItemTag)input : For(tserver, input.ToString()));
 }
Example #19
0
 public static ColorTag For(TemplateObject obj)
 {
     return obj is ColorTag ? (ColorTag)obj : For(obj.ToString());
 }
 /// <summary>Returns the input text.</summary>
 /// <returns>The input text.</returns>
 public override string ToString()
 {
     return(InputValue.ToString());
 }
 TemplateObject verify(TemplateObject input)
 {
     string low = input.ToString().ToLowerFast();
     if (low == "primary" || low == "secondary")
     {
         return new TextTag(low);
     }
     return null;
 }
 /// <summary>Gets a system tag. Shouldn't be used.</summary>
 /// <param name="data">The data.</param>
 /// <param name="input">The input.</param>
 public static SystemTag For(TemplateObject input, TagData data)
 {
     return(input is SystemTag tag ? tag : For(data, input.ToString()));
 }
Example #23
0
 /// <summary>Returns the dynamic tag data.</summary>
 /// <returns>The data.</returns>
 public override string ToString()
 {
     return(Internal.ToString());
 }
Example #24
0
 /// <summary>Gets a ternary pass tag. Shouldn't be used.</summary>
 /// <param name="data">The data.</param>
 /// <param name="input">The input.</param>
 public static TernaryPassTag For(TemplateObject input, TagData data)
 {
     return(input as TernaryPassTag ?? For(data, input.ToString()));
 }
Example #25
0
 public static ColorTag For(TemplateObject obj)
 {
     return(obj is ColorTag ? (ColorTag)obj : For(obj.ToString()));
 }
Example #26
0
 public static PlayerTag For(Server tserver, TemplateObject obj)
 {
     return (obj is PlayerTag) ? (PlayerTag)obj : For(tserver, obj.ToString());
 }
Example #27
0
 public static ItemTag For(Server tserver, TemplateObject input)
 {
     return input is ItemTag ? (ItemTag)input : For(tserver, input.ToString());
 }
 TemplateObject verify(TemplateObject input)
 {
     string low = input.ToString().ToLowerFast();
     if (low == "award" || low == "take")
     {
         return new TextTag(low);
     }
     return null;
 }
Example #29
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 obj      = entry.GetArgumentObject(queue, 0);
            FunctionTag    function = FunctionTag.CreateFor(obj, queue.GetTagData());

            if (function == null)
            {
                queue.HandleError(entry, "Cannot call function '" + TextStyle.Separate + obj.ToString() + TextStyle.Base + "': it does not exist!");
                return;
            }
            CommandScript script = function.Internal;

            if (entry.ShouldShowGood(queue))
            {
                entry.GoodOutput(queue, "Calling '" + function.GetDebugString() + TextStyle.Base + "'...");
            }
            CompiledCommandRunnable runnable = script.Compiled.ReferenceCompiledRunnable.Duplicate();

            if (runnable.Entry.Entries.Length > 0)
            {
                Dictionary <string, SingleCILVariable> varlookup = runnable.Entry.Entries[0].VarLookup;
                foreach (string var in entry.NamedArguments.Keys)
                {
                    if (!var.StartsWithNull())
                    {
                        if (varlookup.TryGetValue(var, out SingleCILVariable varx))
                        {
                            // TODO: Type verification!
                            runnable.Entry.GetSetter(varx.Index).Invoke(runnable, entry.GetNamedArgumentObject(queue, var));
                        }
                    }
                }
            }
            if (entry.NamedArguments.ContainsKey(CommandEntry.SAVE_NAME_ARG_ID))
            {
                bool   sgood = entry.ShouldShowGood(queue);
                string vname = entry.NamedArguments[CommandEntry.SAVE_NAME_ARG_ID].ToString();
                if (sgood)
                {
                    entry.GoodOutput(queue, "Noticing variable track for " + vname + ".");
                }
                CompiledCommandRunnable curRunnable = queue.CurrentRunnable;
                if (!entry.VarLookup.TryGetValue(vname, out SingleCILVariable locVar))
                {
                    queue.HandleError(entry, "Invalid save-to variable: " + vname + "!");
                    return;
                }
                runnable.Callback = () =>
                {
                    // TODO: Fix!

                    /*if (runnable.Entry.Entries.Length > 0)
                     * {
                     *  MapTag mt = new MapTag();
                     *  Dictionary<string, SingleCILVariable> varlookup = runnable.Entry.Entries[0].VarLookup;
                     *  foreach (SingleCILVariable vara in varlookup.Values)
                     *  {
                     *      if (runnable.LocalVariables[vara.Index].Internal != null)
                     *      {
                     *          mt.Internal.Add(vara.Name, runnable.LocalVariables[vara.Index].Internal);
                     *      }
                     *  }
                     *  curRunnable.LocalVariables[locVar.Index].Internal = mt;
                     * }*/
                    if (sgood)
                    {
                        entry.GoodOutput(queue, "Call complete.");
                    }
                };
            }
            queue.RunningStack.Push(runnable);
        }
Example #30
0
 /// <summary>Get a binary tag relevant to the specified input, erroring on the command system if invalid input is given (Returns null in that case).</summary>
 /// <param name="dat">The TagData used to construct this BinaryTag.</param>
 /// <param name="input">The input to create or get binary data from.</param>
 /// <returns>The binary tag.</returns>
 public static BinaryTag For(TemplateObject input, TagData dat)
 {
     return(input as BinaryTag ?? For(dat, input.ToString()));
 }
Example #31
0
 public static PlayerTag For(Server tserver, TemplateObject obj)
 {
     return((obj is PlayerTag) ? (PlayerTag)obj : For(tserver, obj.ToString()));
 }