예제 #1
0
 public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry)
 {
     try
     {
         IntegerTag num = IntegerTag.TryFor(entry.GetArgumentObject(queue, 1));
         if (num == null)
         {
             queue.HandleError(entry, "Invalid amount number!");
             return;
         }
         PlayerTag player = PlayerTag.For(entry.GetArgument(queue, 0));
         if (player == null)
         {
             queue.HandleError(entry, "Invalid player!");
             return;
         }
         player.Internal.player.life.askWarm((uint)num.Internal);
         if (entry.ShouldShowGood(queue))
         {
             entry.Good(queue, "Successfully adjusted the warmth level of a player!");
         }
     }
     catch (Exception ex) // TODO: Necessity?
     {
         queue.HandleError(entry, "Failed to adjust player's warmth level: " + ex.ToString());
     }
 }
예제 #2
0
        public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry)
        {
            IntegerTag num = IntegerTag.TryFor(entry.GetArgumentObject(queue, 1));

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

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

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

            if (entity.TryGetPlayer(out player))
            {
                GameObject          playerObj  = player.Internal.player.gameObject;
                UFMHealthController controller = playerObj.GetComponent <UFMHealthController>();
                if (controller == null)
                {
                    controller = playerObj.AddComponent <UFMHealthController>();
                }
                controller.maxHealth = (uint)num.Internal;
                PlayerLife life = player.Internal.player.life;
                byte       curr = life.health;
                controller.health = curr >= controller.maxHealth ? controller.maxHealth : curr;
                life._health      = controller.Translate();
                life.channel.send("tellHealth", ESteamCall.OWNER, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[]
                {
                    life.health
                });
                if (entry.ShouldShowGood(queue))
                {
                    entry.Good(queue, "Successfully set max health of a player to " + controller.maxHealth + "!");
                }
                return;
            }
            queue.HandleError(entry, "That entity can't be healed!");
        }
예제 #3
0
 public int GetAttributeI(string attr, int def)
 {
     if (Attributes.TryGetValue(attr, out TemplateObject outp))
     {
         return((int)IntegerTag.TryFor(outp).Internal);
     }
     return(def);
 }
 /// <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);
 }
예제 #5
0
        public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry)
        {
            IntegerTag itag = IntegerTag.TryFor(entry.GetArgumentObject(queue, 0));
            uint       ti   = (uint)itag.Internal;

            SDG.Unturned.LightingManager.time = ti;
            if (entry.ShouldShowGood(queue))
            {
                entry.Good(queue, "World time set to " + ti + "!");
            }
        }
예제 #6
0
        /// <summary>Executes the numbered input part of the repeat command, without debug.</summary>
        /// <param name="queue">The command queue involved.</param>
        /// <param name="entry">Entry to be executed.</param>
        public static bool TryRepeatNumberedCIL_NoDebug(CommandQueue queue, CommandEntry entry)
        {
            int target = (int)IntegerTag.TryFor(entry.GetArgumentObject(queue, 0)).Internal;

            if (target <= 0)
            {
                return(false);
            }
            entry.SetData(queue, new RepeatCommandData()
            {
                Index = 1, Total = target
            });
            return(true);
        }
예제 #7
0
        public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry)
        {
            IntegerTag num = IntegerTag.TryFor(entry.GetArgumentObject(queue, 2));

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

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

            if (num.Internal > 0)
            {
                PlayerSkills skills = player.Internal.player.skills;
                if (award)
                {
                    skills._experience += (uint)num.Internal;
                }
                else
                {
                    skills._experience -= (uint)num.Internal;
                }
                skills.channel.send("tellExperience", ESteamCall.OWNER, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[]
                {
                    skills.experience
                });
            }
            else
            {
                queue.HandleError(entry, "Amount must be positive!");
                return;
            }
            if (entry.ShouldShowGood(queue))
            {
                entry.Good(queue, "Successfully " + (award ? "awarded experience to" : "took experience from") + " a player!");
            }
        }
