コード例 #1
0
 public double GetAttributeF(string attr, double def)
 {
     if (Attributes.TryGetValue(attr, out TemplateObject outp))
     {
         return(NumberTag.TryFor(outp).Internal);
     }
     return(def);
 }
コード例 #2
0
 /// <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);
 }
コード例 #3
0
        public double JetpackHoverStrength()
        {
            double    baseHover = GetMass();
            ItemStack its       = Items.GetItemForSlot(Items.cItem);

            if (its.SharedAttributes.TryGetValue("jetpack_hovermod", out TemplateObject mod))
            {
                NumberTag nt = NumberTag.TryFor(mod);
                if (nt != null)
                {
                    return(baseHover * nt.Internal);
                }
            }
            return(baseHover);
        }
コード例 #4
0
        public override void ReleaseClick(Entity entity, ItemStack item)
        {
            if (!(entity is PlayerEntity))
            {
                // TODO: non-player support
                return;
            }
            PlayerEntity player = (PlayerEntity)entity;

            player.ItemDoSpeedMod = false;
            if (player.ItemStartClickTime < 0)
            {
                player.ItemStartClickTime = -1;
                return;
            }
            double         drawRate = DrawRate;
            TemplateObject dw2;

            if (item.SharedAttributes.TryGetValue("drawrate", out dw2))
            {
                NumberTag nt = NumberTag.TryFor(dw2);
                if (nt != null)
                {
                    drawRate = (double)nt.Internal;
                }
            }
            double         drawMin = DrawMinimum;
            TemplateObject dm2;

            if (item.SharedAttributes.TryGetValue("drawmin", out dm2))
            {
                NumberTag nt = NumberTag.TryFor(dm2);
                if (nt != null)
                {
                    drawMin = (double)nt.Internal;
                }
            }
            double timeStretched = Math.Min((player.TheRegion.GlobalTickTime - player.ItemStartClickTime) * drawRate, 3) + drawMin;

            player.ItemStartClickTime = -1;
            if (timeStretched < DrawMinimum + 0.25)
            {
                return;
            }
            SpawnArrow(player, item, timeStretched);
        }
コード例 #5
0
        public double JetpackBoostRate(out double max)
        {
            const double baseBoost = 1500.0;
            const double baseMax   = 2000.0f;

            max = baseMax; // TODO: Own mod
            ItemStack its = Items.GetItemForSlot(Items.cItem);

            if (its.SharedAttributes.TryGetValue("jetpack_boostmod", out TemplateObject mod))
            {
                NumberTag nt = NumberTag.TryFor(mod);
                if (nt != null)
                {
                    return(baseBoost * nt.Internal);
                }
            }
            return(baseBoost);
        }
コード例 #6
0
ファイル: NumberParser.cs プロジェクト: lism/jntemplate
        /// <summary>
        /// 分析标签
        /// </summary>
        /// <param name="parser">TemplateParser</param>
        /// <param name="tc">Token集合</param>
        /// <returns></returns>
        public Tag Parse(TemplateParser parser, TokenCollection tc)
        {
            if (tc.Count == 1 && tc.First.TokenKind == TokenKind.Number)
            {
                NumberTag tag = new NumberTag();
                if (tc.First.Text.IndexOf('.') == -1)
                {
                    tag.Value = Int32.Parse(tc.First.Text);
                }
                else
                {
                    tag.Value = Double.Parse(tc.First.Text);
                }

                return(tag);
            }

            return(null);
        }
コード例 #7
0
ファイル: ITagParser.cs プロジェクト: webconfig/project
        public Tag Parse(TemplateParser parser, TokenCollection tc)
        {
            if (tc.Count == 1 && tc.First.TokenKind == TokenKind.Number)
            {
                NumberTag tag = new NumberTag();
                if (tc.First.Text.IndexOf('.') == -1)
                {
                    tag.Value = Int32.Parse(tc.First.Text);
                }
                else
                {
                    tag.Value = Double.Parse(tc.First.Text);
                }

                return tag;
            }

            return null;
        }
コード例 #8
0
ファイル: BowItem.cs プロジェクト: MoTo1496/Voxalia
        public override void SwitchTo(Entity entity, ItemStack item)
        {
            if (!(entity is PlayerEntity))
            {
                // TODO: non-player support
                return;
            }
            PlayerEntity player = (PlayerEntity)entity;
            double       speedm = 1f;

            if (item.SharedAttributes.ContainsKey("cspeedm"))
            {
                NumberTag nt = NumberTag.TryFor(item.SharedAttributes["cspeedm"]);
                if (nt != null)
                {
                    speedm = (double)nt.Internal;
                }
            }
            player.ItemSpeedMod   = speedm;
            player.ItemDoSpeedMod = false;
        }
