Esempio n. 1
0
        public void Use(IClient iClient, string commandName, string[] tokens)
        {
            Client  client = iClient as Client;
            Vector3 facing = new Vector3(client.Owner.Yaw, client.Owner.Pitch);

            Vector3 start = new Vector3(client.Owner.Position.X, client.Owner.Position.Y + client.Owner.EyeHeight, client.Owner.Position.Z);
            Vector3 end   = facing * 100 + start;

            if (end.Y < 0)
            {
                end   = end * (Math.Abs(end.Y) / start.Y);
                end.Y = 0;
            }

            RayTraceHitBlock hit = client.Owner.World.RayTraceBlocks(new AbsWorldCoords(start), new AbsWorldCoords(end));

            if (hit != null)
            {
                if (tokens.Length == 0)
                {
                }
                else
                {
                    MobType mobType;
                    if (Enum.TryParse <MobType>(tokens[0], true, out mobType))
                    {
                        Mob theMob = MobFactory.Instance.CreateMob(client.Owner.World, client.Server, mobType, null) as Mob;
                        theMob.Position = new AbsWorldCoords(client.Owner.World.FromFace(hit.TargetBlock, hit.FaceHit));
                        client.Server.AddEntity(theMob);
                    }
                    else if (tokens[0] == "update")
                    {
                        UniversalCoords coords = UniversalCoords.FromAbsWorld(client.Owner.Position);
                        foreach (EntityBase entity in client.Server.GetNearbyEntitiesInternal(client.Owner.World, coords))
                        {
                            entity.TeleportTo(entity.Position);
                        }
                    }
                    else
                    {
                        client.SendMessage(String.Format("Unrecognised mob type: '{0}'", tokens[0]));
                    }
                }
            }
        }
Esempio n. 2
0
        public void Use(IClient iClient, string commandName, string[] tokens)
        {
            Client  client = iClient as Client;
            Vector3 facing = new Vector3(client.Owner.Yaw, client.Owner.Pitch);

            Vector3 start = new Vector3(client.Owner.Position.X, client.Owner.Position.Y + client.Owner.EyeHeight, client.Owner.Position.Z);
            Vector3 end   = facing * 100 + start;

            if (end.Y < 0)
            {
                end   = end * (Math.Abs(end.Y) / start.Y);
                end.Y = 0;
            }

            RayTraceHitBlock hit = client.Owner.World.RayTraceBlocks(new AbsWorldCoords(start), new AbsWorldCoords(end));

            if (hit != null)
            {
                if (tokens.Length == 0)
                {
                }
                else
                {
                    MobType mobType;
                    if (Enum.TryParse <MobType>(tokens[0], true, out mobType))
                    {
                        Mob theMob = MobFactory.Instance.CreateMob(client.Owner.World, client.Server, mobType, null) as Mob;
                        theMob.Position = new AbsWorldCoords(UniversalCoords.FromFace(hit.TargetBlock, hit.FaceHit));
                        client.Server.AddEntity(theMob);
                    }
                    else if (tokens[0] == "update")
                    {
                        UniversalCoords coords = UniversalCoords.FromAbsWorld(client.Owner.Position);
                        foreach (EntityBase entity in client.Server.GetNearbyEntitiesInternal(client.Owner.World, coords))
                        {
                            entity.TeleportTo(entity.Position);
                        }
                    }
                    else if (tokens[0] == "path")
                    {
                        PathFinder finder = new PathFinder(client.Owner.World);
                        var        path   = finder.CreatePathToCoordinate(client.Owner, new AbsWorldCoords(UniversalCoords.FromFace(hit.TargetBlock, hit.FaceHit)));
                        if (path != null)
                        {
                            foreach (var item in path)
                            {
                                client.Owner.World.SetBlockAndData(item.Coordinate,
                                                                   (byte)
                                                                   Chraft.Utilities.Blocks.BlockData.Blocks.
                                                                   Redstone_Torch_On, 0);
                            }
                        }
                        else
                        {
                            client.SendMessage(String.Format("Unable to determine path to '{0}'", hit.TargetBlock.Offset(0, 1, 0)));
                        }
                    }
                    else
                    {
                        client.SendMessage(String.Format("Unrecognised mob type: '{0}'", tokens[0]));
                    }
                }
            }
        }
Esempio n. 3
0
        public void Use(IClient iClient, string commandName, string[] tokens)
        {
            Client  client = iClient as Client;
            Vector3 facing = new Vector3(client.Owner.Yaw, client.Owner.Pitch);

            Vector3 start = new Vector3(client.Owner.Position.X, client.Owner.Position.Y + client.Owner.EyeHeight, client.Owner.Position.Z);
            Vector3 end   = facing * 100 + start;

            if (end.Y < 0)
            {
                end   = end * (Math.Abs(end.Y) / start.Y);
                end.Y = 0;
            }

            if (tokens.Length == 0)
            {
                // Ray trace out along client facing direction
                RayTraceHitBlock hit = client.Owner.World.RayTraceBlocks(new AbsWorldCoords(start), new AbsWorldCoords(end));

                if (hit == null)
                {
                    client.SendMessage(String.Format("No block targetted within {0} metres", start.Distance(end)));
                }
                else
                {
                    client.SendMessage(String.Format("{0} metres to {1}", start.Distance(hit.Hit), hit.ToString()));
                }
            }
            else if (tokens[0] == "destroy") // destroy the targetted block
            {
                RayTraceHitBlock hit = client.Owner.World.RayTraceBlocks(new AbsWorldCoords(start), new AbsWorldCoords(end));

                if (hit != null)
                {
                    client.Owner.World.SetBlockAndData(hit.TargetBlock, 0, 0);
                }
            }
            else if (tokens[0] == "pink") // make the targetted block pink wool
            {
                RayTraceHitBlock hit = client.Owner.World.RayTraceBlocks(new AbsWorldCoords(start), new AbsWorldCoords(end));

                if (hit != null)
                {
                    client.Owner.World.SetBlockAndData(hit.TargetBlock, 35, 6);
                }
            }
            else if (tokens[0] == "perf") // performance check
            {
                DateTime         startTime = DateTime.Now;
                RayTraceHitBlock hit       = null;
                for (int i = 0; i < 1000; i++)
                {
                    hit = client.Owner.World.RayTraceBlocks(new AbsWorldCoords(start), new AbsWorldCoords(end));
                }

                DateTime endTime = DateTime.Now;
                if (hit != null)
                {
                    client.SendMessage(String.Format("Time to ray trace {0} metres (with hit):", start.Distance(hit.Hit)));
                }
                else
                {
                    client.SendMessage(String.Format("Time to ray trace {0} metres:", start.Distance(end)));
                }
                client.SendMessage(((endTime - startTime).TotalMilliseconds / 1000.0).ToString() + " ms");
            }
        }