Beispiel #1
0
        public override void Process(CmdTrigger <RealmServerCmdArgs> trigger)
        {
            WorldObject obj = trigger.Args.Target;

            var    zone = obj.Zone;
            string zoneStr;

            if (zone != null)
            {
                zoneStr = zone.Id.ToString();

                while ((zone = zone.ParentZone) != null)
                {
                    zoneStr += " in " + zone;
                }
            }
            else
            {
                zoneStr = "<null>";
            }

            var height = obj.TerrainHeight;

            trigger.Reply("Map: " + obj.Map + ", Zone: " + zoneStr);
            trigger.Reply("Position X: " + obj.Position.X + ", Y: " + obj.Position.Y + ", Z: " + obj.Position.Z + ", O: " + obj.Orientation +
                          "(" + Math.Abs(obj.Position.Z - height) + " yds from Ground)");

            int tileX, tileY;

            PositionUtil.GetTileXYForPos(obj.Position, out tileX, out tileY);
            trigger.ReplyFormat("Tile: X={0}, Y={1} (Collision Data {2})", tileX, tileY,
                                obj.Map.Terrain.IsAvailable(tileX, tileY) ?
                                ChatUtility.Colorize("Available", Color.Green) :
                                ChatUtility.Colorize("Unavailable", Color.Red));
        }
Beispiel #2
0
        public static TileIdentifier ByPosition(MapId mapId, Vector3 position)
        {
            int tileX, tileY;

            if (!PositionUtil.GetTileXYForPos(position, out tileX, out tileY))
            {
                return(null);
            }

            return(new TileIdentifier
            {
                MapId = mapId,
                MapName = InternalMapNames[mapId],
                TileX = tileX,
                TileY = tileY
            });
        }
Beispiel #3
0
        public float GetGroundHeightUnderneath(Vector3 worldPos)
        {
            int tileX, tileY;

            if (PositionUtil.GetTileXYForPos(worldPos, out tileX, out tileY))
            {
                // shoot a ray straight down
                var tile = GetTile(tileX, tileY);
                if (tile != null)
                {
                    float dist;
                    if (tile.FindFirstTriangleUnderneath(worldPos, out dist) != -1)
                    {
                        return(worldPos.Z - dist);
                    }
                    return(TerrainConstants.MinHeight);                                 // TODO: Minimal z value
                }
            }
            return(worldPos.Z);                                                                         // Could not reliably lookup the value
        }
Beispiel #4
0
        /// <summary>
        /// TODO: Connect meshes between different tiles
        /// </summary>
        public void FindPath(Vector3 from, Vector3 to, Core.Paths.Path path)
        {
            int fromX, fromY, toX, toY;

            if (!PositionUtil.GetTileXYForPos(from, out fromX, out fromY))
            {
                return;
            }
            if (!PositionUtil.GetTileXYForPos(to, out toX, out toY))
            {
                return;
            }

            if (toX != fromX || toY != fromY)
            {
                return;
            }

            TerrainTile tile1, tile2;

            if (LoadOnDemand)
            {
                tile1 = GetTile(fromX, fromY);
                tile2 = GetTile(toX, toY);
            }
            else
            {
                tile1 = Tiles[fromX, fromY];
                tile2 = Tiles[toX, toY];
            }

            // cannot traverse tiles yet
            if (tile1 == null || tile1 != tile2)
            {
                return;
            }

            tile1.Pathfinder.FindPath(from, to, path);
        }
Beispiel #5
0
        public static TileIdentifier GetTileAt(MapId mapId, Vector3 position)
        {
            int tileX, tileY;

            if (!PositionUtil.GetTileXYForPos(position, out tileX, out tileY))
            {
                return(null);
            }

            string name;

            if (InternalMapNames.TryGetValue(mapId, out name))
            {
                return(new TileIdentifier
                {
                    MapId = mapId,
                    MapName = InternalMapNames[mapId],
                    X = tileX,
                    Y = tileY
                });
            }
            return(null);
        }