コード例 #9
0
ファイル: NumberParser.cs プロジェクト: ithanshui/jntemplate
        /// <summary>
        /// 分析标签
        /// </summary>
        /// <param name="parser">TemplateParser</param>
        /// <param name="tc">Token集合</param>
        /// <returns></returns>
        public ITag Parse(TemplateParser parser, TokenCollection tc)
        {
            if (tc != null &&
                tc.Count == 1 &&
                tc.First.TokenKind == TokenKind.Number)
            {
                NumberTag tag = new NumberTag();
                if (tc.First.Text.IndexOf('.') == -1)
                {
                    if (tc.First.Text.Length < 9)
                    {
                        tag.Value = int.Parse(tc.First.Text);
                    }
                    else if (tc.First.Text.Length == 9)
                    {
                        var value = long.Parse(tc.First.Text);
                        if (value <= int.MaxValue)
                        {
                            tag.Value = int.Parse(tc.First.Text);
                        }
                        else
                        {
                            tag.Value = value;
                        }
                    }
                    else
                    {
                        tag.Value = long.Parse(tc.First.Text);
                    }
                }
                else
                {
                    tag.Value = Double.Parse(tc.First.Text);
                }

                return(tag);
            }

            return(null);
        }
コード例 #10
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)
        {
            NumberTag delay = NumberTag.TryFor(entry.GetArgumentObject(queue, 0));

            if (delay is null)
            {
                queue.HandleError(entry, "Invalid delay value - not a number!");
                return;
            }
            if (queue.Delayable)
            {
                if (entry.ShouldShowGood(queue))
                {
                    entry.GoodOutput(queue, "Delaying for " + TextStyle.Separate + delay.Internal + TextStyle.Base + " seconds.");
                }
                queue.Wait = delay.Internal;
            }
            else
            {
                queue.HandleError(entry, "Cannot delay, inside an instant queue!");
            }
        }
コード例 #11
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.
            }
        }
コード例 #12
0
ファイル: PlayerEntity.cs プロジェクト: Fortifier42/Voxalia
        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;
        }
コード例 #13
0
        public static LocationTag For(Server tserver, TagData dat, string input)
        {
            string[] spl = input.Split(',');
            Location coord;

            if (spl.Length < 3)
            {
                dat.Error("Invalid LocationTag input!");
            }
            coord.X = NumberTag.For(dat, spl[0]).Internal;
            coord.Y = NumberTag.For(dat, spl[1]).Internal;
            coord.Z = NumberTag.For(dat, spl[2]).Internal;
            World w = null;

            if (spl.Length >= 4)
            {
                w = tserver.GetWorld(spl[3]);
                if (w == null)
                {
                    dat.Error("Invalid world for LocationTag input!");
                }
            }
            return(new LocationTag(coord, w));
        }