예제 #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)
        {
            int count = 1;

            if (entry.Arguments.Length > 0)
            {
                IntegerTag inter = IntegerTag.TryFor(entry.GetArgumentObject(queue, 0));
                if (inter != null)
                {
                    count = (int)inter.Internal;
                }
            }
            if (count <= 0)
            {
                ShowUsage(queue, entry);
                return;
            }
            for (int i = 0; i < count; i++)
            {
                CompiledCommandRunnable runnable = queue.CurrentRunnable;
                for (int ind = runnable.Index; ind < runnable.Entry.Entries.Length; ind++)
                {
                    CommandEntry tentry = runnable.Entry.Entries[ind];
                    if (tentry.Command.Meta.IsBreakable && tentry.IsCallback)
                    {
                        runnable.Index = ind + 1;
                        goto completed;
                    }
                }
                if (queue.RunningStack.Count > 1)
                {
                    queue.RunningStack.Pop();
                }
                else
                {
                    queue.HandleError(entry, "Not in that many blocks!");
                    return;
                }
completed:
                continue;
            }
            entry.GoodOutput(queue, "Broke free successfully.");
        }
예제 #9
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.
            }
        }
예제 #10
0
        /// <summary>Executes the numbered input part of the repeat command.</summary>
        /// <param name="queue">The command queue involved.</param>
        /// <param name="entry">Entry to be executed.</param>
        public static bool TryRepeatNumberedCIL(CommandQueue queue, CommandEntry entry)
        {
            int target = (int)IntegerTag.TryFor(entry.GetArgumentObject(queue, 0)).Internal;

            if (target <= 0)
            {
                if (entry.ShouldShowGood(queue))
                {
                    entry.GoodOutput(queue, "Not repeating.");
                }
                return(false);
            }
            entry.SetData(queue, new RepeatCommandData()
            {
                Index = 1, Total = target
            });
            if (entry.ShouldShowGood(queue))
            {
                entry.GoodOutput(queue, "Repeating " + TextStyle.Separate + target + TextStyle.Base + " times...");
            }
            return(true);
        }
예제 #11
0
 public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry)
 {
     try
     {
         IntegerTag num = IntegerTag.TryFor(entry.GetArgumentObject(queue, 1));
         if (num == null)
         {
             queue.HandleError(entry, "Invalid amount number!");
             return;
         }
         PlayerTag player = PlayerTag.For(entry.GetArgument(queue, 0));
         if (player == null)
         {
             queue.HandleError(entry, "Invalid player!");
             return;
         }
         int        amount = (int)num.Internal;
         PlayerLife life   = player.Internal.player.life;
         if (amount >= 0)
         {
             life.askRest((byte)amount);
         }
         else
         {
             life.askTire((byte)-amount);
         }
         if (entry.ShouldShowGood(queue))
         {
             entry.Good(queue, "Successfully adjusted the stamina level of a player!");
         }
     }
     catch (Exception ex) // TODO: Necessity?
     {
         queue.HandleError(entry, "Failed to adjust player's stamina level: " + ex.ToString());
     }
 }
예제 #12
0
        public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry)
        {
            string    animation = entry.GetArgument(queue, 1).ToUpperInvariant();
            EntityTag entity    = EntityTag.For(entry.GetArgumentObject(queue, 0));

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

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

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

            if (entity.TryGetAnimal(out animal))
            {
                if (animation == "STARTLE")
                {
                    AnimalManager.sendAnimalStartle(animal.Internal);
                }
                else if (animation == "PANIC")
                {
                    AnimalManager.sendAnimalPanic(animal.Internal);
                }
                else if (animation == "ATTACK")
                {
                    AnimalManager.sendAnimalAttack(animal.Internal);
                }
                else
                {
                    queue.HandleError(entry, "Invalid animation specified!");
                    return;
                }
                if (entry.ShouldShowGood(queue))
                {
                    entry.Good(queue, "Animated an animal!");
                }
                return;
            }
            queue.HandleError(entry, "That entity can't be animated!");
        }