Beispiel #6
0
            public override void Process(CmdTrigger <RealmServerCmdArgs> trigger)
            {
                var chr = trigger.Args.Character;

                if (chr == null)
                {
                    trigger.Reply("Character required in context.");
                    return;
                }

                if (!NPCMgr.Loaded)
                {
                    trigger.Reply("Loading NPCs...");
                    NPCMgr.LoadAllLater();
                    return;
                }

                var figurines = TerrainVisualizations.ClearVis(chr);

                var radius  = trigger.Text.NextFloat(30.0f);
                var p       = chr.Position;
                var map     = chr.Map;
                var terrain = TerrainMgr.GetTerrain(map.MapId) as SimpleTerrain;

                if (terrain == null)
                {
                    trigger.Reply("No Terrain created for Map: " + map);
                    return;
                }

                int tileX, tileY;

                PositionUtil.GetTileXYForPos(p, out tileX, out tileY);
                var tile = terrain.GetTile(tileX, tileY);

                if (tile == null || tile.NavMesh == null)
                {
                    trigger.Reply("No NavMesh present on Tile.");
                    return;
                }

                var mesh = tile.NavMesh;

                foreach (var poly in mesh.Polygons)
                {
                    Debug.Assert(poly.Indices.Length == 3);
                    var v1 = mesh.Vertices[poly.Indices[0]];
                    var v2 = mesh.Vertices[poly.Indices[1]];
                    var v3 = mesh.Vertices[poly.Indices[2]];

                    // only get polygons that are narby
                    if (p.GetDistance(ref v1) > radius &&
                        p.GetDistance(ref v2) > radius &&
                        p.GetDistance(ref v3) > radius)
                    {
                        continue;
                    }

                    var dumm1 = new NavFigurine();
                    var dumm2 = new NavFigurine();
                    var dumm3 = new NavFigurine();

                    dumm1.SetOrientationTowards(ref v2);
                    dumm1.ChannelObject = dumm2;
                    map.AddObject(dumm1, ref v1);

                    dumm2.SetOrientationTowards(ref v3);
                    dumm2.ChannelObject = dumm3;
                    map.AddObject(dumm2, ref v2);

                    dumm3.SetOrientationTowards(ref v1);
                    dumm3.ChannelObject = dumm1;
                    map.AddObject(dumm3, ref v3);

                    figurines.Add(dumm1);
                    figurines.Add(dumm2);
                    figurines.Add(dumm3);
                }

                trigger.Reply("Created {0} figurines.", figurines.Count);
            }
Beispiel #7
0
            public override void Process(CmdTrigger <RealmServerCmdArgs> trigger)
            {
                MapId mapId;
                int   tileX, tileY;

                if (trigger.Text.HasNext)
                {
                    mapId = trigger.Text.NextEnum(MapId.End);
                    tileX = trigger.Text.NextInt(-1);
                    tileY = trigger.Text.NextInt(-1);
                }
                else if (trigger.Args.Character == null)
                {
                    trigger.Reply("You did not specify map id and tile location.");
                    return;
                }
                else
                {
                    mapId = trigger.Args.Character.MapId;
                    PositionUtil.GetTileXYForPos(trigger.Args.Character.Position, out tileX, out tileY);
                }

                var terrain = TerrainMgr.GetTerrain(mapId);

                if (terrain == null)
                {
                    trigger.Reply("Invalid MapId.");
                    return;
                }

                if (!PositionUtil.VerifyTileCoords(tileX, tileY))
                {
                    trigger.Reply("Invalid tile coordinates.");
                    return;
                }

                trigger.Reply("Loading tile...");
                RealmServer.RealmServer.IOQueue.AddMessage(() =>
                {
                    terrain.ForceLoadTile(tileX, tileY);

                    if (terrain.IsAvailable(tileX, tileY))
                    {
                        trigger.Reply("Done. Tile ({0}, {1}) in Map {2} has been loaded.", tileX, tileY, mapId);
                    }
                    else
                    {
                        // try to extract from MPQ
                        //var adt = ADTReader.ReadADT(terrain, tileX, tileY);
                        trigger.Reply("WARNING: Tile ({0}, {1}) in Map {2} has not been exported yet...", tileX, tileY, mapId);
                        trigger.Reply("Extraction will take a while and block the IO queue, please have patience...");

                        var adt = WDT.LoadTile(mapId, tileX, tileY);
                        if (adt != null)
                        {
                            trigger.Reply("Tile ({0}, {1}) in Map {2} has been imported...", tileX, tileY, mapId);
                            trigger.Reply("Writing to file...");

                            // export to file
                            SimpleTileWriter.WriteADT(adt);

                            // try loading again
                            trigger.Reply("Loading extracted tile and generating Navigation mesh...");
                            terrain.ForceLoadTile(tileX, tileY);

                            if (terrain.IsAvailable(tileX, tileY))
                            {
                                trigger.Reply("Done. Tile ({0}, {1}) in Map {2} has been loaded successfully.", tileX, tileY, mapId);
                                return;
                            }
                        }

                        trigger.Reply("Loading FAILED: Tile ({0}, {1}) in Map {2} could not be loaded", tileX, tileY, mapId);
                    }
                });
            }