コード例 #14
0
        public override TemplateObject Handle(TagData data)
        {
            if (data.Remaining == 0)
            {
                return(this);
            }
            switch (data[0])
            {
            // <--[tag]
            // @Name LocationTag.x
            // @Group General Information
            // @ReturnType NumberTag
            // @Returns the X coordinate of this location.
            // @Example "0,1,2" .x returns "0".
            // -->
            case "x":
                return(new NumberTag(X).Handle(data.Shrink()));

            // <--[tag]
            // @Name LocationTag.y
            // @Group General Information
            // @ReturnType NumberTag
            // @Returns the Y coordinate of this location.
            // @Example "0,1,2" .y returns "1".
            // -->
            case "y":
                return(new NumberTag(Y).Handle(data.Shrink()));

            // <--[tag]
            // @Name LocationTag.z
            // @Group General Information
            // @ReturnType NumberTag
            // @Returns the Z coordinate of this location.
            // @Example "0,1,2" .z returns "2".
            // -->
            case "z":
                return(new NumberTag(Z).Handle(data.Shrink()));

            // <--[tag]
            // @Name LocationTag.add[<LocationTag>]
            // @Group Mathematics
            // @ReturnType LocationTag
            // @Returns the result of adding the specified location to this location.
            // @Example "0,1,2" .add[2,1,0] returns "2,2,2".
            // -->
            case "add":
            {
                LocationTag modif = LocationTag.For(data.GetModifier(0));
                return(new LocationTag(X + modif.X, Y + modif.Y, Z + modif.Z).Handle(data.Shrink()));
            }

            // <--[tag]
            // @Name LocationTag.subtract[<LocationTag>]
            // @Group Mathematics
            // @ReturnType LocationTag
            // @Returns the result of subtracting the specified location from this location.
            // @Example "0,1,2" .subtract[0,1,2] returns "0,0,0".
            // -->
            case "subtract":
            {
                LocationTag modif = LocationTag.For(data.GetModifier(0));
                return(new LocationTag(X - modif.X, Y - modif.Y, Z - modif.Z).Handle(data.Shrink()));
            }

            // <--[tag]
            // @Name LocationTag.length
            // @Group Mathematics
            // @ReturnType NumberTag
            // @Returns the length from this location to the origin.
            // @Warning this tag requires a square root operation, which is a tiny bit slow internally. Consider using <@link tag LocationTag.length_squared>.
            // @Example "0,2,0" .length returns "2".
            // -->
            case "length":
                return(new NumberTag(ToVector3().magnitude).Handle(data.Shrink()));

            // <--[tag]
            // @Name LocationTag.length_squared
            // @Group Mathematics
            // @ReturnType NumberTag
            // @Returns the square of the length from this location to the origin.
            // @Example "0,2,0" .length_squared returns "4".
            // -->
            case "length_squared":
                return(new NumberTag(ToVector3().sqrMagnitude).Handle(data.Shrink()));

            // <--[tag]
            // @Name LocationTag.find_animals_within[<NumberTag>]
            // @Group World
            // @ReturnType ListTag<AnimalTag>
            // @Returns a list of all animals within the specified range (spherical).
            // @Example "0,1,2" .find_animals_within[10] returns "2|3|17".
            // -->
            case "find_animals_within":
            {
                List <TemplateObject> animals = new List <TemplateObject>();
                Vector3 vec3  = ToVector3();
                float   range = (float)NumberTag.For(data, data.GetModifierObject(0)).Internal;
                foreach (Animal animal in AnimalManager.animals)
                {
                    if ((animal.transform.position - vec3).sqrMagnitude <= range * range)
                    {
                        animals.Add(new AnimalTag(animal));
                    }
                }
                return(new ListTag(animals).Handle(data.Shrink()));
            }

            // <--[tag]
            // @Name LocationTag.find_zombies_within[<NumberTag>]
            // @Group World
            // @ReturnType ListTag<ZombieTag>
            // @Returns a list of all zombies within the specified range (spherical).
            // @Example "0,1,2" .find_zombies_within[10] returns "2|3|17".
            // -->
            case "find_zombies_within":
            {
                List <TemplateObject> zombies = new List <TemplateObject>();
                Vector3 vec3  = ToVector3();
                float   range = (float)NumberTag.For(data, data.GetModifierObject(0)).Internal;
                for (int i = 0; i < ZombieManager.regions.Length; i++)
                {
                    foreach (Zombie zombie in ZombieManager.regions[i].zombies)
                    {
                        if ((zombie.transform.position - vec3).sqrMagnitude <= range * range)
                        {
                            zombies.Add(new ZombieTag(zombie));
                        }
                    }
                }
                return(new ListTag(zombies).Handle(data.Shrink()));
            }

            // <--[tag]
            // @Name LocationTag.find_items_within[<NumberTag>]
            // @Group World
            // @ReturnType ListTag<ItemEntityTag>
            // @Returns a list of all items within the specified range (spherical).
            // @Example "0,1,2" .find_items_within[10] returns "2|3|17".
            // -->
            case "find_items_within":
            {
                List <TemplateObject> items = new List <TemplateObject>();
                Vector3 vec3  = ToVector3();
                float   range = (float)NumberTag.For(data, data.GetModifierObject(0)).Internal;
                for (byte x = 0; x < Regions.WORLD_SIZE; x++)
                {
                    for (byte y = 0; y < Regions.WORLD_SIZE; y++)
                    {
                        foreach (ItemDrop drop in ItemManager.regions[x, y].drops)
                        {
                            Transform item = drop.model;
                            if ((item.position - vec3).sqrMagnitude <= range * range)
                            {
                                items.Add(new ItemEntityTag(item.GetChild(0).gameObject.GetComponent <InteractableItem>()));
                            }
                        }
                    }
                }
                return(new ListTag(items).Handle(data.Shrink()));
            }

            // <--[tag]
            // @Name LocationTag.find_resources_within[<NumberTag>]
            // @Group World
            // @ReturnType ListTag<ResourceTag>
            // @Returns a list of all resources within the specified range (spherical).
            // @Example "0,1,2" .find_resources_within[10] returns "2|3|17".
            // -->
            case "find_resources_within":
            {
                List <TemplateObject> resources = new List <TemplateObject>();
                Vector3 vec3  = ToVector3();
                float   range = (float)NumberTag.For(data, data.GetModifierObject(0)).Internal;
                for (byte x = 0; x < Regions.WORLD_SIZE; x++)
                {
                    for (byte y = 0; y < Regions.WORLD_SIZE; y++)
                    {
                        foreach (ResourceSpawnpoint resource in LevelGround.trees[x, y])
                        {
                            if ((resource.model.position - vec3).sqrMagnitude <= range * range)
                            {
                                resources.Add(new ResourceTag(resource));
                            }
                        }
                    }
                }
                return(new ListTag(resources).Handle(data.Shrink()));
            }

            // <--[tag]
            // @Name LocationTag.find_vehicles_within[<NumberTag>]
            // @Group World
            // @ReturnType ListTag<VehicleTag>
            // @Returns a list of all vehicles within the specified range (spherical).
            // @Example "0,1,2" .find_vehicles_within[10] returns "2|3|17".
            // -->
            case "find_vehicles_within":
            {
                List <TemplateObject> vehicles = new List <TemplateObject>();
                Vector3 vec3  = ToVector3();
                float   range = (float)NumberTag.For(data, data.GetModifierObject(0)).Internal;
                foreach (InteractableVehicle veh in VehicleManager.vehicles)
                {
                    if ((veh.gameObject.transform.position - vec3).sqrMagnitude <= range * range)
                    {
                        vehicles.Add(new VehicleTag(veh));
                    }
                }
                return(new ListTag(vehicles).Handle(data.Shrink()));
            }

            // <--[tag]
            // @Name LocationTag.find_barricades_within[<NumberTag>]
            // @Group World
            // @ReturnType ListTag<BarricadeTag>
            // @Returns a list of all barricades within the specified range (spherical).
            // @Example "0,1,2" .find_barricades_within[10] returns "2|3|17".
            // -->
            case "find_barricades_within":
            {
                List <TemplateObject> barricades = new List <TemplateObject>();
                Vector3 vec3  = ToVector3();
                float   range = (float)NumberTag.For(data, data.GetModifierObject(0)).Internal;
                for (byte x = 0; x < Regions.WORLD_SIZE; x++)
                {
                    for (byte y = 0; y < Regions.WORLD_SIZE; y++)
                    {
                        BarricadeRegion region = BarricadeManager.regions[x, y];
                        for (int i = 0; i < region.drops.Count; i++)
                        {
                            Transform model = region.drops[i].model;
                            if ((model.position - vec3).sqrMagnitude <= range * range)
                            {
                                barricades.Add(new BarricadeTag(model, region.barricades[i]));
                            }
                        }
                    }
                }
                return(new ListTag(barricades).Handle(data.Shrink()));
            }

            // <--[tag]
            // @Name LocationTag.find_world_objects_within[<NumberTag>]
            // @Group World
            // @ReturnType ListTag<WorldObjectTag>
            // @Returns a list of all world objects within the specified range (spherical).
            // @Example "0,1,2" .find_world_objects_within[10] returns "2|3|17".
            // @Other Note that any overlap will count; the object's center does not need to be in the sphere.
            // -->
            case "find_world_objects_within":
            {
                // TODO: handle this better, it makes me sad
                List <TemplateObject> worldObjects = new List <TemplateObject>();
                float      range        = (float)NumberTag.For(data, data.GetModifierObject(0)).Internal;
                Collider[] hitColliders = Physics.OverlapSphere(ToVector3(), range);
                List <int> ids          = new List <int>();
                foreach (Collider collider in hitColliders)
                {
                    if (collider.gameObject.transform.parent == LevelObjects.models)
                    {
                        int id = collider.gameObject.GetInstanceID();
                        if (!ids.Contains(id))
                        {
                            worldObjects.Add(WorldObjectTag.For(id));
                            ids.Add(id);
                        }
                    }
                }
                return(new ListTag(worldObjects).Handle(data.Shrink()));
            }

            default:
                return(new TextTag(ToString()).Handle(data));
            }
        }