예제 #13
0
        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;
            }
        }
예제 #14
0
 public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry)
 {
     try
     {
         IntegerTag num = IntegerTag.TryFor(entry.GetArgumentObject(queue, 1));
         if (num.Internal < 0)
         {
             queue.HandleError(entry, "Must provide a non-negative number!");
             return;
         }
         EntityTag entity = EntityTag.For(entry.GetArgumentObject(queue, 0));
         if (entity == null)
         {
             queue.HandleError(entry, "Invalid entity!");
             return;
         }
         PlayerTag player;
         if (entity.TryGetPlayer(out player))
         {
             UFMHealthController healthController = player.Internal.player.gameObject.GetComponent <UFMHealthController>();
             uint amount = (uint)num.Internal;
             if (healthController != null)
             {
                 healthController.Heal(amount);
                 amount = (uint)(((double)amount / healthController.maxHealth) * 100.0);
             }
             PlayerLife life = player.Internal.player.life;
             life._health = healthController.Translate();
             life.channel.send("tellHealth", ESteamCall.OWNER, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[]
             {
                 life.health
             });
             if (entry.ShouldShowGood(queue))
             {
                 uint finalHealth = healthController != null ? healthController.health : life.health;
                 entry.Good(queue, "Successfully healed a player to a new health value of " + finalHealth + "!");
             }
             return;
         }
         ZombieTag zombie;
         if (entity.TryGetZombie(out zombie))
         {
             Zombie inZomb = zombie.Internal;
             inZomb.health += (ushort)num.Internal;
             if (inZomb.health > inZomb.maxHealth)
             {
                 inZomb.health = inZomb.maxHealth;
             }
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully healed a zombie to a new health value of " + inZomb.health + "!");
             }
             return;
         }
         AnimalTag animal;
         if (entity.TryGetAnimal(out animal))
         {
             Animal inAnimal = animal.Internal;
             inAnimal.health += (ushort)num.Internal;
             if (inAnimal.health > inAnimal.asset.health)
             {
                 inAnimal.health = inAnimal.asset.health;
             }
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully healed an animal to a new health value of " + inAnimal.health + "!");
             }
             return;
         }
         BarricadeTag barricade;
         if (entity.TryGetBarricade(out barricade))
         {
             Barricade inBarricade = barricade.InternalData.barricade;
             inBarricade.health += (ushort)num.Internal;
             ushort max = ((ItemBarricadeAsset)Assets.find(EAssetType.ITEM, inBarricade.id)).health;
             if (inBarricade.health > max)
             {
                 inBarricade.health = max;
             }
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully healed a barricade to a new health value of " + inBarricade.health + "!");
             }
             return;
         }
         ResourceTag resource;
         if (entity.TryGetResource(out resource))
         {
             ResourceSpawnpoint inResource = resource.Internal;
             inResource.health += (ushort)num.Internal;
             ushort max = ((ResourceAsset)Assets.find(EAssetType.RESOURCE, inResource.id)).health;
             if (inResource.health > max)
             {
                 inResource.health = max;
             }
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully healed a resource to a new health value of " + inResource.health + "!");
             }
             return;
         }
         StructureTag structure;
         if (entity.TryGetStructure(out structure))
         {
             Structure inStructure = structure.InternalData.structure;
             inStructure.health += (ushort)num.Internal;
             ushort max = ((ItemStructureAsset)Assets.find(EAssetType.ITEM, inStructure.id)).health;
             if (inStructure.health > max)
             {
                 inStructure.health = max;
             }
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully healed a structure to a new health value of " + inStructure.health + "!");
             }
             return;
         }
         VehicleTag vehicle;
         if (entity.TryGetVehicle(out vehicle))
         {
             vehicle.Internal.askRepair((ushort)num.Internal);
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully healed a vehicle to a new health value of " + vehicle.Internal.health + "!");
             }
             return;
         }
         queue.HandleError(entry, "That entity can't be healed!");
     }
     catch (Exception ex) // TODO: Necessity?
     {
         queue.HandleError(entry, ("Failed to heal entity: " + ex.ToString()));
     }
 }
