public static LookAtPacket Parse(NetworkMessage message) { LookAtPacket packet = new LookAtPacket(); packet.Location = message.GetLocation(); packet.Id = message.GetUInt16(); packet.StackPosition = message.GetByte(); return(packet); }
public override void HandleMessageContents(NetworkMessage message, Connection connection) { var lookAtPacket = new LookAtPacket(message); IThing thing = null; var player = Game.Instance.GetCreatureWithId(connection.PlayerId) as Player; if (player == null) { return; } Console.WriteLine($"LookAt {lookAtPacket.ThingId}."); if (lookAtPacket.Location.Type != LocationType.Ground || player.CanSee(lookAtPacket.Location)) { // Get thing at location switch (lookAtPacket.Location.Type) { case LocationType.Ground: thing = Game.Instance.GetTileAt(lookAtPacket.Location).GetThingAtStackPosition(lookAtPacket.StackPosition); break; case LocationType.Container: // TODO: implement containers. // Container container = player.Inventory.GetContainer(location.Container); // if (container != null) // { // return container.GetItem(location.ContainerPosition); // } break; case LocationType.Slot: thing = player.Inventory[(byte)lookAtPacket.Location.Slot]; break; } if (thing != null) { ResponsePackets.Add(new TextMessagePacket { Type = MessageType.DescriptionGreen, Message = $"You see {thing.InspectionText}." }); } } }
public void LookAtPacket_Initialization() { const ushort ExpectedThingId = 1027; const byte ExpectedStackPosition = 1; Location expectedLocation = new Location() { X = 100, Y = 150, Z = 7, }; ILookAtInfo lookAtInfo = new LookAtPacket(expectedLocation, ExpectedThingId, ExpectedStackPosition); Assert.AreEqual(ExpectedThingId, lookAtInfo.ThingId, $"Expected {nameof(lookAtInfo.ThingId)} to match {ExpectedThingId}."); Assert.AreEqual(ExpectedStackPosition, lookAtInfo.StackPosition, $"Expected {nameof(lookAtInfo.StackPosition)} to match {ExpectedStackPosition}."); Assert.AreEqual(expectedLocation, lookAtInfo.Location, $"Expected {nameof(lookAtInfo.Location)} to match {expectedLocation}."); }
public void ParseLookAt(NetworkMessage message) { LookAtPacket packet = LookAtPacket.Parse(message); Game.PlayerLookAt(Player, packet.Id, packet.Location, packet.StackPosition); }