コード例 #15
0
 public override void UpdateVariables(Dictionary <string, TemplateObject> vars)
 {
     Amount = NumberTag.TryFor(vars["amount"]);
     base.UpdateVariables(vars);
 }
コード例 #16
0
 public override void UpdateVariables(Dictionary<string, TemplateObject> vars)
 {
     Amount = NumberTag.TryFor(vars["amount"]);
     base.UpdateVariables(vars);
 }
コード例 #17
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);
            }
        }
コード例 #18
0
ファイル: CdevelCommand.cs プロジェクト: MoTo1496/Voxalia
        public static void Execute(CommandQueue queue, CommandEntry entry)
        {
            if (entry.Arguments.Count < 1)
            {
                ShowUsage(queue, entry);
                return;
            }
            Client TheClient = (entry.Command as CdevelCommand).TheClient;

            switch (entry.GetArgument(queue, 0))
            {
            case "lightDebug":
            {
                Location pos = TheClient.Player.GetPosition();
                pos.Z = pos.Z + 1;
                int XP = (int)Math.Floor(pos.X / Chunk.CHUNK_SIZE);
                int YP = (int)Math.Floor(pos.Y / Chunk.CHUNK_SIZE);
                int ZP = (int)Math.Floor(pos.Z / Chunk.CHUNK_SIZE);
                int x  = (int)(Math.Floor(pos.X) - (XP * Chunk.CHUNK_SIZE));
                int y  = (int)(Math.Floor(pos.Y) - (YP * Chunk.CHUNK_SIZE));
                int z  = (int)(Math.Floor(pos.Z) - (ZP * Chunk.CHUNK_SIZE));
                while (true)
                {
                    Chunk ch = TheClient.TheRegion.GetChunk(new Vector3i(XP, YP, ZP));
                    if (ch == null)
                    {
                        entry.Good(queue, "Passed with flying light sources!");
                        goto end;
                    }
                    while (z < Chunk.CHUNK_SIZE)
                    {
                        if (ch.GetBlockAt((int)x, (int)y, (int)z).IsOpaque())
                        {
                            entry.Info(queue, "Died: " + x + ", " + y + ", " + z + " -- " + XP + ", " + YP + ", " + ZP);
                            goto end;
                        }
                        z++;
                    }
                    ZP++;
                    z = 0;
                }
end:
                break;
            }

            case "vramUsage":
            {
                long c = 0;
                foreach (Tuple <string, long> val in TheClient.CalculateVRAMUsage())
                {
                    entry.Info(queue, "-> " + val.Item1 + ": " + val.Item2 + " (" + (val.Item2 / 1024 / 1024) + "MB)");
                    c += val.Item2;
                }
                entry.Info(queue, "-> Total: " + c + " (" + (c / 1024 / 1024) + "MB)");
                break;
            }

            case "speakText":
            {
                if (entry.Arguments.Count < 3)
                {
                    ShowUsage(queue, entry);
                    break;
                }
                bool male = !entry.GetArgument(queue, 1).ToString().ToLowerFast().StartsWith("f");
                TextToSpeech.Speak(entry.GetArgument(queue, 2), male, entry.Arguments.Count > 3 ? (int)IntegerTag.TryFor(entry.GetArgumentObject(queue, 3)).Internal : 0);
                break;
            }

            case "chunkInfo":
            {
                Chunk ch = TheClient.TheRegion.GetChunk(TheClient.TheRegion.ChunkLocFor(TheClient.Player.GetPosition()));
                if (ch == null)
                {
                    entry.Info(queue, "Chunk is null!");
                    break;
                }
                Vector3i        chunk_pos = ch.WorldPosition;
                ChunkSLODHelper slod      = TheClient.TheRegion.GetSLODHelp(ch.WorldPosition, false);
                if (slod == null)
                {
                    entry.Info(queue, "No SLOD.");
                }
                else
                {
                    bool isgen = slod._VBO != null && slod._VBO.generated;
                    entry.Info(queue, "SLOD: " + slod.Coordinate + ", live chunks contained: " + slod.Users + ", verts: " + slod.FullBlock.Vertices.Count + ", generated: " + isgen);
                    foreach (KeyValuePair <Vector3i, Chunk> entryx in TheClient.TheRegion.LoadedChunks)
                    {
                        if (entryx.Value.PosMultiplier < 5)
                        {
                            continue;
                        }
                        Vector3i slodposser = new Vector3i((int)Math.Floor(entryx.Key.X / (float)Constants.CHUNKS_PER_SLOD), (int)Math.Floor(entryx.Key.Y / (float)Constants.CHUNKS_PER_SLOD), (int)Math.Floor(entryx.Key.Z / (float)Constants.CHUNKS_PER_SLOD));
                        if (slodposser == slod.Coordinate)
                        {
                            entry.Info(queue, "Chunk at " + entryx.Key + " is held");
                        }
                    }
                }
                entry.Info(queue, "Plants: " + ch.Plant_C + ", generated as ID: " + ch.Plant_VAO);
                int  c                     = 0;
                long verts                 = 0;
                long verts_transp          = 0;
                int  total                 = 0;
                int  total_rendered        = 0;
                int  total_rendered_transp = 0;
                foreach (Chunk chunk in TheClient.TheRegion.LoadedChunks.Values)
                {
                    total++;
                    if (chunk._VBOSolid != null && ch._VBOSolid != null && chunk._VBOSolid._VAO == ch._VBOSolid._VAO)
                    {
                        c++;
                    }
                    if (chunk._VBOSolid != null && chunk._VBOSolid.generated)
                    {
                        verts += chunk._VBOSolid.vC;
                        total_rendered++;
                    }
                    if (chunk._VBOTransp != null && chunk._VBOTransp.generated)
                    {
                        verts_transp += chunk._VBOTransp.vC;
                        total_rendered_transp++;
                    }
                }
                entry.Info(queue, "Chunk rendering as " + (ch._VBOSolid == null ? "{NULL}" : ch._VBOSolid._VAO.ToString()) + ", which is seen in " + c + " chunks!");
                entry.Info(queue, "Chunks: " + total + ", rendering " + verts + " solid verts and " + verts_transp +
                           " transparent verts, with " + total_rendered + " solid-existent chunks, and " + total_rendered_transp + " transparent-existent chunks!");
                break;
            }

            case "blockInfo":
            {
                BlockInternal bi = TheClient.TheRegion.GetBlockInternal(TheClient.Player.GetPosition());
                entry.Info(queue, "BLOCK: Material=" + bi.Material + ", Shape=" + bi.BlockData + ", Damage=" + bi.Damage + ", Paint=" + bi.BlockPaint + ",Light=" + bi.BlockLocalData);
                break;
            }

            case "igniteBlock":
            {
                Location   pos = TheClient.Player.GetPosition().GetUpperBlockBorder();
                FireEntity fe  = new FireEntity(pos, null, TheClient.TheRegion);
                TheClient.TheRegion.SpawnEntity(fe);
                break;
            }

            case "torchBlocks":
            {
                Location pos = TheClient.Player.GetPosition().GetUpperBlockBorder();
                for (int x = -3; x <= 3; x++)
                {
                    for (int y = -3; y <= 3; y++)
                    {
                        FireEntity fe = new FireEntity(pos + new Location(x, y, 0), null, TheClient.TheRegion);
                        TheClient.TheRegion.SpawnEntity(fe);
                    }
                }
                break;
            }

            case "lateVR":
            {
                if (!VRSupport.Available())
                {
                    entry.Info(queue, "Can't load VR. Not available!");
                    break;
                }
                if (TheClient.VR != null)
                {
                    entry.Info(queue, "Can't load VR. Already loaded!");
                    break;
                }
                TheClient.VR         = VRSupport.TryInit(TheClient.CWindow);
                TheClient.CWindow.VR = TheClient.VR;
                if (TheClient.VR != null)
                {
                    TheClient.VR.VRScale = 1.5f;         // TODO: VR Scale CVar?
                }
                break;
            }

            case "debugVR":
            {
                if (TheClient.VR == null)
                {
                    entry.Info(queue, "VR not running!");
                    break;
                }
                entry.Info(queue, "Left: " + TheClient.VR.Left?.ToString() + " ||| Right: " + TheClient.VR.Right?.ToString());
                break;
            }

            case "fogEnhance":
            {
                double time   = NumberTag.TryFor(entry.GetArgumentObject(queue, 1)).Internal;
                double fogVal = NumberTag.TryFor(entry.GetArgumentObject(queue, 2)).Internal;
                TheClient.FogEnhanceStrength = (float)fogVal;
                TheClient.FogEnhanceTime     = time;
                break;
            }

            case "flashBang":
            {
                double time = NumberTag.TryFor(entry.GetArgumentObject(queue, 1)).Internal;
                TheClient.MainWorldView.Flashbang(time);
                break;
            }

            case "earRing":
            {
                double time = NumberTag.TryFor(entry.GetArgumentObject(queue, 1)).Internal;
                // TODO: Fix!
                //TheClient.Sounds.Deafen(time);
                break;
            }

            case "topInfo":
            {
                Location pos      = TheClient.Player.GetPosition().GetBlockLocation();
                Vector3i chunkLoc = TheClient.TheRegion.ChunkLocFor(pos);
                Vector2i buaPos   = new Vector2i(chunkLoc.X, chunkLoc.Y);
                if (!TheClient.TheRegion.UpperAreas.TryGetValue(buaPos, out BlockUpperArea bua))
                {
                    entry.Info(queue, "Failed to grab Top data: Out of map?");
                }
                else
                {
                    entry.Info(queue, pos + ": " + bua.Blocks[bua.BlockIndex((int)pos.X - chunkLoc.X * Chunk.CHUNK_SIZE, (int)pos.Y - chunkLoc.Y * Chunk.CHUNK_SIZE)]);
                }
                break;
            }

            case "testDecal":
            {
                Location pos = TheClient.Player.GetPosition() + new Location(0, 0, BEPUphysics.Settings.CollisionDetectionSettings.AllowedPenetration);
                TheClient.AddDecal(pos, new Location(0, 0, 1), Vector4.One, 1f, "white", 15);
                break;
            }

            case "traceDecal":
            {
                Location pos  = TheClient.Player.GetEyePosition();
                Location forw = TheClient.Player.ForwardVector();
                if (TheClient.TheRegion.SpecialCaseRayTrace(pos, forw, 50.0f, MaterialSolidity.FULLSOLID, TheClient.Player.IgnoreThis, out RayCastResult rcr))
                {
                    Location nrm = new Location(rcr.HitData.Normal).Normalize();
                    TheClient.AddDecal(new Location(rcr.HitData.Location) + nrm * 0.005, nrm, Vector4.One, 1f, "white", 15);
                    entry.Info(queue, "Marked at normal " + nrm);
                }
                break;
            }

            case "traceDecalTarg":
            {
                Location pos  = TheClient.Player.GetEyePosition();
                Location forw = TheClient.Player.ForwardVector();
                if (TheClient.TheRegion.SpecialCaseRayTrace(pos, forw, 50.0f, MaterialSolidity.FULLSOLID, TheClient.Player.IgnoreThis, out RayCastResult rcr))
                {
                    Location nrm = new Location(rcr.HitData.Normal).Normalize();
                    TheClient.AddDecal(new Location(rcr.HitData.Location) + nrm * 0.005, nrm, Vector4.One, 1f, "decal_target", 15);
                    entry.Info(queue, "Marked at normal " + nrm);
                }
                break;
            }

            case "soundCount":
            {
                entry.Info(queue, "Sound effects: " + TheClient.Sounds.Effects.Count + ", playing now: " + TheClient.Sounds.PlayingNow.Count);
                break;
            }

            case "testCompute":
            {
                Chunk ch = TheClient.TheRegion.GetChunk(TheClient.TheRegion.ChunkLocFor(TheClient.Player.GetPosition()));
                if (ch == null)
                {
                    throw new Exception("Chunk is null!");
                }
                TheClient.VoxelComputer.sw1.Reset();
                TheClient.VoxelComputer.sw1a.Reset();
                TheClient.VoxelComputer.sw2.Reset();
                TheClient.VoxelComputer.sw3.Reset();
                TheClient.VoxelComputer.Calc(ch);
                entry.Good(queue, "Took: " + TheClient.VoxelComputer.sw1.ElapsedMilliseconds + " (" + TheClient.VoxelComputer.sw1a.ElapsedMilliseconds + ") / "
                           + TheClient.VoxelComputer.sw2.ElapsedMilliseconds + " / " + TheClient.VoxelComputer.sw3.ElapsedMilliseconds);
                break;
            }

            case "testComputeAll":
            {
                TheClient.VoxelComputer.sw1.Reset();
                TheClient.VoxelComputer.sw1a.Reset();
                TheClient.VoxelComputer.sw2.Reset();
                TheClient.VoxelComputer.sw3.Reset();
                TheClient.VoxelComputer.Calc(TheClient.TheRegion.LoadedChunks.Values.ToArray());
                entry.Good(queue, "Took: " + TheClient.VoxelComputer.sw1.ElapsedMilliseconds + " (" + TheClient.VoxelComputer.sw1a.ElapsedMilliseconds + ") / "
                           + TheClient.VoxelComputer.sw2.ElapsedMilliseconds + " / " + TheClient.VoxelComputer.sw3.ElapsedMilliseconds);
                break;
            }

            default:
                ShowUsage(queue, entry);
                break;
            }
        }