예제 #15
0
 public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry)
 {
     try
     {
         IntegerTag num = IntegerTag.TryFor(entry.GetArgumentObject(queue, 1));
         if (num.Internal < 0)
         {
             queue.HandleError(entry, "Must provide a non-negative number!");
             return;
         }
         EntityTag entity = EntityTag.For(entry.GetArgumentObject(queue, 0));
         if (entity == null)
         {
             queue.HandleError(entry, "Invalid entity!");
             return;
         }
         EPlayerKill kill; // for use with "out EPlayerKill" parameters
         PlayerTag   player;
         if (entity.TryGetPlayer(out player))
         {
             PlayerLife          life             = player.Internal.player.life;
             UFMHealthController healthController = player.Internal.player.GetComponent <UFMHealthController>();
             uint health = healthController != null ? healthController.health : life.health;
             if (num.Internal >= health)
             {
                 uint amount = (uint)num.Internal;
                 if (healthController != null)
                 {
                     healthController.health = 0;
                 }
                 if (amount >= byte.MaxValue) // TODO: better handling
                 {
                     life._health = 0;
                     amount       = 1;
                 }
                 life.askDamage((byte)amount, Vector3.zero, EDeathCause.KILL, ELimb.SPINE, CSteamID.Nil, out kill, null);
             }
             else
             {
                 uint amount = (uint)num.Internal;
                 if (healthController != null)
                 {
                     healthController.Damage((uint)num.Internal);
                 }
                 life._health = healthController.Translate();
                 life.channel.send("tellHealth", ESteamCall.OWNER, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[]
                 {
                     life.health
                 });
             }
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully damaged a player by " + TagParser.Escape(num.ToString()) + "!");
             }
             return;
         }
         ZombieTag zombie;
         if (entity.TryGetZombie(out zombie))
         {
             uint xp;
             zombie.Internal.askDamage((byte)num.Internal, Vector3.zero, out kill, out xp);
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully damaged a zombie by " + TagParser.Escape(num.ToString()) + "!");
             }
             return;
         }
         AnimalTag animal;
         if (entity.TryGetAnimal(out animal))
         {
             uint xp;
             animal.Internal.askDamage((byte)num.Internal, Vector3.zero, out kill, out xp);
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully damaged an animal by " + TagParser.Escape(num.ToString()) + "!");
             }
             return;
         }
         BarricadeTag barricade;
         if (entity.TryGetBarricade(out barricade))
         {
             // TODO: Use BarricadeManager?
             barricade.InternalData.barricade.askDamage((ushort)num.Internal);
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully damaged a barricade by " + TagParser.Escape(num.ToString()) + "!");
             }
             return;
         }
         ResourceTag resource;
         if (entity.TryGetResource(out resource))
         {
             // TODO: Use ResourceManager?
             resource.Internal.askDamage((ushort)num.Internal);
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully damaged a resource by " + TagParser.Escape(num.ToString()) + "!");
             }
             return;
         }
         StructureTag structure;
         if (entity.TryGetStructure(out structure))
         {
             // TODO: Use StructureManager?
             structure.InternalData.structure.askDamage((ushort)num.Internal);
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully damaged a structure by " + TagParser.Escape(num.ToString()) + "!");
             }
             return;
         }
         VehicleTag vehicle;
         if (entity.TryGetVehicle(out vehicle))
         {
             vehicle.Internal.askDamage((ushort)num.Internal, false);
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully damaged a vehicle by " + TagParser.Escape(num.ToString()) + "!");
             }
             return;
         }
         queue.HandleError(entry, "That entity can't be damaged!");
     }
     catch (Exception ex) // TODO: Necessity?
     {
         queue.HandleError(entry, "Failed to damage entity: " + ex.ToString());
     }
 }
예제 #16
0
        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;
            }
        }