public CoordHeading FindEntry(int Playfield, int DestinationNumber) { CoordHeading ret = new CoordHeading(); ret.Coordinates.x = -1; foreach (WallCollision.Line l in WallCollision.Destinations[Playfield].Playfield.Lines) { if (l.ID != DestinationNumber) { continue; } ret.Coordinates.x = (l.LineStartPoint.X + l.LineEndPoint.X) / 2; ret.Coordinates.y = (l.LineStartPoint.Y + l.LineEndPoint.Y) / 2; ret.Coordinates.z = (l.LineStartPoint.Z + l.LineEndPoint.Z) / 2; // TODO: Calculate the right Quaternion for the heading... // - Algorithman Quaternion q = new Quaternion( new Vector3( (l.LineEndPoint.X - l.LineStartPoint.X), 1, -(l.LineEndPoint.Z - l.LineStartPoint.Z))); ret.Heading.x = q.x; ret.Heading.y = q.y; ret.Heading.z = q.z; ret.Heading.w = q.w; } return(ret); }
/// <summary> /// Lineteleport /// </summary> /// <param name="Self"></param> /// <param name="Caller"></param> /// <param name="Target"></param> /// <param name="Arguments">UInt32 (LineType?), UInt32 (Combo of Line# and Playfield), Int32 (Playfield to teleport to)</param> /// <returns></returns> public bool FunctionExecute(Dynel Self, Dynel Caller, object Target, object[] Arguments) { uint arg2; int to_pf; Console.WriteLine(Target.GetType().ToString()); if (Target is Statels.Statel) { arg2 = UInt32.Parse((string)Arguments[1]); // Linesegment and playfield (lower word) arg2 = arg2 >> 16; to_pf = Int32.Parse((string)Arguments[2]); } else { arg2 = (UInt32)Arguments[1]; to_pf = (Int32)Arguments[2]; } CoordHeading a = this.FindEntry(to_pf, (Int32)arg2); if (a.Coordinates.x != -1) { ((Character)Self).Client.Teleport(a.Coordinates, a.Heading, to_pf); return(true); } return(false); }
public bool FunctionExecute(Dynel Self, Dynel Caller, object Target, object[] Arguments) { Client cli = ((Character)Self).Client; Identity pfinstance = new Identity(); Identity R = new Identity(); Identity dest = new Identity(); int gs = 1; int sg = 0; if (Target is Statels.Statel) { pfinstance.Type = Int32.Parse((string)Arguments[0]); pfinstance.Instance = Int32.Parse((string)Arguments[1]); R.Type = Int32.Parse((string)Arguments[2]); R.Instance = Int32.Parse((string)Arguments[3]); dest.Type = Int32.Parse((string)Arguments[4]); dest.Instance = Int32.Parse((string)Arguments[5]); } else { pfinstance.Type = (Int32)Arguments[0]; pfinstance.Instance = (Int32)Arguments[1]; R.Type = (Int32)Arguments[2]; R.Instance = (Int32)Arguments[3]; dest.Type = (Int32)Arguments[4]; dest.Instance = (Int32)Arguments[5]; } int to_pf = (Int32)((UInt32)(dest.Instance & 0xffff)); int arg2 = (Int32)((UInt32)(dest.Instance >> 16)); CoordHeading a = this.FindEntry(to_pf, arg2); if (a.Coordinates.x != -1) { cli.TeleportProxy(a.Coordinates, a.Heading, to_pf, pfinstance, gs, sg, R, dest); return(true); } return(false); }
public static CoordHeading GetCoord(LineSegment lineSegment, float x, float z, AOCoord coordinates) { CoordHeading coordHeading = new CoordHeading(); foreach (Line line in Destinations[lineSegment.ZoneToPlayfield].Playfield.Lines) { if (line.ID == lineSegment.ZoneToIndex) { int incX = 0; int incZ = 0; Vector3 temp = new Vector3( line.LineEndPoint.X - line.LineStartPoint.X, 0, line.LineEndPoint.Z - line.LineStartPoint.Z); double factor = 1.0 / Math.Sqrt(Math.Pow(temp.x, 2) + Math.Pow(temp.z, 2)); temp.x = temp.x * factor; temp.z = temp.z * factor; if (line.LineStartPoint.X >= line.LineEndPoint.X) { coordHeading.Coordinates.x = line.LineEndPoint.X; if (Math.Abs(lineSegment.VectorA.X - lineSegment.VectorB.X) >= 1) { if (lineSegment.VectorA.X > lineSegment.VectorB.X) { coordHeading.Coordinates.x += Math.Abs(line.LineEndPoint.X - line.LineStartPoint.X) * (Math.Abs(x - lineSegment.VectorB.X) / Math.Abs(lineSegment.VectorA.X - lineSegment.VectorB.X)); incZ = 1; } else { coordHeading.Coordinates.x += Math.Abs(line.LineEndPoint.X - line.LineStartPoint.X) * (Math.Abs(x - lineSegment.VectorA.X) / Math.Abs(lineSegment.VectorA.X - lineSegment.VectorB.X)); incZ = -1; } } } else { coordHeading.Coordinates.x = line.LineStartPoint.X; if (Math.Abs(lineSegment.VectorA.X - lineSegment.VectorB.X) >= 1) { if (lineSegment.VectorA.X > lineSegment.VectorB.X) { coordHeading.Coordinates.x += Math.Abs(line.LineEndPoint.X - line.LineStartPoint.X) * (Math.Abs(x - lineSegment.VectorB.X) / Math.Abs(lineSegment.VectorA.X - lineSegment.VectorB.X)); incZ = -1; } else { coordHeading.Coordinates.x += Math.Abs(line.LineEndPoint.X - line.LineStartPoint.X) * (Math.Abs(x - lineSegment.VectorA.X) / Math.Abs(lineSegment.VectorA.X - lineSegment.VectorB.X)); incZ = 1; } } } if (line.LineStartPoint.Z >= line.LineEndPoint.Z) { coordHeading.Coordinates.z = line.LineEndPoint.Z; if (Math.Abs(lineSegment.VectorA.Z - lineSegment.VectorB.Z) >= 1) { if (lineSegment.VectorA.Z > lineSegment.VectorB.Z) { coordHeading.Coordinates.z += Math.Abs(line.LineStartPoint.Z - line.LineEndPoint.Z) * (Math.Abs(z - lineSegment.VectorB.Z) / Math.Abs(lineSegment.VectorA.Z - lineSegment.VectorB.Z)); incX = -1; } else { coordHeading.Coordinates.z += Math.Abs(line.LineStartPoint.Z - line.LineEndPoint.Z) * (Math.Abs(z - lineSegment.VectorA.Z) / Math.Abs(lineSegment.VectorA.Z - lineSegment.VectorB.Z)); incX = 1; } } } else { coordHeading.Coordinates.z = line.LineStartPoint.Z; if (Math.Abs(lineSegment.VectorA.Z - lineSegment.VectorB.Z) >= 1) { if (lineSegment.VectorA.Z > lineSegment.VectorB.Z) { coordHeading.Coordinates.z += Math.Abs(line.LineStartPoint.Z - line.LineEndPoint.Z) * (Math.Abs(z - lineSegment.VectorB.Z) / Math.Abs(lineSegment.VectorA.Z - lineSegment.VectorB.Z)); incX = 1; } else { coordHeading.Coordinates.z += Math.Abs(line.LineStartPoint.Z - line.LineEndPoint.Z) * (Math.Abs(z - lineSegment.VectorA.Z) / Math.Abs(lineSegment.VectorA.Z - lineSegment.VectorB.Z)); incX = -1; } } } if ((coordHeading.Coordinates.y < line.LineStartPoint.Y) || (coordinates.y < line.LineEndPoint.Y)) { if (line.LineStartPoint.Y >= line.LineEndPoint.Y) { coordHeading.Coordinates.y = line.LineStartPoint.Y; } else { coordHeading.Coordinates.y = line.LineEndPoint.Y; } } temp.x = temp.x * incZ * 4; temp.z = temp.z * incX * 4; coordHeading.Coordinates.x += Convert.ToSingle(temp.z); coordHeading.Coordinates.z += Convert.ToSingle(temp.x); temp.y = temp.x; temp.x = -temp.z; temp.z = temp.y; temp.y = 0; temp = temp.Normalize(); coordHeading.Heading = coordHeading.Heading.GenerateRotationFromDirectionVector(temp); break; } } return(coordHeading); }
/// <summary> /// TODO: Add a Description of what this Class does.. -Looks at someone else- /// </summary> /// <param name="packet"></param> /// <param name="client"></param> public static void Read(byte[] packet, Client client) { PacketWriter packetWriter = new PacketWriter(); PacketReader packetReader = new PacketReader(packet); Header header = packetReader.PopHeader(); packetReader.PopByte(); byte moveType = packetReader.PopByte(); Quaternion heading = packetReader.PopQuat(); AOCoord coordinates = packetReader.PopCoord(); // TODO: Find out what these (tmpInt) are and name them int tmpInt1 = packetReader.PopInt(); int tmpInt2 = packetReader.PopInt(); int tmpInt3 = packetReader.PopInt(); packetReader.Finish(); if (!client.Character.DoNotDoTimers) { WallCollision.LineSegment teleportPlayfield = WallCollision.WallCollisionCheck( coordinates.x, coordinates.z, client.Character.PlayField); if (teleportPlayfield.ZoneToPlayfield >= 1) { Quaternion newHeading; CoordHeading coordHeading = WallCollision.GetCoord(teleportPlayfield, coordinates.x, coordinates.z, coordinates); if (teleportPlayfield.Flags != 1337 && client.Character.PlayField != 152 || Math.Abs(client.Character.Coordinates.y - teleportPlayfield.Y) <= 2 || teleportPlayfield.Flags == 1337 && Math.Abs(client.Character.Coordinates.y - teleportPlayfield.Y) <= 6) { client.Teleport(coordHeading.Coordinates, coordHeading.Heading, teleportPlayfield.ZoneToPlayfield); Program.zoneServer.Clients.Remove(client); } return; } if (client.Character.Stats.LastConcretePlayfieldInstance.Value != 0) { Doors correspondingDoor = DoorHandler.DoorinRange( client.Character.PlayField, client.Character.Coordinates, 1.0f); if (correspondingDoor != null) { correspondingDoor = DoorHandler.FindCorrespondingDoor(correspondingDoor, client.Character); client.Character.Stats.LastConcretePlayfieldInstance.Value = 0; AOCoord aoc = correspondingDoor.Coordinates; aoc.x += correspondingDoor.hX * 3; aoc.y += correspondingDoor.hY * 3; aoc.z += correspondingDoor.hZ * 3; client.Teleport(aoc, client.Character.Heading, correspondingDoor.playfield); Program.zoneServer.Clients.Remove(client); return; } } } client.Character.RawCoord = coordinates; client.Character.RawHeading = heading; client.Character.UpdateMoveType(moveType); /* Start NV Heading Testing Code * Yaw: 0 to 360 Degrees (North turning clockwise to a complete revolution) * Roll: Not sure, but is always 0 cause we can't roll in AO * Pitch: 90 to -90 Degrees (90 is nose in the air, 0 is level, -90 is nose to the ground) */ /* Comment this line with a '//' to enable heading testing * client.SendChatText("Raw Headings: X: " + client.Character.heading.x + " Y: " + client.Character.heading.y + " Z:" + client.Character.heading.z); * * client.SendChatText("Yaw: " + Math.Round(180 * client.Character.heading.yaw / Math.PI) + " Degrees"); * client.SendChatText("Roll: " + Math.Round(180 * client.Character.heading.roll / Math.PI) + " Degrees"); * client.SendChatText("Pitch: " + Math.Round(180 * client.Character.heading.pitch / Math.PI) + " Degrees"); * /* End NV Heading testing code */ /* start of packet */ packetWriter.PushByte(0xDF); packetWriter.PushByte(0xDF); /* packet type */ packetWriter.PushShort(10); /* unknown */ packetWriter.PushShort(1); /* packet length (writer takes care of this) */ packetWriter.PushShort(0); /* server ID */ packetWriter.PushInt(3086); /* receiver (Announce takes care of this) */ packetWriter.PushInt(0); /* packet ID */ packetWriter.PushInt(0x54111123); /* affected dynel identity */ packetWriter.PushIdentity(50000, client.Character.Id); /* ? */ packetWriter.PushByte(0); /* movement type */ packetWriter.PushByte(moveType); /* Heading */ packetWriter.PushQuat(heading); /* Coordinates */ packetWriter.PushCoord(coordinates); // see reading part for comment packetWriter.PushInt(tmpInt1); packetWriter.PushInt(tmpInt2); packetWriter.PushInt(tmpInt3); byte[] reply = packetWriter.Finish(); Announce.Playfield(client.Character.PlayField, reply); if (Statels.StatelppfonEnter.ContainsKey(client.Character.PlayField)) { foreach (Statels.Statel s in Statels.StatelppfonEnter[client.Character.PlayField]) { if (s.onEnter(client)) { return; } if (s.onTargetinVicinity(client)) { return; } } } }