コード例 #19
0
ファイル: CdevelCommand.cs プロジェクト: BlackCoyote/Voxalia
        public override void Execute(CommandQueue queue, CommandEntry entry)
        {
            if (entry.Arguments.Count < 1)
            {
                ShowUsage(queue, entry);
                return;
            }
            switch (entry.GetArgument(queue, 0))
            {
            case "lightDebug":
            {
                Location pos = TheClient.Player.GetPosition();
                pos.Z = pos.Z + 1;
                int XP = (int)Math.Floor(pos.X / Chunk.CHUNK_SIZE);
                int YP = (int)Math.Floor(pos.Y / Chunk.CHUNK_SIZE);
                int ZP = (int)Math.Floor(pos.Z / Chunk.CHUNK_SIZE);
                int x  = (int)(Math.Floor(pos.X) - (XP * Chunk.CHUNK_SIZE));
                int y  = (int)(Math.Floor(pos.Y) - (YP * Chunk.CHUNK_SIZE));
                int z  = (int)(Math.Floor(pos.Z) - (ZP * Chunk.CHUNK_SIZE));
                while (true)
                {
                    Chunk ch = TheClient.TheRegion.GetChunk(new Vector3i(XP, YP, ZP));
                    if (ch == null)
                    {
                        entry.Good(queue, "Passed with flying light sources!");
                        goto end;
                    }
                    while (z < Chunk.CHUNK_SIZE)
                    {
                        if (ch.GetBlockAt((int)x, (int)y, (int)z).IsOpaque())
                        {
                            entry.Info(queue, "Died: " + x + ", " + y + ", " + z + " -- " + XP + ", " + YP + ", " + ZP);
                            goto end;
                        }
                        z++;
                    }
                    ZP++;
                    z = 0;
                }
end:
                break;
            }

            case "vramUsage":
            {
                long c = 0;
                foreach (Tuple <string, long> val in TheClient.CalculateVRAMUsage())
                {
                    entry.Info(queue, "-> " + val.Item1 + ": " + val.Item2 + " (" + (val.Item2 / 1024 / 1024) + "MB)");
                    c += val.Item2;
                }
                entry.Info(queue, "-> Total: " + c + " (" + (c / 1024 / 1024) + "MB)");
                break;
            }

            case "speakText":
            {
                if (entry.Arguments.Count < 3)
                {
                    ShowUsage(queue, entry);
                    break;
                }
                bool male = !entry.GetArgument(queue, 1).ToString().ToLowerFast().StartsWith("f");
                TextToSpeech.Speak(entry.GetArgument(queue, 2), male, entry.Arguments.Count > 3 ? (int)IntegerTag.TryFor(entry.GetArgumentObject(queue, 3)).Internal : 0);
                break;
            }

            case "chunkInfo":
            {
                Chunk ch = TheClient.TheRegion.GetChunk(TheClient.TheRegion.ChunkLocFor(TheClient.Player.GetPosition()));
                if (ch == null)
                {
                    entry.Info(queue, "Chunk is null!");
                    break;
                }
                entry.Info(queue, "Plants: " + ch.Plant_C + ", generated as ID: " + ch.Plant_VAO);
                int  c                     = 0;
                long verts                 = 0;
                long verts_transp          = 0;
                int  total                 = 0;
                int  total_rendered        = 0;
                int  total_rendered_transp = 0;
                foreach (Chunk chunk in TheClient.TheRegion.LoadedChunks.Values)
                {
                    total++;
                    if (chunk._VBOSolid != null && ch._VBOSolid != null && chunk._VBOSolid._VAO == ch._VBOSolid._VAO)
                    {
                        c++;
                    }
                    if (chunk._VBOSolid != null && chunk._VBOSolid.generated)
                    {
                        verts += chunk._VBOSolid.vC;
                        total_rendered++;
                    }
                    if (chunk._VBOTransp != null && chunk._VBOTransp.generated)
                    {
                        verts_transp += chunk._VBOTransp.vC;
                        total_rendered_transp++;
                    }
                }
                entry.Info(queue, "Chunk rendering as " + (ch._VBOSolid == null ? "{NULL}" : ch._VBOSolid._VAO.ToString()) + ", which is seen in " + c + " chunks!");
                entry.Info(queue, "Chunks: " + total + ", rendering " + verts + " solid verts and " + verts_transp +
                           " transparent verts, with " + total_rendered + " solid-existent chunks, and " + total_rendered_transp + " transparent-existent chunks!");
                break;
            }

            case "blockInfo":
            {
                BlockInternal bi = TheClient.TheRegion.GetBlockInternal(TheClient.Player.GetPosition());
                entry.Info(queue, "BLOCK: Material=" + bi.Material + ", Shape=" + bi.BlockData + ", Damage=" + bi.Damage + ", Paint=" + bi.BlockPaint + ",Light=" + bi.BlockLocalData);
                break;
            }

            case "igniteBlock":
            {
                Location   pos = TheClient.Player.GetPosition().GetUpperBlockBorder();
                FireEntity fe  = new FireEntity(pos, null, TheClient.TheRegion);
                TheClient.TheRegion.SpawnEntity(fe);
                break;
            }

            case "torchBlocks":
            {
                Location pos = TheClient.Player.GetPosition().GetUpperBlockBorder();
                for (int x = -3; x <= 3; x++)
                {
                    for (int y = -3; y <= 3; y++)
                    {
                        FireEntity fe = new FireEntity(pos + new Location(x, y, 0), null, TheClient.TheRegion);
                        TheClient.TheRegion.SpawnEntity(fe);
                    }
                }
                break;
            }

            case "lateVR":
            {
                if (!VRSupport.Available())
                {
                    entry.Info(queue, "Can't load VR. Not available!");
                    break;
                }
                if (TheClient.VR != null)
                {
                    entry.Info(queue, "Can't load VR. Already loaded!");
                    break;
                }
                TheClient.VR = VRSupport.TryInit(TheClient);
                break;
            }

            case "fogEnhance":
            {
                double time   = NumberTag.TryFor(entry.GetArgumentObject(queue, 1)).Internal;
                double fogVal = NumberTag.TryFor(entry.GetArgumentObject(queue, 2)).Internal;
                TheClient.FogEnhanceStrength = (float)fogVal;
                TheClient.FogEnhanceTime     = time;
                break;
            }

            case "flashBang":
            {
                double time = NumberTag.TryFor(entry.GetArgumentObject(queue, 1)).Internal;
                TheClient.MainWorldView.Flashbang(time);
                break;
            }

            case "earRing":
            {
                double time = NumberTag.TryFor(entry.GetArgumentObject(queue, 1)).Internal;
                TheClient.Sounds.Deafen(time);
                break;
            }

            case "topInfo":
            {
                Location pos      = TheClient.Player.GetPosition().GetBlockLocation();
                Vector3i chunkLoc = TheClient.TheRegion.ChunkLocFor(pos);
                Vector2i buaPos   = new Vector2i(chunkLoc.X, chunkLoc.Y);
                if (!TheClient.TheRegion.UpperAreas.TryGetValue(buaPos, out BlockUpperArea bua))
                {
                    entry.Info(queue, "Failed to grab Top data: Out of map?");
                }
                else
                {
                    entry.Info(queue, pos + ": " + bua.Blocks[bua.BlockIndex((int)pos.X - chunkLoc.X * Chunk.CHUNK_SIZE, (int)pos.Y - chunkLoc.Y * Chunk.CHUNK_SIZE)]);
                }
                break;
            }

            case "testDecal":
            {
                Location pos = TheClient.Player.GetPosition() + new Location(0, 0, BEPUphysics.Settings.CollisionDetectionSettings.AllowedPenetration);
                TheClient.AddDecal(pos, new Location(0, 0, 1), Vector4.One, 1f, "white", 15);
                break;
            }

            case "traceDecal":
            {
                Location pos  = TheClient.Player.GetEyePosition();
                Location forw = TheClient.Player.ForwardVector();
                if (TheClient.TheRegion.SpecialCaseRayTrace(pos, forw, 50.0f, MaterialSolidity.FULLSOLID, TheClient.Player.IgnoreThis, out RayCastResult rcr))
                {
                    Location nrm = new Location(rcr.HitData.Normal).Normalize();
                    TheClient.AddDecal(new Location(rcr.HitData.Location) + nrm * 0.005, nrm, Vector4.One, 1f, "white", 15);
                    entry.Info(queue, "Marked at normal " + nrm);
                }
                break;
            }

            case "soundCount":
            {
                entry.Info(queue, "Sound effects: " + TheClient.Sounds.Effects.Count + ", playing now: " + TheClient.Sounds.PlayingNow.Count);
                break;
            }

            default:
                ShowUsage(queue, entry);
                break;
            }
        }
