/// <summary> /// </summary> /// <param name="self"> /// </param> /// <param name="caller"> /// </param> /// <param name="target"> /// </param> /// <param name="arguments"> /// </param> /// <returns> /// </returns> public override bool Execute( INamedEntity self, IEntity caller, IInstancedEntity target, MessagePackObject[] arguments) { if (arguments.Count() != 3) { return(false); } uint arg1 = arguments[1].AsUInt32(); int toPlayfield = arguments[2].AsInt32(); byte destinationIndex = (byte)(arg1 >> 16); PlayfieldData pfd = PlayfieldLoader.PFData[toPlayfield]; PlayfieldDestination pfDestination = pfd.Destinations[destinationIndex]; float newX = (pfDestination.EndX - pfDestination.StartX) * 0.5f + pfDestination.StartX; float newZ = (pfDestination.EndZ - pfDestination.StartZ) * 0.5f + pfDestination.StartZ; float dist = WallCollision.Distance( pfDestination.StartX, pfDestination.StartZ, pfDestination.EndX, pfDestination.EndZ); float headDistX = (pfDestination.EndX - pfDestination.StartX) / dist; float headDistZ = (pfDestination.EndZ - pfDestination.StartZ) / dist; newX -= headDistZ * 4; newZ += headDistX * 4; Coordinate destCoordinate = new Coordinate(newX, pfDestination.EndY, newZ); ((ICharacter)self).Teleport( destCoordinate, ((ICharacter)self).Heading, new Identity() { Type = IdentityType.Playfield, Instance = toPlayfield }); return(true); }
/// <summary> /// </summary> /// <param name="stream"> /// </param> /// <returns> /// </returns> public static DestinationStruct ReadFromStream(Stream stream) { DestinationStruct destinationStruct = new DestinationStruct(); BinaryReader br = new BinaryReader(stream); destinationStruct.Version = br.ReadInt32(); destinationStruct.Id = br.ReadInt32(); byte c; string temp = string.Empty; int maxcount = 32; while (maxcount > 0) { c = br.ReadByte(); if (c != 0) { temp += (char)c; } if (temp.Length == 32) { break; } maxcount--; } // Do the backward search br.BaseStream.Position = br.BaseStream.Length - 4; int destinationCounter; int realCounter = 0; while (true) { destinationCounter = br.ReadInt32(); if (destinationCounter == realCounter) { break; } realCounter++; br.BaseStream.Position = br.BaseStream.Position - (7 * 4) - 4; // -4 because we already read the 4 bytes to check if it is a counter } while (destinationCounter > 0) { // Read the stuff PlayfieldDestination pfd = new PlayfieldDestination(); // We dont need the Destination playfield id here again // so lets skip it br.ReadInt16(); byte destinationId = br.ReadByte(); // We also dont need the following 0, lets save some space here br.ReadByte(); pfd.StartX = br.ReadSingle(); pfd.StartY = br.ReadSingle(); pfd.StartZ = br.ReadSingle(); pfd.EndX = br.ReadSingle(); pfd.EndY = br.ReadSingle(); pfd.EndZ = br.ReadSingle(); destinationStruct.Destinations.Add(destinationId, pfd); destinationCounter--; } return(destinationStruct); }