コード例 #20
0
 /// <summary>Handles the base input for a tag.</summary>
 /// <param name="data">The tag data.</param>
 /// <returns>The correct object.</returns>
 public static NumberTag HandleOne(TagData data)
 {
     return(NumberTag.For(data.GetModifierObjectCurrent(), data));
 }
コード例 #21
0
 /// <summary>Constructs the argument with input text.</summary>
 /// <param name="_text">The input text.</param>
 /// <param name="wasquoted">Whether the argument was quoted at input time.</param>
 /// <param name="perfect">Whether the argument must parse back "perfectly" (meaning, it will ToString to the exact original input).</param>
 /// <param name="_engine">The backing script engine.</param>
 public TextArgumentBit(string _text, bool wasquoted, bool perfect, ScriptEngine _engine)
 {
     Engine = _engine;
     if (wasquoted)
     {
         InputValue = new TextTag(_text);
         ResType    = TextTag.TYPE;
         return;
     }
     else if (_text == "true")
     {
         InputValue = BooleanTag.TRUE;
         ResType    = BooleanTag.TYPE;
         return;
     }
     else if (_text == "false")
     {
         InputValue = BooleanTag.FALSE;
         ResType    = BooleanTag.TYPE;
         return;
     }
     else if (_text == "&{NULL}")
     {
         InputValue = NullTag.NULL_VALUE;
         ResType    = NullTag.TYPE;
         return;
     }
     else if (long.TryParse(_text, out long ti) && ti.ToString() == _text)
     {
         InputValue = new IntegerTag(ti);
         ResType    = IntegerTag.TYPE;
         return;
     }
     else if (double.TryParse(_text, out double tn) && (!perfect || tn.ToString() == _text))
     {
         InputValue = new NumberTag(tn);
         ResType    = NumberTag.TYPE;
         return;
     }
     else if (_text.Contains('|'))
     {
         if (_text.Contains(':'))
         {
             MapTag map = MapTag.For(_text);
             if (map.ToString() == _text)
             {
                 InputValue = map;
                 ResType    = MapTag.TYPE;
                 return;
             }
         }
         ListTag list = ListTag.For(_text);
         if (list.ToString() == _text)
         {
             InputValue = list;
             ResType    = ListTag.TYPE;
             return;
         }
     }
     InputValue = new TextTag(_text);
     ResType    = TextTag.TYPE;
 }